:root {
    --bg: #0b0f1c;
    --ink: #16324f;
    --muted: #5f7590;
    --accent: #2f6fe0;
    --accent-2: #ffd21f;
    --gold: #ffc21f;
    --card: #ffffff;
    --line: rgba(43, 35, 80, 0.16);
    --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
}

/* ---------- HUD ---------- */
.hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hud-right { display: flex; justify-content: flex-end; gap: 8px; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 16px;
    font-weight: 900;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border-radius: 999px;
    box-shadow: 0 3px 0 rgba(43, 35, 80, 0.14);
    font-variant-numeric: tabular-nums;
}
.pill.big { font-size: 22px; padding: 4px 14px 4px 10px; }
.pill .star { font-family: var(--emoji); font-size: 20px; line-height: 1; }
.pill.big.bump { animation: bump 0.45s ease-out; }
@keyframes bump {
    30% { transform: scale(1.35) rotate(-6deg); }
    60% { transform: scale(0.95); }
}

.tool {
    pointer-events: auto;
    position: relative;
    width: 42px; height: 42px;
    display: grid; place-items: center;
    padding: 0;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border: 0;
    border-radius: 50%;
    box-shadow: 0 3px 0 rgba(43, 35, 80, 0.14);
    cursor: pointer;
    touch-action: none;
}
.tool svg { width: 22px; height: 22px; fill: currentColor; overflow: visible; }
.tool .cross { display: none; }
.tool.muted .wave { display: none; }
.tool.muted .cross { display: inline; }
.tool:active { transform: scale(0.94); }

/* ---------- transient messages ---------- */
.banner {
    position: fixed;
    top: calc(84px + env(safe-area-inset-top));
    left: 0; right: 0;
    z-index: 4;
    text-align: center;
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif, var(--emoji);
    font-size: clamp(30px, 9vw, 56px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 3px 0 rgba(10, 10, 40, 0.5), 0 0 24px rgba(180, 140, 255, 0.95);
    opacity: 0;
    pointer-events: none;
}
.banner.show { animation: banner 1.9s ease-out; }
@keyframes banner {
    0% { opacity: 0; transform: scale(0.5) rotate(-6deg); }
    14% { opacity: 1; transform: scale(1.18) rotate(3deg); }
    26% { transform: scale(1) rotate(0); }
    78% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.08); }
}

