/* Fonts are self-hosted subsets (see fonts/README.md): Cinzel for titles, Ma Shan Zheng
   brush calligraphy for the Chinese characters the game uses. */
@font-face { font-family: 'Cinzel'; src: url('fonts/cinzel-600.woff2?v=1') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Cinzel'; src: url('fonts/cinzel-700.woff2?v=1') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Ma Shan Zheng'; src: url('fonts/ma-shan-zheng.woff2?v=1') format('woff2'); font-display: swap; }

:root {
    --night: #0b0f1a;
    --panel: rgba(11, 15, 26, 0.82);
    --slate: #1a2233;
    --text: #f2f4ff;
    --dim: #9aa3bf;
    --sun: #FFD93D;
    --ember: #FF4D4D;
    /* Notches and the home bar (the page is viewport-fit=cover). */
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0; height: 100%; overflow: hidden;
    background: var(--night); color: var(--text);
    font-family: Nunito, system-ui, -apple-system, 'Segoe UI', sans-serif;
    user-select: none;
}

#game, #overlay { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
body[data-state=play] #game { cursor: crosshair; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
body[data-state=menu] #hud > :not(#board):not(#feed) { display: none; }
body:not([data-state=play]) #radar, body:not([data-state=play]) #hud-stats { opacity: 0.25; }

#feed { position: absolute; top: calc(60px + var(--safe-t)); left: calc(18px + var(--safe-l)); font-size: 12.5px; color: rgba(235,235,245,0.6); display: flex; flex-direction: column; gap: 4px; }
#board { position: absolute; top: calc(14px + var(--safe-t)); right: calc(60px + var(--safe-r)); width: 210px; font-size: 12.5px; background: rgba(18,18,26,0.38); border: 1px solid rgba(255,255,255,0.07); border-radius: 14px; padding: 8px 12px; backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); }
#board .row { display: flex; gap: 8px; line-height: 1.7; font-variant-numeric: tabular-nums; }
#board .row.me { background: rgba(255,255,255,0.09); border-radius: 7px; margin: 0 -6px; padding: 0 6px; }
#board .n { width: 22px; color: rgba(235,235,245,0.45); }
#board .name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#board .v { color: var(--dim); }
#board .total { margin-top: 4px; padding-top: 5px; border-top: 1px solid rgba(255,255,255,0.08); text-align: right; font-size: 11px; color: rgba(235,235,245,0.45); }

/* Messages: every toast, tip and voice caption, and the status lines (wall
   warning, steering you clear, reconnecting), in one stack just below the
   centre, newest on top (hud.js), so a new one always lands in the same
   spot. It starts clear of the reticle and the steering dead zone and ends
   above the radar (and on phones the buttons): --msg-top and --msg-foot,
   per layout below. Your own dragon flies just below the centre, so it's
   compact and see-through: thin pills, no blur. */
#msgs { --msg-top: clamp(26px, 4.5vh, 44px); --msg-foot: calc(166px + var(--safe-b));
    position: absolute; left: 0; right: 0; top: calc(50% + var(--msg-top)); max-height: calc(50% - var(--msg-top) - var(--msg-foot));
    display: flex; flex-direction: column; align-items: center; gap: 5px; overflow: hidden; }
#msg-status { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.msg { max-width: min(560px, 86vw); padding: 2px 13px; border-radius: 999px; background: rgba(10, 8, 6, 0.28); text-align: center; text-wrap: balance;
    font-weight: 700; font-size: 17px; line-height: 1.3; letter-spacing: 0.01em; color: #F5EEE1;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75), 0 0 12px rgba(0, 0, 0, 0.45); }
/* A message pops in, holds, then fades out and leaves (on the fade's
   animationend); hud.js msgTime sets the three times per message. */
