:root {
  --bg: #0b0a12;
  --panel: #151324;
  --panel-2: #1d1a31;
  --ink: #ece9ff;
  --muted: #9c97bd;
  --line: #2c2847;
  --accent: #ff4fa3;
  --accent-2: #3ee6ff;
  --good: #5dff9b;
  --bad: #ff5d6c;
  --wood: #3a2417;
  --wood-2: #5a3822;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #221a3d 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

.marquee { text-align: center; padding: 28px 16px 8px; }
.marquee h1 {
  font-family: var(--pixel);
  font-size: clamp(18px, 4vw, 34px);
  margin: 0;
  letter-spacing: 2px;
}
.marquee h1 a {
  color: var(--ink);
  text-decoration: none;
  text-shadow: 0 0 12px var(--accent), 0 0 32px rgba(255, 79, 163, .5);
}
.marquee p { color: var(--muted); margin: 10px 0 0; }

/* ---------- menu ---------- */
.menu {
  width: 100%;
  max-width: 1100px;
  margin: 18px auto 0;
  padding: 0 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
  flex: 1;
}
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--c, var(--accent));
  box-shadow: 0 0 16px var(--c, var(--accent));
}
.card h2 {
  font-family: var(--pixel);
  font-size: 15px;
  margin: 4px 0 0;
  color: var(--c, var(--accent));
  letter-spacing: 1px;
}
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.modes { display: grid; gap: 8px; margin-top: auto; }
.mode-btn {
  text-align: left;
  background: #0f0d1c;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  display: grid;
  gap: 3px;
  transition: border-color .15s, transform .15s;
}
.mode-btn:hover, .mode-btn:focus-visible {
  border-color: var(--c, var(--accent));
  transform: translateY(-1px);
  outline: none;
}
.mode-btn b { font-size: 14px; }
.mode-btn span { font-size: 12.5px; color: var(--muted); }
.mode-btn .who { color: var(--c, var(--accent)); font-weight: 600; }

/* ---------- stage ---------- */
.stage {
  width: 100%;
  max-width: 1000px;
  margin: 12px auto 0;
  padding: 0 16px 16px;
  flex: 1;
}
.stage-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 10px;
}
.stage-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
#stage-name { font-family: var(--pixel); font-size: 14px; }
.pill {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.btn {
  font: inherit; font-size: 14px; cursor: pointer;
  border-radius: 9px; padding: 8px 14px;
  border: 1px solid var(--accent);
  background: var(--accent); color: #1a0010; font-weight: 700;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 600; }
.btn.ghost:hover { border-color: var(--accent-2); }
.btn.alt { background: var(--accent-2); border-color: var(--accent-2); color: #001a20; }
.btn:disabled { opacity: .5; cursor: default; }

.bezel {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: calc(100vh - 170px);
  margin: 0 auto;
  border-radius: 18px;
  padding: 12px;
  background: linear-gradient(145deg, var(--wood-2), var(--wood));
  box-shadow: inset 0 0 0 2px #00000055, 0 20px 50px #0008;
}
@supports (aspect-ratio: 1) {
  .bezel { width: min(100%, calc((100vh - 170px) * 4 / 3)); }
}
#screen {
  display: block;
  width: 100%;
  height: 100%;
  background: #05040a;
  border-radius: 10px;
  touch-action: none;
  outline: none;
  cursor: crosshair;
}
.dom-layer {
  position: absolute; inset: 12px;
  border-radius: 10px;
  background: #07060e;
  overflow: hidden;
}
.overlay {
  position: absolute; inset: 12px;
  border-radius: 10px;
  background: rgba(5, 4, 12, .82);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 5;
}
.overlay .box { max-width: 520px; text-align: center; }
.overlay h3 { font-family: var(--pixel); font-size: clamp(14px, 2.4vw, 22px); margin: 0 0 14px; line-height: 1.5; }
.overlay p { color: var(--muted); line-height: 1.5; margin: 0 0 10px; font-size: 15px; }
.overlay ul { text-align: left; color: var(--ink); line-height: 1.6; font-size: 14px; padding-left: 20px; margin: 0 0 16px; }
.overlay .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.overlay .win { color: var(--good); }
.overlay .lose { color: var(--bad); }
.help { color: var(--muted); font-size: 13px; text-align: center; margin: 10px 0 0; }

.foot { color: #6d6890; font-size: 12px; text-align: center; padding: 16px; }

@media (max-width: 600px) {
  .stage-bar .btn { padding: 6px 10px; font-size: 13px; }
  #stage-name { font-size: 11px; }
  .bezel { padding: 6px; border-radius: 12px; }
  .overlay, .dom-layer { inset: 6px; }
}

/* ---------- Imitation (DOM game) ---------- */
.imi { height: 100%; color: var(--ink); font-size: 15px; }
.imi .btn { font-size: 14px; }
.imi-center { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; text-align: center; }
.imi-center h2 { font-family: var(--pixel); font-size: clamp(13px, 2.4vw, 20px); color: #c0ff3e; margin: 0; line-height: 1.6; }
.imi-sub { color: var(--muted); margin: 0; }
.imi-big { font-size: 17px !important; padding: 14px 28px; background: #c0ff3e; border-color: #c0ff3e; color: #142000; }
.imi-or { color: var(--muted); font-size: 13px; margin-top: 8px; }
.imi-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.imi-row input {
  width: 90px; text-transform: uppercase; text-align: center; letter-spacing: 3px;
  background: #0f0d1c; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; font: inherit; padding: 8px;
}
.imi-code { color: var(--ink); letter-spacing: 4px; }
.imi-spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #c0ff3e33; border-top-color: #c0ff3e; animation: imi-spin 1s linear infinite; }
@keyframes imi-spin { to { transform: rotate(360deg); } }

.imi-chat { position: relative; height: 100%; display: flex; flex-direction: column; }
.imi-top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.imi-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }
.imi-timer { margin-left: auto; font-family: var(--pixel); font-size: 11px; color: #c0ff3e; }
.imi-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.imi-msg { max-width: 75%; padding: 8px 12px; border-radius: 14px; line-height: 1.35; word-wrap: break-word; white-space: pre-wrap; }
.imi-msg.me { align-self: flex-end; background: #2b5cff; color: #fff; border-bottom-right-radius: 4px; }
.imi-msg.them { align-self: flex-start; background: #24213a; border-bottom-left-radius: 4px; }
.imi-sys { align-self: center; color: var(--muted); font-size: 12px; font-style: italic; }
.imi-typing { padding: 0 16px 4px; font-size: 12px; color: var(--muted); min-height: 18px; }
.imi-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.imi-input input { flex: 1; min-width: 0; background: #0f0d1c; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; font: inherit; padding: 10px 12px; }
.imi-input input:focus { outline: none; border-color: #c0ff3e; }
.imi-guess { position: absolute; inset: auto 0 0 0; background: #110f20f2; border-top: 1px solid #c0ff3e; padding: 18px; text-align: center; }
.imi-guess h3 { font-family: var(--pixel); font-size: 14px; margin: 0 0 8px; color: #c0ff3e; }
.imi-guess p { color: var(--muted); margin: 0 0 12px; }
.imi-guess .btn { min-width: 110px; }
.imi-guess .btn.chosen { outline: 2px solid #fff; }
