/* Viral Games — mobile-first dark arcade UI. No build step. */
:root {
  --bg: #0b0716; --bg2: #140d28; --card: #1b1236; --card2: #241a46; --line: #3a2d6b;
  --text: #f4f1ff; --muted: #a79fcf; --yellow: #ffd60a; --cyan: #00e5ff; --pink: #ff4dc4; --green: #3dff8f; --red: #ff4d6d; --violet: #8f6bff;
  --radius: 18px; --nav-h: 64px; --head-h: 54px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(.2, .9, .3, 1.2); --speed: .22s;
  color-scheme: dark;
}
:root[data-theme="neon"] { --bg: #02010a; --card: #0d0b25; --card2: #15123a; --violet: #00ffa3; --pink: #ff00e5; }
:root[data-theme="sunset"] { --bg: #160812; --bg2: #24101c; --card: #2c1424; --card2: #3a1a2f; --violet: #ff7a45; --cyan: #ffb703; }
:root[data-theme="mono"] { --bg: #0d0d0d; --bg2: #151515; --card: #1d1d1d; --card2: #262626; --line: #3b3b3b; --violet: #9a9a9a; --pink: #e0e0e0; --cyan: #ffffff; --yellow: #ffffff; }
@media (prefers-reduced-motion: reduce) { :root { --speed: 0s; } }
:root.reduce-motion { --speed: 0s; }
:root.reduce-motion *, :root.reduce-motion *::before, :root.reduce-motion *::after { animation-duration: .001s !important; transition-duration: .001s !important; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(120% 60% at 50% -10%, #2a1660 0%, var(--bg) 60%) fixed;
  overscroll-behavior-y: none; -webkit-text-size-adjust: 100%;
}
a { color: var(--cyan); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; letter-spacing: .01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; } .wrap { flex-wrap: wrap; } .grow { flex: 1; } .between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; border-radius: 8px; }

/* ---------- shell ---------- */
#top {
  position: sticky; top: 0; z-index: 20; height: calc(var(--head-h) + var(--safe-t)); padding: var(--safe-t) 14px 0;
  display: flex; align-items: center; gap: 10px; background: rgba(11, 7, 22, .82); backdrop-filter: blur(12px); border-bottom: 1px solid rgba(143, 107, 255, .18);
}
#top .logo { font-weight: 900; font-size: 1.15rem; letter-spacing: .06em; text-decoration: none; color: var(--text); display: flex; gap: 6px; align-items: center; }
#top .logo b { color: var(--yellow); }
#top .sp { flex: 1; }
.iconbtn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 1.2rem; display: grid; place-items: center; cursor: pointer; text-decoration: none; }
.chip-me { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: .9rem; max-width: 46vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
main#view { padding: 16px 14px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 760px; margin: 0 auto; min-height: 70vh; }
main#view.enter { animation: viewIn var(--speed) ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(6, 1fr); background: rgba(14, 9, 30, .94); backdrop-filter: blur(12px); border-top: 1px solid rgba(143, 107, 255, .25);
}
#nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 600; }
#nav a span { font-size: 1.35rem; line-height: 1; filter: grayscale(.6); transition: transform var(--speed) var(--ease); }
#nav a.on { color: var(--text); } #nav a.on span { filter: none; transform: translateY(-2px) scale(1.12); }
body.playing #nav, body.playing #top { display: none; }
body.playing main#view { padding: 0; max-width: none; }

/* ---------- components ---------- */
.card { background: linear-gradient(180deg, var(--card2), var(--card)); border: 1px solid rgba(143, 107, 255, .22); border-radius: var(--radius); padding: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 22px; border: 0; border-radius: 14px;
  font: inherit; font-weight: 800; letter-spacing: .03em; color: #160b2e; background: var(--yellow); cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 0 #b39200, 0 8px 22px rgba(255, 214, 10, .25); transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b39200; }
.btn.big { min-height: 62px; font-size: 1.2rem; width: 100%; }
.btn.alt { background: var(--cyan); box-shadow: 0 4px 0 #00a3b5, 0 8px 22px rgba(0, 229, 255, .2); }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 4px 0 #b3268a, 0 8px 22px rgba(255, 77, 196, .25); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn.danger { background: var(--red); color: #fff; box-shadow: 0 4px 0 #a32a40; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .9rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.seg button { flex: none; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--violet); color: #fff; border-color: transparent; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 800; letter-spacing: .03em; }
.badge.ok { background: rgba(61, 255, 143, .15); color: var(--green); } .badge.warn { background: rgba(255, 214, 10, .15); color: var(--yellow); }
.badge.bad { background: rgba(255, 77, 109, .18); color: var(--red); } .badge.info { background: rgba(0, 229, 255, .14); color: var(--cyan); }
label.field { display: block; } label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #120c26; color: var(--text); font: inherit; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid rgba(143, 107, 255, .12); }
.switch input { width: 52px; min-height: 30px; height: 30px; appearance: none; background: #3a2d6b; border-radius: 999px; position: relative; border: 0; cursor: pointer; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left var(--speed); }
.switch input:checked { background: var(--green); } .switch input:checked::after { left: 25px; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.notice { border-left: 4px solid var(--yellow); background: rgba(255, 214, 10, .08); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
.notice.red { border-color: var(--red); background: rgba(255, 77, 109, .08); }
.notice.cyan { border-color: var(--cyan); background: rgba(0, 229, 255, .07); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: .95rem; } .kv b { text-align: right; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--card); border: 1px solid rgba(143, 107, 255, .16); text-decoration: none; color: var(--text); }
.item .av { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; background: var(--card2); flex: none; }
.item.me { border-color: var(--yellow); background: rgba(255, 214, 10, .07); }
.rank { width: 34px; text-align: center; font-weight: 900; font-size: 1.05rem; color: var(--muted); flex: none; }
.rank.r1 { color: var(--yellow); } .rank.r2 { color: #d9e2ff; } .rank.r3 { color: #ff9e5e; }
.val { font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- home / games ---------- */
.hero { text-align: center; padding: 18px 6px 8px; }
.hero h1 { font-size: 2rem; background: linear-gradient(90deg, var(--yellow), var(--pink), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.gcard { position: relative; display: flex; flex-direction: column; border-radius: var(--radius); overflow: hidden; background: var(--card); border: 1px solid rgba(143, 107, 255, .22); text-decoration: none; color: var(--text); transition: transform var(--speed) var(--ease); }
.gcard:active { transform: scale(.97); }
.gcard .thumb { aspect-ratio: 4 / 3; display: block; width: 100%; }
.gcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.gcard .name { font-weight: 800; font-size: .98rem; line-height: 1.2; }
.gcard .tag { font-size: .78rem; color: var(--muted); line-height: 1.3; flex: 1; }
.gcard .play { align-self: flex-start; margin-top: 4px; background: var(--yellow); color: #160b2e; font-weight: 900; font-size: .8rem; padding: 6px 12px; border-radius: 999px; }
.gcard .pb { position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, .55); padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.daily-strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.daily-strip > * { scroll-snap-align: start; flex: 0 0 78%; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 900; color: var(--cyan); }

/* ---------- game screen ---------- */
.gscreen { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--bg); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.ghead { display: flex; align-items: center; gap: 10px; padding: calc(var(--safe-t) + 8px) 12px 8px; }
.ghead .t { flex: 1; font-weight: 800; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hud { display: flex; gap: 8px; padding: 0 12px 6px; justify-content: center; flex-wrap: wrap; }
.hud .h { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 72px; text-align: center; }
.hud .h small { display: block; font-size: .65rem; color: var(--muted); font-weight: 700; letter-spacing: .05em; }
.stage { position: relative; flex: 1; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; gap: 14px; pointer-events: none; }
.overlay > * { pointer-events: auto; }
.bigcount { font-size: 6rem; font-weight: 900; color: var(--yellow); text-shadow: 0 0 40px rgba(255, 214, 10, .5); animation: pop .9s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }
.gpanel { position: absolute; inset: 0; overflow-y: auto; padding: 8px 16px calc(24px + var(--safe-b)); touch-action: pan-y; user-select: text; }
.gpanel .inner { max-width: 560px; margin: 0 auto; }
.howto { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.howto li { counter-increment: s; position: relative; padding: 6px 0 6px 38px; }
.howto li::before { content: counter(s); position: absolute; left: 0; top: 5px; width: 26px; height: 26px; border-radius: 8px; background: var(--violet); color: #fff; font-weight: 900; display: grid; place-items: center; font-size: .85rem; }
.result-hero { text-align: center; padding: 10px 0; }
.result-hero .score { font-size: 3.2rem; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; background: linear-gradient(90deg, var(--yellow), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result-hero .newpb { display: inline-block; margin-top: 6px; background: var(--pink); color: #fff; font-weight: 900; padding: 4px 12px; border-radius: 999px; animation: pop .6s ease-out; }
.ranks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.ranks div { background: var(--card); border-radius: 12px; padding: 8px 4px; }
.ranks b { display: block; font-size: 1.3rem; } .ranks small { color: var(--muted); font-size: .72rem; }
.ach { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 12px; background: rgba(61, 255, 143, .08); border: 1px solid rgba(61, 255, 143, .3); animation: pop .6s ease-out; }
.ach span { font-size: 1.8rem; }
.tapzone { position: absolute; inset: 0; display: grid; touch-action: none; }
.meter { height: 16px; border-radius: 999px; background: #120c26; overflow: hidden; border: 1px solid var(--line); }
.meter > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--yellow), var(--red)); transition: width .06s linear; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 60; background: rgba(5, 2, 12, .72); display: flex; align-items: flex-end; justify-content: center; animation: fadeIn var(--speed); }
.modal { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); animation: up var(--speed) var(--ease); }
@media (min-width: 620px) { .modal-bg { align-items: center; } .modal { border-radius: 22px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 480px); }
#toast div { background: #fff; color: #160b2e; padding: 10px 16px; border-radius: 12px; font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); animation: up .2s ease-out; text-align: center; }
#toast div.err { background: var(--red); color: #fff; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--cyan); animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
table.t { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.t th, table.t td { padding: 7px 6px; border-bottom: 1px solid rgba(143, 107, 255, .14); text-align: left; vertical-align: top; }
table.t th { color: var(--muted); font-weight: 700; }
.scroll-x { overflow-x: auto; }
.stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .stat-tiles { grid-template-columns: repeat(4, 1fr); } }
.stat-tiles .card b { display: block; font-size: 1.5rem; } .stat-tiles .card small { color: var(--muted); }
video.replay { width: 100%; max-height: 60vh; border-radius: 14px; background: #000; }
/* Overlays on top of a live camera feed get a dark backing so text stays readable on any background. */
.stage.on-video .overlay > * { background: rgba(11, 7, 22, .72); padding: 6px 16px; border-radius: 14px; color: #fff; }
.stage.on-video .overlay > .muted { color: #e6e0ff; }
/* Leaflet on high-DPI screens: hide hairline seams between map tiles. */
.leaflet-container { background: #120c26; font: inherit; }
.leaflet-tile-container img.leaflet-tile { width: 256.5px !important; height: 256.5px !important; }
