:root {
  --w: #ffffff;
  --b: #000000;
  --dim: #888888;
  --line: #2a2a2a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--b); color: var(--w);
  font-family: "Courier New", ui-monospace, monospace;
  letter-spacing: 1px;
  overflow: hidden;
  user-select: none;
}

#app { position: fixed; inset: 0; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
.screen.active { display: flex; }

/* CRT scanline overlay + vignette + flicker — only active in the CRT theme. */
.crt { pointer-events: none; position: fixed; inset: 0; z-index: 50; display: none; }
body.theme-crt .crt {
  display: block;
  background: repeating-linear-gradient(
    to bottom, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px, rgba(0,0,0,0.22) 3px);
  mix-blend-mode: multiply;
  animation: crt-flicker 5.5s steps(60) infinite;
}
/* Vignette + corner darkening so the screen feels curved/tube-like. */
body.theme-crt .crt::after {
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 0 0 120px 24px rgba(0,0,0,0.9);
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%);
}

/* CRT / LCD switch button — shows the mode it will switch TO. */
.theme-switch {
  position: absolute; top: 16px; right: 16px; z-index: 6;
  width: 64px; height: 34px; padding: 0;
  border: 2px solid var(--w); border-radius: 6px;
  background: rgba(255,255,255,0.18);
  box-shadow: 0 0 0 2px #000;            /* black outline so it pops on any bg */
  display: flex; align-items: center; cursor: pointer;
}
.theme-switch .lab {
  flex: 1; font-family: inherit; font-size: 12px; font-weight: 700;
  letter-spacing: 1px; color: var(--w); text-align: center;
}
.theme-switch:active { background: var(--w); }
.theme-switch:active .lab { color: #000; }
/* Menu variant: centered at the top of the main screen. */
.theme-switch.on-menu { right: auto; left: 50%; transform: translateX(-50%); }
@keyframes crt-flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.82; }
  98% { opacity: 0.96; }
  99% { opacity: 0.78; }
}
@keyframes phosphor {
  0%, 100% { text-shadow: 0 0 6px rgba(255,255,255,0.55), 0 0 14px rgba(255,255,255,0.25); }
  50% { text-shadow: 0 0 8px rgba(255,255,255,0.7), 0 0 20px rgba(255,255,255,0.35); }
}

