:root {
  color-scheme: dark;
  --bg: #030404;
  --panel: rgba(4, 8, 8, 0.72);
  --panel-strong: rgba(1, 3, 3, 0.88);
  --line: rgba(174, 232, 212, 0.22);
  --line-hot: rgba(104, 255, 176, 0.62);
  --text: #e7f4ee;
  --muted: #78928a;
  --green: #64ffad;
  --cyan: #86dcff;
  --red: #ff4d52;
  --amber: #ffc15a;
  --shadow: rgba(104, 255, 176, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(112deg, rgba(100, 255, 173, 0.05), transparent 28%),
    radial-gradient(circle at 66% 48%, rgba(100, 255, 173, 0.12), transparent 18rem),
    radial-gradient(circle at 23% 78%, rgba(255, 77, 82, 0.08), transparent 20rem),
    linear-gradient(135deg, #010202 0%, #07100e 54%, #050303 100%);
  color: var(--text);
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

body::before {
  content: "";
  position: fixed;
  inset: -22vh -14vw;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(101deg, transparent 0 31%, rgba(104, 255, 176, 0.06) 31.2% 31.6%, transparent 31.9%),
    linear-gradient(101deg, transparent 0 49%, rgba(117, 215, 255, 0.035) 49.2% 49.55%, transparent 49.8%),
    linear-gradient(101deg, transparent 0 67%, rgba(255, 77, 82, 0.045) 67.1% 67.4%, transparent 67.8%);
  transform: rotate(-7deg);
}

button,
a,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

#machine-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.noise,
.scanline {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.noise {
  opacity: 0.1;
  background-image:
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.055) 1px, transparent 1px);
  background-size: 5px 5px;
  mix-blend-mode: screen;
}

.scanline {
  background: linear-gradient(
    to bottom,
    transparent,
    transparent 48%,
    rgba(104, 255, 176, 0.055) 50%,
    transparent 52%,
    transparent
  );
  background-size: 100% 6px;
}

.shell {
  position: relative;
  z-index: 2;
  width: min(1360px, calc(100% - 36px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 42px;
  margin-bottom: 14px;
}

.brand-block,
.top-actions,
.hero-actions,
.panel-label,
.command-line {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 10px;
  min-width: 0;
}

.unit-id,
.status-text,
.eyebrow,
.readout > span,
.panel-label,
.transmission-label,
.contract-line,
.stage-code,
.death-order,
.machine-proof span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 16px var(--green);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.top-actions {
  gap: 8px;
}

.icon-button,
.primary-action,
.secondary-action,
.command-line button {
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: rgba(2, 5, 5, 0.72);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
}

.icon-button {
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
}

.sound-off {
  display: none;
}

body.audio-active .sound-on {
  display: none;
}

body.audio-active .sound-off {
  display: inline;
  color: var(--green);
}

.machine-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(330px, 0.78fr) minmax(420px, 1.04fr) minmax(210px, 0.44fr);
  gap: 18px;
  align-items: center;
  min-height: calc(100vh - 120px);
  padding: clamp(28px, 4vw, 54px);
  border: 1px solid rgba(174, 232, 212, 0.16);
  background:
    linear-gradient(116deg, rgba(104, 255, 176, 0.07), transparent 27%),
    linear-gradient(286deg, rgba(117, 215, 255, 0.06), transparent 32%),
    rgba(2, 5, 5, 0.34);
  clip-path: polygon(0 4.5%, 4.5% 0, 100% 0, 100% 88%, 94% 100%, 0 100%);
  transform: perspective(1200px) rotateX(1.15deg) rotateZ(-0.72deg);
  transform-origin: 50% 45%;
  box-shadow: 0 34px 110px rgba(0, 0, 0, 0.34);
}

.machine-stage::before,
.machine-stage::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.machine-stage::before {
  inset: 18px;
  border: 1px solid rgba(104, 255, 176, 0.12);
  clip-path: polygon(0 6%, 6% 0, 100% 0, 100% 85%, 92% 100%, 0 100%);
}

.machine-stage::after {
  top: 0;
  bottom: 0;
  left: 52%;
  width: 1px;
  background: linear-gradient(transparent, rgba(104, 255, 176, 0.38), transparent);
  transform: rotate(12deg);
}

.stage-code {
  position: absolute;
  right: 22px;
  top: 20px;
  display: flex;
  gap: 18px;
  max-width: calc(100% - 44px);
  color: rgba(120, 146, 138, 0.74);
  overflow: hidden;
  white-space: nowrap;
}

.death-order {
  position: absolute;
  left: min(45vw, 615px);
  top: clamp(88px, 9vw, 118px);
  z-index: 3;
  display: grid;
  gap: 5px;
  width: 210px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 77, 82, 0.32);
  color: rgba(255, 77, 82, 0.86);
  background:
    linear-gradient(90deg, rgba(255, 77, 82, 0.12), transparent),
    rgba(0, 0, 0, 0.26);
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
  transform: rotateZ(-0.8deg);
}

.death-order strong {
  color: var(--text);
  font-size: 0.9rem;
}

.death-order em {
  color: rgba(189, 209, 201, 0.7);
  font-style: normal;
  text-transform: none;
}

.hero-copy {
  position: relative;
  z-index: 2;
  max-width: 640px;
  transform: translateY(12px);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--red);
}

h1 {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(3.2rem, 7.2vw, 7.8rem);
  line-height: 0.82;
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: 0 0 34px rgba(104, 255, 176, 0.15);
}

h1 span {
  display: block;
}

h1 span:nth-child(2) {
  margin-left: clamp(18px, 4vw, 54px);
  color: rgba(231, 244, 238, 0.78);
}

h1 span:nth-child(3) {
  color: var(--green);
}

.machine-proof {
  max-width: 560px;
  margin: 20px 0 0;
  display: grid;
  gap: 7px;
}

.machine-proof div {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 12px;
  min-height: 34px;
  align-items: center;
  padding: 7px 10px;
  border-left: 1px solid rgba(104, 255, 176, 0.38);
  background: linear-gradient(90deg, rgba(104, 255, 176, 0.075), transparent 82%);
}

.machine-proof strong {
  color: #bdd1c9;
  font-size: clamp(0.92rem, 1.12vw, 1.04rem);
  line-height: 1.38;
  font-weight: 500;
  text-transform: none;
}

.hero-actions {
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.primary-action,
.secondary-action {
  min-height: 48px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.primary-action {
  border-color: rgba(104, 255, 176, 0.7);
  background: rgba(104, 255, 176, 0.12);
  color: var(--green);
  box-shadow: 0 0 24px rgba(104, 255, 176, 0.1);
}

.secondary-action {
  color: var(--muted);
}

.icon-button:hover,
.primary-action:hover,
.secondary-action:hover,
.command-line button:hover {
  border-color: rgba(104, 255, 176, 0.86);
  color: var(--green);
  transform: translateY(-1px);
}

.readout,
.core-panel,
.terminal-panel,
.transmission {
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 12px);
}

.core-panel {
  position: relative;
  z-index: 1;
  min-height: min(64vh, 610px);
  overflow: hidden;
  background:
    linear-gradient(105deg, rgba(104, 255, 176, 0.06), transparent 38%),
    linear-gradient(180deg, rgba(4, 8, 8, 0.86), rgba(1, 3, 3, 0.96));
  transform: translateY(-4px) rotateZ(0.55deg);
}

.core-panel::before {
  content: "";
  position: absolute;
  inset: 46px 18px 18px;
  z-index: -1;
  background:
    linear-gradient(rgba(104, 255, 176, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 255, 176, 0.04) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}

.panel-label {
  justify-content: space-between;
  min-height: 46px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.core-visual {
  position: relative;
  height: min(52vh, 500px);
  min-height: 390px;
  overflow: hidden;
  background:
    linear-gradient(rgba(104, 255, 176, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(104, 255, 176, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 68% 48%, rgba(255, 77, 82, 0.06), transparent 16rem),
    linear-gradient(180deg, rgba(1, 4, 4, 0.58), rgba(0, 0, 0, 0.18));
  background-size: 22px 22px, 22px 22px, auto, auto;
}

#core-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.core-read {
  position: absolute;
  min-width: 112px;
  padding: 7px 9px;
  border: 1px solid rgba(104, 255, 176, 0.22);
  color: rgba(205, 238, 226, 0.72);
  background: rgba(0, 0, 0, 0.54);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
}

.core-read-a {
  left: 18px;
  top: 18px;
}

.core-read-b {
  right: 18px;
  top: 18px;
  text-align: right;
}

.core-read-c {
  right: 18px;
  bottom: 18px;
  color: rgba(255, 77, 82, 0.78);
  text-align: right;
}

.event-strip {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  gap: 4px;
  height: 90px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background:
    linear-gradient(rgba(104, 255, 176, 0.04) 1px, transparent 1px),
    rgba(0, 0, 0, 0.38);
  background-size: 100% 18px;
  overflow: hidden;
}

.event-cell {
  align-self: end;
  min-height: 10px;
  border: 1px solid rgba(104, 255, 176, 0.2);
  background: rgba(104, 255, 176, 0.16);
  box-shadow: 0 0 12px rgba(104, 255, 176, 0.1);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
}

.event-cell.sell {
  border-color: rgba(255, 77, 82, 0.32);
  background: rgba(255, 77, 82, 0.2);
  box-shadow: 0 0 12px rgba(255, 77, 82, 0.12);
}

.event-cell.idle {
  opacity: 0.24;
}

.vitals {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateY(34px) rotateZ(0.42deg);
}

.readout {
  min-height: 92px;
  padding: 13px 14px;
}

.readout:nth-child(even) {
  transform: translateX(-18px);
}

.readout strong {
  display: block;
  margin-top: 10px;
  color: var(--green);
  font-size: clamp(1.26rem, 2.5vw, 2.04rem);
  line-height: 1;
  font-weight: 700;
}

.readout-alert strong {
  color: var(--red);
}

.console-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 0.45fr);
  gap: 14px;
  margin-top: 14px;
  transform: perspective(1200px) rotateZ(0.38deg);
  transform-origin: 50% 0;
}

.terminal-panel {
  min-height: 330px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.log-feed {
  flex: 1;
  margin: 0;
  padding: 16px;
  list-style: none;
  overflow: hidden;
}

.log-feed li {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 12px;
  min-height: 24px;
  color: #c8ddd5;
  font-size: 0.88rem;
  line-height: 1.45;
}

.log-feed time {
  color: var(--muted);
}

.log-feed b {
  color: var(--green);
  font-weight: 600;
}

.log-feed .error b {
  color: var(--red);
}

.log-feed .warn b {
  color: var(--amber);
}

.command-line {
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}

.command-line label {
  color: var(--green);
  white-space: nowrap;
}

.command-line input {
  min-width: 0;
  flex: 1;
  height: 38px;
  border: 1px solid rgba(180, 226, 210, 0.12);
  border-radius: 0;
  padding: 0 10px;
  color: var(--text);
  outline: none;
  background: rgba(255, 255, 255, 0.03);
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
}

.command-line input:focus {
  border-color: rgba(104, 255, 176, 0.62);
}

.command-line button {
  height: 38px;
  padding: 0 14px;
}

.transmission {
  min-height: 330px;
  padding: clamp(18px, 2.4vw, 26px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}

.transmission-label,
.contract-line {
  margin: 0;
}

.response-line {
  margin: 12px 0 18px;
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(2.4rem, 5vw, 6.4rem);
  line-height: 0.86;
  font-weight: 800;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.contract-line {
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 5;
  max-width: min(480px, calc(100% - 32px));
  min-height: 42px;
  padding: 12px 14px;
  border: 1px solid rgba(104, 255, 176, 0.34);
  border-radius: 0;
  color: var(--green);
  background: rgba(5, 8, 8, 0.94);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translate(-50%, 18px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.shutdown .status-dot {
  background: var(--red);
  box-shadow: 0 0 20px var(--red), 0 0 80px rgba(255, 77, 82, 0.16);
}

body.shutdown .readout-alert strong,
body.shutdown #core-state,
body.shutdown #log-state {
  color: var(--red);
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.84);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

@media (max-width: 1080px) {
  .machine-stage {
    grid-template-columns: minmax(0, 1fr) minmax(330px, 0.86fr);
    min-height: auto;
  }

  .core-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .vitals {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    transform: none;
  }

  .readout:nth-child(even) {
    transform: none;
  }

  .readout {
    min-height: 84px;
  }

  .console-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 24px, 720px);
    padding-top: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .machine-stage,
  .console-grid {
    transform: none;
  }

  .machine-stage {
    grid-template-columns: 1fr;
    padding: 22px;
  }

  .stage-code {
    position: static;
    grid-row: 1;
    flex-wrap: wrap;
    white-space: normal;
  }

  .death-order {
    position: static;
    grid-row: 2;
    width: 100%;
    transform: none;
  }

  .hero-copy,
  .core-panel,
  .vitals {
    grid-column: auto;
    grid-row: auto;
  }

  .hero-copy {
    transform: none;
  }

  .core-panel {
    min-height: 480px;
    transform: none;
  }

  .core-visual {
    height: 390px;
  }

  .vitals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .top-actions,
  .vitals {
    width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr);
  }

  .hero-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .icon-button,
  .primary-action,
  .secondary-action {
    min-width: 0;
    width: 100%;
    padding-left: 10px;
    padding-right: 10px;
  }

  .machine-proof div {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .vitals {
    grid-template-columns: 1fr;
  }

  .readout {
    min-height: 76px;
  }

  .core-panel,
  .terminal-panel,
  .transmission {
    min-height: 360px;
  }

  .log-feed li {
    grid-template-columns: 72px 1fr;
    font-size: 0.78rem;
  }

  .command-line {
    flex-wrap: wrap;
  }

  .command-line label {
    width: 100%;
  }
}

@media (max-height: 760px) and (min-width: 1081px) {
  .machine-stage {
    min-height: 580px;
    padding: 28px 38px;
  }

  h1 {
    font-size: clamp(3rem, 6vw, 6.2rem);
  }

  .thesis {
    font-size: 0.98rem;
    line-height: 1.5;
  }

  .core-panel {
    min-height: 500px;
  }

  .core-visual {
    height: 340px;
    min-height: 300px;
  }

  .readout {
    min-height: 78px;
  }

  .readout strong {
    margin-top: 8px;
    font-size: clamp(1.14rem, 2vw, 1.66rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