/* ---------- screens ---------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    padding: 16px;
    background: rgba(3, 4, 18, 0.55);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    overflow-y: auto;
}
.card {
    width: min(420px, 100%);
    margin: auto;
    padding: 22px 22px 18px;
    text-align: center;
    background: var(--card);
    border-radius: 28px;
    box-shadow: 0 10px 0 rgba(43, 35, 80, 0.16), 0 24px 60px rgba(43, 35, 80, 0.3);
}

h1, h2 { margin: 0; font-weight: 900; letter-spacing: 0.01em; }
h1 {
    font-size: clamp(27px, 8.2vw, 38px);
    line-height: 1.05;
    background: linear-gradient(90deg, #2f80ed, #36c66f 50%, #f2b52a);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
h2 { font-size: 28px; margin-bottom: 10px; }

.tagline { margin: 6px 0 14px; color: var(--muted); font-size: 16px; font-weight: 700; }

.logo { display: block; width: 200px; height: 104px; margin: 0 auto 6px; border-radius: 18px; }

.howto {
    list-style: none;
    margin: 0 0 6px;
    padding: 0;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    color: #4a4570;
}
.howto li { display: flex; gap: 10px; align-items: flex-start; padding: 4px 0; }
.howto strong { color: var(--ink); }
.dot { flex: none; width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; }

.keys { margin: 12px 0 0; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); }

.btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 14px 16px;
    font: inherit;
    font-size: 18px;
    font-weight: 900;
    color: var(--ink);
    background: #f1f0f8;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 4px 0 #d8d5ea;
    cursor: pointer;
    transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d8d5ea; }
.btn:hover { filter: brightness(1.04); }
.btn:focus-visible, .tool:focus-visible, input:focus-visible { outline: 3px solid #2f9cf0; outline-offset: 2px; }
.btn.primary {
    padding: 16px;
    font-size: 22px;
    color: #fff;
    background: linear-gradient(180deg, #4fd384, #23a35a);
    box-shadow: 0 5px 0 #17703d;
    text-shadow: 0 2px 0 rgba(30, 10, 90, 0.4);
}
.btn.primary:active { box-shadow: 0 2px 0 #17703d; }
.btn.small { width: auto; margin: 0; padding: 0 16px; font-size: 14px; white-space: nowrap; background: #ffe7a3; box-shadow: 0 3px 0 #f0c64a; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- finish screen ---------- */
.newbest {
    display: inline-block;
    margin-bottom: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #4a3200;
    background: var(--gold);
    border-radius: 999px;
}
.final {
    font-size: clamp(54px, 17vw, 76px);
    font-weight: 900;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 0 rgba(47, 111, 224, 0.2);
}
.unit { margin: 2px 0 0; font-size: 14px; font-weight: 800; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stats div { padding: 10px 4px; background: #f6f5fb; border-radius: 16px; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.save { display: flex; gap: 8px; }
.save input {
    flex: 1;
    min-width: 0;
    height: 46px;
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    background: #fff;
    border: 2px solid #d8d5ea;
    border-radius: 14px;
    -webkit-user-select: text;
    user-select: text;
}
.save .btn { height: 43px; }

.note { min-height: 18px; margin: 10px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

.board { list-style: none; margin: 0 0 6px; padding: 0; text-align: left; font-size: 14px; font-weight: 700; }
.board li {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 10px;
    border-radius: 12px;
    font-variant-numeric: tabular-nums;
}
.board li:nth-child(odd) { background: #f6f5fb; }
.board li.me { background: #fff0c2; outline: 2px solid var(--gold); }
.board .rank { font-weight: 900; color: var(--muted); }
.board li:nth-child(1) .rank { color: #e08a00; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 900; }
.board li.empty { display: block; text-align: center; color: var(--muted); background: none; }

@media (max-height: 620px) {
    .card { padding: 14px 18px; }
    .logo { display: none; }
    .howto { font-size: 13px; margin-bottom: 8px; }
    .howto li { padding: 2px 0; }
    .btn { padding: 10px 14px; margin-top: 8px; }
    .btn.primary { padding: 12px; font-size: 20px; }
    .stats { margin: 10px 0; }
}

@media (prefers-reduced-motion: reduce) {
    .pill.big.bump { animation: none; }
}


/* ---------- Tank Clash extras ---------- */
body { background: #0b0f1c; }
#stage { cursor: crosshair; touch-action: none; }
.card { color: var(--ink); }
.howto .dot { width: auto; height: auto; margin: 0; border-radius: 0; font-family: var(--emoji); font-size: 18px; line-height: 1.2; }
.logo { display: flex; justify-content: center; gap: 8px; width: auto; height: auto; margin-bottom: 4px; font-family: var(--emoji); font-size: 44px; line-height: 1.2; }
.logo span { animation: bob 2.4s ease-in-out infinite; }
.logo span:nth-child(2) { animation-delay: 0.3s; }
.logo span:nth-child(3) { animation-delay: 0.6s; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-6deg); } }
.btn small { display: block; margin-top: 2px; font-size: 12px; font-weight: 700; opacity: 0.85; text-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.card.wide { width: min(600px, 100%); }
.card h3 { margin: 14px 0 6px; font-size: 13px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); text-align: left; }
.micon { font-family: var(--emoji); font-size: 50px; line-height: 1.1; margin-bottom: 4px; }
.bigstars { margin: 2px 0 6px; font-family: var(--emoji); font-size: 38px; letter-spacing: 4px; }
.stats b { font-family: ui-rounded, system-ui, var(--emoji); }

/* HUD */
.hud {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    grid-template-columns: none;
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left));
    pointer-events: none;
    color: #fff;
}
.hud-left { flex: 1; min-width: 0; display: grid; gap: 2px; line-height: 1.15; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8); }
.hud-left b { font-size: 16px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-left span { font-size: 14px; font-weight: 800; color: #ffe27a; font-family: ui-rounded, system-ui, var(--emoji); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-mid { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px; max-width: 52%; }
.hud .pill { padding: 2px 9px; font-size: 14px; color: #0d1430; background: rgba(255, 255, 255, 0.88); white-space: nowrap; }
.hud .pill .ico { font-family: var(--emoji); font-size: 13px; }
.pill.hp { font-family: var(--emoji); font-size: 13px; letter-spacing: 1px; }
.pill.pw { font-family: ui-rounded, system-ui, var(--emoji); font-size: 13px; background: #ffe27a; }
.hud-right { display: flex; gap: 6px; pointer-events: auto; }
.hud .tool { width: 38px; height: 38px; }
.hud .tool svg { width: 20px; height: 20px; }

.msg {
    position: fixed;
    top: calc(70px + env(safe-area-inset-top));
    left: 50%;
    z-index: 6;
    max-width: min(560px, calc(100% - 24px));
    padding: 8px 14px;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    text-align: center;
    background: rgba(10, 14, 30, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
    font-family: ui-rounded, system-ui, var(--emoji);
}
.msg.show { opacity: 1; }
.banner { top: 34%; font-size: clamp(28px, 7vw, 52px); color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.6), 0 0 24px rgba(80, 220, 140, 0.95); z-index: 7; }

/* touch controls */
.touch { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 calc(16px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); pointer-events: none; }
.stick { position: relative; width: 132px; height: 132px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.24); pointer-events: auto; touch-action: none; }
.stick.aim { background: rgba(255, 120, 80, 0.1); border-color: rgba(255, 150, 110, 0.45); }
.knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: rgba(120, 180, 255, 0.55); box-shadow: 0 0 14px rgba(120, 180, 255, 0.6); }
.stick.aim .knob { background: rgba(255, 140, 100, 0.6); box-shadow: 0 0 14px rgba(255, 120, 80, 0.6); }
.slabel { position: absolute; left: 50%; bottom: -16px; transform: translateX(-50%); font-size: 10px; font-weight: 900; letter-spacing: 0.08em; color: rgba(255, 255, 255, 0.55); white-space: nowrap; pointer-events: none; }

/* campaign */
.zone { margin: 0 0 12px; text-align: left; }
.zone h3 { margin: 6px 2px 6px; }
.lvls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lvl { display: grid; place-items: center; gap: 0; padding: 8px 2px 6px; font: inherit; color: #fff; background: linear-gradient(180deg, #c99a4e, #9c7232); border: 0; border-radius: 14px; box-shadow: 0 3px 0 #6b4c1d; cursor: pointer; }
.lvl.z1 { background: linear-gradient(180deg, #5b8fd6, #3a67a8); box-shadow: 0 3px 0 #23436f; }
.lvl.z2 { background: linear-gradient(180deg, #7a4fd6, #4c2ca0); box-shadow: 0 3px 0 #2e1868; }
.lvl b { font-size: 18px; font-weight: 900; }
.lvl small { font-family: var(--emoji); font-size: 10px; letter-spacing: -1px; line-height: 1.2; min-height: 12px; }
.lvl.locked { color: #9aa3c4; background: #e7e9f3; box-shadow: none; cursor: default; }

@media (max-width: 480px) {
    .hud-left b { font-size: 14px; }
    .hud-left span { font-size: 13px; }
    .hud .tool { width: 34px; height: 34px; }
    .hud .pill { font-size: 12px; padding: 2px 7px; }
}
@media (max-height: 520px) {
    .stick { width: 110px; height: 110px; }
    .knob { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
    .msg { top: calc(56px + env(safe-area-inset-top)); font-size: 13px; }
    .logo { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .logo span { animation: none; }
}
