:root {
  --bg: #0f1226; --panel: #1a1f3d; --panel2: #232a52; --text: #eef1ff; --muted: #9aa3d4; --accent: #ffb703; --accent2: #3ddbd9;
  --good: #4cd964; --bad: #ff6b6b; --radius: 14px; --glow: 0 0 0 1px rgba(255,255,255,.06), 0 8px 24px rgba(0,0,0,.28); color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { --bg: #f2f4ff; --panel: #ffffff; --panel2: #e6eaff; --text: #151a3a; --muted: #5a6290; --accent: #d97706; --accent2: #0e8f8d; --glow: 0 0 0 1px rgba(20,26,58,.08), 0 8px 24px rgba(20,26,58,.10); color-scheme: light; }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font: 16px/1.45 system-ui, "Segoe UI", sans-serif; background: var(--bg); background-image: radial-gradient(1200px 500px at 50% -120px, rgba(61,219,217,.12), transparent 70%), radial-gradient(900px 400px at 100% 0, rgba(255,183,3,.08), transparent 70%); background-repeat: no-repeat; color: var(--text); }
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); box-shadow: var(--glow); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
header h1 { font-size: 20px; margin: 0; letter-spacing: .5px; display: flex; align-items: center; gap: 10px; }
header h1 img, .brand img { width: 34px; height: 34px; border-radius: 9px; display: block; }
header .stats { margin-left: auto; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 14px; }
header .stats b { color: var(--text); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--panel2); }
.chip.coin b { color: var(--accent); }
nav { display: flex; gap: 6px; padding: 8px 16px; overflow-x: auto; background: var(--panel2); scrollbar-width: thin; }
nav button { white-space: nowrap; background: transparent; border-radius: 999px; transition: background .15s, transform .15s; }
nav button:hover { background: rgba(255,255,255,.08); filter: none; }
nav button.on { background: var(--accent); color: #1b1300; outline: none; font-weight: 600; }
main { padding: 16px; max-width: 980px; margin: 0 auto; }
section.card, .card { background: var(--panel); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--glow); }
h2 { margin: 0 0 10px; font-size: 18px; }
h3 { margin: 12px 0 6px; font-size: 15px; color: var(--muted); }
button, .btn { font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 8px 14px; background: var(--panel2); color: var(--text); min-height: 40px; transition: transform .1s, filter .15s; }
button:hover { filter: brightness(1.15); }
button:active { transform: translateY(1px) scale(.98); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }
button.primary { background: linear-gradient(180deg, #ffc933, var(--accent)); color: #1b1300; font-weight: 700; box-shadow: 0 4px 14px rgba(255,183,3,.28); }
button.danger { background: var(--bad); color: #2a0000; }
button.on { outline: 2px solid var(--accent2); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--panel2); background: var(--bg); color: var(--text); min-height: 40px; max-width: 100%; }
label { display: block; margin: 8px 0 2px; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.item { background: var(--panel2); border-radius: 12px; padding: 12px; border: 1px solid rgba(255,255,255,.05); transition: transform .15s, border-color .15s; }
.item:hover { transform: translateY(-2px); border-color: rgba(61,219,217,.45); }
.item b { display: block; }
.muted { color: var(--muted); font-size: 14px; }
.bar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .5s ease; }
canvas { width: 100%; max-width: 100%; border-radius: var(--radius); background: #0a1a2b; touch-action: none; display: block; box-shadow: var(--glow); }
.auth-hero { text-align: center; }
.auth-hero img { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 10px 30px rgba(61,219,217,.25); }
.auth-hero h1 { margin: 12px 0 4px; background: linear-gradient(90deg, var(--accent2), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-hero p { margin: 0 0 12px; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--panel2); padding: 10px 18px; border-radius: 12px; transition: transform .2s; z-index: 20; max-width: 90vw; box-shadow: var(--glow); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #2a0000; }
.chatlog { height: 220px; overflow-y: auto; background: var(--bg); border-radius: 10px; padding: 8px; }
.chatlog p { margin: 2px 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--panel2); font-size: 14px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--panel2); font-size: 12px; }
.tag.CRITICAL, .tag.HIGH { background: var(--bad); color: #2a0000; }
.tag.MEDIUM { background: var(--accent); color: #1b1300; }
.hidden { display: none !important; }
@media (max-width: 700px) {
  main { padding: 10px; }
  header { position: static; padding: 8px 10px; gap: 8px; }
  header h1 { font-size: 16px; } header h1 img { width: 28px; height: 28px; }
  header .stats { margin-left: 0; gap: 6px; font-size: 13px; flex-basis: 100%; }
  header .stats .chip { padding: 2px 8px; }
  header .stats button { min-height: 32px; padding: 4px 10px; margin-left: auto; }
  nav { padding: 8px 10px; position: sticky; top: 0; z-index: 5; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* Shared legal footer */
.footer { background: var(--panel); color: var(--text); padding: 40px 20px 24px; margin-top: 24px; }
.footer-container { max-width: 1200px; margin: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 28px; }
.footer-section h4 { margin: 0 0 10px; }
.footer-section a, .footer-section p { display: block; color: var(--muted); text-decoration: none; margin: 0 0 8px; font-size: 14px; word-break: break-word; }
.footer-section a:hover { color: var(--text); text-decoration: underline; }
.footer-bottom { max-width: 1200px; margin: 28px auto 0; border-top: 1px solid var(--panel2); padding-top: 16px; text-align: center; color: var(--muted); font-size: 13px; }
@media (max-width: 768px) { .footer-container { text-align: center; } }
a { color: var(--accent2); }

/* Legal Center grid */
.legal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.legal-grid a { display: block; padding: 18px; background: var(--panel2); border-radius: 10px; text-decoration: none; color: var(--text); font-weight: 600; transition: filter .2s; }
.legal-grid a:hover { filter: brightness(1.2); }
.card { overflow-x: auto; }

/* Racing */
canvas.preview { max-width: 420px; border-radius: 12px; }
canvas.racecanvas { aspect-ratio: auto; background: #101528; }
.pad { display: none; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 10px 0; user-select: none; touch-action: none; }
.ctl { min-width: 72px; min-height: 64px; font-weight: 800; font-size: 18px; border-radius: 14px; background: var(--panel2); -webkit-user-select: none; user-select: none; touch-action: none; }
.ctl.hot { background: linear-gradient(180deg, #ffc933, var(--accent)); color: #1b1300; }
.ctl.down { transform: scale(.94); filter: brightness(1.3); }
@media (pointer: coarse), (max-width: 700px) { .pad { display: flex; } }

/* 3D world */
.worldbox { position: relative; border-radius: 14px; overflow: hidden; background: #0f1226; min-height: 320px; }
.worldbox canvas { display: block; width: 100%; border-radius: 0; }
.worldhud { position: absolute; inset: 0; pointer-events: none; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(8,10,30,.8), 0 0 8px rgba(8,10,30,.7); }
.wh-lvl { position: absolute; left: 10px; top: 10px; width: min(46%, 230px); }
.wh-lvltxt { font-size: 13px; margin-bottom: 3px; }
.wh-bar { height: 10px; background: rgba(8,10,30,.6); border-radius: 6px; overflow: hidden; border: 1px solid rgba(255,255,255,.25); }
.wh-fill { height: 100%; width: 0; background: linear-gradient(90deg, #3ddbd9, #ffd23f); }
.wh-st { position: absolute; left: 10px; bottom: 12px; width: min(40%, 200px); }
.wh-st .wh-fill { background: linear-gradient(90deg, #4cd964, #b6ff7a); }
.wh-st .wh-fill.low { background: #ff7b7b; }
.wh-combo { position: absolute; right: 14px; top: 10px; font-size: 30px; font-style: italic; color: #ffd23f; opacity: 0; transform: scale(.8); transition: opacity .15s, transform .15s; }
.wh-combo.on { opacity: 1; transform: scale(1); }
.wh-toast { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); font-size: 20px; text-align: center; max-width: 86%; opacity: 0; transition: opacity .25s; }
.wh-toast.on { opacity: 1; }
.wh-tip { position: absolute; left: 10px; right: 10px; bottom: 34px; font-size: 12px; text-align: center; opacity: .85; }
.wh-nums { position: absolute; inset: 0; overflow: hidden; }
.wh-num { position: absolute; left: 0; top: 0; font-size: 22px; font-style: italic; color: #fff; }
.wh-num.big { font-size: 32px; color: #ffd23f; }
.wh-mute { position: absolute; right: 10px; bottom: 10px; pointer-events: auto; min-height: 32px; padding: 4px 10px; font-size: 13px; background: rgba(8,10,30,.6); color: #fff; border-radius: 10px; }
.wh-stick { position: absolute; left: 16px; bottom: 56px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.4); pointer-events: auto; touch-action: none; }
.wh-knob { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.6); }
.wh-btn { position: absolute; pointer-events: auto; touch-action: none; min-height: 0; border-radius: 50%; color: #1b1300; background: linear-gradient(180deg, #ffc933, #ffb703); font-weight: 900; font-size: 13px; padding: 0; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.wh-btn.down { transform: scale(.92); filter: brightness(1.3); }
.wh-atk { right: 16px; bottom: 60px; width: 92px; height: 92px; }
.wh-jmp { right: 118px; bottom: 56px; width: 70px; height: 70px; background: linear-gradient(180deg, #8ff0ff, #3ddbd9); }
.wh-ddg { right: 36px; bottom: 164px; width: 70px; height: 70px; background: linear-gradient(180deg, #d9b8ff, #9b5de5); color: #fff; }
table.controls { width: 100%; border-collapse: collapse; font-size: 14px; }
table.controls td, table.controls th { padding: 6px 8px; border-bottom: 1px solid var(--panel2); text-align: left; vertical-align: top; }
table.controls td:first-child { font-weight: 700; white-space: nowrap; }
kbd { background: var(--panel2); border: 1px solid rgba(255,255,255,.2); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; font: 600 12px ui-monospace, Consolas, monospace; white-space: nowrap; }
@media (max-width: 700px) {
  .wh-stick { width: 96px; height: 96px; left: 10px; bottom: 44px; }
  .wh-knob { left: 28px; top: 28px; width: 40px; height: 40px; }
  .wh-atk { right: 10px; bottom: 46px; width: 70px; height: 70px; font-size: 11px; }
  .wh-jmp { right: 86px; bottom: 40px; width: 54px; height: 54px; font-size: 10px; }
  .wh-ddg { right: 22px; bottom: 124px; width: 54px; height: 54px; font-size: 10px; }
  .wh-tip { display: none; }
  .wh-toast { font-size: 15px; top: 14%; }
}

/* fighting-move buttons */
.wh-skills { position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); display: flex; gap: 8px; pointer-events: none; }
.wh-skill { position: relative; overflow: hidden; pointer-events: auto; touch-action: none; width: 62px; height: 62px; min-height: 0; padding: 0; border-radius: 14px; background: rgba(8,10,30,.7); border: 2px solid rgba(255,255,255,.45); color: #fff; font-weight: 900; }
.wh-skill .wh-sk-cd { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(255,255,255,.28); }
.wh-skill .wh-sk-name { position: relative; display: block; font-size: 11px; margin-top: 12px; }
.wh-skill .wh-sk-key { position: relative; display: block; font-size: 15px; color: #ffd23f; }
.wh-skill.off { opacity: .6; }
.wh-skill.ready { border-color: #ffd23f; box-shadow: 0 0 14px #ffd23f; animation: pulse 0.8s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
@media (max-width: 700px) {
  .wh-skills { left: auto; right: 8px; top: 44px; bottom: auto; transform: none; flex-direction: column; gap: 6px; }
  .wh-skill { width: 46px; height: 46px; border-radius: 12px; }
  .wh-skill .wh-sk-name { font-size: 9px; margin-top: 6px; } .wh-skill .wh-sk-key { font-size: 12px; }
  .wh-combo { right: 66px; font-size: 24px; }
}

/* world HUD v2: health, shield, armor, coins, fuel, hints */
.wh-stats { position: absolute; left: 10px; top: 10px; width: min(46%, 240px); }
.wh-lvl, .wh-lvltxt { font-size: 13px; }
.wh-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.wh-rowlab { width: 44px; font-size: 9px; letter-spacing: .5px; opacity: .9; }
.wh-rownum { width: 44px; font-size: 10px; text-align: right; }
.wh-bar.thin { flex: 1; height: 8px; }
.wh-bar.hp .wh-fill { background: linear-gradient(90deg, #ff5d5d, #4cd964); }
.wh-bar.shield .wh-fill { background: linear-gradient(90deg, #4d7dff, #9ff3ff); }
.wh-bar.armor .wh-fill { background: linear-gradient(90deg, #8a93a8, #e5e9f5); }
.wh-coins { margin-top: 4px; font-size: 14px; color: #ffd23f; }
.wh-fuel { position: absolute; left: 10px; bottom: 30px; width: min(40%, 200px); opacity: 0; transition: opacity .2s; }
.wh-fuel.on { opacity: 1; }
.wh-fuel .wh-fill { background: linear-gradient(90deg, #ff7b25, #ffd23f); }
.wh-hint { position: absolute; left: 50%; bottom: 112px; transform: translateX(-50%); font-size: 13px; background: rgba(8,10,30,.7); padding: 4px 12px; border-radius: 999px; opacity: 0; transition: opacity .15s; max-width: 90%; text-align: center; }
.wh-hint.on { opacity: 1; }
.wh-hurt { position: absolute; inset: 0; box-shadow: inset 0 0 60px 10px rgba(255,40,40,.55); opacity: 0; transition: opacity .2s; pointer-events: none; }
.wh-hurt.on { opacity: 1; }
.wh-skill .wh-sk-icon { position: relative; display: block; font-size: 18px; line-height: 1; margin-top: 4px; }
.wh-skill .wh-sk-name { margin-top: 2px; font-size: 9px; line-height: 1.05; }
.wh-use { right: 150px; bottom: 124px; width: 54px; height: 54px; background: linear-gradient(180deg, #b6ff7a, #4cd964); font-size: 11px; }
@media (max-width: 700px) {
  .wh-stats { width: min(54%, 200px); }
  .wh-skills { display: grid; grid-template-columns: repeat(2, 44px); gap: 5px; right: 6px; top: 118px; }
  .wh-skill { width: 44px; height: 44px; } .wh-skill .wh-sk-icon { font-size: 15px; margin-top: 2px; } .wh-skill .wh-sk-name { display: none; } .wh-skill .wh-sk-key { font-size: 11px; }
  .wh-use { right: 84px; bottom: 112px; width: 46px; height: 46px; }
  .wh-hint { bottom: 150px; font-size: 11px; }
  .wh-fuel { bottom: 150px; }
}
/* backpack, move book, character picker (below the 3D view) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip-btn { min-height: 34px; padding: 4px 12px; border-radius: 999px; font-size: 13px; }
.chip-btn.on { background: var(--accent); color: #1b1300; outline: none; font-weight: 700; }
.itemgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.itemcard { background: var(--panel2); border-radius: 12px; padding: 10px; border-left: 4px solid var(--c, #888); }
.itemcard b { display: block; } .itemcard .muted { display: block; margin: 2px 0 6px; }
.itemcard button { min-height: 32px; padding: 3px 10px; font-size: 13px; margin: 2px 4px 2px 0; }
.movecard { background: var(--panel2); border-radius: 12px; padding: 10px; border-left: 5px solid var(--c, #888); }
.movecard h4 { margin: 0 0 2px; font-size: 15px; } .movecard .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.slotrow { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.slotrow button { min-height: 30px; min-width: 32px; padding: 2px 8px; font-size: 12px; }
.slotrow button.on { background: var(--accent2); color: #062a2a; font-weight: 700; outline: none; }
