:root {
  color-scheme: light dark;
  --ground: #fbf1f1;
  --panel: #fdf7f6;
  --panel-2: #f6e7ea;
  --ink: #3a2247;
  --ink-soft: #7a6288;
  --rose: #d4638e;
  --orchid: #8e6fb4;
  --champagne: #b8935a;
  --line: #ebd5dc;
  --line-strong: #d9b9c6;
  --scene-ink: #6e4b86;
  --shadow: 0 20px 50px rgba(58, 34, 71, 0.12);
  --game-sky-top: #e4cbee;
  --game-sky-mid: #f4cddb;
  --game-sky-low: #fdf3ed;
  --game-card: #fdf7f6;
  --game-card-ink: #3a2247;
  --game-subtle: rgba(110, 75, 134, 0.16);
  --game-target-add: #f4cddb;
  --game-target-sub: #e4cbee;
  --game-target-mul: #fbe4dc;
  --game-target-div: #f6e7ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #251531;
    --panel: #2e1c3d;
    --panel-2: #1d1027;
    --ink: #f4e9f1;
    --ink-soft: #c2a9cc;
    --rose: #ee8fb4;
    --orchid: #b79adb;
    --champagne: #d8b57e;
    --line: #432c55;
    --line-strong: #5c3f72;
    --scene-ink: #d8bfe8;
    --shadow: 0 22px 60px rgba(14, 5, 24, 0.38);
    --game-sky-top: #170d26;
    --game-sky-mid: #2c1840;
    --game-sky-low: #6d3d62;
    --game-card: #f4e9f1;
    --game-card-ink: #251531;
    --game-subtle: rgba(216, 191, 232, 0.15);
    --game-target-add: #f3bfd3;
    --game-target-sub: #d9c7ec;
    --game-target-mul: #f7dccf;
    --game-target-div: #d8bfe8;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 12% 0%, rgba(212, 99, 142, 0.13), transparent 28%),
    linear-gradient(180deg, var(--ground), var(--panel-2));
  color: var(--ink);
  font-family: "EB Garamond", "Hoefler Text", Baskerville, Georgia, serif;
  font-size: 17px;
  line-height: 1.55;
  overflow-x: hidden;
  transition:
    background 1.2s ease,
    color 1.2s ease;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

a {
  color: var(--rose);
  text-decoration: none;
  background-image: linear-gradient(var(--rose), var(--rose));
  background-repeat: no-repeat;
  background-size: 0% 1.5px;
  background-position: 0 100%;
  padding-bottom: 3px;
  transition: background-size 0.35s ease;
}

a:hover,
a:focus-visible {
  background-size: 100% 1.5px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  width: min(1240px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 30px 28px 46px;
}

.game-column,
.side-panel {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
}

.title-block {
  max-width: 560px;
}

.eyebrow,
.run-summary span,
.answer-readout span,
dt,
.shortcut-grid span,
.control-label,
#overlayKicker,
.project-note {
  color: var(--champagne);
  font-family: "IBM Plex Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  font-weight: 300;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 8px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: "GFS Didot", "Bodoni 72", "Playfair Display", Georgia, serif;
  font-weight: 500;
  text-wrap: balance;
}

h1 {
  margin-bottom: 0;
  color: var(--ink);
  font-size: clamp(3rem, 7vw, 6.6rem);
  line-height: 0.86;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.project-note {
  max-width: 56ch;
  margin: 14px 0 0;
  color: var(--ink-soft);
  line-height: 1.8;
  letter-spacing: 0.08em;
}

.run-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 1px;
  min-width: min(390px, 50vw);
  border: 1px solid var(--line);
  background: var(--line);
}

.run-summary div,
.answer-readout,
.panel-block,
.keypad button,
.fire-button {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
}

.run-summary div {
  min-height: 60px;
  padding: 10px 13px;
}

.run-summary strong {
  display: block;
  margin-top: 3px;
  font-family: "GFS Didot", "Bodoni 72", Georgia, serif;
  font-size: 1.42rem;
  font-weight: 500;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 3 / 2;
  min-height: 380px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--panel-2);
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 26px;
  background: color-mix(in srgb, var(--ground) 78%, transparent);
  backdrop-filter: blur(2px);
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  width: min(480px, 100%);
  padding: 28px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.overlay-panel p {
  color: var(--ink-soft);
}

#overlayKicker {
  margin-bottom: 10px;
  color: var(--rose);
}

.primary-button,
.secondary-button,
.fire-button,
.text-button,
.icon-button,
.segmented button {
  min-height: 42px;
  font-family: "IBM Plex Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  font-weight: 300;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.primary-button,
.fire-button {
  background: var(--rose);
  color: #fdf7f6;
  transition:
    background 0.3s ease,
    transform 0.3s ease;
}

.primary-button:hover,
.fire-button:hover {
  background: var(--ink);
  transform: translateY(-1px);
}

.primary-button {
  width: 100%;
  margin-top: 8px;
  padding-inline: 18px;
}

.secondary-button {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--rose);
}

.answer-dock {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr) 144px;
  gap: 1px;
  align-items: stretch;
  margin-top: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.answer-readout {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 124px;
  padding: 16px;
}

.answer-readout strong {
  overflow: hidden;
  margin-top: 7px;
  color: var(--ink);
  font-family: "GFS Didot", "Bodoni 72", Georgia, serif;
  font-size: clamp(2.4rem, 5vw, 3.7rem);
  font-weight: 500;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 1fr));
  gap: 1px;
  background: var(--line);
}