#msgs > .msg { animation: msg-pop var(--msg-in) ease-out, msg-out var(--msg-fade) ease-out var(--msg-fade-at) forwards; }
.msg.big { font-size: 22px; font-weight: 800; color: #FFD60A; }
.msg.nm { color: #64D2FF; }
.msg.bad, #hud-warn { color: #FF453A; }
.msg.hint { font-size: 14px; font-weight: 600; color: rgba(245, 238, 225, 0.92); }
.msg.caption { border-radius: 14px; padding: 1px 16px 3px; }
.msg.caption .zh { font-family: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', serif; font-weight: 400; font-size: 32px; line-height: 1.15; letter-spacing: 0.08em; color: #F3DDA4; }
.msg.caption .say { font-size: 12px; font-weight: 600; letter-spacing: 0.03em; color: rgba(245, 238, 225, 0.78); }
#msg-status .msg { animation: msg-in 0.2s ease-out; }
#hud-warn { font-weight: 800; }
#hud-assist { font-size: 13px; color: var(--jade); }
#net-note { display: none; font-size: 14px; }
#msg-status #net-note { animation: gPulse 0.9s ease-in-out infinite alternate; }
body[data-net=reconnecting]:not([data-state=pause]) #net-note { display: block; }   /* paused, the pause panel says it */
@keyframes msg-pop { from { opacity: 0; transform: translateY(-6px) scale(0.96); } }
@keyframes msg-out { to { opacity: 0; } }
@keyframes msg-in { from { opacity: 0; } }


#radar { position: absolute; left: 50%; bottom: calc(8px + var(--safe-b)); width: 220px; height: 150px; transform: translateX(-50%); }
#hud-fps { position: absolute; right: 18px; bottom: 4px; font-size: 10px; color: var(--dim); }

/* ---------------- Panels ---------------- */
.panel {
    position: fixed; left: calc(50% + (var(--safe-l) - var(--safe-r)) / 2); top: calc(50% + (var(--safe-t) - var(--safe-b)) / 2); transform: translate(-50%, -50%);
    background: var(--panel); border: 1px solid var(--slate); border-radius: 16px;
    padding: 22px 26px; width: min(420px, calc(100vw - 32px - var(--safe-l) - var(--safe-r))); text-align: center;
    max-height: calc(100% - 24px - var(--safe-t) - var(--safe-b)); overflow-y: auto;
    display: none; backdrop-filter: blur(4px);
}
body[data-state=menu]:not([data-overlay]) #menu { display: block; }
body[data-state=pause]:not([data-overlay]) #pause { display: block; }
body[data-overlay=settings] #settings, body[data-overlay=controls] #controls { display: block; }
body[data-state=dead][data-card="1"] #card { display: block; }

h1 { margin: 0; font-size: 56px; letter-spacing: 0.12em; font-weight: 900; color: var(--sun); text-shadow: 0 0 24px rgba(255,217,61,0.35); }
h2 { margin: 0 0 14px; font-size: 22px; }
.sub { color: var(--dim); font-size: 13px; margin-bottom: 16px; }

#name { width: 100%; font: inherit; font-size: 18px; font-weight: 700; text-align: center; padding: 10px; border-radius: 10px; border: 1px solid var(--slate); background: #0f1526; color: var(--text); }
.arenas { display: flex; gap: 8px; margin: 12px 0; }
.arenas label { flex: 1; border: 1px solid var(--slate); border-radius: 10px; padding: 8px; cursor: pointer; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.arenas label span { font-size: 11px; color: var(--dim); }
.arenas label:has(input:checked) { border-color: var(--sun); background: rgba(255,217,61,0.08); }
.arenas input { display: none; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--slate); background: #141b2e; color: var(--text); padding: 8px 16px; margin: 4px; }
button.cta { background: var(--sun); color: #1a1400; border: none; font-weight: 900; font-size: 20px; width: 100%; padding: 12px; margin: 6px 0; }
button.cta small { font-weight: 600; font-size: 12px; opacity: 0.7; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; text-align: left; font-size: 13px; color: var(--dim); margin: 6px 0 12px; }
.keys b { color: var(--text); font-weight: 700; }
.keys kbd { display: inline-block; font: 700 15px/1 ui-monospace, Menlo, Consolas, monospace; padding: 2px 7px 1px; border: 1px solid var(--gold-line); border-radius: 5px; background: rgba(255, 240, 210, 0.08); }
.menu-row { display: flex; gap: 8px; }
.menu-row button { flex: 1; margin: 4px 0; }
.opt { display: flex; gap: 10px; align-items: flex-start; text-align: left; font-size: 14px; padding: 8px 4px; border-bottom: 1px solid var(--slate); cursor: pointer; }
.opt input { flex: none; margin-top: 3px; width: 16px; height: 16px; accent-color: var(--sun); }
.opt small { display: block; color: var(--dim); font-size: 12px; }
.opt.big { font-size: 16px; }
.home { display: inline-block; margin-top: 10px; color: var(--dim); font-size: 12px; text-decoration: none; }

#card .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; }
#card .grid div { background: rgba(255,255,255,0.04); border-radius: 10px; padding: 8px; }
#card .grid span { display: block; font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; }
#card .grid b { font-size: 24px; font-variant-numeric: tabular-nums; }

/* ---------------- Tuning panel ---------------- */
#tune-btn { position: fixed; top: 10px; right: 10px; width: 36px; height: 36px; padding: 0; margin: 0; font-size: 18px; background: var(--panel); z-index: 5; }
#tune { position: fixed; top: 54px; right: 10px; bottom: 10px; width: 330px; overflow-y: auto; background: var(--panel); border: 1px solid var(--slate); border-radius: 12px; padding: 10px 12px; font-size: 12px; display: none; z-index: 5; }
#tune.open { display: block; }
.tune-head { color: var(--dim); margin-bottom: 6px; }
.tune-stats { white-space: pre-line; background: rgba(255,255,255,0.05); border-radius: 8px; padding: 6px 8px; font-variant-numeric: tabular-nums; line-height: 1.5; }
.tune-btns { display: flex; flex-wrap: wrap; margin: 6px -4px; }
.tune-btns button { font-size: 12px; padding: 5px 9px; }
#tune details { margin-top: 6px; }
#tune summary { cursor: pointer; font-weight: 800; padding: 4px 0; }
.tune-row { display: grid; grid-template-columns: 118px 1fr 44px; align-items: center; gap: 6px; padding: 1px 0; }
.tune-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); }
.tune-row.changed span:first-child { color: var(--sun); }
.tune-row input { width: 100%; }
.tune-val { text-align: right; font-variant-numeric: tabular-nums; }

/* Settings tabs: Server (room rules) vs Player (personal) */
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs .tab { flex: 1; margin: 0; font-weight: 800; }
#settings[data-tab=server] .tab[data-tab=server], #settings[data-tab=player] .tab[data-tab=player] { background: var(--sun); color: #1a1400; border-color: var(--sun); }
#settings[data-tab=server] [data-body=player], #settings[data-tab=player] [data-body=server] { display: none; }
.note { font-size: 12px; color: var(--dim); margin: 4px 0 6px; text-align: left; }
.opt-range { display: grid; grid-template-columns: 130px 1fr 52px; gap: 8px; align-items: center; text-align: left; font-size: 14px; padding: 8px 4px; border-bottom: 1px solid var(--slate); }
.opt-range input { width: 100%; accent-color: var(--sun); }
.opt-range b { text-align: right; font-variant-numeric: tabular-nums; }
.opt-range small { display: block; color: var(--dim); font-size: 12px; }
.opt-range input:disabled { opacity: 0.4; cursor: default; }     /* online: the room's values, read-only */
/* Settings and Controls: when the list is taller than the screen it
   scrolls on its own, so the tabs and the Done button stay in view. */
body[data-overlay=settings] #settings, body[data-overlay=controls] #controls { display: flex; flex-direction: column; }
#settings .tab-body, #controls .keys { min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--gold-line) transparent; }
#settings > .close-overlay, #controls > .close-overlay { flex: none; }
#settings .tab-body[data-more], #controls .keys[data-more] {
    -webkit-mask-image: linear-gradient(#000 calc(100% - 36px), transparent); mask-image: linear-gradient(#000 calc(100% - 36px), transparent); }


/* Lobby */
#menu { width: min(460px, calc(100vw - 32px - var(--safe-l) - var(--safe-r))); }
/* "more ▾" at the foot of a menu that scrolls (main.js sets data-more). */
.more-below { display: none; }
#menu[data-more] .more-below { display: flex; align-items: flex-end; justify-content: center; position: sticky; bottom: 8px; height: 0; pointer-events: none;
    font: 700 11px/1 'Cinzel', Georgia, serif; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-hi); }
#menu[data-more] .more-below::before { content: ''; position: absolute; left: -40px; right: -40px; bottom: -8px; height: 56px; z-index: -1;
    background: linear-gradient(rgba(14, 11, 9, 0), rgba(14, 11, 9, 0.94) 65%); }
.lobby, .solo { text-align: left; margin-top: 12px; }
.lobby-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); margin-bottom: 6px; }
.lobby-head b { color: var(--text); }
#lobby-status { text-transform: none; letter-spacing: 0; font-size: 12px; }
#room-list { display: flex; flex-direction: column; gap: 6px; }
.room { display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--slate); border-radius: 10px; background: rgba(255,255,255,0.03); }
.room > div:first-child { min-width: 0; }
.room .rn { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room .rm { font-size: 11px; color: var(--dim); }
.room .rc { font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.room button { margin: 0; padding: 6px 12px; font-weight: 800; background: var(--sun); color: #1a1400; border: none; }
.room button:disabled { background: #333; color: #888; }
.badge { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: 0.05em; padding: 1px 6px; border-radius: 6px; background: rgba(124,227,139,0.16); color: #8CF09A; vertical-align: 1px; }
.room .badge { margin-left: 6px; }
.badge[hidden] { display: none; }
.badge.fight { margin: 0 6px 0 0; background: rgba(255, 110, 80, 0.18); color: #FFA58A; }          /* fight mode (rule fight) */
#create-fight-opt { border-bottom: none; padding: 2px 2px 8px; }
.opt .badge { font-size: 11px; }
button.ghost { width: 100%; margin: 8px 0 0; background: transparent; border: 1px dashed var(--slate); color: var(--dim); }
#create-form { margin-top: 8px; padding: 10px; border: 1px solid var(--slate); border-radius: 10px; }
.room-pick { display: flex; gap: 6px; }
#create-name { flex: 1; min-width: 0; font-weight: 700; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--slate); background: #0f1526; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#create-reroll { flex: none; margin: 0; padding: 0 12px; font-size: 18px; line-height: 1; }
button.cta.small { font-size: 15px; padding: 8px; margin: 0; }
#create-form .menu-row button { flex: 1 1 0; width: auto; min-height: 40px; margin: 0; padding: 8px 6px; font-size: 14px; letter-spacing: 0.06em; }
.err { color: #FF7A6A; font-size: 12px; min-height: 0; margin-top: 4px; text-align: left; }
.err:empty { display: none; }
#pause .note { text-align: center; font-size: 13px; max-width: 300px; margin: 0 auto 10px; }
/* Invites: a 🔗 on each server row, a button on the pause panel (online),
   the invited server pinned and lit at the top of the list, and the link
   in a field when it can't be shared or copied. */
.room button.share { padding: 6px 7px; font-size: 15px; line-height: 1; letter-spacing: 0; background: transparent; border: 1px solid var(--gold-line); box-shadow: none; }
.room button.share:hover { background: rgba(255, 240, 210, 0.09); filter: none; }
.room.pinned { border-color: var(--gold); background: rgba(217, 181, 108, 0.12); box-shadow: 0 0 0 1px rgba(217, 181, 108, 0.35), 0 0 22px rgba(217, 181, 108, 0.22); }
.room.pinned::before { content: "You're invited"; grid-column: 1 / -1; margin-bottom: -4px;
    font: 700 10.5px/1.2 'Cinzel', Georgia, serif; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-hi); }
.room.pinned button:not(.share):not(:disabled) { padding: 9px 16px; font-size: 15px; }
#invite { width: 100%; margin: 0 0 4px; }
.invite-link { display: block; width: 100%; margin: 6px 0; padding: 7px 9px; border-radius: 8px; border: 1px solid var(--gold-line); background: rgba(0, 0, 0, 0.35);
    color: var(--gold-hi); font: 12px/1.3 ui-monospace, Menlo, Consolas, monospace; -webkit-user-select: all; user-select: all; }
.invite-link[hidden] { display: none; }
#notice { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 8px); z-index: 6; max-width: calc(100vw - 32px); pointer-events: none;
    padding: 8px 16px; border-radius: 999px; border: 1px solid var(--gold-line); background: rgba(14, 11, 9, 0.92); color: var(--gold-hi);
    font-size: 14px; font-weight: 700; text-align: center; opacity: 0; transition: opacity 0.2s, transform 0.2s; }
#notice.show { opacity: 1; transform: translate(-50%, 0); }
/* A narrow phone: tighter server rows, the player and bot counts stacked,
   so the name keeps its room beside the 🔗 and Join. */
@media (max-width: 480px) {
    .room { gap: 6px; padding: 8px; }
    .room .rc { font-size: 12px; line-height: 1.35; text-align: right; }
    .room .rc span { display: block; }
    .room .rc .sep { display: none; }
    .room button.share { padding: 5px 6px; font-size: 14px; }
    .room button:not(.share) { padding: 6px 10px; letter-spacing: 0.08em; }
    .room.pinned button:not(.share):not(:disabled) { padding: 8px 12px; font-size: 14px; }
}
#privacy-link { display: inline-block; margin-top: 2px; padding: 8px 12px; color: var(--dim); font-size: 12px; text-decoration: none; }
#privacy-link:hover { color: var(--gold-hi); text-decoration: underline; }

/* ---------------- Status (bottom left): understated, icons over words ---------------- */
#hud-stats { position: absolute; left: calc(22px + var(--safe-l)); bottom: calc(20px + var(--safe-b)); font-family: -apple-system, 'SF Pro Display', 'Inter', system-ui, sans-serif;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 0, 0, 0.35); }
.hud-len { display: flex; align-items: baseline; gap: 4px; }
#hud-len { font-size: 42px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.hud-len small { font-size: 15px; font-weight: 500; color: rgba(235,235,245,0.7); }
#hud-kills { margin-left: 10px; font-size: 14px; font-weight: 600; color: rgba(235,235,245,0.6); font-variant-numeric: tabular-nums; }
.hud-tier { margin-top: 6px; }
#hud-tier { font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(235,235,245,0.75); }
.hair { width: 132px; height: 2px; border-radius: 1px; background: rgba(255,255,255,0.12); margin-top: 5px; overflow: hidden; }
#hud-stats .hair { box-shadow: 0 0 4px rgba(0, 0, 0, 0.35); }
#hud-tierbar { height: 100%; width: 0; background: rgba(255,255,255,0.85); transition: width 0.4s ease; }
#hud-gauges { display: flex; gap: 10px; margin-top: 14px; }
.g { position: relative; width: 40px; height: 40px; color: #fff; transition: opacity 0.25s, transform 0.25s; }
.g[hidden] { display: none; }
.g svg { position: absolute; inset: 0; }
.g .ring { transform: rotate(-90deg); }
.g .ring circle { fill: rgba(18,18,26,0.35); stroke-width: 2.6; }
.g .ring .track { stroke: rgba(255,255,255,0.12); }
.g .ring .val { fill: none; stroke: currentColor; stroke-linecap: round; transition: stroke-dashoffset 0.2s linear; }
.g .icon { inset: 11px; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.g-thrust { color: #64D2FF; }
.g-thrust[data-state=empty] { color: #FF453A; animation: gPulse 0.5s ease-in-out infinite alternate; }
.g-fire { color: #FF6B35; }
.g-fire[data-state=empty] { opacity: 0.28; color: #fff; }
.g-fire[data-state=ready] { filter: drop-shadow(0 0 6px rgba(255,107,53,0.9)); animation: gPulse 0.9s ease-in-out infinite alternate; }
.g-fire[data-state=breathing] { color: #FFD60A; filter: drop-shadow(0 0 8px rgba(255,190,40,0.9)); }
.g-fire kbd { position: absolute; right: -4px; bottom: -4px; font: 700 9px/1 -apple-system, system-ui, sans-serif; padding: 2px 4px; border-radius: 4px; background: rgba(255,255,255,0.9); color: #111; display: none; }
.g-fire[data-state=ready] kbd { display: block; }
/* Stacked dragonfire: one lit arc per charge; the gauge grows and glows with each. */
.g-fire { --ch: 0; scale: calc(1 + 0.06 * max(0, var(--ch) - 1)); }
.g-fire[data-state=ready] { filter: drop-shadow(0 0 calc(4px + 2.5px * var(--ch)) currentColor); }
.g-fire .ring .track { stroke: rgba(255,255,255,0.3); }
.g-fire .ring circle { stroke-width: 3.2; }
/* Breath elements: the gauge wears the one you hold. Chilled / stunned gauges show only while it lasts. */
.g-fire[data-el=ice], .g-chill { color: #8FE6FF; }
.g-fire[data-el=bolt], .g-stun { color: #C9A0FF; }
.g-fire[data-el=acid] { color: #7CFF4F; }
.g-chill, .g-stun { filter: drop-shadow(0 0 6px currentColor); animation: gPulse 0.45s ease-in-out infinite alternate; }
.g-shield { color: #FF9F0A; }
.g-magnet { color: #3D8BFF; filter: drop-shadow(0 0 5px rgba(61,139,255,0.8)); }
.g-poison { color: #B36BFF; filter: drop-shadow(0 0 5px rgba(140,255,90,0.75)); }          /* Poison Skin (fight mode) */
@keyframes gPulse { from { opacity: 0.7; } to { opacity: 1; transform: scale(1.06); } }

/* ================= Theme: ink & gold (Chinese-dragon feel) =================
   One block of overrides so the look can be tuned or removed in one place. */
:root {
    --ink: #0d0b09;
    --lacquer: rgba(19, 16, 13, 0.88);
    --gold: #D9B56C;
    --gold-hi: #F3DDA4;
    --gold-line: rgba(217, 181, 108, 0.26);
    --cinnabar: #B3322A;
    --jade: #86D9B0;
    --panel: var(--lacquer);
    --slate: rgba(217, 181, 108, 0.16);
    --dim: #A99F8E;
    --sun: #E7C57A;
}
/* Lattice-window corner brackets, drawn as background so they stay in the
   corners when a panel scrolls. */
.panel {
    background:
        url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18'><path d='M.75 18V6A5.25 5.25 0 0 1 6 .75H18' fill='none' stroke='%23D9B56C' stroke-opacity='.55' stroke-width='1.5'/></svg>") left 9px top 9px / 18px 18px no-repeat,
        url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18'><path d='M17.25 0V12A5.25 5.25 0 0 1 12 17.25H0' fill='none' stroke='%23D9B56C' stroke-opacity='.55' stroke-width='1.5'/></svg>") right 9px bottom 9px / 18px 18px no-repeat,
        linear-gradient(180deg, rgba(24, 20, 16, 0.9), rgba(12, 10, 8, 0.92));
    border: 1px solid var(--gold-line);
    border-radius: 18px;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 236, 200, 0.05);
    backdrop-filter: blur(12px) saturate(1.2); -webkit-backdrop-filter: blur(12px) saturate(1.2);
}

.brand { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 4px; }
h1 {
    font-family: 'Cinzel', 'Trajan Pro', Georgia, serif; font-weight: 700; font-size: clamp(28px, 8.4vw, 44px); letter-spacing: 0.2em; margin-right: -0.2em;
    background: linear-gradient(180deg, var(--gold-hi) 10%, var(--gold) 55%, #9C7A3C 100%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    text-shadow: none; filter: drop-shadow(0 2px 14px rgba(217, 181, 108, 0.25));
}
.seal {
    width: 46px; height: 46px; flex: none; display: grid; place-items: center;
    font-family: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', serif; font-size: 36px; line-height: 1; color: #F7E8CC;
    background: radial-gradient(circle at 30% 25%, #C8453B, var(--cinnabar) 60%, #8E2620);
    border-radius: 7px; transform: rotate(-5deg);
    box-shadow: inset 0 0 0 2.5px rgba(247, 232, 204, 0.75), inset 0 0 0 5px var(--cinnabar), 0 4px 14px rgba(179, 50, 42, 0.35);
}
.sub { font-family: 'Cinzel', Georgia, serif; font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--dim); margin-top: 6px; }
h2 { font-family: 'Cinzel', Georgia, serif; font-weight: 600; letter-spacing: 0.12em; color: var(--gold-hi); }

.couplet {
    position: fixed; top: 50%; transform: translateY(-50%); display: none;
    /* One character per line (the trimmed web font has no vertical metrics, so no writing-mode). */
    width: 1.05em; word-break: break-all; text-align: center;
    font-family: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', serif; font-size: clamp(34px, 5.2vh, 58px); line-height: 1.22;
    color: var(--gold); opacity: 0.55; text-shadow: 0 0 22px rgba(217, 181, 108, 0.35); pointer-events: none;
}
.couplet.left { left: max(24px, calc(50vw - 330px)); }
.couplet.right { right: max(24px, calc(50vw - 330px)); }
#vignette { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.6s;
    background: radial-gradient(ellipse 60% 75% at 50% 50%, rgba(8, 6, 4, 0.55), rgba(8, 6, 4, 0.2) 55%, rgba(0, 0, 0, 0.55)); }
body[data-state=menu] #vignette, body[data-state=pause] #vignette, body[data-state=dead][data-card="1"] #vignette { opacity: 1; }
@media (min-width: 900px) and (min-height: 560px) { body[data-state=menu]:not([data-overlay]) .couplet { display: block; } }

#name { background: rgba(0, 0, 0, 0.35); border-color: var(--gold-line); color: var(--gold-hi); letter-spacing: 0.02em; }
#create-name { background: rgba(0, 0, 0, 0.35); border-color: var(--gold-line); color: var(--gold-hi); }
#name:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 181, 108, 0.15); }
button { background: rgba(255, 240, 210, 0.04); border-color: var(--gold-line); color: #EDE3D1; transition: background 0.15s, border-color 0.15s; }
button:hover { background: rgba(255, 240, 210, 0.09); border-color: rgba(217, 181, 108, 0.45); }
button.cta, .room button {
    background: linear-gradient(180deg, #F0D48E, var(--gold) 55%, #B8904A); color: #221606;
    border: none; box-shadow: 0 6px 18px rgba(217, 181, 108, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.45);
    font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.12em;
}
button.cta:hover, .room button:hover { filter: brightness(1.06); }
.room { border-color: var(--gold-line); background: rgba(255, 240, 210, 0.025); }
.room .rn { color: #F1E6D2; }
.lobby-head { font-family: 'Cinzel', Georgia, serif; letter-spacing: 0.16em; }
.lobby-head b { color: var(--gold-hi); }
.arenas label { border-color: var(--gold-line); }
.arenas label:has(input:checked) { border-color: var(--gold); background: rgba(217, 181, 108, 0.08); }
.badge { background: rgba(134, 217, 176, 0.14); color: var(--jade); }
.opt input, .opt-range input { accent-color: var(--gold); }

/* ---------------- Lives: dragon pearls + respawn countdown ---------------- */
.pearls { display: flex; gap: 6px; }
.pearls span { width: 9px; height: 9px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #F3DDA4 40%, #C9973E); box-shadow: 0 0 6px rgba(243, 221, 164, 0.6); }
.pearls span.used { background: none; box-shadow: inset 0 0 0 1.2px rgba(255, 255, 255, 0.28); }
#hud-lives { margin: 8px 0 2px; }
#hud-lives:empty { display: none; }
/* It ends at the centre, so the message stack (the death line, jade) shows below it. */
#respawn { position: fixed; left: 0; right: 0; bottom: 50%; display: none; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; text-align: center; }
body[data-state=dead][data-respawn="1"] #respawn { display: flex; }
#respawn-text { font-size: 18px; font-weight: 600; color: rgba(245, 238, 225, 0.85); text-shadow: 0 1px 12px rgba(0, 0, 0, 0.7); }
#respawn-count { font-family: 'Cinzel', Georgia, serif; font-size: 72px; font-weight: 700; line-height: 1; color: #F3DDA4; text-shadow: 0 0 30px rgba(217, 181, 108, 0.45); }
#respawn .pearls span { width: 12px; height: 12px; }
#card-sub { color: var(--dim); font-size: 13px; margin: -6px 0 14px; }

#opt-gfx { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--gold-line); background: rgba(0, 0, 0, 0.35); color: #EDE3D1; }
/* ---------------- Profile: rank seal, jade, perks & colours ---------------- */
#profile-strip { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 10px; border: 1px solid var(--gold-line); border-radius: 12px; text-align: left; background: rgba(255, 240, 210, 0.03); }
.rank-seal { width: 34px; height: 34px; flex: none; display: grid; place-items: center; font-family: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', serif; font-size: 24px; color: #F7E8CC;
    background: radial-gradient(circle at 30% 25%, #C8453B, var(--cinnabar) 60%, #8E2620); border-radius: 6px; box-shadow: inset 0 0 0 2px rgba(247, 232, 204, 0.7); }
.pinfo { flex: 1; min-width: 0; font-size: 13px; }
.pinfo b { font-family: 'Cinzel', Georgia, serif; color: var(--gold-hi); letter-spacing: 0.06em; }
#rank-name, #rank-jade { white-space: nowrap; }
#rank-jade { color: var(--jade); font-size: 12px; }
#rank-perks { font-size: 12px; }
#profile-strip .hair { width: 100%; margin-top: 6px; }
#rank-bar { height: 100%; width: 0; background: var(--jade); }
#open-dojo { width: auto; margin: 0; padding: 6px 10px; font-size: 12px; }
body[data-overlay=dojo] #dojo { display: block; }
.perk { display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 10px; margin: 6px 0; border: 1px solid var(--gold-line); border-radius: 10px; cursor: pointer; }
.perk .pi { font-size: 22px; width: 28px; text-align: center; }
.perk .pt { flex: 1; font-size: 13px; }
.perk .pt small { display: block; color: var(--dim); font-size: 12px; }
.perk.on { border-color: var(--jade); background: rgba(134, 217, 176, 0.08); }
.perk.locked { opacity: 0.45; cursor: default; }
.perk .tag { font-size: 11px; color: var(--dim); white-space: nowrap; }
#dojo-skins { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.swatch { width: 54px; padding: 6px 0 4px; border: 1px solid var(--gold-line); border-radius: 10px; font-size: 10px; color: var(--dim); cursor: pointer; background: none; margin: 0; }
.swatch i { display: block; width: 26px; height: 26px; margin: 0 auto 4px; border-radius: 50%; }
.swatch.on { border-color: var(--gold); color: var(--gold-hi); }
.swatch:disabled { opacity: 0.4; cursor: default; }
#card-jade, #respawn-jade { color: var(--jade); font-weight: 700; font-size: 14px; margin: -4px 0 12px; }
#respawn-jade { margin: 0; text-shadow: 0 1px 10px rgba(0, 0, 0, 0.7); }
#card-jade:empty, #respawn-jade:empty { display: none; }

/* ---------------- Touch controls + small screens ---------------- */
#game { touch-action: none; }
html, body { overscroll-behavior: none; -webkit-touch-callout: none; }
#touch-ui { display: none; }
body[data-touch="1"][data-state=play] #touch-ui { display: block; }
#touch-ui button { position: fixed; margin: 0; padding: 0; border-radius: 50%; display: grid; place-items: center; touch-action: none;
    -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
    background: rgba(18, 16, 14, 0.42); border: 1px solid rgba(243, 221, 164, 0.35); color: #F3DDA4;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); z-index: 4; }
#touch-ui button.down { background: rgba(243, 221, 164, 0.35); transform: scale(0.94); }
#touch-ui svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#t-boost { right: max(18px, env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); width: 76px; height: 76px; color: #64D2FF; }
#t-fire { right: calc(max(18px, env(safe-area-inset-right)) + 10px); bottom: calc(112px + env(safe-area-inset-bottom)); width: 56px; height: 56px; color: #FF6B35; }
#t-brake { right: calc(max(18px, env(safe-area-inset-right)) + 78px); bottom: calc(112px + env(safe-area-inset-bottom)); width: 56px; height: 56px; }
body:not([data-fire="1"]) #t-fire { opacity: 0.3; }
/* Stored dragonfire charges, readable at a glance on a phone. */
#t-fire[data-charge]:not([data-charge=""])::after { content: attr(data-charge); position: absolute; top: -5px; right: -5px; min-width: 21px; height: 21px; padding: 0 4px; box-sizing: border-box;
    border-radius: 11px; background: var(--el, #FF6B35); color: #1a0c00; box-shadow: 0 0 10px var(--el, #FF6B35); font: 800 13px/21px -apple-system, system-ui, sans-serif; text-align: center; }
#t-fire[data-el=ice] { --el: #8FE6FF; color: var(--el); }
#t-fire[data-el=bolt] { --el: #C9A0FF; color: var(--el); }
#t-fire[data-el=acid] { --el: #7CFF4F; color: var(--el); }
#t-pause { left: calc(14px + var(--safe-l)); top: calc(12px + env(safe-area-inset-top)); width: 40px; height: 40px; }
body[data-touch="1"] #tune-btn, body[data-touch="1"] #hud-fps { display: none; }
/* Keyboard and mouse hints and settings mean nothing on a touch screen. */
body[data-touch="1"] .no-touch, body[data-touch="1"] .g-fire kbd { display: none; }
body[data-touch="1"][data-state=play] #feed { top: calc(60px + var(--safe-t)); }
body[data-touch="1"] #hud-stats { bottom: calc(18px + env(safe-area-inset-bottom)); }
/* Phones, upright (narrow) or on their side (short): a compact HUD. */
@media (max-width: 640px), (max-height: 500px) {
    #board { width: 168px; right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); font-size: 11.5px; padding: 6px 10px; }
    #board .row:nth-child(n+6):not(.me) { display: none; }
    #hud-len { font-size: 34px; }
    #hud-gauges { gap: 7px; flex-wrap: wrap-reverse; max-width: 124px; }   /* three a row; timed ones stack above, clear of the radar */
    .g { width: 34px; height: 34px; }
    .g .icon { inset: 9px; width: 16px; height: 16px; }
    .msg { max-width: 92vw; font-size: 16px; line-height: 1.25; }
    .msg.big { font-size: 20px; }
    .msg.hint { font-size: 13px; }
    .msg.caption .zh { font-size: 27px; }
    /* A full-screen panel hides the leaderboard and kill feed instead of covering them. */
    body[data-state=menu] #board, body[data-state=pause] #board, body[data-overlay] #board, body[data-card="1"] #board,
    body[data-state=menu] #feed, body[data-state=pause] #feed, body[data-overlay] #feed, body[data-card="1"] #feed { display: none; }
}
/* Upright: the radar stacks above the stats (bottom left; hud.js keeps their
   height, which grows with timed gauges, in --stats-h), clear of the buttons
   and of your dragon in the middle; the feed stops short of the leaderboard.
   Messages end above the radar and the brake and fire buttons. */
@media (max-width: 640px) {
    #radar { left: calc(22px + var(--safe-l)); bottom: calc(var(--stats-h, 132px) + 28px + var(--safe-b)); transform: none; width: 140px; height: 95px; }
    #msgs { --msg-foot: calc(max(var(--stats-h, 132px) + 123px, 168px) + 8px + var(--safe-b)); }
    #feed { max-width: calc(100vw - 210px - var(--safe-l) - var(--safe-r)); }
}
/* On its side: a smaller radar low in the middle, messages between the
   stats and the buttons and above the radar, the feed kept clear of the
   leaderboard and the mirror, and a two-column menu. */
@media (max-height: 500px) {
    #radar { width: 132px; height: 90px; bottom: calc(4px + var(--safe-b)); }
    #msgs { --msg-top: 26px; --msg-foot: calc(98px + var(--safe-b)); gap: 4px; }
    .msg { max-width: calc(100vw - 380px - 2 * max(var(--safe-l), var(--safe-r))); padding: 1px 11px; font-size: 14px; }
    .msg.big { font-size: 17px; }
    .msg.hint, #net-note { font-size: 12.5px; }
    .msg.caption .zh { font-size: 22px; }
    .msg.caption .say { font-size: 11px; }
    #feed { max-width: calc(36vw - 30px - var(--safe-l)); }
    #feed > :nth-last-child(n+3) { display: none; }      /* the latest two, clear of tall stats */
    .panel { padding: 16px 22px; }
    h2 { margin-bottom: 10px; }
    #card .grid { grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 10px; }
    #card .grid b { font-size: 20px; }
    #card { width: min(560px, calc(100vw - 32px - var(--safe-l) - var(--safe-r))); }
}
@media (max-height: 500px) and (min-width: 560px) {
    body[data-state=menu]:not([data-overlay]) #menu { display: grid; }
    #menu { width: min(780px, calc(100vw - 24px - var(--safe-l) - var(--safe-r)));
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-rows: repeat(8, auto); column-gap: 22px; align-items: start; }
    /* (Not a 1fr last row: the menu's max-height would cap it, a long server
       list would spill out of its rows, and "more ▾" would scroll up over it.) */
    #menu > * { grid-column: 1; }
    #menu > .brand { grid-row: 1; }
    #menu > .sub { grid-row: 2; margin-bottom: 10px; }
    #menu > #name { grid-row: 3; padding: 8px; }
    #menu > #name-error { grid-row: 4; }
    #menu > #profile-strip { grid-row: 5; }
    #menu > .menu-row { grid-row: 6; margin-top: 8px; }
    #menu > #privacy-link { grid-row: 7; justify-self: center; }
    #menu > .solo { grid-column: 2; grid-row: 1 / 6; margin-top: 0; }
    #menu > .lobby { grid-column: 2; grid-row: 6 / 9; margin-top: 8px; }
    #menu > .more-below { grid-column: 1 / -1; grid-row: 9; }
    #menu .arenas { margin: 8px 0; }
    #menu h1 { font-size: 34px; }
    #menu .seal { width: 40px; height: 40px; font-size: 30px; }
}

/* ---------------- Sound on/off: a speaker button, top left on every screen ---------------- */
#mute-btn { position: fixed; left: calc(14px + var(--safe-l)); top: calc(12px + var(--safe-t)); width: 40px; height: 40px; margin: 0; padding: 0;
    border-radius: 50%; display: grid; place-items: center; z-index: 4; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    background: rgba(18, 16, 14, 0.42); border: 1px solid rgba(243, 221, 164, 0.35); color: #F3DDA4;
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#mute-btn::before { content: ''; position: absolute; inset: -6px; border-radius: 50%; }      /* a thumb-sized target */
#mute-btn:hover { background: rgba(243, 221, 164, 0.16); }
#mute-btn svg { width: 50%; height: 50%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#mute-btn .off, #mute-btn[aria-pressed=true] .on { display: none; }
#mute-btn[aria-pressed=true] .off { display: inline; }
#mute-btn[aria-pressed=true] { color: rgba(243, 221, 164, 0.6); }
#mute-btn .flash { position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); white-space: nowrap; pointer-events: none; opacity: 0;
    font-size: 13px; font-weight: 700; color: #F3DDA4; padding: 5px 12px; border-radius: 999px; background: rgba(18, 18, 26, 0.55); border: 1px solid rgba(255, 255, 255, 0.07); }
#mute-btn .flash.show { animation: muteFlash 1.4s ease-out forwards; }
@keyframes muteFlash { 0% { opacity: 0; transform: translate(-4px, -50%); } 12% { opacity: 1; transform: translate(0, -50%); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(0, -50%); } }
body[data-touch="1"] #mute-btn { left: calc(66px + var(--safe-l)); }                         /* beside ❚❚ */
body[data-overlay] #mute-btn { display: none; }                                                  /* Settings has the switch */
/* The start menu sits a little lower, so even a tall menu on a phone on its
   side starts below the speaker button. */
#menu { top: calc(50% + 23px + (var(--safe-t) - var(--safe-b)) / 2); max-height: calc(100% - 70px - var(--safe-t) - var(--safe-b)); }

/* Settings → Player: the last problem this device hit, to copy into a report. */
#last-problem { margin-top: 10px; padding: 8px 10px; border: 1px solid rgba(255, 120, 90, 0.4); border-radius: 8px; }
#last-problem pre { white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: auto; font-size: 11px; margin: 6px 0; opacity: 0.85; }
#last-problem button { font: inherit; font-size: 12px; padding: 3px 10px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.08); color: inherit; cursor: pointer; }
