:root {
  --paper: #f7f3ea;
  --ink: #1f2428;
  --muted: #66706c;
  --line: #d5cdbc;
  --panel: #fffdf7;
  --accent: #266f78;
  --accent-strong: #174f57;
  --gold: #b7832f;
  --success: #287a45;
  --error: #a33a34;
  --shadow: 0 12px 28px rgba(34, 29, 19, 0.14);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
}

#app {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

button {
  border: 1px solid var(--line);
  background: #fffaf0;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.62rem 0.82rem;
  font: inherit;
  cursor: pointer;
}

button:hover,
button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: #eef7f6;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.primary:hover {
  background: var(--accent-strong);
  color: white;
}

.secondary {
  background: transparent;
}

.view {
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.menu-view {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.menu-shell,
.definitions-shell,
.about-shell {
  width: min(900px, 100%);
}

h1 {
  margin: 0 0 1.6rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.4rem, 6vw, 5rem);
  font-weight: 500;
  line-height: 0.95;
}

h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

.menu-actions {
  display: grid;
  gap: 0.75rem;
  width: min(420px, 100%);
}

.menu-choice {
  text-align: left;
  font-size: 1.05rem;
}

#levelView {
  display: grid;
  grid-template-columns: 1fr;
}

#levelView.menu-screen {
  grid-template-columns: minmax(280px, 420px);
  justify-content: center;
  background: var(--paper);
}

#levelView.game-screen {
  grid-template-columns: minmax(0, 1fr) 360px;
}

#levelView.game-screen.info-collapsed {
  grid-template-columns: minmax(0, 1fr) 46px;
}

#levelView.menu-screen .game-area,
#levelView.menu-screen .game-info-panel,
#levelView.game-screen .side-panel {
  display: none;
}

.side-panel {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--panel);
  height: 100vh;
  padding: 1rem;
  overflow: auto;
}

.panel-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 1.6rem;
  line-height: 1;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.book-block {
  border-top: 1px solid var(--line);
  padding: 0.8rem 0;
}

.book-title {
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.prop-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.25rem 0;
  padding: 0.5rem 0.6rem;
}

.prop-label {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
}

.prop-title,
.prop-best-time {
  display: block;
}

.prop-best-time {
  color: var(--muted);
  font-size: 0.78rem;
}

.completion-markers {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 1.3rem;
  justify-content: flex-end;
}

.completion-check {
  color: var(--success);
  font-weight: 700;
}

.completion-star {
  color: var(--gold);
  font-weight: 700;
}

.reset-data-button {
  margin-top: 1.25rem;
}

.game-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

.tool-row,
.problem-band {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.92);
}

.problem-band p {
  margin: 0;
  max-width: 100%;
}

.instruction-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 0.75rem;
}

.instruction-panel ol,
.instruction-panel ul {
  margin: 0.3rem 0 0;
  padding-left: 1.25rem;
}

.instruction-panel h3 {
  margin: 0;
  font-size: 0.9rem;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
}

.game-info-panel {
  height: 100vh;
  min-width: 0;
  overflow: hidden;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.game-info-inner {
  height: 100%;
  overflow: auto;
  padding: 1rem;
}

.game-info-heading {
  margin: 0.75rem 0 0.85rem;
}

.time-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.time-summary strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  margin-left: 0.2rem;
}

.game-info-panel .problem-band {
  margin-top: 1rem;
  padding: 0;
  border-bottom: 0;
  background: transparent;
}

#levelView.info-collapsed .game-info-inner {
  padding: 0.5rem 0.25rem;
  overflow: hidden;
}

#levelView.info-collapsed .game-info-heading,
#levelView.info-collapsed #returnToLevels,
#levelView.info-collapsed .problem-band {
  display: none;
}

#levelView.info-collapsed #collapseInfoPanel {
  transform: rotate(180deg);
}

.segmented,
.command-row,
.color-row {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.color-button {
  width: 32px;
  height: 32px;
  padding: 0;
}

.color-button.active {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 0.75rem;
  background:
    linear-gradient(rgba(31, 36, 40, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 36, 40, 0.05) 1px, transparent 1px),
    #fbf8ef;
  background-size: 42px 42px;
}

canvas {
  width: 1200px;
  height: 760px;
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
  background: rgba(255, 253, 247, 0.56);
  box-shadow: 0 0 0 1px rgba(31, 36, 40, 0.12);
}

.toast {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  max-width: min(560px, calc(100% - 2rem));
  padding: 0.8rem 1rem;
  border-radius: 6px;
  color: white;
  box-shadow: var(--shadow);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

.definitions-shell,
.about-shell {
  align-self: start;
  margin-top: 4vh;
}

.definitions-grid,
.about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.definitions-grid article,
.about-grid article {
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.cookie-banner {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: min(390px, calc(100% - 2rem));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow);
  z-index: 5;
}

.cookie-banner p {
  margin: 0 0 0.75rem;
}

.cookie-banner div {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

@media (max-width: 840px) {
  #levelView,
  #levelView.game-screen,
  #levelView.game-screen.info-collapsed {
    grid-template-columns: 1fr;
  }

  #levelView.game-screen {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  #levelView.game-screen.info-collapsed {
    grid-template-rows: minmax(0, 1fr) 44px;
  }

  .game-info-panel {
    height: auto;
    max-height: 38vh;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .side-panel {
    width: 100%;
    border-left: 0;
    border-right: 0;
  }

  .instruction-panel,
  .definitions-grid,
  .about-grid {
    grid-template-columns: 1fr;
  }
}
