@font-face { font-family: Nunito; src: url("fonts/Nunito-Regular.ttf") format("truetype"); font-weight: 200 1000; font-display: swap; }
:root {
  --bg: #0b1026; --bg2: #161d4a; --panel: rgba(21, 27, 61, 0.72); --panel-line: rgba(255, 255, 255, 0.08);
  --text: #eef1ff; --muted: #9aa2d6; --accent: #8f7bff; --gold: #ffd27a; --good: #4fd69c; --bad: #ff6b81;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: radial-gradient(ellipse at 50% 20%, var(--bg2), var(--bg) 70%) fixed; color: var(--text);
       font: 16px/1.55 Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* header / footer */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; max-width: 1320px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.2rem; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
nav a { color: var(--muted); text-decoration: none; margin-left: 18px; font-weight: 600; }
nav a:hover { color: var(--text); }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 18px 0 26px; }
.foot a { color: var(--muted); }

/* 3 columns: leaderboard | game | account */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr) 300px; gap: 24px; max-width: 1320px; margin: 0 auto; padding: 0 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 20px; padding: 18px; backdrop-filter: blur(8px); }
.panel h2 { font-size: 1.05rem; font-weight: 800; margin: 0 0 12px; letter-spacing: .02em; }
.panel section + section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--panel-line); }
.muted { color: var(--muted); font-size: .92rem; margin: 0 0 12px; }

