:root {
  --night: #101a3a;
  --window: #1b2a66;
  --window-deep: #121d4c;
  --line: #e9e4d4;
  --text: #f4f1e6;
  --muted: #b7bddb;
  --gold: #f0c75e;
  --good: #7fe0a0;
  --bad: #ff8b7d;
  --hp: #58d68d;
  --mp: #5cb8ff;
  --enemy: #ef5350;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--night);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h1 { font-size: 30px; letter-spacing: 0.02em; color: var(--gold); }
h2 { font-size: 20px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 6px; }
p { margin: 8px 0; }
a { color: var(--gold); }
small { color: var(--muted); }
ul, ol { list-style: none; margin: 0; padding: 0; }

button, input, select { font: inherit; color: inherit; }

button {
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--window-deep);
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

button.primary {
  width: 100%;
  margin-top: 12px;
  background: var(--gold);
  border-color: var(--gold);
  color: #2a2008;
  font-weight: 700;
}

.window {
  margin-top: 12px;
  padding: 14px;
  background: linear-gradient(180deg, var(--window), var(--window-deep));
  border: 3px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 0 0 2px #05091f;
}

.title { display: flex; justify-content: space-between; align-items: baseline; }

.bar {
  flex: 1;
  display: inline-block;
  height: 10px;
  min-width: 60px;
  background: #060b24;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; transition: width 0.35s ease; }
.bar-hp > span { background: var(--hp); }
.bar-mp > span { background: var(--mp); }
.bar-xp > span { background: var(--gold); }
.bar-enemy > span { background: var(--enemy); }
.num { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }

.login { padding-top: 20vh; text-align: center; }
.primary-link {
  display: block;
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--gold);
  color: #2a2008;
  font-weight: 700;
  text-decoration: none;
}

.unlocked { margin: 8px 0 0; color: var(--gold); }
.goal.done b { color: var(--gold); }
.goal-progress { display: flex; align-items: center; gap: 6px; min-width: 96px; flex: none; }

.row-actions { display: flex; gap: 6px; flex: none; }
.ward-list li { display: block; }
.ward-lesson small { display: block; }

.hero-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--window-deep);
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.level { font-weight: 700; white-space: nowrap; }
.badge { padding: 0 6px; border-radius: 4px; background: var(--gold); color: #2a2008; font-size: 13px; font-weight: 700; }

.hint { font-size: 14px; color: var(--muted); }
.lesson { margin-top: 16px; }
.lesson summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 12px;
  background: var(--window-deep);
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.lesson summary h3 { margin: 0; font-size: 18px; }
.path-title { color: var(--gold); }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 44px; flex: 1; }
.toggle input { width: 22px; height: 22px; accent-color: var(--gold); }
.book-link { display: inline-block; margin-top: 10px; }

.tree { position: relative; height: calc(var(--rows) * 116px); margin-top: 8px; }
.paths { position: absolute; inset: 0; width: 100%; height: 100%; }
.paths line {
  stroke: var(--muted);
  stroke-width: 2;
  stroke-dasharray: 5 5;
  opacity: 0.5;
  vector-effect: non-scaling-stroke;
}
.paths line.walked { stroke: var(--gold); stroke-dasharray: none; opacity: 1; }
.node {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc((var(--row) + 0.5) / var(--rows) * 100%);
  transform: translate(-50%, -50%);
  width: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px;
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
  color: var(--text);
  text-decoration: none;
  background: var(--window);
  border: 2px solid var(--line);
  border-radius: 8px;
}
.node small { font-size: 11px; }
.node .sprite { width: 44px; height: 44px; filter: hue-rotate(var(--hue, 0deg)); }
.node.done { background: var(--window-deep); border-color: var(--good); }
.node.open { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(240, 199, 94, 0.35); }
.node.locked { background: var(--window-deep); border-style: dashed; border-color: var(--muted); color: var(--muted); }
.node.locked .sprite { filter: brightness(0) opacity(0.6); }
.node-boss .sprite { width: 56px; height: 56px; }

.battle { position: relative; }
.flee {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  min-height: 32px;
  padding: 2px 10px;
  font-size: 13px;
  border-width: 1px;
  background: rgba(5, 9, 31, 0.6);
}

