:root {
  /* Pure Processing brand palette (Brand Guide v1.0) */
  --deep-cobalt: #13294b;
  --sterilization-blue: #3776c3;
  --surgical-gray: #384967;
  --focal-signal: #e57200;
  --rinse-cycle: #99d6ea;
  --aseptic-white: #ffffff;

  --bg-0: var(--deep-cobalt);
  --bg-1: #2b3e5d; /* Deep Cobalt, 90% tint */
  --panel: var(--surgical-gray);
  --panel-border: #4c5b76; /* Surgical Gray, 90% tint */
  --text: var(--aseptic-white);
  --text-dim: #9ca4b3; /* Surgical Gray, 50% tint */
  --accent: var(--focal-signal);
  --accent-2: var(--sterilization-blue);
  --danger: #ff4d6d;
}

* { box-sizing: border-box; }

.hidden { display: none; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-1) 0%, var(--bg-0) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 20px;
  padding: 24px;
  min-height: 100vh;
}

.stage {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--panel-border);
}

canvas#gameCanvas {
  display: block;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  touch-action: none;
}

/* In the side-by-side layout, shrink the canvas (keeping its aspect ratio) to
   fit short windows or short embeds instead of cutting off the bottom rows. */
@media (min-width: 721px) {
  canvas#gameCanvas {
    width: auto;
    height: auto;
    max-height: calc(100vh - 48px);
  }

  /* In full screen, grow the board to fill the screen's height. */
  html.is-fullscreen canvas#gameCanvas {
    height: calc(100vh - 48px);
    max-height: none;
  }
}

.overlay {
  line-height: normal;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 240px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px;
}

.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
}

.stat-label {
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.next-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}

#nextCanvas {
  display: block;
}

#nextNextCanvas {
  display: block;
  opacity: 0.75;
}

.buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  background: linear-gradient(180deg, var(--panel-border), var(--bg-1));
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn:hover {
  background: linear-gradient(180deg, #5a6b8a, var(--panel-border));
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.small {
  padding: 8px 12px;
  font-size: 13px;
}

.hint {
  font-size: 13px;
  color: var(--text-dim);
}

.hint strong {
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

.hint ul {
  margin: 0;
  padding-left: 18px;
}

.hint li {
  margin-bottom: 4px;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(19, 41, 75, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay .panel {
  text-align: center;
  padding: 28px 32px;
  max-width: 320px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
}

.overlay h1 {
  margin: 0 0 10px;
  font-size: 28px;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(229, 114, 0, 0.35);
}

.overlay p {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 18px;
}

.controls-hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
}

.final-score {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-2);
  margin-bottom: 18px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}

.hint-text {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  margin: 14px 0 0;
}

.hint-text a {
  color: var(--rinse-cycle);
}

/* ---- high scores ---- */

.highscore-entry {
  margin-bottom: 16px;
}

p.highscore-callout {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  margin: 0 0 8px;
}

.name-input {
  width: 100%;
  background: var(--bg-0);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 16px; /* 16px stops iOS Safari from zooming the page when the field gets focus */
  margin-bottom: 8px;
}

.name-input:focus {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

.highscore-saved {
  color: var(--accent-2);
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 16px;
}

p.save-error {
  color: var(--danger);
  font-size: 12px;
  margin: 0 0 8px;
  min-height: 14px;
}

.section-label {
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
  margin: 18px 0 8px;
}

.share-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

.highscore-list {
  list-style: none;
  counter-reset: hs;
  margin: 0 0 8px;
  padding: 0;
  text-align: left;
  max-height: 320px;
  overflow-y: auto;
}

.highscore-list li {
  counter-increment: hs;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--panel-border);
  font-size: 14px;
}

.highscore-list li::before {
  content: counter(hs);
  width: 20px;
  flex: none;
  color: var(--text-dim);
  font-weight: 700;
  text-align: right;
}

.highscore-list .hs-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.highscore-list .hs-score {
  color: var(--accent);
  font-weight: 700;
}

.highscore-empty {
  color: var(--text-dim);
  justify-content: center;
}

li.highscore-empty::before {
  content: none;
}

/* ---- education mode ---- */

.edu-panel,
.gameover-panel {
  max-width: 400px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
}

.quiz-block {
  text-align: left;
}

.quiz-topic-label {
  display: inline-block;
  color: var(--bg-0);
  background: var(--rinse-cycle);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 10px;
}

p.quiz-question {
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 14px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.quiz-option {
  background: var(--bg-0);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.quiz-option:hover:not(:disabled) {
  background: var(--bg-1);
  border-color: var(--accent-2);
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-option.correct {
  background: rgba(62, 203, 74, 0.18);
  border-color: #3ecb4a;
  color: #b8f5c0;
}

.quiz-option.incorrect {
  background: rgba(255, 77, 109, 0.18);
  border-color: var(--danger);
  color: #ffb3ba;
}

p.quiz-feedback {
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 10px;
}

p.quiz-feedback.correct {
  color: #3ecb4a;
  font-weight: 700;
}

p.quiz-feedback.incorrect {
  color: var(--text);
}

p.quiz-difficulty-hint {
  font-size: 12px;
  font-style: italic;
  color: var(--text-dim);
  margin: 0 0 16px;
}

/* ---- mobile / narrow viewports ---- */

@media (max-width: 720px) {
  .wrap {
    flex-direction: column;
    align-items: center;
    padding: 12px;
    gap: 12px;
  }

  .stage {
    width: 100%;
    max-width: 420px;
  }

  canvas#gameCanvas {
    width: 100%;
    height: auto;
    max-width: 420px;
  }

  .sidebar {
    width: 100%;
    max-width: 420px;
  }

  .overlay .panel {
    width: 90%;
    padding: 22px 20px;
  }

  .edu-panel,
  .gameover-panel {
    max-width: 360px;
  }
}

