:root {
  --ink: #17212e;
  --muted: #5b6675;
  --paper: #fff8e8;
  --surface: #ffffff;
  --soft: #f4f8fb;
  --line: #d8e0ea;
  --green: #21685f;
  --wine: #8b2d43;
  --gold: #b78317;
  --blue: #285f9f;
  --danger: #b3261e;
  --success: #1f7a4d;
  --shadow: 0 14px 34px rgba(23, 33, 46, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(33, 104, 95, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(183, 131, 23, 0.06) 1px, transparent 1px),
    #fbf5e8;
  background-size: 32px 32px;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #f3be46;
  outline-offset: 3px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.hud {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 0.7rem;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand-button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  background: transparent;
  padding: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 950;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green), var(--wine));
}

.brand-copy {
  display: none;
}

.brand-copy small {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.stats {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  max-width: calc(100vw - 64px);
}

.stats span,
.pill {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.25rem 0.6rem;
  color: #fff;
  background: var(--wine);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 900;
}

.stage {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 0.85rem 0.85rem calc(5.4rem + env(safe-area-inset-bottom));
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
  padding: 0.45rem 0.45rem calc(0.45rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.bottom-nav button {
  min-height: 48px;
  color: var(--muted);
  background: #f4f8fb;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 900;
}

.bottom-nav button.active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.hero {
  position: relative;
  overflow: hidden;
  min-height: 210px;
  display: grid;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(1.05) saturate(0.92);
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255, 248, 232, 0.96), rgba(255, 248, 232, 0.68), rgba(255, 248, 232, 0.2));
}

.hero-content {
  position: relative;
  z-index: 1;
  padding: 1rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--wine);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 9vw, 4rem);
}

h2 {
  font-size: clamp(1.45rem, 6vw, 2.7rem);
}

h3 {
  font-size: 1.15rem;
}

p {
  margin: 0;
  line-height: 1.55;
}

.menu-grid {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.9rem;
}

.game-button,
.choice,
.secondary,
.primary,
.danger {
  width: 100%;
  min-height: 58px;
  padding: 0.85rem;
  text-align: left;
  font-weight: 900;
  border: 1px solid var(--line);
}

.game-button {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 10px 24px rgba(23, 33, 46, 0.08);
}

.game-button strong {
  display: block;
}

.game-button small {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-weight: 750;
}

.game-button.locked {
  opacity: 0.62;
}

.primary {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
  text-align: center;
}

.secondary {
  color: var(--ink);
  background: #f5f8fb;
}

.primary:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.danger {
  color: #fff;
  background: var(--wine);
  border-color: var(--wine);
  text-align: center;
}

.panel,
.micro,
.feedback,
.mission-card,
.grimoire-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel,
.micro,
.mission-card,
.grimoire-card {
  padding: 1rem;
}

.stack {
  display: grid;
  gap: 0.85rem;
}

.micro {
  display: grid;
  gap: 0.85rem;
}

.module-header {
  display: grid;
  gap: 0.55rem;
}

.bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef4;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--gold));
  transition: width 180ms ease;
}

.math-box {
  overflow-x: auto;
  padding: 0.8rem;
  border-radius: 12px;
  background: #fffaf0;
  border: 1px solid #ead8aa;
}

.exercise-data {
  display: grid;
  gap: 0.45rem;
}

.exercise-data .math-box {
  background: #f7fbff;
  border-color: #c8d8e8;
}

.choices {
  display: grid;
  gap: 0.55rem;
}

.choice {
  color: #253545;
  background: #f5f8fb;
}

.choice.correct {
  border-color: var(--success);
  background: #e7f6ed;
}

.choice.wrong {
  border-color: var(--danger);
  background: #fdebea;
}

.choice:disabled {
  cursor: not-allowed;
  opacity: 0.78;
}

.feedback {
  display: none;
  padding: 0.85rem;
  border-left: 6px solid var(--gold);
  background: #fff8dd;
}

