:root {
  --phosphor: #f4c15d;
  --phosphor-bright: #ffe49b;
  --phosphor-dim: rgba(244, 193, 93, 0.62);
  --screen-shadow: rgba(0, 0, 0, 0.72);
  --danger: #ff6848;
  --good: #8fffc0;
  --panel: rgba(8, 7, 5, 0.78);
  --room-aspect: 1.24755;
  --tight-aspect: 1.18766;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  margin: 0;
  background: #050403;
  color: var(--phosphor);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  overflow: hidden;
  width: 100vw;
  height: 100dvh;
}

button {
  font: inherit;
  color: var(--phosphor-bright);
  background: rgba(42, 26, 5, 0.76);
  border: 1px solid rgba(244, 193, 93, 0.5);
  box-shadow: inset 0 0 12px rgba(244, 193, 93, 0.11), 0 0 18px rgba(244, 193, 93, 0.08);
  padding: 0.72rem 0.85rem;
  cursor: pointer;
  text-align: left;
}

button:hover, button:focus-visible {
  outline: 1px solid var(--phosphor-bright);
  background: rgba(72, 45, 11, 0.88);
}

.terminal-room {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.scene {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100vw, calc(100dvh * var(--room-aspect)));
  height: max(100dvh, calc(100vw / var(--room-aspect)));
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: #050403;
}

.terminal-room.focused .scene {
  width: min(100vw, calc(100dvh * var(--tight-aspect)));
  height: min(100dvh, calc(100vw / var(--tight-aspect)));
}

.room-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  filter: contrast(1.04) saturate(0.95);
  opacity: 1;
  transition: opacity 900ms cubic-bezier(.2,.7,.15,1);
}

.tight-bg { opacity: 0; }
.terminal-room.focused .wide-bg { opacity: 0; }
.terminal-room.focused .tight-bg { opacity: 1; }

.screen-hotspot {
  position: absolute;
  left: 29.2%;
  top: 20.7%;
  width: 36.7%;
  height: 39.6%;
  overflow: hidden;
  border-radius: 5.2% / 8%;
  transform: perspective(900px) rotateX(0.4deg) rotateY(-0.8deg);
  background: radial-gradient(circle at 50% 48%, rgba(49, 72, 50, 0.18), rgba(0,0,0,0.22) 55%, rgba(0,0,0,0.72));
  box-shadow: inset 0 0 38px rgba(0,0,0,0.86), inset 0 0 7px rgba(244,193,93,0.14), 0 0 24px rgba(244,193,93,0.02);
  transition:
    left 900ms cubic-bezier(.2,.7,.15,1),
    top 900ms cubic-bezier(.2,.7,.15,1),
    width 900ms cubic-bezier(.2,.7,.15,1),
    height 900ms cubic-bezier(.2,.7,.15,1),
    border-radius 900ms cubic-bezier(.2,.7,.15,1);
}

.terminal-room.focused .screen-hotspot {
  left: 7.15%;
  top: 11.2%;
  width: 80.9%;
  height: 71.8%;
  border-radius: 3.8% / 5.2%;
}

.terminal-room.focused .terminal-text {
  inset: 5.9% 6.8% 5.4% 6.8%;
  font-size: clamp(10px, 1.36vw, 23px);
  line-height: 1.12;
}

.terminal-room.focused .game-stage {
  inset: 6.5% 6.5% 5.6% 6.5%;
}

.terminal-room.focused .ttt-board {
  width: min(46%, 420px);
}

.screen-hotspot::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(255, 226, 142, 0.055) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 50%, transparent 54%, rgba(0,0,0,0.44) 100%);
  mix-blend-mode: screen;
  z-index: 6;
}

.screen-hotspot::after {
  content: "";
  position: absolute;
  inset: -16%;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 0 38%, rgba(255,255,255,0.055) 44%, transparent 52% 100%);
  z-index: 7;
}

.crt-glass {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(circle at center, rgba(121, 91, 27, 0.06), transparent 58%);
  animation: idleFlicker 3.6s infinite steps(9);
}

.terminal-text {
  position: absolute;
  inset: 6.8% 7.4% 5.8% 7.4%;
  z-index: 2;
  white-space: pre-wrap;
  overflow: hidden;
  color: var(--phosphor);
  text-shadow: 0 0 5px rgba(244, 193, 93, 0.72), 0 0 16px rgba(244, 193, 93, 0.28);
  font-size: clamp(8px, 0.93vw, 17px);
  line-height: 1.18;
  letter-spacing: 0.035em;
}

.terminal-line { min-height: 1.2em; }
.cursor::after {
  content: "█";
  animation: blink 0.82s steps(1) infinite;
  color: var(--phosphor-bright);
}

.menu-grid {
  display: grid;
  gap: 0.22rem;
  margin-top: 0.42rem;
}

