:root {
  --ink: #f4ead6;
  --muted: #b9a988;
  --panel: rgba(27, 23, 18, 0.88);
  --line: rgba(232, 200, 140, 0.25);
  --gold: #e8b65a;
  --red: #d9483b;
  --green: #5fbf6a;
  --blue: #5aa8e8;
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1712; color: var(--ink); overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }

/* Screens */
.screen, .overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay { background: rgba(0, 0, 0, 0.45); z-index: 30; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); backdrop-filter: blur(6px); }
.title-panel { text-align: center; }
h1 { margin: 4px 0 0; font-size: 34px; letter-spacing: 2px; line-height: 1; text-transform: uppercase; color: var(--muted); }
h1 span { color: var(--gold); font-size: 46px; }
h2 { margin: 0 0 4px; color: var(--gold); letter-spacing: 1px; }
h3 { margin: 8px 0 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 2px; }
.tag { margin: 0 0 8px; color: var(--muted); font-style: italic; }
.ver { margin: 4px 0 0; font-size: 11px; color: var(--muted); opacity: .6; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.list { display: flex; flex-direction: column; gap: 10px; }

.btn { font: inherit; color: var(--ink); background: linear-gradient(#5b4426, #3d2d18); border: 1px solid #8a6a3a; border-radius: 10px; padding: 12px 14px; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn:active { transform: translateY(1px); }
.btn.big { padding: 15px; font-size: 17px; }
.btn.sm { padding: 8px 12px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }

.card { background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 12px; padding: 12px; color: var(--ink); text-align: left; font: inherit; display: flex; flex-direction: column; gap: 6px; }
button.card { cursor: pointer; }
button.card:hover { border-color: var(--gold); }
.q-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.q-stars { color: var(--gold); letter-spacing: 2px; }
.q-name { font-size: 20px; font-weight: 800; }
.q-title { font-size: 12px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; }
.q-desc { font-size: 13px; color: var(--muted); }
.s-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.s-name { font-weight: 800; font-size: 16px; }
.s-sub { font-size: 12px; color: var(--muted); }
.s-stat { font-size: 13px; }
.s-stat b { color: var(--gold); }
.lv { color: var(--gold); }
.s-cost { display: flex; flex-wrap: wrap; gap: 6px; }
.mat { font-size: 11px; padding: 3px 7px; border-radius: 6px; background: rgba(255, 255, 255, .06); }
.mat.ok { color: var(--green); }
.mat.no { color: #e88; }
.box-row { display: flex; justify-content: space-between; padding: 6px 2px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.box-row:last-child { border-bottom: 0; }
.box-row.dim { opacity: .4; }
.box-row.rare span { color: var(--gold); }
.lbl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input { font: inherit; font-size: 16px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .35); color: var(--ink); width: 100%; }
#code { text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.status { min-height: 18px; font-size: 13px; color: var(--muted); margin: 0; text-align: center; }
.code-box { margin: 0; text-align: center; font-size: 14px; color: var(--muted); }
.code-box b { color: var(--gold); font-size: 26px; letter-spacing: 6px; display: block; }
.lob-p { padding: 4px 0; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
.chip.on { background: var(--gold); color: #1b1712; border-color: var(--gold); font-weight: 700; }
.chip:disabled { cursor: default; }
#result-title.win { color: var(--gold); }
#result-title.lose { color: var(--red); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
.hud-tl { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); width: min(38vw, 260px); display: flex; flex-direction: column; gap: 5px; }
.hud-tc { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(36vw, 340px); text-align: center; }
.hud-tr { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 10px; }
.bar { position: relative; height: 14px; background: rgba(0, 0, 0, .55); border: 1px solid rgba(255, 255, 255, .2); border-radius: 8px; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; transition: width .15s; }
.bar.hp i { background: linear-gradient(90deg, #3fa04a, #7fdc6a); }
.bar.hp span { position: absolute; right: 6px; top: -1px; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.bar.st { height: 7px; }
.bar.st i { background: #e8c95a; transition: none; }
.bar.mon { height: 10px; }
.bar.mon i { background: linear-gradient(90deg, #a8302a, #e0574a); }
.bar.mon.enraged { box-shadow: 0 0 10px #ff4b3a; }
#mon-name { font-weight: 800; letter-spacing: 2px; text-transform: uppercase; font-size: 13px; text-shadow: 0 1px 3px #000; margin-bottom: 3px; }
#timer { font-weight: 800; font-size: 16px; text-shadow: 0 1px 3px #000; }
#faints { color: var(--green); letter-spacing: 2px; font-weight: 800; }
.icon { pointer-events: auto; font: inherit; font-size: 18px; width: 40px; height: 40px; border-radius: 10px; background: rgba(0, 0, 0, .5); color: var(--ink); border: 1px solid rgba(255, 255, 255, .2); }
#party { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.pm { position: relative; font-size: 11px; padding: 1px 6px; background: rgba(0, 0, 0, .45); border-radius: 6px; overflow: hidden; }
.pm span { position: relative; z-index: 1; }
.pm i { position: absolute; inset: 0 auto 0 0; background: rgba(95, 191, 106, .45); }
#prompt { position: absolute; bottom: 30%; left: 50%; transform: translateX(-50%); font-weight: 700; text-shadow: 0 1px 3px #000; font-size: 15px; white-space: nowrap; }
.keys-hint { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 11px; color: rgba(255, 255, 255, .6); text-shadow: 0 1px 2px #000; white-space: nowrap; }
@media (pointer: coarse) { .keys-hint { display: none; } }

/* Touch */
#touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#joy-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 60%; pointer-events: auto; touch-action: none; }
#joy-base { position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); background: rgba(0, 0, 0, .2); opacity: 0; }
#joy-base.on { opacity: 1; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, .45); transform: translate(-50%, -50%); }
.btns { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); width: 220px; height: 210px; }
.tb { position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .3); color: #fff; font: inherit; font-weight: 800; font-size: 13px; text-shadow: 0 1px 2px #000; }
.tb.down { transform: scale(.92); filter: brightness(1.3); }
.tb.atk { right: 0; bottom: 0; width: 92px; height: 92px; background: rgba(217, 72, 59, .55); font-size: 15px; }
.tb.hvy { right: 100px; bottom: 6px; width: 70px; height: 70px; background: rgba(232, 182, 90, .5); }
.tb.dge { right: 14px; bottom: 102px; width: 70px; height: 70px; background: rgba(90, 168, 232, .5); }
.tb.pot { right: 104px; bottom: 92px; width: 52px; height: 52px; background: rgba(95, 191, 106, .5); font-size: 18px; }
.tb.pot small { position: absolute; right: -4px; bottom: -4px; font-size: 11px; background: #222; border-radius: 8px; padding: 1px 5px; }
.tb.lck { right: 160px; bottom: 140px; width: 46px; height: 46px; background: rgba(0, 0, 0, .4); font-size: 18px; }
.tb.lck.on { background: rgba(232, 182, 90, .8); }

/* FX */
#dmg-layer { position: fixed; inset: 0; pointer-events: none; z-index: 7; overflow: hidden; }
.ft { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 18px; color: #fff; text-shadow: 0 2px 3px #000; animation: ft .9s ease-out forwards; }
.ft.weak { color: #ffd84a; font-size: 21px; }
.ft.crit { color: #ff8a3a; font-size: 24px; }
.ft.hurt { color: #ff5a4a; }
@keyframes ft { 0% { opacity: 0; margin-top: 0; } 15% { opacity: 1; } 100% { opacity: 0; margin-top: -50px; } }
.nametag { position: absolute; left: 0; top: 0; font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000; white-space: nowrap; }
#hurt-flash { position: fixed; inset: 0; pointer-events: none; z-index: 4; box-shadow: inset 0 0 120px rgba(255, 30, 20, .8); opacity: 0; }
#hurt-flash.on { animation: hf .5s ease-out; }
@keyframes hf { from { opacity: 1; } to { opacity: 0; } }
#toast { position: fixed; top: 22%; left: 50%; transform: translate(-50%, -10px); background: rgba(20, 16, 12, .85); border: 1px solid var(--gold); color: var(--ink); padding: 10px 16px; border-radius: 10px; font-weight: 700; z-index: 40; opacity: 0; transition: .25s; pointer-events: none; text-align: center; max-width: 90vw; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