.feedback.show {
  display: block;
}

.feedback.success {
  border-left-color: var(--success);
  background: #eaf7ef;
}

.feedback.danger {
  border-left-color: var(--danger);
  background: #fdebea;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  font-size: 0.78rem;
  font-weight: 900;
}

.source-chip.soft {
  color: var(--ink);
  background: #e9f0f7;
  border: 1px solid var(--line);
}

.hint,
.solution {
  padding: 0.75rem;
  border: 1px solid #ead8aa;
  border-radius: 12px;
  background: #fffaf0;
}

.hint summary,
.solution summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  color: var(--wine);
  font-weight: 950;
  cursor: pointer;
}

.solution div {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.55rem;
}

.actions {
  display: grid;
  gap: 0.55rem;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.inline-actions button {
  flex: 1 1 150px;
  min-height: 46px;
  padding: 0.55rem;
  color: var(--wine);
  background: #fff4ee;
  border: 1px solid #e8c8bb;
  font-weight: 850;
}

.mission-list,
.medal-list,
.boss-grid,
.grimoire-grid {
  display: grid;
  gap: 0.7rem;
}

.mission-card {
  display: grid;
  gap: 0.45rem;
}

.mission-card.unlocked {
  border-color: #9bc6ba;
}

.mission-card.locked {
  opacity: 0.66;
}

.medal-list {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.medal {
  min-height: 74px;
  display: grid;
  place-items: center;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: #f5f8fb;
  text-align: center;
  font-weight: 850;
}

.medal.earned {
  color: #fff;
  background: linear-gradient(135deg, var(--gold), var(--wine));
}

.checklist {
  display: grid;
  gap: 0.55rem;
}

.checklist label {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-weight: 800;
}

.checklist input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--green);
}

.grimoire-card {
  display: grid;
  gap: 0.55rem;
}

.grimoire-card ul {
  margin: 0;
  padding-left: 1.1rem;
}

.tiny {
  color: var(--muted);
  font-size: 0.9rem;
}

.MathJax {
  font-size: 1.02em !important;
}

@media (min-width: 760px) {
  .brand-copy {
    display: block;
  }

  .stage {
    padding: 1.2rem 1.2rem calc(5.7rem + env(safe-area-inset-bottom));
  }

  .menu-grid,
  .boss-grid,
  .grimoire-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero {
    min-height: 300px;
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1060px) {
  .bottom-nav {
    width: min(100%, 760px);
    left: 50%;
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
  }
}

/* RPG v2 experimental theme */
:root {
  --bg: #070912;
  --bg-2: #11162b;
  --surface: rgba(22, 25, 43, 0.88);
  --surface-2: rgba(34, 30, 49, 0.92);
  --surface-3: rgba(255, 244, 211, 0.94);
  --text: #f8edd4;
  --muted: #cdbd9d;
  --gold: #f2c76b;
  --gold-2: #9d6424;
  --danger: #f07070;
  --success: #59d98f;
  --warning: #f3a943;
  --arcane: #7bcfff;
  --arcane-2: #8367e8;
  --wine: #7d2944;
  --green: #1e725f;
  --blue: #406fe8;
  --ink: var(--text);
  --paper: #f7e6bd;
  --soft: rgba(255, 255, 255, 0.08);
  --line: rgba(242, 199, 107, 0.28);
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
  --glow: 0 0 28px rgba(123, 207, 255, 0.18), 0 0 18px rgba(242, 199, 107, 0.14);
}

body {
  color: var(--text);
  background:
    radial-gradient(circle at 18% 8%, rgba(125, 41, 68, 0.28), transparent 32rem),
    radial-gradient(circle at 90% 18%, rgba(64, 111, 232, 0.22), transparent 30rem),
    linear-gradient(180deg, rgba(7, 9, 18, 0.72), rgba(7, 9, 18, 0.98)),
    url("assets/rpg-arcane-map.svg") center top / cover fixed,
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, transparent, #000 12%, #000 88%, transparent);
}

button {
  border-radius: 14px;
}

.hud {
  color: var(--text);
  background: linear-gradient(180deg, rgba(14, 16, 30, 0.92), rgba(14, 16, 30, 0.72));
  border-bottom: 1px solid rgba(242, 199, 107, 0.22);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.28);
}