/* ---- Welcome ---- */
.centerbox { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.logo { font-size: 56px; line-height: 0.9; margin: 0 0 4px; font-weight: 900; }
.logo span { font-size: 28px; letter-spacing: 8px; }
.tag { color: var(--dim); margin: 0 0 12px; font-size: 12px; }
.field-label { color: var(--dim); font-size: 12px; text-align: left; }

input[type=text], input:not([type]), input[type=email] {
  width: 100%; padding: 14px; text-align: center;
  background: #000; color: var(--w);
  border: 2px solid var(--w); border-radius: 30px;
  font-family: inherit; font-size: 22px; letter-spacing: 3px;
  text-transform: uppercase;
}
input::placeholder { color: var(--dim); }

.btn {
  width: 100%; padding: 14px; margin-top: 4px;
  background: #000; color: var(--w);
  border: 2px solid var(--w); border-radius: 30px;
  font-family: inherit; font-size: 18px; font-weight: 700; letter-spacing: 3px;
  cursor: pointer;
}
.btn.primary { background: var(--w); color: #000; }
.btn:active { transform: translateY(1px); }

.error { color: var(--w); background: #000; border: 1px dashed var(--w); padding: 6px; font-size: 12px; }
.hint { color: var(--dim); font-size: 12px; }

.register { text-align: left; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.register summary { cursor: pointer; color: var(--dim); font-size: 13px; }
.register input { margin: 8px 0; font-size: 16px; letter-spacing: 1px; text-transform: none; }

/* ---- Menu / circular ring ---- */
.ring { position: relative; width: min(92vw, 92vh, 560px); height: min(92vw, 92vh, 560px); }
.hub {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  text-align: center;
}
.hub-title { font-size: 40px; font-weight: 900; }
.hub-sub { font-size: 16px; color: var(--w); margin-top: 2px; }
.hub-hint { font-size: 11px; color: var(--dim); margin-top: 6px; }

.tile {
  position: absolute; transform: translate(-50%, -50%);
  width: 86px; height: 40px; border-radius: 22px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  border: 2px solid var(--w); color: var(--w);
  font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
  background: #000; cursor: pointer; text-align: center; line-height: 1;
}
.tile .ico { display: inline-flex; flex: none; }
.tile .ico svg { width: 14px; height: 14px; display: block; }
.tile.soon { border-color: var(--dim); color: var(--dim); cursor: default; }
.tile.soon::after {
  content: "SOON"; position: absolute; bottom: -14px; left: 0; right: 0;
  font-size: 9px; color: var(--dim);
}
.tile.playable:active { background: var(--w); color: #000; }

.corner-btn {
  position: absolute; top: 16px; background: #000; color: var(--w);
  border: 2px solid var(--w); border-radius: 50%;
  width: 44px; height: 44px; font-size: 20px; cursor: pointer; z-index: 5;
}
.corner-btn.top-right { right: 16px; }
.corner-btn.top-right2 { right: 70px; }   /* mute, left of the gear */
.corner-btn.top-left { left: 16px; }
.corner-btn.small { width: 38px; height: 38px; font-size: 16px; }
.corner-btn.muted { color: var(--dim); border-color: var(--dim); text-decoration: line-through; }
body.theme-crt .corner-btn.muted { box-shadow: none; text-shadow: none; }

/* ---- Panels (settings / scores) ---- */
.panel { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.panel h2 { text-align: center; font-size: 26px; margin: 0 0 6px; letter-spacing: 4px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.toggle input { width: 20px; height: 20px; accent-color: #fff; }

input[type=range] { width: 100%; accent-color: #fff; height: 28px; }

.tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.tabs button {
  background: #000; color: var(--w); border: 2px solid var(--w);
  border-radius: 20px; padding: 6px 14px; font-family: inherit; font-size: 13px; cursor: pointer;
}
.tabs button.on { background: var(--w); color: #000; }
/* Period row (day/month/overall): separated from the game tabs by a thin line. */
#periodTabs { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 2px; }
#periodTabs button { font-size: 12px; padding: 5px 12px; }
.scorelist { min-height: 220px; }
.score-row { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 16px; }
.score-row .rank { width: 28px; color: var(--dim); }
.score-row .nm { flex: 1; text-align: left; padding-left: 6px; }

/* ---- Game ---- */
#screen-game { padding: 0; }
#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #000; }

.touch {
  position: absolute; left: 0; right: 0; bottom: 18px; z-index: 6;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 18px; pointer-events: none;
}
.touch .ctl, .dpad { pointer-events: auto; }
.dpad { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dpad-mid { display: flex; gap: 6px; align-items: center; }
.ctl {
  width: 56px; height: 56px; border-radius: 12px;
  background: rgba(255,255,255,0.08); color: var(--w);
  border: 2px solid var(--w); font-size: 20px; cursor: pointer;
}
.ctl.action { width: 84px; height: 84px; border-radius: 50%; font-size: 26px; }
.ctl:active { background: var(--w); color: #000; }

/* Per-game control legend: compact 2x2 grid centred below the game screen. */
.ctl-hint {
  align-self: flex-end;
  display: grid; grid-template-columns: auto auto; gap: 2px 16px;
  font-family: monospace; font-size: 11px; line-height: 1.4;
  color: var(--w); opacity: 0.75;
  border: 1px solid var(--w); border-radius: 8px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.45);
}
.ctl-hint[hidden] { display: none; }
.ctl-hint .row { display: flex; gap: 6px; white-space: nowrap; }
.ctl-hint .k { min-width: 30px; }

.go { font-size: 36px; letter-spacing: 6px; margin: 0; }
.goscore { font-size: 24px; margin: 10px 0; }

@media (hover: hover) and (pointer: fine) {
  /* On desktop, hint that keyboard works; keep touch controls visible but smaller. */
  .touch { opacity: 0.5; }
}

/* ============ CRT phosphor theme (body.theme-crt) ============ */
body.theme-crt .logo { animation: phosphor 3.2s ease-in-out infinite; }
body.theme-crt .logo span,
body.theme-crt .tag { text-shadow: 0 0 6px rgba(255,255,255,0.4); }

body.theme-crt .hub-title { text-shadow: 0 0 8px rgba(255,255,255,0.6), 0 0 18px rgba(255,255,255,0.3); }
body.theme-crt .hub-sub { text-shadow: 0 0 6px rgba(255,255,255,0.45); }

body.theme-crt .panel h2,
body.theme-crt .go,
body.theme-crt .goscore { text-shadow: 0 0 8px rgba(255,255,255,0.5), 0 0 16px rgba(255,255,255,0.25); }

/* Glowing game bubbles. */
body.theme-crt .tile {
  text-shadow: 0 0 6px rgba(255,255,255,0.5);
  box-shadow: 0 0 7px rgba(255,255,255,0.35), inset 0 0 6px rgba(255,255,255,0.18);
}
body.theme-crt .tile.playable { animation: phosphor 2.6s ease-in-out infinite; }
body.theme-crt .tile.soon { text-shadow: none; box-shadow: none; opacity: 0.7; }

/* Glowing primary controls. */
body.theme-crt .btn.primary { box-shadow: 0 0 10px rgba(255,255,255,0.45); }
body.theme-crt .corner-btn {
  box-shadow: 0 0 8px rgba(255,255,255,0.35);
  text-shadow: 0 0 6px rgba(255,255,255,0.5);
}
body.theme-crt input:not([type=range]):focus {
  outline: none;
  box-shadow: 0 0 10px rgba(255,255,255,0.5), inset 0 0 6px rgba(255,255,255,0.2);
}

/* Power-on sweep when the app first loads (CRT only). */
body.theme-crt #app { animation: crt-on 0.6s ease-out 1; }
@keyframes crt-on {
  0% { transform: scaleY(0.004); filter: brightness(3); opacity: 0.2; }
  35% { transform: scaleY(0.02); filter: brightness(2.4); }
  60% { transform: scaleY(1); filter: brightness(1.4); opacity: 1; }
  100% { transform: scaleY(1); filter: brightness(1); }
}

/* ============ LCD theme (body.theme-lcd) — crisp, flat, no glow ============ */
/* Base styles already give sharp white-on-black; keep SOON tiles dimmed. */
body.theme-lcd .tile.soon { opacity: 0.7; }
body.theme-lcd input:not([type=range]):focus { outline: none; box-shadow: inset 0 0 0 1px var(--w); }

/* Respect users who don't want motion. */
@media (prefers-reduced-motion: reduce) {
  .crt, .logo, .tile.playable, #app { animation: none; }
}