.menu-item {
  display: grid;
  grid-template-columns: 2.2ch 1fr auto;
  gap: 0.55rem;
  color: var(--phosphor-bright);
}
.menu-item span:last-child { color: var(--phosphor-dim); }

.game-stage {
  position: absolute;
  inset: 5.2% 4.8% 3.4% 4.8%;
  z-index: 3;
  background: rgba(0,0,0,0.9);
  border: 1px solid rgba(244,193,93,0.44);
  box-shadow: inset 0 0 22px rgba(244,193,93,0.08);
  overflow: hidden;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(244,193,93,0.34);
  color: var(--phosphor-bright);
  background: rgba(62, 41, 10, 0.28);
  font-size: 0.78em;
}

.frame-module {
  width: 100%;
  height: calc(100% - 1.7rem);
  border: 0;
  display: block;
  background: black;
}

.frame-module--fullscreen {
  height: 100%;
}

.board-wrap {
  height: calc(100% - 1.7rem);
  display: grid;
  place-items: center;
  padding: 0.35rem;
}

.checker-board, .chess-board {
  display: grid;
  width: min(92%, 42vh);
  aspect-ratio: 1;
  border: 1px solid rgba(244,193,93,0.62);
  box-shadow: 0 0 22px rgba(244,193,93,0.12);
}

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(58%, 310px);
  max-height: calc(100% - 1rem);
  aspect-ratio: 1;
  border: 1px solid rgba(244,193,93,0.62);
  box-shadow: 0 0 22px rgba(244,193,93,0.12);
}
.ttt-cell {
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid rgba(244,193,93,0.38);
  color: var(--phosphor-bright);
  font-size: clamp(18px, 2.7vw, 34px);
  text-align: center;
  padding: 0;
}

.checker-board, .chess-board { grid-template-columns: repeat(8, 1fr); }
.square { position: relative; display: grid; place-items: center; color: #1d1303; }
.square.dark { background: rgba(244,193,93,0.62); }
.square.light { background: rgba(244,193,93,0.16); }
.piece {
  width: 66%; height: 66%; border-radius: 50%;
  border: 1px solid rgba(255,235,177,0.75);
  background: radial-gradient(circle at 35% 30%, #fff4bb, #b25d32 68%, #3f1708);
  box-shadow: 0 0 12px rgba(244,193,93,0.22);
}
.piece.blue { background: radial-gradient(circle at 35% 30%, #e2ffff, #4fa8b3 68%, #082732); }

.placeholder-copy {
  position: absolute;
  left: 0.75rem; right: 0.75rem; bottom: 0.65rem;
  background: rgba(0,0,0,0.62);
  padding: 0.45rem;
  border: 1px solid rgba(244,193,93,0.28);
  font-size: 0.78em;
}

.war-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.45s ease;
}
.war-mode .war-canvas { opacity: 1; }
.war-mode .terminal-text {
  z-index: 4;
  inset: 7.2% auto auto 7.1%;
  width: min(61%, 760px);
  max-height: 33%;
  padding: 0.25rem 0.45rem;
  background: linear-gradient(90deg, rgba(0,0,0,0.72), rgba(0,0,0,0.34) 76%, transparent);
  border-left: 1px solid rgba(244,193,93,0.24);
  font-size: clamp(9px, 1.12vw, 20px);
  line-height: 1.1;
}
.war-mode.war-intro-hidden .terminal-text {
  opacity: 0;
  pointer-events: none;
}
.terminal-room.war-active .control-panel {
  width: min(270px, calc(100vw - 2rem));
  transform: scale(0.86);
  transform-origin: bottom right;
  opacity: 0.9;
}

.control-panel {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: min(320px, calc(100vw - 2rem));
  display: grid;
  gap: 0.5rem;
  padding: 0.85rem;
  background: var(--panel);
  border: 1px solid rgba(244,193,93,0.26);
  box-shadow: 0 12px 44px rgba(0,0,0,0.48);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.status-row { display: flex; gap: 0.5rem; align-items: center; color: var(--good); font-size: 0.85rem; }
.led { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--good); box-shadow: 0 0 14px var(--good); }
.hint { margin: 0.2rem 0 0; font-size: 0.74rem; color: rgba(255,226,155,0.72); line-height: 1.35; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes idleFlicker { 0%,100% { opacity: 0.96; } 55% { opacity: 0.84; } 60% { opacity: 1; } }

@media (max-width: 900px) {
  .control-panel { left: 0.75rem; right: 0.75rem; bottom: 0.75rem; width: auto; grid-template-columns: 1fr 1fr; }
  .status-row, .hint { grid-column: 1 / -1; }
  .terminal-text { font-size: clamp(8px, 2.25vw, 14px); }
  .war-mode .terminal-text { width: min(78%, 620px); max-height: 28%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