.brand-button {
  color: var(--text);
}

.brand-mark {
  position: relative;
  overflow: hidden;
  color: transparent;
  background: #11192f url("assets/rpg-sigil.svg") center / 88% no-repeat;
  border: 1px solid rgba(242, 199, 107, 0.7);
  box-shadow: var(--glow);
}

.brand-mark::after {
  content: "SL";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.brand-copy small,
.stats span {
  color: var(--muted);
}

.stats span {
  min-height: 34px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(242, 199, 107, 0.18), rgba(125, 41, 68, 0.2));
  border: 1px solid rgba(242, 199, 107, 0.28);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
}

.bottom-nav {
  background: rgba(8, 10, 22, 0.9);
  border-top: 1px solid rgba(242, 199, 107, 0.22);
  box-shadow: 0 -18px 44px rgba(0, 0, 0, 0.42);
}

.bottom-nav button {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(242, 199, 107, 0.2);
}

.bottom-nav button.active {
  color: #17100a;
  background: linear-gradient(135deg, var(--gold), #f8e3a7);
  border-color: var(--gold);
  box-shadow: 0 0 24px rgba(242, 199, 107, 0.24);
}

.hero {
  min-height: 260px;
  border: 1px solid rgba(242, 199, 107, 0.28);
  background:
    linear-gradient(180deg, rgba(8, 10, 22, 0.18), rgba(8, 10, 22, 0.68)),
    url("assets/rpg-arcane-map.svg") center / cover,
    var(--surface);
  box-shadow: var(--shadow), var(--glow);
}

.hero img {
  opacity: 0;
}

.hero::after {
  background:
    linear-gradient(90deg, rgba(8, 10, 22, 0.94), rgba(16, 21, 46, 0.64), rgba(8, 10, 22, 0.2)),
    radial-gradient(circle at 78% 26%, rgba(123, 207, 255, 0.22), transparent 20rem);
}

.hero-content {
  padding: 1.1rem;
}

.eyebrow {
  color: var(--gold);
}

h1,
h2,
h3 {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.32);
}

p,
li,
small,
.tiny {
  color: var(--muted);
}

.panel,
.micro,
.mission-card,
.grimoire-card,
.feedback {
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035)),
    var(--surface);
  border: 1px solid rgba(242, 199, 107, 0.24);
  box-shadow: var(--shadow);
}

.micro,
.panel {
  position: relative;
  overflow: hidden;
}

.micro::before,
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(242, 199, 107, 0.12), transparent 32%, rgba(123, 207, 255, 0.08));
}

.micro > *,
.panel > * {
  position: relative;
}

.module-header {
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(242, 199, 107, 0.18);
}

.module-header::after {
  content: "";
  display: block;
  height: 24px;
  margin-top: 0.35rem;
  background: url("assets/rpg-divider.svg") center / contain no-repeat;
  opacity: 0.62;
}

.bar {
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(242, 199, 107, 0.26);
}

.bar span {
  background: linear-gradient(90deg, var(--arcane), var(--gold), var(--success));
  box-shadow: 0 0 24px rgba(123, 207, 255, 0.28);
}

.pill,
.source-chip {
  color: #17100a;
  background: linear-gradient(135deg, var(--gold), #f8e3a7);
  border: 1px solid rgba(255, 239, 186, 0.55);
}

.source-chip.soft {
  color: var(--text);
  background: rgba(123, 207, 255, 0.12);
  border-color: rgba(123, 207, 255, 0.25);
}

.menu-grid,
.boss-grid {
  gap: 0.75rem;
}

.game-button {
  position: relative;
  overflow: hidden;
  min-height: 86px;
  padding: 1rem 1rem 1rem 4.15rem;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(242, 199, 107, 0.12), transparent 38%),
    linear-gradient(180deg, rgba(32, 36, 63, 0.92), rgba(19, 21, 37, 0.96));
  border: 1px solid rgba(242, 199, 107, 0.28);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.32);
}

