:root {
  --font: "STKaiti", "KaiTi", "Kaiti TC", "BiauKai", Georgia, serif;
  --ink: #1a1410;
  --cream: #f6ecd4;
  --red: #c8361f;
  --gold: #f0c35a;
  --jade: #3e8f83;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a1410; touch-action: none; user-select: none; -webkit-user-select: none; }
body { font-family: var(--font); color: var(--cream); }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }
.overlay { display: flex; align-items: center; justify-content: center; background: rgba(20, 12, 8, 0.55); z-index: 30; padding: 16px; }

.outline { -webkit-text-stroke: 0; }
.ink-text, .ptitle, #timer, .num, #bannerText, .btn, #prompt {
  font-weight: 900;
  paint-order: stroke fill;
  -webkit-text-stroke: 5px var(--ink);
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.65);
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#xpbar { position: absolute; left: calc(10px + env(safe-area-inset-left)); right: 64px; top: calc(10px + env(safe-area-inset-top)); height: 16px; border: 2px solid var(--ink); border-radius: 9px; background: rgba(26, 20, 16, 0.6); overflow: hidden; }
#xpfill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: linear-gradient(90deg, #2f8f86, #8fe3c8); transition: width 0.12s; }
#lvtext { position: absolute; left: 8px; top: -2px; font-size: 14px; font-weight: 900; color: #fff; paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); }
#stats { position: absolute; left: calc(10px + env(safe-area-inset-left)); top: calc(34px + env(safe-area-inset-top)); width: 150px; display: flex; flex-direction: column; gap: 5px; }
#stats .row { display: flex; align-items: center; gap: 5px; }
.seal { flex: 0 0 auto; width: 24px; height: 24px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 900; color: var(--cream); border: 2px solid var(--ink); transform: rotate(-4deg); }
.seal.red { background: var(--red); }
.seal.gold { background: #b0821e; }
.seal.ink { background: #2b2420; }
.bar { position: relative; flex: 1; height: 16px; border: 2px solid var(--ink); border-radius: 8px; background: rgba(26, 20, 16, 0.65); overflow: hidden; }
.bar > div { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; }
#hpfill { background: linear-gradient(180deg, #ef6a4b, #b52a17); transition: width 0.15s; }
#ultfill { background: linear-gradient(180deg, #ffe08a, #d49b1f); width: 0%; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 13px; font-weight: 900; color: #fff; paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); white-space: nowrap; }
#ultbar.ready { animation: glow 0.6s ease-in-out infinite alternate; }
@keyframes glow { from { box-shadow: 0 0 0 rgba(255, 210, 80, 0); } to { box-shadow: 0 0 12px rgba(255, 210, 80, 1); } }
#stats .row.small { gap: 6px; }
.num { font-size: 18px; color: var(--cream); -webkit-text-stroke: 4px var(--ink); min-width: 28px; }
#goldicon { width: 26px; height: 26px; object-fit: contain; margin-left: 4px; }
#center { position: absolute; left: 50%; top: calc(32px + env(safe-area-inset-top)); transform: translateX(-50%); text-align: center; }
#timer { font-size: 30px; line-height: 1; color: var(--cream); letter-spacing: 1px; }
#sect { margin-top: 4px; font-size: 14px; font-weight: 900; color: var(--gold); paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); white-space: nowrap; }
#bossbar { position: absolute; left: 50%; transform: translateX(-50%); top: calc(118px + env(safe-area-inset-top)); width: min(82%, 420px); text-align: center; }
#bossname { font-size: 16px; font-weight: 900; color: #ffd9c9; paint-order: stroke fill; -webkit-text-stroke: 4px var(--ink); margin-bottom: 2px; }
.bar.boss { height: 14px; }
#bossfill { background: linear-gradient(180deg, #e2483a, #7d1308); transition: width 0.1s; }
#tutorial { position: absolute; left: 50%; top: 34%; transform: translateX(-50%); width: 92%; text-align: center; font-size: 15px; font-weight: 900; color: var(--cream); paint-order: stroke fill; -webkit-text-stroke: 4px var(--ink); transition: opacity 0.6s; opacity: 0; }
#tutorial.show { opacity: 1; }

/* ---------- Title ---------- */
#title { z-index: 20; overflow: hidden; cursor: pointer; }
#titlebg { position: absolute; inset: -3%; background: #e9dcc0 url(assets/cover-bg.webp) center / cover no-repeat; animation: drift 14s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.07) translate(-1%, 1%); } }
#logo { position: absolute; left: 50%; top: 5%; width: 84%; max-height: 30%; object-fit: contain; transform: translateX(-50%); filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.35)); animation: logoIn 0.65s cubic-bezier(0.3, 1.6, 0.5, 1) both, float 3.2s ease-in-out 0.7s infinite; }
@keyframes logoIn { from { transform: translateX(-50%) translateY(-60px) scale(0.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-6px); } }
#prompt { position: absolute; left: 0; right: 0; bottom: 11%; text-align: center; font-size: 24px; color: var(--cream); -webkit-text-stroke: 6px var(--ink); animation: pulse 1.3s ease-in-out infinite; padding: 0 12px; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.6; transform: scale(0.96); } }
.corner { position: absolute; top: calc(12px + env(safe-area-inset-top)); width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(26, 20, 16, 0.8); background: rgba(26, 20, 16, 0.45); display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer; transition: transform 0.12s; }
.corner:active { transform: scale(0.9); }
.corner.left { left: calc(12px + env(safe-area-inset-left)); }
.corner.right { right: calc(12px + env(safe-area-inset-right)); }
.corner svg { width: 26px; height: 26px; fill: var(--gold); }
.corner img { width: 34px; height: 34px; object-fit: contain; }
.corner .key { position: absolute; bottom: -18px; font-size: 11px; font-weight: 900; color: var(--cream); paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); font-family: Arial, sans-serif; }

/* ---------- Panels ---------- */
.panel { position: relative; border: 34px solid transparent; border-image: url(assets/ui-panel.webp) 23% fill / 34px stretch; color: var(--ink); padding: 0; width: min(100%, 420px); text-align: center; animation: pop 0.28s cubic-bezier(0.3, 1.5, 0.6, 1) both; }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.ptitle { font-size: 30px; color: var(--red); -webkit-text-stroke: 5px var(--cream); text-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35); line-height: 1.15; }
.psub { font-size: 15px; font-weight: 700; color: #4a3a2c; margin: 2px 0 10px; }
#cards { display: flex; flex-direction: column; gap: 10px; }
.card { position: relative; display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 10px; border-radius: 12px; border: 3px solid var(--ink); background: rgba(255, 248, 230, 0.92); cursor: pointer; font-family: var(--font); color: var(--ink); transition: transform 0.12s, box-shadow 0.12s, background 0.12s; min-height: 72px; width: 100%; }
.card.focus, .card:hover { transform: scale(1.03); background: #fff4d6; box-shadow: 0 0 0 3px var(--gold), 0 4px 0 rgba(0, 0, 0, 0.3); }
.card:active { transform: scale(0.97); }
.glyph { flex: 0 0 auto; width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 900; color: var(--cream); background: radial-gradient(circle at 35% 30%, #3a302a, #120d0a); border: 3px solid var(--gold); box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.35); }
.glyph.passive { border-color: var(--jade); background: radial-gradient(circle at 35% 30%, #2c5c55, #0f2522); }
.glyph.bun { background: radial-gradient(circle at 35% 30%, #a97a3a, #4a2c10); }
.cinfo { flex: 1; min-width: 0; }
.cname { font-size: 19px; font-weight: 900; color: var(--ink); display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.clv { font-size: 13px; font-weight: 900; color: var(--red); }
.cnew { font-size: 12px; font-weight: 900; color: var(--cream); background: var(--red); border-radius: 4px; padding: 1px 6px; transform: rotate(-4deg); display: inline-block; }
.cdesc { font-size: 14px; line-height: 1.3; color: #3c2f24; margin-top: 2px; }

.btn { display: block; width: 100%; min-height: 52px; margin: 8px 0 0; border: 16px solid transparent; border-image: url(assets/ui-button.webp) 30% fill / 16px stretch; background: none; color: var(--cream); font-family: var(--font); font-size: 19px; -webkit-text-stroke: 4px var(--ink); cursor: pointer; padding: 0 4px; line-height: 1.1; transition: transform 0.1s, filter 0.1s; }
.btn.focus, .btn:hover { filter: brightness(1.15); transform: scale(1.03); }
.btn:active { transform: scale(0.95); }
.btn:disabled { filter: grayscale(0.8) brightness(0.8); cursor: default; }
.btn.small { width: auto; min-height: 44px; font-size: 16px; padding: 0 10px; }
.btn img { width: 22px; height: 22px; vertical-align: -5px; margin-right: 4px; object-fit: contain; }
#rvmsg { min-height: 20px; font-size: 14px; font-weight: 900; color: var(--red); margin-top: 6px; }
#helptext { font-size: 16px; line-height: 1.45; text-align: left; white-space: pre-line; color: #2c2219; font-weight: 700; margin: 8px 0; }

/* ---------- Banner / subtitles ---------- */
#banner { position: fixed; left: 0; right: 0; top: 24%; text-align: center; z-index: 15; pointer-events: none; }
#banner.show { animation: slam 0.45s cubic-bezier(0.2, 1.8, 0.5, 1) both; }
#banner.out { animation: fadeOut 0.4s ease-in both; }
@keyframes slam { from { transform: scale(2.4) rotate(-8deg); opacity: 0; } to { transform: scale(1) rotate(-4deg); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; transform: rotate(-4deg); } to { opacity: 0; transform: rotate(-4deg) translateY(-20px); } }
#bannerText { display: inline-block; font-size: 42px; color: var(--cream); -webkit-text-stroke: 8px var(--ink); padding: 6px 22px; background: linear-gradient(90deg, transparent, rgba(200, 54, 31, 0.92) 12%, rgba(200, 54, 31, 0.92) 88%, transparent); }
#bannerSub { font-size: 16px; font-weight: 900; color: var(--gold); paint-order: stroke fill; -webkit-text-stroke: 4px var(--ink); margin-top: 6px; }
#subtitle { position: fixed; left: 50%; top: calc(168px + env(safe-area-inset-top)); transform: translateX(-50%); max-width: 88%; text-align: center; z-index: 16; pointer-events: none; font-size: 17px; font-weight: 900; color: #fff; background: rgba(26, 20, 16, 0.6); border-radius: 10px; padding: 6px 12px; paint-order: stroke fill; -webkit-text-stroke: 3px var(--ink); }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 12; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(200, 30, 20, 0.75) 100%); }

/* ---------- Intro ---------- */
#intro { position: fixed; inset: 0; z-index: 40; background: #e9dcc0 url(assets/cover-bg.webp) center / cover no-repeat; }
#introVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#skip { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); margin: 0; }
#introSub { position: absolute; left: 6%; right: 6%; bottom: 9%; text-align: center; font-size: 19px; font-weight: 900; color: #fff; paint-order: stroke fill; -webkit-text-stroke: 4px var(--ink); text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6); }