/* leaderboard */
.lb-tabs { display: flex; gap: 6px; background: rgba(0,0,0,.25); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.lb-tabs button { flex: 1; border: 0; border-radius: 9px; padding: 6px 0; background: transparent; color: var(--muted); font-weight: 700; font-size: .88rem; }
.lb-tabs button.on { background: rgba(255,255,255,.12); color: var(--text); }
.lb-list { list-style: none; margin: 0; padding: 0; }
.lb-list li, .lb-me { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.lb-list li:nth-child(odd) { background: rgba(255,255,255,.03); }
.lb-list li.me, .lb-me { background: rgba(143,123,255,.18); }
.lb-list li.empty { color: var(--muted); justify-content: center; background: none; }
.rank { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem; background: rgba(255,255,255,.08); flex: none; }
.rank.r1 { background: #ffd27a; color: #2a1d00; } .rank.r2 { background: #d7def5; color: #1b2040; } .rank.r3 { background: #e8a46b; color: #2a1400; }
.name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pts { font-weight: 800; color: var(--gold); }
.lb-me { margin-top: 10px; }

/* game column */
.game { display: flex; flex-direction: column; align-items: center; --w: min(100%, 640px, calc(100vh - 250px)); }
.hud, .hud2 { width: var(--w); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hud { margin-bottom: 4px; }
.hud2 { margin-bottom: 12px; }
.pill { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px; padding: 8px 14px; font-weight: 800; }
.pill img { width: 26px; height: 26px; }
.best span { color: var(--gold); font-size: 1.25rem; }
.stars span { color: #ffd45a; }
.score { font-size: clamp(2.6rem, 6vw, 4.2rem); font-weight: 900; line-height: 1; letter-spacing: -.02em; }
.score.bump { animation: bump .3s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.15); } 100% { transform: scale(1); } }
.next .label { color: var(--muted); font-size: .78rem; letter-spacing: .14em; }
.next-balls { display: flex; gap: 6px; min-height: 34px; }
.next-ball { position: relative; width: 34px; height: 34px; background-size: cover; }
.next-ball img { position: absolute; inset: 0; width: 100%; height: 100%; }
.next-ball img.badge { inset: auto; right: -4px; top: -4px; width: 16px; height: 16px; }
.icon-btn { position: relative; display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--panel-line); color: var(--gold);
            border-radius: 16px; padding: 8px 16px; font-weight: 800; }
.icon-btn img { width: 26px; height: 26px; opacity: .9; }
.icon-btn:hover:not(:disabled) { background: rgba(255,255,255,.1); }
.icon-btn:disabled { opacity: .45; cursor: default; }
.board-wrap { position: relative; width: var(--w); aspect-ratio: 1; }
#board { width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
.keys { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
.keys b { color: var(--text); }

/* banner / toast / game over */
.banner { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font-weight: 900; font-size: clamp(1.8rem, 5vw, 3rem);
          color: var(--gold); text-shadow: 0 3px 0 rgba(0,0,0,.5), 0 0 24px rgba(255,210,122,.4); opacity: 0; pointer-events: none; }
.banner.show { animation: banner 1.3s ease-out; }
@keyframes banner { 0% { opacity: 0; transform: scale(.6); } 15% { opacity: 1; transform: scale(1.05); } 25% { transform: scale(1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-20px); } }
.toast { position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 10px); background: #232b5e; border: 1px solid rgba(255,255,255,.15);
         padding: 8px 16px; border-radius: 12px; font-weight: 700; opacity: 0; transition: .25s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5,7,20,.62); border-radius: 18px; animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
.card { background: #181f4b; border: 1px solid rgba(255,255,255,.1); border-radius: 22px; padding: 26px 30px; text-align: center; width: min(86%, 380px);
        box-shadow: 0 30px 80px rgba(0,0,0,.5); animation: pop .4s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.card h1 { margin: 0 0 6px; font-size: 2rem; font-weight: 900; }
.ov-label { color: var(--muted); font-size: .8rem; letter-spacing: .16em; font-weight: 700; }
.ov-score { font-size: 3.4rem; font-weight: 900; line-height: 1.1; }
.ov-badge { display: inline-block; background: var(--gold); color: #2a1d00; font-weight: 900; padding: 4px 14px; border-radius: 10px; margin: 4px 0; }
.ov-best { color: var(--muted); font-weight: 700; margin-top: 4px; }
.ov-save { min-height: 1.4em; color: var(--text); font-size: .92rem; }

/* forms and buttons */
form input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.12); background: rgba(0,0,0,.25);
             color: var(--text); font: inherit; margin-bottom: 10px; outline: none; }
form input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; }
.primary, .secondary { flex: 1; border-radius: 12px; padding: 11px 16px; font-weight: 800; border: 0; }
.primary { background: #6f5bff; color: #fff; }
.primary:hover { background: #7f6dff; }
.secondary { background: rgba(255,255,255,.08); color: var(--text); border: 1px solid rgba(255,255,255,.12); }
.secondary:hover { background: rgba(255,255,255,.14); }
.card .primary { width: 100%; margin-top: 8px; padding: 13px; font-size: 1.1rem; }
.link { background: none; border: 0; color: var(--accent); font-weight: 800; padding: 0; text-decoration: underline; }
.error { color: var(--bad); min-height: 1.2em; font-size: .9rem; margin: 0 0 8px; }
.stats { display: flex; gap: 10px; margin-bottom: 14px; }
.stats div { flex: 1; background: rgba(0,0,0,.2); border-radius: 12px; padding: 10px; text-align: center; }
.stats .v { display: block; font-size: 1.5rem; font-weight: 900; color: var(--gold); }
.stats .k { color: var(--muted); font-size: .8rem; }
#logged-in .secondary { width: 100%; }

/* settings switches */
.switch { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; cursor: pointer; font-weight: 600; }
.switch input { display: none; }
.switch i { width: 44px; height: 26px; border-radius: 13px; background: rgba(255,255,255,.15); position: relative; transition: .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + i { background: var(--good); }
.switch input:checked + i::after { left: 21px; }
.how ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: .9rem; }
.how li { margin-bottom: 6px; }
.how b { color: var(--text); }

/* text pages */
.doc { max-width: 760px; margin: 0 auto; padding: 16px 20px 40px; }
.doc h1 { font-size: 2rem; margin: 0 0 4px; }
.doc h2 { font-size: 1.15rem; margin: 28px 0 8px; }
.meta { color: var(--muted); margin: 0 0 24px; }
table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .95rem; }
th, td { text-align: left; vertical-align: top; padding: 8px; border-bottom: 1px solid rgba(255,255,255,.1); }
th { color: var(--muted); font-weight: 600; }

/* tablets: panels under the game, side by side */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .game { grid-column: 1 / -1; order: -1; --w: min(100%, 600px); }
}
/* phones: one column */
@media (max-width: 640px) {
  .layout { grid-template-columns: 1fr; padding: 0 10px; gap: 16px; }
  .top { padding: 10px 12px; }
  nav a { margin-left: 12px; }
  .pill, .icon-btn { padding: 6px 10px; border-radius: 13px; }
  .next-ball { width: 28px; height: 28px; }
  .keys { display: none; }
}

/* the profile section replaces the login section: no divider above it */
#logged-in { margin-top: 0 !important; padding-top: 0 !important; border-top: 0 !important; }

/* theme button (header) */
.theme-btn { margin-left: 18px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--panel-line); background: var(--panel);
             color: var(--gold); font-size: 1.15rem; line-height: 1; display: inline-grid; place-items: center; vertical-align: middle; }