.keypad button {
  min-height: 62px;
  color: var(--ink);
  font-family: "GFS Didot", "Bodoni 72", Georgia, serif;
  font-size: 1.28rem;
  font-weight: 500;
}

.keypad button:active,
.segmented button.active {
  background: var(--panel-2);
  color: var(--rose);
}

.fire-button {
  min-height: 124px;
  font-size: 11px;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel-block {
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.panel-block.compact {
  padding-bottom: 14px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--orchid);
}

.text-button {
  min-height: 30px;
  padding: 0 2px;
  background: transparent;
  color: var(--ink-soft);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: var(--line);
}

.segmented button {
  background: var(--panel);
  color: var(--ink-soft);
}

.mode-segmented {
  grid-template-columns: 1fr;
}

.control-label {
  margin: 12px 0 8px;
}

.toggle-row,
.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  color: var(--ink);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--rose);
}

.slider-row {
  margin: 6px 0 14px;
}

.slider-row input {
  width: 150px;
  accent-color: var(--rose);
}

.difficulty-segmented {
  margin-bottom: 14px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 0;
  border: 1px solid var(--line);
  background: var(--line);
}

.stat-grid div {
  min-height: 68px;
  padding: 12px;
  background: var(--panel);
}

dd {
  margin: 4px 0 0;
  font-family: "GFS Didot", "Bodoni 72", Georgia, serif;
  font-size: 1.45rem;
  font-weight: 500;
}

.badge {
  max-width: 140px;
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--champagne);
  font-family: "IBM Plex Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.skill-list {
  display: grid;
  gap: 12px;
}

.skill-item {
  display: grid;
  gap: 7px;
}

.skill-item header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink-soft);
  font-family: "IBM Plex Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.meter {
  overflow: hidden;
  height: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--rose);
}

.shortcut-grid {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 8px 12px;
  margin-top: 12px;
}

.shortcut-grid strong {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 400;
}

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

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 760px) {
  .app-shell {
    padding: 18px 14px 32px;
  }

  .topbar,
  .answer-dock {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .run-summary {
    width: 100%;
    min-width: 0;
  }

  .canvas-wrap {
    min-height: 310px;
  }

  .answer-dock {
    display: grid;
  }

  .answer-readout,
  .fire-button {
    min-height: 78px;
  }

  .keypad {
    grid-template-columns: repeat(3, 1fr);
  }

  .keypad button {
    min-height: 54px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}
