:root {
    --ash-0: #1a0606;
    --ash-1: #2b0909;
    --ash-2: #5c1d13;
    --ash-3: #9e2a2b;
    --ember: #ff4d00;
    --ember-2: #ff9e00;
    --gold: #ffb703;
    --clay: #b5651d;
    --parch: #f3e2c7;
    --ink: #2a1608;
}

* { box-sizing: border-box; }

html, body, #root {
    width: 100%; height: 100%; height: 100dvh;
    margin: 0; padding: 0;
    background: #000; color: var(--parch);
    font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
    overflow: hidden; -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 30%, #3a120a 0%, #120404 70%, #000 100%);
}
#game-container { position: absolute; inset: 0; width: 100%; height: 100%; }
#game-container canvas { display: block; }

#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud .screen, #hud .hud-top, #hud .hud-resources, #hud .objective, #hud .joy, #hud .attack-btn, #hud .modal { pointer-events: auto; }

/* ---------------- Buttons ---------------- */
.btn {
    font-family: inherit; font-weight: 800; letter-spacing: 0.06em;
    border: none; border-radius: 12px; cursor: pointer; color: var(--parch);
    padding: 12px 22px; font-size: 15px; transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
    text-transform: uppercase;
}
.btn:active { transform: translateY(2px) scale(0.99); }
.btn-lg { font-size: 22px; padding: 16px 40px; border-radius: 16px; }
.btn-primary {
    background: linear-gradient(180deg, var(--gold), #e07a1f);
    color: #2a1004; box-shadow: 0 6px 0 #7a3c08, 0 10px 26px rgba(255, 150, 0, 0.45);
}
.btn-primary:hover { box-shadow: 0 6px 0 #7a3c08, 0 14px 34px rgba(255, 170, 0, 0.6); transform: translateY(-1px); }
.btn-ghost { background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 183, 3, 0.35); color: var(--parch); }
.btn-ghost:hover { background: rgba(255, 183, 3, 0.14); }
.btn-ghost.danger { border-color: rgba(255, 77, 0, 0.5); color: #ffcaa0; }
.btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.wide { width: 100%; display: flex; gap: 10px; align-items: center; justify-content: center; margin: 8px 0; }

/* ---------------- Screens ---------------- */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; }

/* Menu */
.menu-screen { background: radial-gradient(ellipse at 50% 120%, rgba(217, 90, 43, 0.5), transparent 60%), linear-gradient(180deg, rgba(26, 6, 6, 0.35), rgba(20, 4, 4, 0.82)); }
.menu-embers { position: absolute; inset: 0; background-image: radial-gradient(2px 2px at 20% 30%, rgba(255, 158, 0, 0.8), transparent), radial-gradient(2px 2px at 70% 60%, rgba(255, 77, 0, 0.7), transparent), radial-gradient(1.5px 1.5px at 40% 80%, rgba(255, 183, 3, 0.7), transparent), radial-gradient(1.5px 1.5px at 85% 25%, rgba(255, 120, 0, 0.6), transparent); animation: drift 9s linear infinite; opacity: 0.8; }
@keyframes drift { from { transform: translateY(0); } to { transform: translateY(-40px); } }
.menu-inner { position: relative; z-index: 2; padding: 24px; max-width: 640px; }
.eyebrow { letter-spacing: 0.4em; font-size: 12px; color: var(--ember-2); margin: 0 0 6px; font-weight: 700; }
.title { font-size: clamp(56px, 13vw, 120px); line-height: 0.9; margin: 0; font-weight: 900; letter-spacing: 0.02em; color: var(--parch); text-shadow: 0 0 24px rgba(255, 77, 0, 0.6), 0 6px 0 #3a0e04; }
.title span { color: var(--gold); }
.subtitle { font-size: clamp(16px, 3.4vw, 26px); margin: 6px 0 2px; color: #ffd9a8; font-weight: 700; letter-spacing: 0.12em; }
.tagline { font-style: italic; color: #e9b98c; margin: 0 0 22px; font-size: clamp(13px, 2.4vw, 17px); }
.diff-row { display: flex; gap: 8px; justify-content: center; margin: 4px 0 18px; }
.diff-btn { font-family: inherit; font-weight: 800; font-size: 13px; letter-spacing: 0.08em; padding: 8px 16px; border-radius: 999px; cursor: pointer; color: #e9b98c; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 183, 3, 0.25); transition: all 0.12s; }
.diff-btn.on { background: linear-gradient(180deg, var(--gold), #e07a1f); color: #2a1004; border-color: transparent; box-shadow: 0 4px 14px rgba(255, 150, 0, 0.4); }
.hint { margin-top: 18px; font-size: 12px; color: rgba(243, 226, 199, 0.6); letter-spacing: 0.04em; }

/* Modal */
.modal { position: absolute; inset: 0; background: rgba(10, 3, 3, 0.7); display: flex; align-items: center; justify-content: center; backdrop-filter: blur(3px); z-index: 5; }
.modal-card { background: linear-gradient(180deg, #2e120a, #1c0806); border: 1px solid rgba(255, 183, 3, 0.3); border-radius: 18px; padding: 28px 30px; max-width: 460px; width: 90%; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); }
.modal-card h2 { margin: 0 0 14px; color: var(--gold); letter-spacing: 0.05em; }
/* ---- Harvest Protector settings & polish toggles (QA wiring) ---- */
.settings-head { margin: 14px 0 8px; font-size: 12px; font-weight: 800; letter-spacing: 0.14em; color: var(--ember-2); text-transform: uppercase; }
.protector-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.protector-btn { text-align: left; padding: 10px 12px; border-radius: 12px; }
.protector-btn .diff-name { display: block; font-size: 12px; }
.protector-btn .diff-desc { display: block; font-size: 10px; opacity: 0.75; margin-top: 2px; }
.protector-btn.on { box-shadow: 0 0 0 1px var(--rank-color, var(--gold)), 0 4px 14px rgba(255, 150, 0, 0.35); }
.settings-slider { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #e9b98c; margin: 10px 0; }
.settings-slider input[type="range"] { flex: 1; accent-color: var(--gold); }
.hud-card.protector-card { min-width: 170px; border-color: rgba(140, 195, 74, 0.35); }
.help-list { text-align: left; line-height: 1.7; font-size: 14px; color: #f0d9b8; padding-left: 18px; }
.help-list b { color: var(--ember-2); }

/* ---- QA: menu rank badge & mode button label/desc stacking (fix "Bronze III0 RP" run-on) ---- */
.rank-meta { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.rank-tier { font-weight: 800; letter-spacing: 0.06em; }
.rank-sub { font-size: 11px; opacity: 0.8; }
.diff-btn .diff-name { display: block; font-size: 13px; font-weight: 800; letter-spacing: 0.08em; }
.diff-btn .diff-desc { display: block; font-size: 10px; opacity: 0.75; margin-top: 2px; }

/* ---- QA: Season 2 Battle Pass track (Settings hub tab) ---- */
.bp-track { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.bp-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(255, 183, 3, 0.18); background: rgba(0, 0, 0, 0.25); opacity: 0.65; }
.bp-row.unlocked { opacity: 1; border-color: rgba(255, 183, 3, 0.5); }
.bp-row.claimed { border-color: rgba(140, 195, 74, 0.55); }
.bp-icon { font-size: 22px; }
.bp-meta { flex: 1; display: flex; flex-direction: column; gap: 2px; text-align: left; }
.bp-name { font-size: 12px; font-weight: 800; letter-spacing: 0.05em; color: var(--gold, #ffb703); }
.bp-desc { font-size: 10px; opacity: 0.75; }
.bp-req { font-size: 10px; opacity: 0.6; }
.bp-claim { min-width: 92px; font-size: 11px; }

/* ---- Settings & Guide Hub (tabbed) ---- */
.settings-card { max-width: 620px; max-height: 86%; display: flex; flex-direction: column; }
.settings-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid rgba(255, 183, 3, 0.2); padding-bottom: 10px; }
.tab-btn { font-family: inherit; font-weight: 800; font-size: 12px; letter-spacing: 0.06em; padding: 7px 13px; border-radius: 999px; cursor: pointer; color: #e9b98c; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 183, 3, 0.25); transition: all 0.12s; }
.tab-btn.on { background: linear-gradient(180deg, var(--gold), #e07a1f); color: #2a1004; border-color: transparent; box-shadow: 0 3px 12px rgba(255, 150, 0, 0.4); }
.settings-tab-pane { flex: 1; overflow-y: auto; text-align: left; padding-right: 4px; }
.settings-note { font-size: 12px; line-height: 1.6; color: #e9b98c; font-style: italic; margin: 8px 0; }
.guide-grid { display: flex; flex-direction: column; }
.guide-abilities { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 6px; }
.guide-ability { display: flex; gap: 10px; align-items: flex-start; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 183, 3, 0.15); border-radius: 10px; padding: 8px 10px; }
.guide-ability b { display: block; font-size: 13px; color: var(--parch); }
.guide-ability span:not(.ga-icon) { display: block; font-size: 11px; line-height: 1.5; color: #e9b98c; }
.ga-icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.ga-icon svg { width: 18px; height: 18px; }
.ga-icon.spear { background: rgba(255, 183, 3, 0.15); color: var(--gold); }
.ga-icon.charm { background: rgba(140, 195, 74, 0.15); color: #8cc34a; }
.ga-icon.water { background: rgba(95, 179, 212, 0.15); color: #5fb3d4; }
.protector-stat-card { margin: 12px 0 6px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 183, 3, 0.25); border-left: 3px solid var(--rank-color, var(--gold)); border-radius: 10px; padding: 10px 12px; }
.psc-title { font-size: 13px; font-weight: 900; letter-spacing: 0.06em; color: var(--rank-color, var(--gold)); margin-bottom: 8px; }
.psc-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.stat-pill { font-size: 11px; font-weight: 700; color: #f0d9b8; background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255, 183, 3, 0.2); border-radius: 999px; padding: 4px 10px; }

/* Countdown */
.count-screen { flex-direction: column; background: radial-gradient(circle at 50% 50%, rgba(43, 9, 9, 0.2), rgba(10, 2, 2, 0.55)); }
.brief { font-size: clamp(18px, 4vw, 30px); font-weight: 900; letter-spacing: 0.1em; color: var(--parch); text-shadow: 0 0 18px rgba(255, 77, 0, 0.6); margin-bottom: 10px; }
.count-num { font-size: clamp(80px, 22vw, 200px); font-weight: 900; color: var(--gold); text-shadow: 0 0 40px rgba(255, 150, 0, 0.8), 0 8px 0 #3a0e04; animation: pop 1s ease-out; }
@keyframes pop { 0% { transform: scale(0.3); opacity: 0; } 40% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }

/* ---------------- HUD ---------------- */
.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 12px; align-items: stretch; padding: 12px 14px; }
.hud-card { background: linear-gradient(180deg, rgba(40, 14, 8, 0.82), rgba(20, 6, 4, 0.82)); border: 1px solid rgba(255, 183, 3, 0.22); border-radius: 12px; padding: 8px 12px; min-width: 150px; backdrop-filter: blur(2px); }
.hud-card.granary-card { flex: 1; max-width: 360px; }
.hud-card.granary-card.low { border-color: rgba(255, 77, 0, 0.7); }
.hud-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; letter-spacing: 0.1em; color: var(--ember-2); margin-bottom: 6px; }
.hud-label svg { width: 14px; height: 14px; }
.bar { height: 12px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); overflow: hidden; border: 1px solid rgba(0, 0, 0, 0.4); }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.25s ease; }
.bar-pulse { animation: barpulse 0.8s ease-in-out infinite; }
@keyframes barpulse { 0%, 100% { box-shadow: 0 0 0 rgba(255, 77, 0, 0); } 50% { box-shadow: 0 0 14px rgba(255, 77, 0, 0.8); } }
.score-card { text-align: right; min-width: 160px; }
.score-val { font-size: 24px; font-weight: 900; color: var(--gold); line-height: 1; }
.wave-val { font-size: 11px; color: #e9b98c; letter-spacing: 0.06em; margin-top: 4px; }
.hud-btn { margin-left: auto; align-self: center; width: 46px; height: 46px; border-radius: 12px; border: 1px solid rgba(255, 183, 3, 0.3); background: rgba(40, 14, 8, 0.82); color: var(--gold); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.hud-btn svg { width: 22px; height: 22px; }

.hud-resources { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 10px; }
.res-badge { display: flex; align-items: center; gap: 6px; background: rgba(20, 6, 4, 0.8); border: 1px solid rgba(255, 183, 3, 0.22); border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: 15px; color: var(--parch); }
.res-badge .ri { width: 18px; height: 18px; display: inline-flex; }
.res-badge .ri svg { width: 18px; height: 18px; }
.res-badge .food { color: var(--gold); }
.res-badge .wood { color: #c98a4b; }
.res-badge .water { color: #5fb3d4; }

.objective { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: 80%; text-align: center; font-size: 13px; font-weight: 700; letter-spacing: 0.04em; color: #ffd9a8; background: rgba(20, 6, 4, 0.72); border: 1px solid rgba(255, 183, 3, 0.2); border-radius: 999px; padding: 8px 18px; text-shadow: 0 1px 2px #000; }
.objective.break { color: var(--gold); border-color: rgba(255, 183, 3, 0.5); animation: barpulse 1.2s infinite; }

/* ---------------- Pause / Over ---------------- */
.pause-screen, .over-screen { background: rgba(8, 2, 2, 0.72); backdrop-filter: blur(4px); z-index: 6; }
.pause-card { display: flex; flex-direction: column; gap: 12px; align-items: center; background: linear-gradient(180deg, #2e120a, #1c0806); border: 1px solid rgba(255, 183, 3, 0.3); border-radius: 18px; padding: 30px 40px; }
.pause-card h2 { margin: 0 0 6px; color: var(--gold); letter-spacing: 0.12em; font-size: 30px; }
.over-card { display: flex; flex-direction: column; align-items: center; gap: 10px; background: linear-gradient(180deg, #2e120a, #160604); border: 1px solid rgba(255, 183, 3, 0.3); border-radius: 22px; padding: 34px 44px; max-width: 520px; width: 92%; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6); }
.over-card h2 { margin: 0; font-size: clamp(26px, 6vw, 44px); letter-spacing: 0.04em; }
.over-card.won h2 { color: var(--gold); text-shadow: 0 0 24px rgba(255, 183, 3, 0.6); }
.over-card.lost h2 { color: #ff6a3d; text-shadow: 0 0 24px rgba(255, 77, 0, 0.5); }
.over-reason { font-style: italic; color: #e9b98c; margin: 0 0 8px; }
.over-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 8px 0 14px; width: 100%; }
.over-stats div { display: flex; flex-direction: column; }
.over-stats span { font-size: 26px; font-weight: 900; color: var(--parch); }
.over-stats label { font-size: 10px; letter-spacing: 0.12em; color: var(--ember-2); }

/* ---------------- Touch controls ---------------- */
.joy { position: absolute; left: 22px; bottom: 78px; width: 132px; height: 132px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 183, 3, 0.12), rgba(0, 0, 0, 0.28)); border: 2px solid rgba(255, 183, 3, 0.3); touch-action: none; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: linear-gradient(180deg, var(--gold), #e07a1f); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); pointer-events: none; will-change: transform; }

/* ---- Season 2 directional compass joystick (plan §2/§4) ---- */
.joy-compass { position: absolute; inset: -10px; border-radius: 50%; border: 2px solid rgba(255, 215, 102, 0.45); box-shadow: 0 0 14px rgba(255, 158, 0, 0.25), inset 0 0 12px rgba(255, 158, 0, 0.15); pointer-events: none; }
.joy-dir-label { position: absolute; font-size: 11px; font-weight: 900; letter-spacing: 0.08em; color: #ffd766; text-shadow: 0 0 6px rgba(255, 122, 0, 0.8); pointer-events: none; }
.joy-n { left: 50%; top: -4px; transform: translate(-50%, -100%); }
.joy-s { left: 50%; bottom: -4px; transform: translate(-50%, 100%); }
.joy-w { top: 50%; left: -4px; transform: translate(-100%, -50%); }
.joy-e { top: 50%; right: -4px; transform: translate(100%, -50%); }
.joy-pointer-ring { position: absolute; inset: 6px; border-radius: 50%; border: 2px dashed rgba(255, 183, 3, 0.55); pointer-events: none; will-change: transform; }
.joy-arrow { position: absolute; left: 50%; top: -3px; width: 0; height: 0; margin-left: -7px; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 13px solid #ffd766; filter: drop-shadow(0 0 6px rgba(255, 122, 0, 0.9)); }
.joy.joy-active { border-color: rgba(255, 215, 102, 0.65); }
.attack-btn { position: absolute; right: 22px; bottom: 86px; width: 104px; height: 104px; border-radius: 50%; border: none; background: radial-gradient(circle at 40% 35%, #ff7a3d, #b5300a); color: #fff; box-shadow: 0 6px 0 #6e1c04, 0 10px 26px rgba(255, 77, 0, 0.5); display: flex; align-items: center; justify-content: center; touch-action: none; }
.attack-btn svg { width: 52px; height: 52px; }
.attack-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #6e1c04; }

@media (max-width: 560px) {
    .hud-card { min-width: 110px; padding: 6px 8px; }
    .score-val { font-size: 18px; }
    .over-stats { grid-template-columns: repeat(2, 1fr); }
}