.theme-btn:hover { background: var(--soft); }
@media (max-width: 640px) { .theme-btn { margin-left: 12px; } }

/* light theme */
:root { --soft: rgba(255,255,255,.1); }
:root[data-theme="light"] {
  --bg: #d9dde8; --bg2: #e8ebf2; --panel: rgba(240,242,247,.88); --panel-line: rgba(40,50,90,.1);
  --text: #33395a; --muted: #6a7092; --accent: #5a45f0; --gold: #b67a00; --good: #23b97a; --bad: #e0435c; --soft: rgba(30,40,100,.07);
  color-scheme: light;
}
[data-theme="light"] .panel { box-shadow: 0 8px 24px rgba(40,50,90,.06); }
[data-theme="light"] .lb-tabs { background: rgba(30,40,100,.07); }
[data-theme="light"] .lb-tabs button.on { background: #f5f6fa; box-shadow: 0 1px 3px rgba(40,50,90,.12); }
[data-theme="light"] .lb-list li:nth-child(odd) { background: rgba(30,40,100,.035); }
[data-theme="light"] .lb-list li.me, [data-theme="light"] .lb-me { background: rgba(90,69,240,.12); }
[data-theme="light"] .lb-list li.empty { background: none; }
[data-theme="light"] .rank { background: rgba(30,40,100,.08); }
[data-theme="light"] .stars span { color: #b67a00; }
[data-theme="light"] .icon-btn:hover:not(:disabled) { background: #f5f6fa; }
[data-theme="light"] .overlay { background: rgba(30,36,80,.35); }
[data-theme="light"] .card { background: #eef0f5; border-color: rgba(30,40,100,.1); box-shadow: 0 30px 80px rgba(30,40,100,.25); }
[data-theme="light"] form input { background: #f5f6fa; border-color: rgba(30,40,100,.16); }
[data-theme="light"] .secondary { background: rgba(30,40,100,.06); border-color: rgba(30,40,100,.14); }
[data-theme="light"] .secondary:hover { background: rgba(30,40,100,.1); }
[data-theme="light"] .stats div { background: rgba(30,40,100,.05); }
[data-theme="light"] .switch i { background: rgba(30,40,100,.18); }
[data-theme="light"] th, [data-theme="light"] td { border-bottom-color: rgba(30,40,100,.12); }
[data-theme="light"] .rank.r2 { background: #c9d1ec; }
[data-theme="light"] .best img, [data-theme="light"] .icon-btn img { filter: brightness(0.25) sepia(1) hue-rotate(200deg) saturate(3); opacity: .75; }
[data-theme="light"] .theme-btn { color: #5a45f0; }
