/* =========================================================
   Manav Jain — CRT
   A dark room, one television, one cartridge.
   ========================================================= */

:root {
  --room:     #0b0b0e;
  --room-2:   #131318;
  --plastic:  #1c1c22;
  --plastic-2:#26262e;
  --ink:      #e9e6dc;
  --ink-2:    #a19d92;
  --ink-3:    #6d6a62;
  --line:     rgba(233, 230, 220, 0.10);
  --gold:     #fcd848;
  --red:      #e4502c;
  --sky:      #6b8cff;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --term:  'VT323', ui-monospace, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(107, 140, 255, 0.10), transparent 70%),
    radial-gradient(ellipse at 50% 120%, #17171d, var(--room) 60%);
  background-color: var(--room);
  color: var(--ink);
  font-family: var(--pixel);
  font-size: 10px;
  line-height: 1.6;
  -webkit-font-smoothing: none;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  overflow: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
::selection { background: var(--gold); color: #111; }

/* ---------- top / bottom bars ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px clamp(16px, 3vw, 32px); }
.bar__brand { text-decoration: none; font-size: 10px; letter-spacing: 0.04em; white-space: nowrap; }
.bar__brand span { color: var(--ink-3); }
.bar__tools { display: flex; gap: 8px; }
.chip {
  font-size: 8px; letter-spacing: 0.06em; padding: 8px 10px;
  border: 2px solid var(--line); color: var(--ink-2);
  transition: color 150ms, border-color 150ms, background 150ms;
}
.chip[aria-pressed="true"] { color: var(--room); background: var(--gold); border-color: var(--gold); }
.chip--hi { color: var(--ink); border-color: rgba(233, 230, 220, 0.35); }
@media (hover: hover) { .chip:hover { color: var(--ink); border-color: var(--ink-2); } }

.bar--bottom { flex-wrap: wrap; justify-content: center; gap: 10px 28px; font-size: 8px; color: var(--ink-3); padding-bottom: 18px; }
.keys { white-space: nowrap; }
kbd {
  font: inherit; color: var(--ink); padding: 3px 5px; margin: 0 4px 0 10px;
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 2px;
}
.keys kbd:first-child { margin-left: 0; }
.hint { color: var(--gold); opacity: 0.75; min-width: 0; }
.hint span { display: inline-block; transition: opacity 400ms; }
.links { display: flex; gap: 16px; }
.links a { color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; padding-bottom: 2px; }
@media (hover: hover) { .links a:hover { color: var(--ink); border-color: var(--red); } }

/* ---------- the television ---------- */
.stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 0 clamp(16px, 3vw, 32px); min-height: 0;
}
.tv {
  --w: min(100%, calc((100svh - 220px) * 16 / 9 + 56px), 1480px);
  width: var(--w);
  padding: clamp(10px, 1.6vw, 22px) clamp(10px, 1.6vw, 22px) 0;
  border-radius: clamp(14px, 2vw, 28px);
  background: linear-gradient(180deg, var(--plastic-2), var(--plastic) 40%, #141418);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -2px 0 rgba(0, 0, 0, 0.5),
    0 30px 80px -20px rgba(0, 0, 0, 0.9),
    0 0 120px -10px rgba(107, 140, 255, 0.18);
}
.tv__screen {
  position: relative; aspect-ratio: 16 / 9; width: 100%;
  border-radius: clamp(8px, 1.4vw, 18px); overflow: hidden; background: #000;
  box-shadow: inset 0 0 0 2px #050507, inset 0 0 30px rgba(0, 0, 0, 0.9);
}
.tv__screen::after { /* glass sheen */
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background:
    radial-gradient(ellipse 60% 40% at 30% 12%, rgba(255, 255, 255, 0.06), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 30%);
  box-shadow: inset 0 0 40px 6px rgba(0, 0, 0, 0.55);
}
.tv__gl { display: block; width: 100%; height: 100%; }
.tv__gl.is-fallback { image-rendering: pixelated; image-rendering: crisp-edges; }
.tv__screen.is-fallback::before { /* poor man's scanlines when WebGL is unavailable */
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: repeating-linear-gradient(180deg, transparent 0 2px, rgba(0, 0, 0, 0.28) 2px 3px);
}
.tv__plate {
  display: flex; align-items: center; gap: 10px; height: clamp(24px, 3vw, 34px);
  padding: 0 4px; font-size: 7px; letter-spacing: 0.12em; color: var(--ink-3);
}
.tv__led { width: 6px; height: 6px; background: var(--red); box-shadow: 0 0 8px var(--red); }
.tv.is-off .tv__led { background: #3a1a12; box-shadow: none; }
.tv__grille {
  margin-left: auto; width: 90px; height: 8px;
  background: repeating-linear-gradient(90deg, #0d0d10 0 3px, transparent 3px 6px);
}

/* ---------- touch controller ---------- */
.pad { display: none; }
@media (pointer: coarse), (max-width: 820px) {
  body { overflow: auto; }
  .stage { justify-content: flex-start; padding-top: 4px; }
  .tv { --w: 100%; }
  .keys { display: none; }
  .pad {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
    width: 100%; max-width: 520px; padding: 10px 6px 4px;
    touch-action: none; user-select: none; -webkit-user-select: none;
  }
}
.pad__dpad { position: relative; width: 132px; height: 132px; }
.pad__btn {
  position: absolute; width: 44px; height: 44px; background: #222228;
  box-shadow: inset 0 -4px 0 #0e0e12, inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.pad__btn::after { content: ""; position: absolute; inset: 0; margin: auto; width: 0; height: 0; border: 6px solid transparent; }
.pad__up    { left: 44px; top: 0; }
.pad__down  { left: 44px; bottom: 0; }
.pad__left  { left: 0; top: 44px; }
.pad__right { right: 0; top: 44px; }
.pad__up::after    { border-bottom-color: var(--ink-3); margin-top: 10px; }
.pad__down::after  { border-top-color: var(--ink-3); margin-bottom: 10px; }
.pad__left::after  { border-right-color: var(--ink-3); margin-left: 10px; }
.pad__right::after { border-left-color: var(--ink-3); margin-right: 10px; }
.pad__hub { position: absolute; left: 44px; top: 44px; width: 44px; height: 44px; background: #222228; }
.pad__mid { display: flex; justify-content: center; gap: 10px; }
.pad__pill {
  font-size: 7px; letter-spacing: 0.08em; color: var(--ink-3); padding: 14px 8px 6px; position: relative;
}
.pad__pill::before { content: ""; position: absolute; left: 50%; top: 0; width: 34px; height: 9px; margin-left: -17px; border-radius: 9px; background: #2a2a31; box-shadow: inset 0 -2px 0 #111; }
.pad__ab { display: flex; gap: 14px; transform: rotate(-18deg); }
.pad__round {
  width: 56px; height: 56px; border-radius: 50%; background: var(--red); color: rgba(0, 0, 0, 0.55);
  font-size: 12px; box-shadow: inset 0 -5px 0 #8f2a14, 0 4px 14px rgba(228, 80, 44, 0.25);
}
.pad__btn.is-down, .pad__round.is-down, .pad__pill.is-down { transform: translateY(2px); filter: brightness(1.3); }


/* ---------- text mode ---------- */
.text {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.text-mode .text {
  position: fixed; inset: 0; z-index: 20; width: auto; height: auto; clip: auto; clip-path: none; white-space: normal;
  overflow-y: auto; background: #f1ede2; color: #1b1a17;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 17px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.text-mode .stage, .text-mode .bar--bottom { visibility: hidden; }
.text-mode .bar--top { position: relative; z-index: 25; background: #f1ede2; color: #1b1a17; }
.text-mode .bar--top .bar__brand span, .text-mode .chip { color: #57534a; border-color: rgba(27, 26, 23, 0.2); }
.text-mode .chip[aria-pressed="true"] { color: #f1ede2; background: #1b1a17; border-color: #1b1a17; }
.text__inner { max-width: 68ch; margin: 0 auto; padding: 96px 20px 120px; }
.text__kicker { font-family: var(--pixel); font-size: 9px; color: #b4401f; letter-spacing: 0.06em; }
.text h1 { font-family: var(--pixel); font-size: clamp(22px, 5vw, 40px); line-height: 1.2; margin: 18px 0 20px; font-weight: 400; }
.text h2 { font-family: var(--pixel); font-weight: 400; font-size: 12px; line-height: 1.6; margin: 48px 0 14px; padding-top: 14px; border-top: 2px solid #1b1a17; }
.text h2 small { display: block; margin-top: 6px; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; color: #6b675e; }
.text__lede { font-size: 20px; line-height: 1.45; }
.text__actions { margin-top: 18px; }
.text a { color: #b4401f; text-underline-offset: 3px; }
.text ul { padding-left: 1.1em; }
.text li { margin: 6px 0; }
.text li::marker { content: "▪  "; color: #b4401f; }
.text__inv { display: grid; grid-template-columns: 9rem 1fr; gap: 8px 16px; }
.text__inv dt { font-family: var(--pixel); font-size: 9px; padding-top: 5px; }
.text__back { margin-top: 56px; }
@media (max-width: 560px) { .text__inv { grid-template-columns: 1fr; gap: 2px; } .text__inv dd { margin-bottom: 10px; } }

@media (max-width: 560px) {
  .bar__brand span { display: none; }
  .bar { padding: 12px 14px; }
}

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

/* ---------- narrow phones ---------- */
@media (max-width: 480px) {
  .bar__tools { gap: 6px; }
  .chip { padding: 7px 7px; font-size: 7px; }
  .chip[data-act="raw"] { display: none; }
  .pad { gap: 6px; padding-inline: 0; }
  .pad__dpad { width: 114px; height: 114px; }
  .pad__btn, .pad__hub { width: 38px; height: 38px; }
  .pad__up, .pad__down { left: 38px; }
  .pad__left, .pad__right, .pad__hub { top: 38px; }
  .pad__hub { left: 38px; }
  .pad__mid { flex-direction: column; align-items: center; gap: 4px; }
  .pad__ab { gap: 8px; }
  .pad__round { width: 50px; height: 50px; }
  .hint { text-align: center; }
}
