:root {
  --bg: #07060f;
  --panel: #13112a;
  --panel-2: #1c1940;
  --ink: #e9e6ff;
  --dim: #9a94c9;
  --accent: #ff4fd8;
  --accent-2: #4ff3ff;
  --good: #7dff7a;
  --bad: #ff5a5a;
  --pixel: "Press Start 2P", ui-monospace, Menlo, Consolas, monospace;
  --term: "VT323", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #1b1046 0%, var(--bg) 60%) fixed;
  color: var(--ink);
  font-family: var(--term);
  font-size: 22px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- marquee ---------- */
.marquee { text-align: center; padding: 28px 16px 8px; }
.marquee h1 {
  font-family: var(--pixel);
  font-size: clamp(22px, 5vw, 46px);
  margin: 0;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(255, 79, 216, .7), 0 0 30px rgba(255, 79, 216, .35);
}
.marquee h1 span { color: var(--accent-2); margin-left: .5em; text-shadow: 0 0 12px rgba(79, 243, 255, .7); }
.marquee p { margin: 10px 0 0; color: var(--dim); }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px; }
footer { text-align: center; color: var(--dim); padding: 16px; font-size: 18px; }

/* ---------- menu grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}
.card {
  color: inherit;
  text-decoration: none;
  position: relative;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 2px solid var(--c, var(--accent));
  border-radius: 14px;
  padding: 18px 16px 16px;
  text-align: left;
  box-shadow: 0 0 0 0 transparent;
  transition: transform .12s ease, box-shadow .12s ease;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card:hover, .card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 0 22px -4px var(--c, var(--accent));
  outline: none;
}
.card h3 { font-family: var(--pixel); font-size: 15px; margin: 0; color: var(--c); }
.card p { margin: 0; color: var(--dim); line-height: 1.05; }
.card .flip { margin-top: auto; color: var(--ink); font-size: 19px; }
.card .num { position: absolute; top: 12px; right: 14px; font-family: var(--pixel); font-size: 10px; color: var(--dim); }

/* ---------- setup ---------- */
.link { background: none; border: 0; color: var(--accent-2); padding: 0; }
.link:hover { text-decoration: underline; }
#setup h2 { font-family: var(--pixel); font-size: 24px; margin: 18px 0 6px; color: var(--c, var(--accent)); }
.tagline { color: var(--dim); margin: 0 0 18px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.modes.single { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.play-big { font-size: 20px; padding: 14px 44px; }
.single-best { margin: 0; color: var(--dim); }
.guide-play { display: flex; justify-content: center; margin-top: 18px; }
.mode {
  background: var(--panel);
  border: 2px solid #2d2963;
  border-radius: 12px;
  padding: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mode:hover, .mode:focus-visible { border-color: var(--c, var(--accent)); outline: none; }
.mode .who { font-family: var(--pixel); font-size: 12px; line-height: 1.7; }
.mode .who b { color: var(--good); font-weight: normal; }
.mode .who i { color: var(--accent-2); font-style: normal; }
.mode .how { color: var(--dim); line-height: 1.05; }
.mode .best { color: var(--ink); font-size: 18px; margin-top: auto; }

/* ---------- play ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.bar .spacer { flex: 1; }
#play-title { font-family: var(--pixel); font-size: 12px; color: var(--c, var(--accent)); }
.chip {
  background: var(--panel);
  border: 1px solid #3a3580;
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 19px;
}
.chip:hover { border-color: var(--accent-2); }

#stage {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  aspect-ratio: 4 / 3;
  border: 3px solid var(--c, var(--accent));
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 40px -10px var(--c, var(--accent));
}
#screen { width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }
#dom-stage { position: absolute; inset: 0; }
.help { max-width: 800px; margin: 10px auto 0; color: var(--dim); line-height: 1.1; text-align: center; }

#overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 12px;
  background: rgba(5, 3, 15, .82);
  text-align: center;
  padding: 16px;
  overflow-y: auto; /* a tall dialog on a small screen scrolls instead of being cut off */
}
#overlay > :first-child { margin-top: auto; }  /* centred when it fits */
#overlay > :last-child { margin-bottom: auto; }
#overlay h2 { font-family: var(--pixel); font-size: clamp(16px, 3.4vw, 26px); margin: 0; color: var(--accent); }
#overlay p { margin: 0; }
#overlay .row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 10px; }
.btn {
  background: var(--accent);
  color: #12001a;
  border: 0;
  border-radius: 8px;
  padding: 8px 18px;
  font-family: var(--pixel);
  font-size: 12px;
}
.btn.alt { background: var(--panel-2); color: var(--ink); border: 1px solid #3a3580; }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- Imitation (DOM game) ---------- */
.imit [hidden] { display: none !important; }
.imit-chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.imit-small { font-size: 18px; }
.imit-reveal-box { background: var(--panel); border: 1px solid #3a3580; border-radius: 10px; padding: 12px 18px; display: flex; flex-direction: column; gap: 6px; }
.imit-reveal-box .good { color: var(--good); }
.imit-reveal-box .bad { color: var(--bad); }
.imit { position: absolute; inset: 0; display: flex; flex-direction: column; background: #050414; font-size: 21px; }
.imit-pane { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 18px; text-align: center; }
.imit-pane h2 { font-family: var(--pixel); font-size: 18px; color: var(--accent-2); margin: 0; }
.imit-pane p { margin: 0; max-width: 560px; color: var(--dim); line-height: 1.1; }
.imit-stats { color: var(--ink) !important; }
.spinner { width: 54px; height: 54px; border: 5px solid #2a2660; border-top-color: var(--accent-2); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.imit-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #241f55; background: #0d0b24; }
.imit-head .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }
.imit-head .timer { margin-left: auto; font-family: var(--pixel); font-size: 12px; }
.imit-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 75%; padding: 5px 11px; border-radius: 12px; line-height: 1.05; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: #3b1d6e; }
.msg.them { align-self: flex-start; background: #1d2a52; }
.msg.sys { align-self: center; background: none; color: var(--dim); font-size: 18px; }
.imit-typing { height: 22px; padding: 0 14px; color: var(--dim); font-size: 18px; }
.imit-form { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid #241f55; }
.imit-form input { flex: 1; min-width: 0; background: #0d0b24; border: 1px solid #3a3580; border-radius: 8px; color: var(--ink); font: inherit; padding: 4px 10px; }
.imit-form input:focus { outline: 2px solid var(--accent-2); }
.verdict-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.big-choice { font-family: var(--pixel); font-size: 14px; padding: 16px 22px; border-radius: 10px; border: 2px solid; background: var(--panel); }
.big-choice.human { border-color: var(--good); color: var(--good); }
.big-choice.ai { border-color: var(--accent); color: var(--accent); }

@media (max-width: 600px) {
  body { font-size: 19px; }
  .imit { font-size: 18px; }
  .msg { max-width: 88%; }
}

/* ---------- touch buttons (shown on touch devices only) ---------- */
#touchpad {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  max-width: 800px;
  margin: 12px auto 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#touchpad[hidden] { display: none; }
.pad-group { display: flex; gap: 10px; flex-wrap: wrap; }
.pad {
  min-width: 64px;
  height: 64px;
  padding: 0 14px;
  border-radius: 16px;
  border: 2px solid var(--c, var(--accent));
  background: rgba(19, 17, 42, .85);
  color: var(--ink);
  font-family: var(--pixel);
  font-size: 15px;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.pad.wide { min-width: 108px; }
.pad.on { background: var(--c, var(--accent)); color: #12001a; }

/* ---------- fullscreen (the browser's, or a fill-the-window fallback for iPhone) ---------- */
#arena { position: relative; }
#fs-bar { display: none; }
#arena:fullscreen, #arena.fake-fs {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
#arena:-webkit-full-screen { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; }
#arena:fullscreen #stage, #arena.fake-fs #stage, #arena:-webkit-full-screen #stage {
  width: min(100vw, calc(100vh * 4 / 3));
  width: min(100vw, calc(100dvh * 4 / 3));
  max-width: none;
  border: 0;
  border-radius: 0;
}
#arena:fullscreen #touchpad, #arena.fake-fs #touchpad, #arena:-webkit-full-screen #touchpad {
  position: absolute;
  left: 0; right: 0; bottom: 14px;
  margin: 0;
  max-width: none;
  padding: 0 14px;
  pointer-events: none;
}
#arena:fullscreen .pad, #arena.fake-fs .pad, #arena:-webkit-full-screen .pad { pointer-events: auto; opacity: .82; }
#arena:fullscreen #fs-bar, #arena.fake-fs #fs-bar, #arena:-webkit-full-screen #fs-bar {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
  left: calc(10px + env(safe-area-inset-left, 0px));
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  z-index: 3;
  opacity: .85;
  pointer-events: none; /* only the buttons take taps, not the strip between them */
}
#fs-bar .chip { pointer-events: auto; }
body.no-scroll { overflow: hidden; }

@media (max-width: 600px) {
  main { padding: 10px; }
  .bar { gap: 6px; }
  .chip { font-size: 17px; padding: 3px 10px; }
  #play-title { flex-basis: 100%; order: -1; }
}

/* Sideways phone in fullscreen: the game is letterboxed, so stack the buttons in the side bars. */
@media (orientation: landscape) {
  #arena:fullscreen #touchpad, #arena.fake-fs #touchpad, #arena:-webkit-full-screen #touchpad {
    top: 0; bottom: 0;
    align-items: center;
    padding: 0 max(10px, env(safe-area-inset-left, 0px));
  }
  #arena:fullscreen .pad-group, #arena.fake-fs .pad-group, #arena:-webkit-full-screen .pad-group {
    flex-direction: column;
    flex-wrap: nowrap;
  }
}

/* Page-style games (Imitation's chat) use the room they're given instead of a 4:3 box. */
@media (max-width: 700px) {
  #arena.dom-game #stage { aspect-ratio: auto; height: 72vh; height: 72dvh; }
}
#arena.dom-game:fullscreen #stage, #arena.dom-game.fake-fs #stage, #arena.dom-game:-webkit-full-screen #stage {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  aspect-ratio: auto;
}

/* ---------- how-to-play guides ---------- */
.guide { margin-top: 22px; background: var(--panel); border: 1px solid #2d2963; border-radius: 12px; padding: 16px 20px; line-height: 1.15; }
.guide:empty { display: none; }
.guide h3 { font-family: var(--pixel); font-size: 14px; color: var(--c, var(--accent)); margin: 0 0 10px; }
.guide h4 { font-family: var(--pixel); font-size: 11px; color: var(--accent-2); margin: 16px 0 6px; }
.guide p, .guide li { color: var(--ink); }
.guide .goal { font-size: 1.05em; }
.guide ul { margin: 0; padding-left: 1.2em; }
.guide li { margin: 3px 0; }
.guide .table-wrap { overflow-x: auto; }
.guide table { border-collapse: collapse; width: 100%; min-width: 420px; }
.guide table.touch { min-width: 0; }
.guide th, .guide td { text-align: left; padding: 4px 10px; border-bottom: 1px solid #2d2963; vertical-align: top; }
.guide th { color: var(--dim); font-weight: normal; }
#overlay .guide.in-overlay h3 { display: none; } /* the overlay already says HOW TO PLAY */
#overlay .guide.in-overlay { margin: 0; max-width: 680px; width: 100%; text-align: left; }

/* ---------- cheat codes ---------- */
.cheat-form { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.cheat-form input { font-family: var(--pixel); font-size: 14px; text-transform: uppercase; background: #0d0b24; color: var(--ink); border: 2px solid var(--c, var(--accent)); border-radius: 8px; padding: 8px 10px; width: 14em; max-width: 70vw; }
.cheat-form .cheat-msg { flex-basis: 100%; min-height: 1.2em; color: #ffd23a; }
/* landscape phones in fullscreen: stack the fullscreen buttons in the side bar, clear of the game */
@media (orientation: landscape) and (max-height: 500px) {
  #arena:fullscreen #fs-bar, #arena.fake-fs #fs-bar, #arena:-webkit-full-screen #fs-bar { flex-direction: column; align-items: flex-end; left: auto; }
  #fs-bar .chip { font-size: 12px; padding: 4px 8px; }
}
