/* ENT Quest — styles. Dark "night shift" theme, right-to-left, phone first. */
:root {
  --bg: #0b1019;
  --bg2: #111827;
  --card: #172033;
  --card2: #1e2a42;
  --line: #2c3a58;
  --text: #e9eef8;
  --dim: #9aa9c6;
  --gold: #f5c85a;
  --gold-d: #c9962a;
  --ok: #4fd18b;
  --bad: #ff6f6f;
  --realm: #7cc4ff;
  --realm-rgb: 124, 196, 255;
  --hud-h: 68px;
  --maxw: 760px;
  --display: 'Suez One', 'Heebo', system-ui, sans-serif;
}
.realm-otology { --realm: #f2b84b; --realm-rgb: 242, 184, 75; }
.realm-rhino { --realm: #f2879a; --realm-rgb: 242, 135, 154; }
.realm-laryngology { --realm: #b796f5; --realm-rgb: 183, 150, 245; }
.realm-hn { --realm: #f2765c; --realm-rgb: 242, 118, 92; }
.realm-gpo { --realm: #4fd0b5; --realm-rgb: 79, 208, 181; }
.realm-peds { --realm: #74b9ff; --realm-rgb: 116, 185, 255; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(92, 120, 220, 0.20), transparent 60%),
    radial-gradient(900px 500px at 0% 105%, rgba(245, 200, 90, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
body.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; text-align: inherit; }
button:disabled { cursor: default; }
button:focus-visible, label.btn:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }
h1, h2, h3, h4, p { margin: 0; }
bdi { unicode-bidi: isolate; }
img { max-width: 100%; height: auto; }
[hidden] { display: none !important; }

#app { max-width: var(--maxw); margin: 0 auto; padding: 18px 14px 40px; }
body[data-view='battle'] #app { padding-top: 0; padding-bottom: 110px; }
.loading { text-align: center; color: var(--dim); padding: 80px 0; }

/* ---------- Buttons, cards, bars ---------- */
.btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 10px 18px; border-radius: 12px; background: var(--card2); border: 1px solid var(--line);
  font-weight: 600; text-align: center; transition: transform .12s, background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: #263556; border-color: #40527c; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn small { font-weight: 400; font-size: .8rem; opacity: .85; }
.btn.primary {
  background: linear-gradient(180deg, #ffd978, var(--gold) 45%, var(--gold-d));
  color: #2a1d02; border-color: #ffe9a8; box-shadow: 0 6px 22px rgba(245, 200, 90, .22);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffe08f, #f8cf6b 45%, #d3a136); border-color: #fff1c4; }
.btn.big { width: 100%; padding: 15px 18px; font-size: 1.12rem; font-weight: 800; border-radius: 14px; }
.btn.small { padding: 7px 12px; font-size: .88rem; border-radius: 10px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, .05); border-color: transparent; color: var(--text); }
.btn.danger { background: #3a1c22; border-color: #7a3540; color: #ffb3b3; }
.btn.danger:hover:not(:disabled) { background: #4a222a; border-color: #a04452; }
.back { color: var(--dim); font-size: .92rem; padding: 6px 2px; margin-bottom: 6px; }
.back:hover { color: var(--text); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--realm); transition: width .6s ease; }
.bar.xp > i { background: linear-gradient(90deg, #6ea8ff, #9b8cff); }
.bar.gold > i { background: linear-gradient(90deg, var(--gold-d), var(--gold)); }
.bar-label { display: flex; justify-content: space-between; font-size: .8rem; color: var(--dim); margin: 4px 0 12px; }
.bar-label:last-child { margin-bottom: 0; }
.section-title { font-size: .95rem; font-weight: 700; color: var(--dim); margin: 22px 0 10px; letter-spacing: .02em; }
.section-title small { font-weight: 400; font-size: .8rem; margin-inline-start: 6px; opacity: .8; }
.fineprint { color: var(--dim); font-size: .8rem; text-align: center; margin-top: 18px; opacity: .8; }
.empty { color: var(--dim); font-size: .92rem; padding: 10px 0; }

/* ---------- Home ---------- */
.home { display: flex; flex-direction: column; gap: 12px; }
.logo { text-align: center; padding: 14px 0 6px; }
.logo-mark {
  width: 84px; height: 84px; margin: 0 auto 8px; border-radius: 50%; display: grid; place-items: center; font-size: 44px;
  background: radial-gradient(circle at 35% 30%, rgba(245, 200, 90, .35), rgba(245, 200, 90, .05) 70%);
  border: 1px solid rgba(245, 200, 90, .35); box-shadow: 0 0 40px rgba(245, 200, 90, .18);
  animation: bob 4s ease-in-out infinite;
}
.logo h1 { font-family: var(--display); font-size: 2.3rem; font-weight: 400; letter-spacing: .01em; color: #fff3cf; text-shadow: 0 2px 18px rgba(245, 200, 90, .25); }
.logo p { color: var(--dim); font-size: .92rem; }
.player-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.rank small { display: block; color: var(--dim); font-size: .78rem; }
.rank b { font-family: var(--display); font-weight: 400; font-size: 1.35rem; color: #fff3cf; }
.streak { display: flex; align-items: baseline; gap: 5px; color: var(--dim); filter: grayscale(1); opacity: .7; }
.streak.on { filter: none; opacity: 1; color: var(--text); }
.streak b { font-size: 1.3rem; }
.streak small { font-size: .78rem; }
.nudge { display: flex; align-items: center; gap: 12px; text-align: start; width: 100%; border-color: rgba(255, 111, 111, .35); background: linear-gradient(90deg, rgba(255, 111, 111, .12), var(--card)); transition: transform .12s, border-color .15s; }
.nudge:hover { border-color: rgba(255, 111, 111, .6); transform: translateY(-1px); }
.nudge-e { font-size: 1.7rem; }
.nudge b { display: block; }
.nudge small { color: var(--dim); }
.realm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.realm-tile {
  position: relative; display: flex; flex-direction: column; gap: 5px; padding: 12px; border-radius: 14px; text-align: start;
  background: linear-gradient(160deg, rgba(var(--realm-rgb), .14), var(--card) 60%); border: 1px solid rgba(var(--realm-rgb), .28);
  transition: transform .12s, border-color .15s;
}
.realm-tile:hover { transform: translateY(-2px); border-color: rgba(var(--realm-rgb), .6); }
.realm-tile .ri { font-size: 1.5rem; line-height: 1; }
.realm-tile b { font-size: .95rem; }
.realm-tile small { color: var(--dim); font-size: .76rem; text-align: end; }
.realm-tile .crown { position: absolute; top: 8px; inset-inline-end: 10px; font-size: 1rem; }
.home-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }

/* ---------- Setup ---------- */
.setup h2, .codex h2, .trophies h2 { font-family: var(--display); font-weight: 400; font-size: 1.8rem; color: #fff3cf; }
.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.chips.three { grid-template-columns: repeat(3, 1fr); }
.chip {
  display: flex; flex-direction: column; gap: 2px; padding: 11px 12px; border-radius: 12px; text-align: start;
  background: var(--card); border: 1px solid var(--line); transition: border-color .15s, background .15s;
}
.chip:hover:not(:disabled) { border-color: #4a5d8a; }
.chip b { font-size: .98rem; }
.chip small { color: var(--dim); font-size: .78rem; line-height: 1.35; }
.chip.on { border-color: var(--gold); background: linear-gradient(160deg, rgba(245, 200, 90, .16), var(--card) 70%); box-shadow: 0 0 0 1px var(--gold) inset; }
.chip[class*='realm-'].on { border-color: var(--realm); background: linear-gradient(160deg, rgba(var(--realm-rgb), .2), var(--card) 70%); box-shadow: 0 0 0 1px var(--realm) inset; }
.chip:disabled { opacity: .45; }
.setup .btn.big { margin-top: 24px; }

/* ---------- HUD ---------- */
#hud { display: none; }
#hud.on {
  display: block; position: sticky; top: 0; z-index: 30; height: var(--hud-h);
  background: rgba(11, 16, 25, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.hud-row { max-width: var(--maxw); margin: 0 auto; padding: 8px 12px 4px; display: flex; align-items: center; gap: 10px; }
.hud-btn { width: 38px; height: 38px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line); display: grid; place-items: center; flex: none; font-size: 1.05rem; }
.hud-btn:hover { background: #263556; }
.hud-btn.bag { width: auto; padding: 0 10px; display: flex; gap: 4px; align-items: center; }
.hud-btn.bag b { font-size: .88rem; }
.hearts { flex: 1; display: flex; flex-wrap: wrap; gap: 1px; font-size: 1.05rem; line-height: 1.1; }
.heart.empty { opacity: .45; }
.hud-stat { display: flex; align-items: center; gap: 3px; font-size: .95rem; flex: none; }
.hud-stat b { font-variant-numeric: tabular-nums; }
.hud-stat.combo { opacity: .55; filter: grayscale(1); transition: all .2s; }
.hud-stat.combo.hot { opacity: 1; filter: none; color: #ffb35c; text-shadow: 0 0 12px rgba(255, 150, 60, .6); }
.floors { max-width: var(--maxw); margin: 0 auto; padding: 0 14px; display: flex; align-items: center; gap: 5px; height: 16px; }
.fdot { flex: 1; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .12); display: grid; place-items: center; font-style: normal; font-size: .7rem; line-height: 1; }
.fdot.done { background: rgba(245, 200, 90, .55); }
.fdot.cur { background: var(--gold); box-shadow: 0 0 10px rgba(245, 200, 90, .7); }
.fdot.boss { flex: none; width: 18px; height: 16px; background: none; box-shadow: none; opacity: .6; }
.fdot.boss.cur { opacity: 1; filter: drop-shadow(0 0 6px rgba(245, 200, 90, .9)); }
.shake { animation: shake .4s; }

/* ---------- Scenes (doors, reward, rest, shop, event) ---------- */
.scene { text-align: center; padding-top: 18px; animation: rise .35s ease both; }
.scene-emoji { font-size: 3.4rem; line-height: 1.1; margin-bottom: 6px; animation: bob 3.5s ease-in-out infinite; }
.scene-emoji.big { font-size: 4.6rem; }
.scene-title { font-family: var(--display); font-weight: 400; font-size: 1.75rem; color: #fff3cf; }
.scene-title small { font-family: 'Heebo', sans-serif; font-size: .95rem; color: var(--dim); }
.scene-sub { color: var(--dim); margin: 4px 0 18px; }
.scene-text { max-width: 520px; margin: 10px auto 20px; font-size: 1.05rem; line-height: 1.7; }
.scene-got { color: var(--gold); font-weight: 700; margin: 8px 0 16px; }
.scene .btn.big { max-width: 420px; margin-top: 18px; }

.doors { display: flex; gap: 10px; justify-content: center; align-items: stretch; margin-top: 8px; }
.door {
  flex: 1 1 0; max-width: 220px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 12px 8px 14px; border-radius: 110px 110px 16px 16px; text-align: center;
  background: linear-gradient(180deg, rgba(var(--realm-rgb), .2), var(--card) 55%, #121a2b);
  border: 1px solid rgba(var(--realm-rgb), .4); box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  transition: transform .16s, box-shadow .16s, border-color .16s; animation: rise .4s ease both;
}
.door:nth-child(2) { animation-delay: .07s; }
.door:nth-child(3) { animation-delay: .14s; }
.door:hover { transform: translateY(-6px); border-color: var(--realm); box-shadow: 0 16px 40px rgba(var(--realm-rgb), .25); }
.door.calm { --realm: #c9d4ea; --realm-rgb: 201, 212, 234; }
.door.t-elite, .door.t-boss { box-shadow: 0 10px 30px rgba(0, 0, 0, .35), 0 0 0 2px rgba(var(--realm-rgb), .35) inset; }
.door-top { font-size: .8rem; font-weight: 700; color: var(--realm); letter-spacing: .03em; margin-top: 8px; }
.door-face {
  width: 78px; height: 78px; border-radius: 50%; display: grid; place-items: center; margin: 4px 0;
  background: radial-gradient(circle at 35% 30%, rgba(var(--realm-rgb), .4), rgba(var(--realm-rgb), .06) 70%);
  border: 1px solid rgba(var(--realm-rgb), .45);
}
.door-emoji { font-size: 2.5rem; line-height: 1; }
.door.t-boss .door-face { width: 92px; height: 92px; }
.door.t-boss .door-emoji { font-size: 3rem; }
.door-name { font-size: .98rem; line-height: 1.25; }
.door-realm { font-size: .8rem; color: var(--dim); }
.door-hint { font-size: .76rem; color: var(--dim); background: rgba(255, 255, 255, .06); padding: 2px 8px; border-radius: 99px; }
.door.calm .door-hint, .door .door-hint:empty { background: none; }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 640px; margin: 0 auto 14px; }
.choices.two { grid-template-columns: repeat(2, 1fr); max-width: 520px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 16px 10px; border-radius: 14px; text-align: center;
  background: var(--card); border: 1px solid var(--line); transition: transform .14s, border-color .15s, background .15s; animation: rise .4s ease both;
}
.choice:nth-child(2) { animation-delay: .06s; }
.choice:nth-child(3) { animation-delay: .12s; }
.choice:hover:not(:disabled) { transform: translateY(-4px); border-color: var(--gold); background: var(--card2); }
.choice:disabled { opacity: .45; }
.choice.relic { border-color: rgba(245, 200, 90, .4); background: linear-gradient(170deg, rgba(245, 200, 90, .12), var(--card) 60%); }
.choice-e { font-size: 2rem; line-height: 1.1; flex: none; }
.choice b { font-size: 1rem; }
.choice small { color: var(--dim); font-size: .84rem; line-height: 1.4; }

.shop { display: flex; flex-direction: column; gap: 8px; max-width: 560px; margin: 0 auto; text-align: start; }
.shop-row, .bag-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; width: 100%;
  background: var(--card); border: 1px solid var(--line); text-align: start;
}
.shop-row { transition: border-color .15s, background .15s; }
.shop-row:hover:not(:disabled) { border-color: var(--gold); background: var(--card2); }
.shop-row.relic, .bag-row.relic { border-color: rgba(245, 200, 90, .35); }
.shop-row:disabled { opacity: .5; }
.shop-row.sold { opacity: .4; }
.shop-text { flex: 1; min-width: 0; }
.shop-text b { display: block; }
.shop-text small { color: var(--dim); font-size: .84rem; line-height: 1.4; display: block; }
.price { font-weight: 700; color: var(--gold); white-space: nowrap; }
.bag-list { display: flex; flex-direction: column; gap: 8px; }
.bag-row.none { opacity: .45; }

/* ---------- Battle ---------- */
.battle { animation: rise .3s ease both; }
.stage {
  position: sticky; top: var(--hud-h); z-index: 20; display: flex; align-items: center; gap: 14px;
  margin: 0 -14px 12px; padding: 10px 16px;
  background: linear-gradient(180deg, rgba(var(--realm-rgb), .16), rgba(11, 16, 25, .96) 85%), var(--bg);
  border-bottom: 1px solid rgba(var(--realm-rgb), .3);
}
.enemy {
  position: relative; flex: none; width: 70px; height: 70px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, rgba(var(--realm-rgb), .45), rgba(var(--realm-rgb), .06) 70%);
  border: 1px solid rgba(var(--realm-rgb), .5); box-shadow: 0 0 26px rgba(var(--realm-rgb), .22);
}
.enemy > span:first-child { font-size: 2.5rem; line-height: 1; animation: bob 2.8s ease-in-out infinite; display: block; }
.k-elite .enemy, .k-boss .enemy { box-shadow: 0 0 0 3px rgba(var(--realm-rgb), .28), 0 0 34px rgba(var(--realm-rgb), .35); }
.k-boss .enemy { width: 82px; height: 82px; }
.k-boss .enemy > span:first-child { font-size: 3rem; }
.enemy.hit { animation: enemy-hit .45s; }
.enemy.crit { animation: enemy-crit .6s; }
.enemy.dead > span:first-child { animation: enemy-die .7s forwards; }
.enemy.dead { box-shadow: none; border-color: var(--line); background: rgba(255, 255, 255, .03); }
.float {
  position: absolute; top: -6px; left: 50%; font-weight: 800; font-size: 1.4rem; color: #fff; pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .7); animation: float-up 1s ease-out forwards; direction: ltr;
}
.float.crit { font-size: 1.9rem; color: var(--gold); }
.stage-info { flex: 1; min-width: 0; }
.enemy-kind { font-size: .76rem; font-weight: 700; color: var(--realm); letter-spacing: .03em; }
.enemy-name { font-family: var(--display); font-size: 1.2rem; line-height: 1.25; color: #fff; }
.enemy-line { font-size: .84rem; color: var(--dim); font-style: italic; margin-top: 2px; }
.pips { display: flex; gap: 4px; margin-top: 5px; }
.pip { width: 22px; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .12); transition: background .3s; }
.pip.on { background: var(--realm); box-shadow: 0 0 8px rgba(var(--realm-rgb), .55); }

.qcard { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.qmeta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { font-size: .76rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: rgba(255, 255, 255, .07); color: var(--dim); }
.tag.revenge { background: rgba(255, 111, 111, .16); color: #ffb0b0; }
.tag.due { background: rgba(245, 200, 90, .15); color: #ffe09a; }
.tag.fresh { background: rgba(124, 196, 255, .14); color: #b6dcff; }
.tag.realm { background: rgba(var(--realm-rgb), .14); color: var(--realm); }
.stem { font-size: 1.06rem; line-height: 1.75; }
.qimg { display: block; margin: 14px auto 0; border-radius: 10px; overflow: hidden; background: #fff; border: 1px solid var(--line); cursor: zoom-in; }
.qimg img { display: block; max-height: 46vh; width: auto; }
.opts { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.opt {
  display: flex; align-items: flex-start; gap: 11px; width: 100%; padding: 12px 13px; border-radius: 12px; text-align: start;
  background: var(--card2); border: 1px solid var(--line); line-height: 1.6; transition: border-color .12s, background .12s, transform .1s, opacity .3s;
}
.opt[data-act]:hover { border-color: var(--realm); background: #25345a; }
.opt[data-act]:active { transform: scale(.995); }
.letter {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .92rem;
  background: rgba(255, 255, 255, .08); border: 1px solid var(--line); margin-top: 1px;
}
.otext { flex: 1; min-width: 0; }
.opt.removed { opacity: .28; }
.opt.removed .otext { text-decoration: line-through; }
.opt.right { background: rgba(79, 209, 139, .14); border-color: var(--ok); }
.opt.right .letter { background: var(--ok); border-color: var(--ok); color: #06301b; }
.opt.wrong { background: rgba(255, 111, 111, .13); border-color: var(--bad); }
.opt.wrong .letter { background: var(--bad); border-color: var(--bad); color: #3a0c0c; }
.opt:disabled:not(.right):not(.wrong):not(.removed) { opacity: .6; }

.items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.item {
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 6px; border-radius: 12px; font-size: .88rem;
  background: var(--card); border: 1px dashed var(--line); transition: border-color .15s, background .15s;
}
.item:hover:not(:disabled) { border-color: var(--gold); border-style: solid; background: var(--card2); }
.item:disabled { opacity: .35; }
.item-e { font-size: 1.15rem; }
.item b { color: var(--gold); }

.result { margin-top: 14px; padding: 13px 16px; border-radius: 14px; scroll-margin-top: 180px; animation: pop .35s ease both; }
.result.ok { background: rgba(79, 209, 139, .13); border: 1px solid rgba(79, 209, 139, .5); }
.result.bad { background: rgba(255, 111, 111, .12); border: 1px solid rgba(255, 111, 111, .5); }
.result-head { font-family: var(--display); font-size: 1.25rem; }
.result.ok .result-head { color: #a8f0c8; }
.result.bad .result-head { color: #ffc0c0; }
.dmg { direction: ltr; unicode-bidi: isolate; }
.result-lines { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; font-size: .92rem; color: var(--text); opacity: .92; }

.exp { margin-top: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; animation: rise .4s .1s ease both; }
.exp-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .8rem; color: var(--dim); margin-bottom: 8px; }
.exp h4 { font-size: 1.06rem; line-height: 1.45; margin-bottom: 10px; color: #fff3cf; }
.exp p { line-height: 1.75; margin-bottom: 11px; color: #dfe6f3; }
.exp p:last-child { margin-bottom: 0; }
.exp [dir='ltr'] { text-align: left; }
.exp [dir='rtl'] { text-align: right; }

#bar { display: none; }
#bar.on {
  display: block; position: fixed; inset-inline: 0; bottom: 0; z-index: 25;
  padding: 26px 14px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(11, 16, 25, .94) 38%); pointer-events: none;
}
#bar .btn { max-width: calc(var(--maxw) - 28px); margin: 0 auto; display: flex; pointer-events: auto; }

/* ---------- Summary ---------- */
.over { text-align: center; padding-top: 14px; animation: rise .4s ease both; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 6px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--dim); font-size: .78rem; }
.xp-card { text-align: start; }
.xp-card .rank { margin: 4px 0 10px; }
.xp-gain { font-family: var(--display); font-size: 1.7rem; color: #b9c8ff; direction: ltr; text-align: end; float: inline-end; }
.levelup { margin-top: 10px; font-weight: 800; color: var(--gold); }
.unlocks { margin-top: 8px; font-size: .9rem; color: var(--dim); }
.over.won .scene-title { color: var(--gold); }
.over-actions { display: flex; gap: 10px; margin-top: 18px; }
.over-actions .btn { flex: 1; }
.over-actions .btn.big { flex: 2; }
.qlist { display: flex; flex-direction: column; gap: 6px; text-align: start; }
.qrow { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); width: 100%; transition: border-color .15s; }
.qrow:hover { border-color: #4a5d8a; }
.qrow-mark { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: .82rem; font-weight: 800; background: rgba(255, 255, 255, .08); }
.qrow.ok .qrow-mark { background: rgba(79, 209, 139, .2); color: var(--ok); }
.qrow.bad .qrow-mark { background: rgba(255, 111, 111, .2); color: var(--bad); }
.qrow-text { flex: 1; min-width: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #d5deee; }

/* ---------- Codex ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: thin; }
.tab { flex: none; padding: 7px 13px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-size: .9rem; white-space: nowrap; }
.tab.on { background: rgba(var(--realm-rgb), .2); border-color: var(--realm); color: #fff; font-weight: 700; }
.realm-head { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; align-items: center; border-color: rgba(var(--realm-rgb), .4); background: linear-gradient(160deg, rgba(var(--realm-rgb), .14), var(--card) 65%); }
.realm-head b { display: block; font-family: var(--display); font-weight: 400; font-size: 1.2rem; }
.realm-head small { color: var(--dim); font-size: .82rem; }
.realm-head .bar { grid-column: 1 / -1; }
.boss-state { text-align: center; font-size: 1.8rem; line-height: 1.1; }
.boss-state small { display: block; font-size: .72rem; }
.chapters { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.chapter { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); width: 100%; direction: ltr; text-align: left; transition: border-color .15s; }
.chapter:hover { border-color: var(--realm); }
.chapter.unseen { opacity: .62; }
.chapter.m3 { border-color: rgba(245, 200, 90, .6); background: linear-gradient(90deg, rgba(245, 200, 90, .12), var(--card) 50%); }
.ch-num { flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: .9rem; background: rgba(var(--realm-rgb), .16); color: var(--realm); }
.ch-body { flex: 1; min-width: 0; }
.ch-body b { display: block; font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 5px; }
.ch-body .bar { height: 5px; }
.ch-count { flex: none; font-size: .8rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.ch-medal { flex: none; width: 22px; text-align: center; }

/* ---------- Achievements ---------- */
.ach-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.ach { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; align-items: center; padding: 11px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); opacity: .55; }
.ach.on { opacity: 1; border-color: rgba(245, 200, 90, .5); background: linear-gradient(160deg, rgba(245, 200, 90, .12), var(--card) 65%); }
.ach-e { grid-row: span 2; font-size: 1.7rem; }
.ach b { font-size: .92rem; }
.ach small { color: var(--dim); font-size: .78rem; line-height: 1.35; }
.bestiary { display: flex; flex-direction: column; gap: 6px; }
.beast-row { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.beast-realm { flex: 1; font-size: .86rem; color: var(--realm); font-weight: 600; }
.beast { width: 40px; text-align: center; opacity: .35; }
.beast.on { opacity: 1; }
.beast-e { display: block; font-size: 1.45rem; line-height: 1.2; }
.beast small { display: block; font-size: .68rem; color: var(--dim); height: 1em; }
.beast.k-boss.on .beast-e { filter: drop-shadow(0 0 6px rgba(245, 200, 90, .8)); }

/* ---------- Modal, lightbox, toasts ---------- */
#modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 14px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 7, 13, .78); backdrop-filter: blur(3px); }
.modal-box { position: relative; width: 100%; max-width: 540px; max-height: calc(100vh - 28px); overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; animation: pop .22s ease both; }
.modal-box.wide { max-width: 760px; }
.modal-body { padding: 20px 16px 18px; }
.modal-x { position: sticky; top: 8px; float: inline-end; margin: 8px; width: 34px; height: 34px; border-radius: 50%; background: var(--card2); border: 1px solid var(--line); z-index: 2; display: grid; place-items: center; }
.modal-title { font-family: var(--display); font-weight: 400; font-size: 1.3rem; color: #fff3cf; margin-bottom: 6px; }
.modal-body .qcard { margin-top: 8px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.set-row:last-of-type { border-bottom: 0; }
.set-row b { display: block; }
.set-row small { color: var(--dim); font-size: .82rem; line-height: 1.4; display: block; }
.set-btns { display: flex; flex-direction: column; gap: 6px; flex: none; }
label.btn { cursor: pointer; }
.confirm-text { font-size: 1.05rem; line-height: 1.6; margin-top: 8px; }
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(4, 7, 13, .93); display: grid; place-items: center; padding: 12px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 8px; }
#toasts { position: fixed; top: 12px; inset-inline: 0; z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 14px; background: #1c2740; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: drop .35s ease both; transition: opacity .5s, transform .5s; }
.toast.ach { border-color: var(--gold); background: linear-gradient(160deg, #3a2f12, #1c2740 70%); }
.toast.bad { border-color: var(--bad); }
.toast.out { opacity: 0; transform: translateY(-12px); }
.toast-e { font-size: 1.7rem; }
.toast small { display: block; color: var(--gold); font-size: .74rem; font-weight: 700; }
#flash { position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: 0; }
#flash.hurt { background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 60, 60, .5)); animation: flash .6s ease-out; }

/* ---------- Animations ---------- */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes enemy-hit { 0% { transform: none; filter: none; } 25% { transform: translateX(9px) rotate(6deg); filter: brightness(2.2); } 55% { transform: translateX(-6px) rotate(-4deg); } 100% { transform: none; filter: none; } }
@keyframes enemy-crit { 0% { transform: none; filter: none; } 15% { transform: scale(1.25) rotate(10deg); filter: brightness(3) saturate(2); } 40% { transform: translateX(-12px) rotate(-10deg); } 65% { transform: translateX(8px) rotate(5deg); } 100% { transform: none; filter: none; } }
@keyframes enemy-die { to { transform: rotate(180deg) scale(.55); filter: grayscale(1); opacity: .3; } }
@keyframes float-up { from { opacity: 0; transform: translate(-50%, 6px) scale(.7); } 20% { opacity: 1; transform: translate(-50%, -8px) scale(1.15); } to { opacity: 0; transform: translate(-50%, -46px) scale(1); } }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Phones ---------- */
@media (max-width: 520px) {
  #app { padding: 14px 12px 36px; }
  .logo h1 { font-size: 2rem; }
  .realm-grid { grid-template-columns: repeat(2, 1fr); }
  .chips.three .chip { padding: 10px 8px; }
  .doors { gap: 7px; }
  .door { padding: 10px 5px 12px; border-radius: 80px 80px 14px 14px; }
  .door-face { width: 60px; height: 60px; }
  .door-emoji { font-size: 2rem; }
  .door.t-boss .door-face { width: 78px; height: 78px; }
  .door-name { font-size: .86rem; }
  .door-realm, .door-hint { font-size: .72rem; }
  .door-hint { padding: 2px 6px; }
  .stage { margin: 0 -12px 10px; padding: 8px 12px; gap: 11px; }
  .enemy { width: 56px; height: 56px; }
  .enemy > span:first-child { font-size: 2rem; }
  .k-boss .enemy { width: 64px; height: 64px; }
  .k-boss .enemy > span:first-child { font-size: 2.3rem; }
  .enemy-name { font-size: 1.05rem; }
  .qcard, .exp { padding: 13px; border-radius: 14px; }
  .stem { font-size: 1.02rem; }
  .choices { grid-template-columns: 1fr; max-width: 360px; }
  .choices.two { grid-template-columns: 1fr; }
  .choice { flex-direction: row; text-align: start; align-items: center; gap: 12px; padding: 13px 14px; flex-wrap: wrap; }
  .choice b { flex: 1 1 40%; }
  .choice small { flex: 1 1 100%; }
  .choice .choice-e + b + small { flex: 1 1 100%; margin-inline-start: 0; }
  .ach-grid { grid-template-columns: 1fr; }
  .item { flex-direction: column; gap: 1px; font-size: .8rem; padding: 7px 4px; }
  .beast { width: 32px; }
  .beast-e { font-size: 1.2rem; }
  .set-row { flex-wrap: wrap; }
}

/* ---------- Action rooms ---------- */
body[data-arena] #app { padding-top: 0; padding-bottom: 8px; }
body[data-arena] { overscroll-behavior: none; }
.arena { animation: rise .25s ease both; }
.arena .stage { margin-bottom: 8px; }
.arena-title { text-align: center; color: var(--dim); font-size: .92rem; padding: 9px 0 7px; }
.arena-title b { color: #fff3cf; font-family: var(--display); font-weight: 400; font-size: 1.1rem; }
.room { position: relative; width: 100%; max-width: 600px; margin: 0 auto; border-radius: 14px; touch-action: none; user-select: none; -webkit-user-select: none; box-shadow: 0 14px 40px rgba(0, 0, 0, .45); }
.room canvas { display: block; width: 100%; border-radius: 14px; touch-action: none; cursor: crosshair; }
.plaques { position: absolute; top: 0; inset-inline: 0; pointer-events: none; direction: ltr; }
.plaque { position: absolute; top: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 3px 3px 0; text-align: center; direction: rtl; line-height: 1.22; overflow: hidden; }
.plaque.calm { --realm: #c9d4ea; }
.pl-top { font-size: .92em; font-weight: 700; color: var(--realm); white-space: nowrap; }
.plaque b { font-size: 1.08em; color: #fff; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.plaque small { font-size: .9em; color: var(--dim); white-space: nowrap; }
.arena-hint { text-align: center; color: var(--dim); font-size: .8rem; padding: 7px 4px 0; line-height: 1.4; }
.pad { display: none; }
.hud-stat.shield { color: #a9c8ff; }
@media (hover: none) and (pointer: coarse) {
  .pad { display: flex; justify-content: space-between; align-items: center; max-width: 600px; margin: 6px auto 0; padding: 0 10px; touch-action: none; user-select: none; -webkit-user-select: none; }
  .stick { width: 124px; height: 124px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .09), rgba(255, 255, 255, .03)); border: 2px solid rgba(255, 255, 255, .16); display: grid; place-items: center; touch-action: none; }
  .stick i { width: 52px; height: 52px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #8fa7d8, #4a5d8a); box-shadow: 0 4px 14px rgba(0, 0, 0, .5); pointer-events: none; }
  .fire { width: 96px; height: 96px; border-radius: 50%; font-size: 2.3rem; display: grid; place-items: center; touch-action: none;
    background: radial-gradient(circle at 35% 30%, #ffe08f, var(--gold) 55%, var(--gold-d)); border: 2px solid #ffe9a8; box-shadow: 0 6px 22px rgba(245, 200, 90, .3); }
  .fire:active { transform: scale(.94); filter: brightness(1.15); }
}

@media (max-width: 520px) {
  .hud-row { gap: 7px; padding-inline: 10px; }
  .hearts { font-size: .86rem; }
  .hud-stat { font-size: .88rem; }
  .hud-btn { width: 34px; height: 34px; }
}

/* ---------- Tools, supply room, daily challenge, 3D rooms ---------- */
.room { overflow: hidden; }
.plaques { position: absolute; inset: 0; pointer-events: none; }
.plaque { position: absolute; top: 0; left: 0; height: auto; transform: translate(-50%, -100%); padding: 2px 2px 4px; justify-content: flex-end;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .9), 0 0 10px rgba(0, 0, 0, .8); }
.home-links { grid-template-columns: repeat(4, 1fr); }
.home-links .btn small { color: var(--gold); font-weight: 700; }
.daily { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: start; border-color: rgba(245, 200, 90, .4);
  background: linear-gradient(120deg, rgba(245, 200, 90, .14), var(--card) 60%); transition: transform .12s, border-color .15s; }
.daily:hover { border-color: var(--gold); transform: translateY(-1px); }
.daily.done { border-color: rgba(79, 209, 139, .5); background: linear-gradient(120deg, rgba(79, 209, 139, .12), var(--card) 60%); }
.daily-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.daily-top b { font-size: 1.05rem; }
.daily-top small { color: var(--gold); font-weight: 600; }
.daily.done .daily-top small { color: var(--ok); }
.daily-row { font-size: .9rem; }
.daily-row.dim { color: var(--dim); font-size: .84rem; }
.supply h2 { font-family: var(--display); font-weight: 400; font-size: 1.8rem; color: #fff3cf; }
.supply .shop { max-width: none; }
.supply .shop-row { cursor: default; }
.supply .shop-row.on { border-color: var(--gold); background: linear-gradient(120deg, rgba(245, 200, 90, .12), var(--card) 60%); }
.supply .shop-row .btn { flex: none; min-width: 84px; }
.pips.up { margin-top: 5px; }
.pips.up .pip { width: 16px; height: 6px; }
.pips.up .pip.on { background: var(--gold); box-shadow: none; }
.score-line { margin: 4px 0 12px; color: var(--dim); }
.score-line b { font-family: var(--display); font-size: 1.6rem; color: #fff3cf; margin-inline: 4px; }
.score-line .best { color: var(--gold); font-weight: 800; }
@media (hover: none) and (pointer: coarse) {
  .stick { position: relative; }
  .stick small { position: absolute; bottom: -20px; inset-inline: 0; text-align: center; font-size: .72rem; color: var(--dim); pointer-events: none; }
  .stick.aim { border-color: rgba(245, 200, 90, .5); background: radial-gradient(circle, rgba(245, 200, 90, .14), rgba(245, 200, 90, .03)); }
  .stick.aim i { background: radial-gradient(circle at 35% 30%, #ffe08f, var(--gold) 55%, var(--gold-d)); }
}
@media (max-width: 520px) {
  .home-links { grid-template-columns: repeat(2, 1fr); }
}

.plaques { z-index: 3; }

/* ---------- Two tools and the switch button ---------- */
.chip.on.second { border-color: #8fa7d8; box-shadow: 0 0 0 1px #8fa7d8 inset; background: linear-gradient(160deg, rgba(143, 167, 216, .16), var(--card) 70%); }
.slot { font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: rgba(245, 200, 90, .2); color: var(--gold); margin-inline-start: 4px; vertical-align: middle; }
.chip.second .slot { background: rgba(143, 167, 216, .22); color: #b9c8ea; }
.arena-hint b { color: var(--text); }
.kbd { display: inline-block; min-width: 1.5em; padding: 0 5px; border-radius: 5px; border: 1px solid var(--line); background: var(--card2); font-size: .74rem; font-weight: 700; color: var(--text); text-align: center; direction: ltr; }
.swap { display: none; }
@media (hover: none) and (pointer: coarse) {
  .swap:not([hidden]) { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; width: 66px; height: 66px; border-radius: 50%; touch-action: none;
    background: var(--card2); border: 2px solid rgba(255, 255, 255, .2); box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
  .swap span { font-size: 1.6rem; line-height: 1.1; }
  .swap small { font-size: .62rem; color: var(--dim); }
  .swap:active { transform: scale(.93); border-color: var(--gold); }
}

.chips.four { grid-template-columns: repeat(4, 1fr); }
.chips.four .chip { text-align: center; padding: 10px 4px; }
@media (max-width: 520px) { .chips.four { grid-template-columns: repeat(2, 1fr); } }