.game-button::before {
  content: attr(data-icon);
  position: absolute;
  left: 0.85rem;
  top: 50%;
  width: 2.45rem;
  height: 2.45rem;
  display: grid;
  place-items: center;
  color: #1c1309;
  background: radial-gradient(circle, #f8e3a7, var(--gold));
  border: 1px solid rgba(255, 239, 186, 0.76);
  border-radius: 14px;
  transform: translateY(-50%);
  box-shadow: 0 0 22px rgba(242, 199, 107, 0.26);
  font-size: 1.25rem;
}

.game-button strong {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.03rem;
}

.game-button small {
  color: var(--muted);
}

.game-button.locked {
  filter: grayscale(0.4);
  opacity: 0.58;
}

.primary,
.secondary,
.danger,
.choice {
  border-radius: 14px;
}

.primary {
  color: #17100a;
  background: linear-gradient(135deg, var(--gold), #ffe7a1);
  border-color: rgba(255, 239, 186, 0.75);
  box-shadow: 0 12px 30px rgba(242, 199, 107, 0.2);
}

.secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(242, 199, 107, 0.22);
}

.choice {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(123, 207, 255, 0.2);
}

.choice.correct {
  color: #062315;
  border-color: rgba(89, 217, 143, 0.9);
  background: linear-gradient(135deg, #8ef0b4, #55d98c);
}

.choice.wrong {
  color: #fff2ee;
  border-color: rgba(240, 112, 112, 0.9);
  background: linear-gradient(135deg, #8d253b, #4b1221);
}

.feedback {
  border-left: 6px solid var(--gold);
  background: rgba(255, 248, 221, 0.1);
}

.feedback.success {
  color: #eafff2;
  border-left-color: var(--success);
  background: rgba(89, 217, 143, 0.14);
}

.feedback.danger {
  color: #fff2ee;
  border-left-color: var(--danger);
  background: rgba(240, 112, 112, 0.14);
}

.math-box,
.hint,
.solution,
.exercise-data .math-box {
  color: #251707;
  background:
    linear-gradient(180deg, rgba(255, 250, 229, 0.98), rgba(239, 218, 166, 0.96));
  border: 1px solid rgba(242, 199, 107, 0.5);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.6);
}

.math-box p,
.hint p,
.solution p,
.math-box li {
  color: #3d2b16;
}

.exercise-data > .source-chip {
  width: fit-content;
}

.medal-list {
  gap: 0.55rem;
}

.medal {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(242, 199, 107, 0.2);
}

.medal.earned {
  color: #17100a;
  background: linear-gradient(135deg, var(--gold), #f8e3a7);
  box-shadow: 0 0 24px rgba(242, 199, 107, 0.26);
}

.grimoire-card {
  background:
    linear-gradient(180deg, rgba(246, 216, 137, 0.11), rgba(255, 255, 255, 0.04)),
    rgba(24, 20, 34, 0.94);
}

.checklist label {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(242, 199, 107, 0.18);
  border-radius: 12px;
  padding: 0.7rem;
}

@media (hover: hover) {
  .game-button:hover,
  .choice:hover,
  .primary:hover,
  .secondary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow), var(--glow);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .micro,
  .panel,
  .game-button {
    animation: rpgFadeIn 220ms ease both;
  }

  .choice.correct {
    animation: rpgCorrect 260ms ease both;
  }
}

@keyframes rpgFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rpgCorrect {
  0% {
    box-shadow: 0 0 0 rgba(89, 217, 143, 0);
  }

  100% {
    box-shadow: 0 0 28px rgba(89, 217, 143, 0.28);
  }
}