.scene {
  position: relative;
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: 10px;
  background:
    repeating-linear-gradient(90deg, transparent 0 56px, rgba(233, 228, 212, 0.13) 56px 72px, transparent 72px 128px),
    linear-gradient(180deg, #2c2a6e 0%, #4b3a7c 58%, #6c4b52 58%, #3d2b35 100%);
  overflow: hidden;
}
.scene-hit { animation: flash 0.4s ease; }
.enemy-status { display: flex; align-items: center; gap: 8px; padding-right: 72px; flex-wrap: wrap; }
.enemy-status .bar { flex-basis: 100%; }
.guard { flex-basis: 100%; color: var(--gold); }
.enemy-name { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.rank { padding: 0 6px; border-radius: 4px; font-size: 12px; font-weight: 700; color: #111; background: var(--muted); }
.rank-champion { background: var(--gold); }
.rank-boss { background: var(--enemy); color: #fff; }
.enemy { position: relative; display: flex; justify-content: center; padding-top: 8px; }
.enemy .sprite { width: min(44vw, 176px); height: min(44vw, 176px); filter: hue-rotate(var(--hue, 0deg)) drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35)); }
.enemy-hit .sprite { animation: recoil 0.4s ease; }
.enemy-strike .sprite { animation: lunge 0.4s ease; }
.enemy-defeated .sprite { animation: vanish 0.7s ease forwards; }
.damage {
  position: absolute;
  top: 30%;
  font: 700 30px var(--serif);
  color: var(--gold);
  text-shadow: 0 2px 0 #000;
  animation: rise 0.9s ease forwards;
}

.player-status { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 10px; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.buffs { grid-column: 1 / -1; font-size: 13px; color: var(--gold); }

.options { display: grid; gap: 8px; margin-top: 10px; }
.option { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; }
.timer { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; font-size: 14px; }
.timer .bar { flex: 1; }
.bar-time > span { background: var(--mp); transition: width 0.2s linear; }
.timer-low { color: var(--bad); }
.timer-low .bar-time > span { background: var(--bad); }
.attack-label { margin: 0; font-size: 13px; color: var(--muted); }
.lemma { margin: 0; font: 600 34px/1.2 var(--serif); color: var(--gold); overflow-wrap: anywhere; }
.lemma.small { font-size: 24px; }
.note { margin: 2px 0 0; font-size: 14px; color: var(--muted); }

fieldset { margin: 12px 0 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { flex: 1 1 auto; min-width: 44px; }
.chip.on { background: var(--gold); border-color: var(--gold); color: #2a2008; font-weight: 700; }
.chip:disabled { text-decoration: line-through; }

.forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 12px; }
.field { display: block; font-size: 14px; color: var(--muted); margin-top: 8px; }
.forms .field { margin-top: 0; }
.field input, .field select {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 16px;
  background: #0a1234;
  border: 2px solid var(--line);
  border-radius: 6px;
}
.field input::placeholder { color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.action { min-height: 38px; padding: 4px 10px; font-size: 14px; border-width: 1px; }
.message { font-size: 14px; color: var(--gold); }

.outcome { margin: 0; font: 700 28px var(--serif); }
.outcome-good { color: var(--good); }
.outcome-bad { color: var(--bad); }
.outcome-neutral { color: var(--mp); }
.outcome-detail { margin-top: 2px; color: var(--muted); }
.solution li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid rgba(233, 228, 212, 0.25); }
.solution span { color: var(--muted); font-size: 14px; }
.solution b { text-align: right; }
.solution .ok b { color: var(--good); }
.solution .ok b::before { content: "✓ "; }
.solution .miss b { color: var(--bad); }
.solution .miss b::before { content: "✗ "; }

.review li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.review span { color: var(--muted); text-align: right; }
.end-buttons { display: grid; gap: 8px; margin-top: 12px; }
.end-buttons .primary { margin-top: 0; }

.stats { color: var(--muted); }
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(233, 228, 212, 0.25);
}
.book-right { text-align: right; }
.pips { display: block; font-size: 11px; color: var(--gold); letter-spacing: 1px; }

.word-card {
  margin-top: 12px;
  padding: 12px;
  background: var(--window-deep);
  border: 2px solid var(--line);
  border-radius: 8px;
}
.word-card.uncertain { border-color: var(--gold); }
.flag { margin: 0; font-size: 14px; color: var(--gold); }
.word-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 8px; }
.word-grid .wide { grid-column: 1 / -1; }
.remove { margin-top: 10px; min-height: 36px; padding: 2px 10px; font-size: 14px; border-width: 1px; }
.lesson-admin li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; }

@keyframes recoil { 25% { transform: translateX(10px); filter: brightness(2.5); } 60% { transform: translateX(-6px); } }
@keyframes lunge { 40% { transform: translateY(14px) scale(1.14); } }
@keyframes flash { 30% { box-shadow: inset 0 0 0 200px rgba(255, 70, 60, 0.4); } }
@keyframes vanish { to { opacity: 0; transform: scale(0.6) translateY(16px); } }
@keyframes rise { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-48px); opacity: 0; } }

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