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

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --ink: #14202e;
    --blue: #1f5fbf;
    --orange: #f28c00;
    --card: rgba(8, 18, 40, .66);
}
html, body { height: 100%; }
/* Inside the site iframe a fixed footer bar (~40px) covers the bottom; the site hides it when height <= 400px. */
html.in-frame { --frame-bottom: 44px; }
@media (max-height: 400px) { html.in-frame { --frame-bottom: 0px; } }

body {
    font-family: Arial, Helvetica, sans-serif; color: #fff; overflow: hidden; user-select: none; -webkit-user-select: none;
    background: radial-gradient(1200px 700px at 50% 25%, #2a4f86 0%, #13274a 55%, #070f20 100%);
}
#app {
    position: relative; z-index: 1;
    height: calc(100vh - var(--frame-bottom));
    height: calc(100dvh - var(--frame-bottom));
    padding: 0 var(--frame-right) 0 var(--frame-left);
    display: flex; justify-content: center;
}
/* The UI column (480 px max). It is transparent and lets clicks through to the 3D view behind it;
   only its active screens, modals and buttons take input. */
#stage { position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; pointer-events: none; z-index: 2; }
#stage > * { pointer-events: auto; }
/* The 3D view behind the column: game.js sizes it to max(column, min(screen width, height)) – square at most */
#scene {
    position: absolute; top: 0; left: 0; display: block; touch-action: none; z-index: 1; background: #1d3f78;
    box-shadow: 0 20px 70px rgba(0, 0, 0, .6); transition: filter .25s;
}
#scene.dim { filter: brightness(.55) saturate(.8); }
.screen { display: none; position: absolute; inset: 0; flex-direction: column; z-index: 2; }
.screen.active { display: flex; }

/* ---------- Buttons ---------- */
.btn {
    display: block; width: 290px; max-width: 100%; border: none; padding: 11px 18px; margin: 6px auto;
    font-size: 18px; font-weight: bold; border-radius: 50px; cursor: pointer; font-family: inherit; min-height: 46px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, .25); transition: transform .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn small { display: block; font-size: 12px; font-weight: normal; opacity: .85; margin-top: 2px; }
