: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;
  }
}
