/* Citadel of Eight: dark citadel aesthetic, mobile-first, no external assets. */

:root {
  --bg: #0a0d18;
  --bg2: #0d1122;
  --panel: #141a30;
  --panel2: #1a2140;
  --line: #2a3357;
  --line2: #394370;
  --ink: #e9ecf8;
  --dim: #8f97bd;
  --faint: #5a6289;
  --gold: #e0b45c;
  --gold-dim: #9c7f45;
  --ember: #ff6b4a;
  --good: #4ade80;
  --bad: #f87171;
  --shield: #7dd3fc;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background:
    radial-gradient(1200px 600px at 50% -200px, #1a2140 0%, transparent 60%),
    radial-gradient(900px 500px at 85% 110%, #131a36 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

input {
  font-family: inherit;
  color: var(--ink);
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 16px;
  width: 100%;
}
input::placeholder { color: var(--faint); }

.serif { font-family: Georgia, "Times New Roman", serif; }

#app {
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 16px calc(28px + env(safe-area-inset-bottom));
  animation: fadein .28s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

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

/* ---------- shared bits ---------- */

.btn {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 13px 18px;
  border-radius: 12px;
  background: var(--panel2);
  border: 1px solid var(--line2);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.985); }
.btn.primary {
  background: linear-gradient(180deg, #f0c775, var(--gold));
  border-color: var(--gold);
  color: #241a06;
}
.btn.ghost { background: transparent; border-color: var(--line); color: var(--dim); }
.btn.danger { border-color: #7a3030; color: var(--bad); background: #2a1520; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; width: auto; display: inline-block; }

.card {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.gold { color: var(--gold); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }

hr.rule { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- header HUD ---------- */

.hud { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.hud .backbtn {
  width: 42px; height: 42px; border-radius: 10px; flex: none;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 18px; color: var(--dim); line-height: 1;
}
.hud .rankbox { flex: 1 1 150px; min-width: 130px; }
.hud .rankname { font-size: 13px; color: var(--gold); font-weight: 700; letter-spacing: .04em; }
.hud .xpbar { height: 6px; background: var(--bg2); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.hud .xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); border-radius: 3px; }
.hud .xptext { font-size: 11px; color: var(--faint); margin-top: 3px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px; flex: none;
  background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--dim);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.chip.on .dot { background: var(--good); }
.chip.pending .dot { background: var(--gold); }
.streakchip { color: var(--ember); border-color: #5a2e22; }

/* ---------- title ---------- */

.title-screen { padding-top: 6vh; text-align: center; }
.wordmark {
  font-family: Georgia, serif;
  font-size: clamp(34px, 9vw, 58px);
  letter-spacing: .12em;
  color: var(--gold);
  text-shadow: 0 0 34px rgba(224, 180, 92, .35);
  line-height: 1.05;
}
.wordmark small { display: block; font-size: clamp(15px, 3.4vw, 20px); letter-spacing: .5em; color: var(--dim); margin-bottom: 10px; }
.tagline { color: var(--dim); margin-top: 14px; font-size: 15px; }
.title-shield { margin: 22px auto 8px; width: 108px; filter: drop-shadow(0 0 26px rgba(224,180,92,.25)); }
.title-actions { max-width: 340px; margin: 26px auto 0; }
.title-actions .btn + .btn { margin-top: 10px; }
.footnote { margin-top: 26px; font-size: 12px; color: var(--faint); line-height: 1.6; }
.footnote a { color: var(--dim); }

/* ---------- citadel map ---------- */

.gates { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .gates { grid-template-columns: 1fr 1fr; } }

.gatecard {
  text-align: left; display: block; width: 100%;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-left: 4px solid var(--gc, var(--gold));
  border-radius: 14px; padding: 13px 14px;
  transition: transform .06s ease;
}
.gatecard:active { transform: scale(.985); }
.gatecard .gname { font-weight: 700; font-size: 15px; }
.gatecard .gsub { color: var(--dim); font-size: 12.5px; margin-top: 2px; }
.gatecard .gprog { margin-top: 9px; height: 5px; background: var(--bg2); border-radius: 3px; overflow: hidden; }
.gatecard .gprog i { display: block; height: 100%; background: var(--gc, var(--gold)); }
.gatecard.sealed { border-color: var(--gold-dim); box-shadow: inset 0 0 24px rgba(224,180,92,.06); }
.sealbadge { color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: .06em; }

.bigcard {
  display: block; width: 100%; text-align: left;
  border-radius: 14px; padding: 14px 16px;
  background: linear-gradient(135deg, #2a1f0e, var(--panel));
  border: 1px solid var(--gold-dim);
}
.bigcard .t { font-weight: 800; color: var(--gold); letter-spacing: .03em; }
.bigcard .s { color: var(--dim); font-size: 13px; margin-top: 3px; }
.bigcard.done { filter: saturate(.55); }

.maprow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.maprow .btn { min-height: 46px; }

/* ---------- gate path ---------- */

.gatehead { padding: 4px 2px 12px; }
.gatehead .lore { color: var(--dim); font-style: italic; font-size: 14px; margin-top: 4px; }
.nodes { display: flex; flex-direction: column; gap: 0; }
.node {
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--line);
}
.node + .node { margin-top: 8px; }
.node .icon {
  width: 42px; height: 42px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--bg2); border: 1px solid var(--line2);
  color: var(--gc, var(--gold));
}
.node .icon svg { width: 22px; height: 22px; }
.node .nl { flex: 1; }
.node .nt { font-weight: 700; font-size: 14.5px; }
.node .ns { color: var(--dim); font-size: 12.5px; margin-top: 1px; }
.node .mark { color: var(--good); font-size: 18px; flex: none; }
.node.locked { opacity: .45; }
.node.cleared { border-color: #2c4a38; }
.node.bossnode { border-color: var(--gold-dim); background: linear-gradient(135deg, #241a0c, var(--panel)); }

/* ---------- battle ---------- */

.enemybar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.enemybar .sigil { width: 62px; height: 62px; flex: none; filter: drop-shadow(0 0 14px rgba(255,107,74,.25)); }
.enemybar .en { font-weight: 800; font-size: 16px; }
.enemybar .et { color: var(--dim); font-size: 12.5px; font-style: italic; }
.hppips { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.hppips i { width: 16px; height: 8px; border-radius: 3px; background: var(--ember); }
.hppips i.off { background: var(--bg2); border: 1px solid var(--line); }

.playerbar { display: flex; align-items: center; justify-content: space-between; margin: 10px 0; }
.hearts { display: flex; gap: 5px; font-size: 17px; }
.hearts .h { color: var(--ember); }
.hearts .h.off { color: var(--faint); opacity: .4; }
.shieldtag { color: var(--shield); font-size: 12.5px; font-weight: 700; }
.streaktag { color: var(--gold); font-size: 12.5px; font-weight: 700; }

.timerwrap { height: 5px; background: var(--bg2); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.timerbar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--gold), var(--ember)); }

.qcard { margin-bottom: 12px; }
.qtext { font-size: 16.5px; line-height: 1.5; font-weight: 600; }
.qmeta { color: var(--faint); font-size: 12px; margin-bottom: 6px; letter-spacing: .05em; text-transform: uppercase; }

.answers { display: grid; grid-template-columns: 1fr; gap: 9px; }
@media (min-width: 700px) { .answers { grid-template-columns: 1fr 1fr; } }
.ans {
  min-height: 52px; padding: 12px 14px; border-radius: 12px; text-align: left;
  background: var(--panel); border: 1px solid var(--line2);
  font-size: 15px; line-height: 1.35;
  display: flex; align-items: center; gap: 10px;
}
.ans .key {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  background: var(--bg2); color: var(--faint); font-size: 12.5px; font-weight: 700;
  border: 1px solid var(--line);
}
.ans.correct { border-color: var(--good); background: #12291c; }
.ans.correct .key { color: var(--good); border-color: var(--good); }
.ans.wrong { border-color: var(--bad); background: #2b171c; animation: shake .3s ease; }
.ans.wrong .key { color: var(--bad); border-color: var(--bad); }
.ans.dimmed { opacity: .5; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.lesson {
  margin-top: 12px; border-radius: 14px; padding: 14px;
  background: var(--bg2); border: 1px solid var(--line2);
  animation: fadein .2s ease;
}
.lesson .lt { font-weight: 800; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.lesson .lt.good { color: var(--good); }
.lesson .lt.bad { color: var(--bad); }
.lesson .lx { margin-top: 7px; font-size: 14.5px; line-height: 1.55; color: var(--ink); }
.lesson .xpnote { color: var(--gold); font-size: 13px; font-weight: 700; margin-top: 7px; }
.lesson .btn { margin-top: 12px; }

/* ---------- verdict / end panels ---------- */

.verdict { text-align: center; padding: 26px 14px; }
.verdict .vh { font-family: Georgia, serif; font-size: 30px; letter-spacing: .06em; color: var(--gold); }
.verdict .vh.lost { color: var(--bad); }
.verdict .vs { color: var(--dim); margin-top: 8px; font-size: 15px; }
.verdict .sigil { width: 90px; height: 90px; margin: 6px auto 2px; }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 18px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 6px; text-align: center; }
.stat .v { font-size: 19px; font-weight: 800; color: var(--gold); }
.stat .k { font-size: 11px; color: var(--faint); margin-top: 3px; letter-spacing: .04em; }

.recap { text-align: left; margin-top: 14px; }
.recap .ri { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
.recap .ri + .ri { margin-top: 8px; }
.recap .rq { font-weight: 600; font-size: 14px; }
.recap .ra { color: var(--good); font-size: 13.5px; margin-top: 4px; }
.recap .rx { color: var(--dim); font-size: 13px; margin-top: 4px; line-height: 1.5; }

/* ---------- match trial ---------- */

.matchgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.mtile {
  min-height: 58px; padding: 10px 11px; border-radius: 12px; text-align: center;
  background: var(--panel); border: 1px solid var(--line2);
  font-size: 13.5px; line-height: 1.3; font-weight: 600;
  display: grid; place-items: center;
}
.mtile.term { border-left: 3px solid var(--gc, var(--gold)); }
.mtile.sel { border-color: var(--gold); background: #241d0f; }
.mtile.ok { border-color: var(--good); background: #12291c; opacity: .55; pointer-events: none; }
.mtile.err { border-color: var(--bad); animation: shake .3s ease; }
.strikes { color: var(--bad); font-weight: 700; font-size: 13px; }

/* ---------- order trial ---------- */

.slots { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.slot {
  min-height: 44px; border-radius: 11px; padding: 10px 13px;
  border: 1px dashed var(--line2); color: var(--faint); font-size: 14px;
  display: flex; align-items: center; gap: 9px;
}
.slot.filled { border-style: solid; border-color: #2c4a38; background: #12291c; color: var(--ink); font-weight: 600; }
.slot .n { color: var(--faint); font-size: 12px; width: 18px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chipbtn {
  padding: 11px 14px; border-radius: 11px;
  background: var(--panel2); border: 1px solid var(--line2);
  font-size: 14px; font-weight: 600;
}
.chipbtn.used { opacity: .25; pointer-events: none; }
.chipbtn.err { border-color: var(--bad); animation: shake .3s ease; }

/* ---------- forge ---------- */

.forgeq { font-size: 15.5px; line-height: 1.6; }
.forgeread {
  margin: 13px 0; padding: 13px; border-radius: 12px; text-align: right;
  background: var(--bg2); border: 1px solid var(--line2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 25px; min-height: 56px; color: var(--gold);
  overflow-x: auto; white-space: nowrap;
}
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.key4 {
  min-height: 50px; border-radius: 11px; font-size: 18px; font-weight: 700;
  background: var(--panel2); border: 1px solid var(--line2);
}
.key4.act { background: #241d0f; border-color: var(--gold-dim); color: var(--gold); }
.tries { color: var(--dim); font-size: 13px; }

/* ---------- codex ---------- */

.tabs { display: flex; gap: 7px; margin-bottom: 14px; }
.tab {
  flex: 1; min-height: 40px; border-radius: 10px; font-size: 13.5px; font-weight: 700;
  background: var(--panel); border: 1px solid var(--line); color: var(--dim);
}
.tab.on { color: var(--gold); border-color: var(--gold-dim); background: #1d1810; }
.dbar { margin: 5px 0 13px; }
.dbar .dl { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 5px; }
.dbar .track { height: 7px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.dbar .track i { display: block; height: 100%; background: var(--gc, var(--gold)); }
.tome { width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
.tome + .tome { margin-top: 7px; }
.tome .tq { font-size: 14px; font-weight: 600; }
.tome .tx { color: var(--dim); font-size: 13px; margin-top: 6px; line-height: 1.5; display: none; }
.tome.open .tx { display: block; }

/* ---------- modal & toast ---------- */

#modal-root:not(:empty) {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 7, 14, .72);
  display: grid; place-items: center;
  padding: 18px;
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 430px; max-height: 86vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line2); border-radius: 18px; padding: 20px;
  animation: fadein .18s ease;
}
.modal h3 { font-family: Georgia, serif; letter-spacing: .04em; color: var(--gold); font-size: 20px; }

#toasts {
  position: fixed; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 80; pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--panel2); border: 1px solid var(--line2); color: var(--ink);
  padding: 11px 17px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  animation: fadein .2s ease;
}
.toast.gold { border-color: var(--gold-dim); color: var(--gold); }
.toast.bad { border-color: #7a3030; color: var(--bad); }

.codeinput { letter-spacing: .5em; text-align: center; font-size: 22px; font-family: ui-monospace, Menlo, monospace; }

.screen-h { font-family: Georgia, serif; font-size: 22px; letter-spacing: .05em; }
.screen-sub { color: var(--dim); font-size: 13.5px; margin-top: 3px; }