.btn-primary { background: #fff; color: var(--ink); }
.btn-secondary { background: rgba(8, 18, 40, .5); color: #fff; border: 2px solid rgba(255, 255, 255, .8); }
.btn-ghost { background: transparent; color: #fff; box-shadow: none; text-decoration: underline; font-size: 15px; padding: 8px 6px; min-height: 40px; }
.btn-orange { background: linear-gradient(#ffb020, #f28c00); color: #3a2200; box-shadow: 0 4px 0 #a65d00, 0 8px 18px rgba(0, 0, 0, .35); font-size: 21px; letter-spacing: .5px; }
.btn-orange small { color: #5a3500; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .12);
    color: #fff; font-size: 17px; font-weight: bold; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-family: inherit;
}
.icon-btn.dark { background: var(--card); border-color: rgba(255, 255, 255, .25); }
.icon-spacer { width: 40px; flex-shrink: 0; }

/* ---------- Start ---------- */
/* the menu shade covers the whole 3D view (also its side parts), not just the column */
#start-screen { background: transparent; }
#scene-shade { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none; display: none; background: linear-gradient(180deg, rgba(5, 12, 30, .55) 0%, rgba(5, 12, 30, .1) 28%, rgba(5, 12, 30, 0) 44%, rgba(5, 12, 30, .55) 66%, rgba(5, 12, 30, .9) 100%); }
#scene-shade.show { display: block; }
.sound-start { position: absolute; top: 15px; left: 15px; z-index: 3; background: rgba(8, 18, 40, .5); }
.title-wrap { margin-top: calc(58px + 1vh); text-align: center; padding: 0 18px; }
.kicker { font-size: 14px; font-weight: 900; letter-spacing: 6px; color: #ffd166; text-shadow: 0 1px 3px #000; }
#start-screen h1 {
    font-size: clamp(38px, 12vw, 54px); letter-spacing: 2px; font-weight: 900; line-height: 1;
    color: #fff; -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill;
    text-shadow: 0 0 18px rgba(255, 190, 90, .55), 0 4px 0 var(--ink), 0 8px 20px rgba(0, 0, 0, .5);
}
#start-screen .desc { font-size: 15px; line-height: 1.45; max-width: 360px; margin: 10px auto 0; text-shadow: 0 1px 3px rgba(0, 0, 0, .9), 0 0 10px rgba(0, 0, 0, .6); }
@media (max-height: 620px) { #start-screen .desc { display: none; } .title-wrap { margin-top: 56px; } }
.start-inner { position: relative; z-index: 2; margin-top: auto; padding: 0 18px 12px; text-align: center; }
.profile { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; min-height: 22px; }
.profile span { background: rgba(0, 0, 0, .35); border: 1px solid rgba(255, 255, 255, .3); border-radius: 14px; padding: 4px 10px; }
.profile b { color: #ffd166; }
.row3 { display: flex; justify-content: center; gap: 10px; }
.row3 .btn { width: auto; margin: 2px 0; }

/* ---------- List screens ---------- */
.list-screen { background: linear-gradient(170deg, #1f3f6e 0%, #13274a 60%, #08142a 100%); }
.topbar {
    height: 54px; display: flex; align-items: center; gap: 8px; padding: 0 10px; flex-shrink: 0; z-index: 5;
    background: linear-gradient(#2a4f86, #1c3a66); box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.topbar .title { flex: 1; text-align: center; font-weight: bold; font-size: 18px; }
.scroll { flex: 1; overflow-y: auto; padding: 10px 10px 24px; -webkit-overflow-scrolling: touch; }
.section-title { font-size: 14px; font-weight: bold; opacity: .85; margin: 10px 2px 8px; text-transform: uppercase; letter-spacing: .5px; }
.info-line { font-size: 13px; opacity: .85; line-height: 1.4; margin: 2px 2px 10px; }
.card {
    display: flex; gap: 12px; align-items: center; background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 255, 255, .14);
    border-radius: 14px; padding: 10px; margin-bottom: 9px; cursor: pointer; width: 100%; color: #fff; text-align: left; font-family: inherit;
}
.card.sel { border-color: #ffd166; background: rgba(255, 209, 102, .12); }
.card.locked { cursor: default; opacity: .65; }
.card canvas { width: 72px; height: 72px; flex-shrink: 0; border-radius: 10px; background: radial-gradient(circle at 50% 60%, #3f6fb0, #17305a); }
.card .info { flex: 1; min-width: 0; }
.card b { font-size: 16px; display: block; }
.card p { font-size: 13px; opacity: .85; margin: 3px 0 5px; line-height: 1.35; }
.card .tag { display: inline-block; font-size: 12px; font-weight: bold; padding: 3px 9px; border-radius: 10px; background: #ffd166; color: #3a2200; }
.card .tag.choose { background: rgba(255, 255, 255, .2); color: #fff; }
.card .tag.lock { background: rgba(0, 0, 0, .3); color: #fff; font-weight: normal; }
.card .bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; font-size: 11px; opacity: .9; margin-bottom: 5px; }
.card .bars i { display: block; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.card .bars i b { display: block; height: 100%; background: linear-gradient(90deg, #6ee7b7, #22c55e); }
.card .crest { width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 18px; border: 3px solid rgba(255, 255, 255, .7); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { flex: 1 1 40%; min-height: 46px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, .18); background: rgba(255, 255, 255, .08); color: #fff; font: inherit; font-size: 14px; font-weight: bold; padding: 6px 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.chip.sel { border-color: #ffd166; background: rgba(255, 209, 102, .14); }
.chip .sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; flex-shrink: 0; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat { background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14); border-radius: 12px; padding: 10px; }
.stat small { display: block; font-size: 12px; opacity: .75; }
.stat b { font-size: 20px; color: #ffd166; }
.spray { display: block; width: 100%; max-width: 300px; margin: 0 auto 4px; border-radius: 12px; background: #2f6b34; }
.legend { text-align: center; font-size: 12px; opacity: .85; margin-bottom: 10px; }
.legend .g { color: #8be07a; } .legend .y { color: #ffd166; } .legend .r { color: #ff7b6b; }
.ach { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, .06); margin-bottom: 6px; }
.ach .ico { font-size: 24px; width: 32px; text-align: center; filter: grayscale(1); opacity: .45; }
.ach.on .ico { filter: none; opacity: 1; }
.ach b { display: block; font-size: 14px; } .ach small { font-size: 12px; opacity: .75; }
.ach.on b { color: #ffd166; }

/* ---------- Game HUD ---------- */
#game-screen { background: transparent; pointer-events: none; }
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.hud-top .left { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.hud-top .right { display: flex; gap: 8px; align-items: center; }
.pill {
    background: var(--card); border: 1px solid rgba(255, 255, 255, .2); border-radius: 999px; padding: 5px 12px; min-height: 36px;
    font-weight: 800; font-size: 19px; text-shadow: 0 1px 2px #000; display: flex; align-items: center; gap: 4px; white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.pill small { font-weight: 600; font-size: 12px; opacity: .85; margin-left: 3px; }
.pill.sub { font-size: 13px; min-height: 26px; padding: 3px 10px; }
.pill.sub .dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid #fff; margin-left: 3px; }
.pill.sub .dot.on { background: #e53935; }
.pill.score { font-size: 15px; display: none; position: absolute; left: 0; top: 0; }
.pill.score.show { display: flex; }
.pill:empty { display: none; }
#btn-pause { pointer-events: auto; width: 40px; height: 40px; }
#btn-pause i { display: block; width: 4px; height: 14px; background: #fff; margin: 0 2px; border-radius: 1px; }
.hud-tag { position: absolute; right: 10px; top: 56px; font-size: 11px; font-weight: bold; letter-spacing: .5px; background: rgba(255, 200, 80, .25); border: 1px solid rgba(255, 200, 80, .6); border-radius: 999px; padding: 3px 9px; color: #ffe8b0; text-shadow: 0 1px 2px #000; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-tag:empty { display: none; }
.hud-wind { position: absolute; right: 10px; top: 84px; display: none; align-items: center; gap: 6px; font-size: 12px; font-weight: bold; background: var(--card); border-radius: 999px; padding: 3px 9px; }
.hud-wind.show { display: flex; }
.hud-wind .arr { display: inline-block; color: #8fd3ff; }
.banner {
    position: absolute; left: 0; right: 0; top: 27%; text-align: center; font-weight: 900; font-size: clamp(32px, 11vw, 46px); letter-spacing: 1px;
    color: #fff; text-shadow: 0 3px 0 #0b1a3f, 0 4px 14px rgba(0, 0, 0, .8); opacity: 0; transform: translateY(10px) scale(.96); transition: opacity .25s, transform .25s;
}
.banner small { display: block; font-size: 15px; font-weight: 800; letter-spacing: 2px; margin-top: 4px; }
.banner.show { opacity: 1; transform: none; }
.banner.good { text-shadow: 0 0 18px rgba(120, 255, 140, .6), 0 3px 0 #0b3f1a, 0 4px 14px rgba(0, 0, 0, .8); }
.banner.bad { color: #ffd9d2; }
.banner.gold { color: #ffe27a; text-shadow: 0 0 22px rgba(255, 200, 60, .8), 0 3px 0 #5a3a00, 0 4px 14px rgba(0, 0, 0, .8); }
.comment {
    position: absolute; left: 50%; bottom: 150px; transform: translate(-50%, 8px); max-width: 88%; text-align: center; font-size: 14px; font-weight: bold;
    background: rgba(8, 18, 40, .75); border-left: 4px solid #ffd166; border-radius: 8px; padding: 7px 12px; opacity: 0; transition: opacity .3s, transform .3s;
}
.comment.show { opacity: 1; transform: translate(-50%, 0); }
.hint { position: absolute; left: 12px; right: 12px; bottom: 24px; text-align: center; font-size: 15px; text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, .6); opacity: 0; transition: opacity .3s; }
.hint.show { opacity: 1; }
.hint small { display: block; font-size: 12px; opacity: .9; margin-top: 2px; }
.hint .keys { display: none; }
@media (hover: hover) and (pointer: fine) { .hint .keys { display: block; } }
.power { position: absolute; left: 14px; bottom: 90px; width: 14px; height: 130px; border-radius: 7px; background: rgba(0, 0, 0, .35); border: 1px solid rgba(255, 255, 255, .5); overflow: hidden; display: none; }
.power.show { display: block; }
.power i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(0deg, #8be07a, #ffd54f, #ff5252); }
.run-btn {
    position: absolute; right: 14px; bottom: 20px; width: 112px; height: 112px; border-radius: 50%; border: 4px solid #fff;
    background: radial-gradient(circle at 50% 35%, #ffcf5a, #f28c00); color: #3a2200; font: 900 20px Arial, sans-serif; display: none; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .5); pointer-events: auto; touch-action: none; cursor: pointer; z-index: 3; animation: pulse .6s ease-in-out infinite alternate;
}
.run-btn small { font-size: 11px; font-weight: bold; }
.run-btn.show { display: flex; }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(255, 210, 90, .5), 0 8px 20px rgba(0, 0, 0, .5); } to { box-shadow: 0 0 0 12px rgba(255, 210, 90, .25), 0 8px 20px rgba(0, 0, 0, .5); } }
.ach-toast {
    position: absolute; left: 50%; top: 100px; transform: translate(-50%, -20px); opacity: 0; transition: opacity .3s, transform .3s;
    background: #fff; color: var(--ink); border-radius: 14px; padding: 8px 14px; display: flex; gap: 10px; align-items: center; box-shadow: 0 8px 22px rgba(0, 0, 0, .35); white-space: nowrap; z-index: 5;
}
.ach-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ach-toast .ico { font-size: 24px; } .ach-toast small { display: block; font-size: 10px; color: #6b7280; text-transform: uppercase; letter-spacing: .5px; } .ach-toast b { font-size: 14px; }

/* ---------- Loading ---------- */
.loading { position: absolute; inset: 0; z-index: 500; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, #2a4f86, #0b1730); font-weight: bold; text-align: center; padding: 24px; }
.loading.hide { display: none; }
.nogl { display: none; }
.spin { width: 46px; height: 46px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .25); border-top-color: #ffd166; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modals ---------- */
.modal-overlay { position: absolute; inset: 0; background: transparent; display: none; align-items: center; justify-content: center; z-index: 400; padding: 12px; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; color: #374151; border-radius: 18px; padding: 16px 16px 0; width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; text-align: center; box-shadow: 0 15px 35px rgba(0, 0, 0, .45); animation: modalIn .25s ease; }
@keyframes modalIn { from { transform: scale(.92); opacity: 0; } }
.modal h2 { font-size: 22px; margin-bottom: 6px; color: var(--ink); }
.modal p { font-size: 14px; line-height: 1.45; margin: 4px 0; }
.modal .btn { width: 100%; max-width: 280px; margin: 5px auto; }
.modal .btn-primary { background: var(--orange); color: #3a2200; }
.modal .btn-secondary { background: #fff; color: var(--ink); border-color: var(--ink); }
.modal .btn-ghost.dark { color: var(--ink); }
.modal-buttons { padding: 8px 0 12px; }
.results .modal-buttons { position: sticky; bottom: 0; background: #fff; margin-top: 8px; box-shadow: 0 -8px 12px -8px rgba(0, 0, 0, .18); }
.modal.help { text-align: left; } .modal.help h2 { text-align: center; } .modal.help p { margin: 8px 0; font-size: 14px; }
.res-title { font-size: 13px; letter-spacing: 2.5px; color: #64748b; font-weight: bold; text-transform: uppercase; margin-bottom: 2px; }
.res-head { font-size: 24px; font-weight: 900; color: var(--ink); margin: 2px 0; }
.res-big { font-size: 48px; font-weight: 900; color: var(--ink); line-height: 1.05; }
.res-big small { font-size: 18px; color: #6b7280; margin-left: 4px; }
.record { display: inline-block; background: linear-gradient(#ffd166, #f5a524); color: #3a2200; font-weight: 900; padding: 5px 14px; border-radius: 14px; margin: 2px 0 6px; animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.res-table { width: 100%; border-collapse: collapse; font-size: 15px; color: #1f2937; margin: 6px 0; }
.res-table td { padding: 5px 4px; border-bottom: 1px solid #eef0f3; text-align: left; }
.res-table td:last-child { text-align: right; font-weight: bold; }
.res-table tr.total td { border-bottom: none; font-size: 18px; color: var(--ink); }
.pairs { display: flex; justify-content: center; gap: 5px; margin: 6px 0; flex-wrap: wrap; }
.pairs span { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: bold; color: #fff; background: #cbd5e1; }
.pairs span.ok { background: #2e7d32; } .pairs span.k { background: #f2a900; } .pairs span.no { background: #c62828; }
.pairs-row { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; font-weight: bold; color: #334155; }
.res-note { font-size: 14px !important; font-weight: bold; border-radius: 10px; padding: 6px 8px; margin: 6px 0 !important; }
.res-note.good { background: #e3f4dc; color: #1e5a20; }
.res-note.info { background: #fff3d6; color: #7a4a00; }
