:root {
  color-scheme: light;
  --ink: #262323;
  --muted: #6f6664;
  --line: #e5dede;
  --panel: #ffffff;
  --paper: #f7f4f2;
  --maple-red: #d31111;
  --maple-red-dark: #a90f0f;
  --maple-burgundy: #8d1f1f;
  --maple-gold: #f0b429;
  --canada-blue: #1677d2;
  --success: #2f7d4a;
  --shadow: 0 18px 50px rgba(80, 35, 35, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(211, 17, 17, 0.08), transparent 240px),
    linear-gradient(135deg, rgba(141, 31, 31, 0.08), transparent 34%),
    var(--paper);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  align-items: center;
}

.play-area {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: var(--maple-red);
  box-shadow: 0 12px 28px rgba(211, 17, 17, 0.22);
  font-size: 1rem;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--maple-red);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2.1rem, 5vw, 4rem);
  line-height: 0.95;
  color: #3a3433;
}

.scoreboard {
  min-width: 104px;
  padding: 10px 14px;
  border: 1px solid rgba(211, 17, 17, 0.22);
  border-radius: 18px;
  background: #fff;
  text-align: center;
}

.scoreboard span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.scoreboard strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
  color: var(--maple-red);
}

.mode-row {
  display: flex;
  width: fit-content;
  max-width: 100%;
  gap: 6px;
  padding: 6px;
  margin-bottom: 16px;
  border: 1px solid rgba(211, 17, 17, 0.16);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(80, 35, 35, 0.08);
}

.mode-button {
  min-width: 76px;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.mode-button.active {
  color: #fff;
  background: var(--maple-red);
}

.stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 18px;
  align-items: stretch;
}

.shape-panel,
.answer-panel {
  min-width: 0;
}

.shape-card,
.answer-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.shape-card {
  position: relative;
  overflow: hidden;
  min-height: 520px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.shape-card.dragging {
  cursor: grabbing;
}

#shape-canvas,
.three-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.three-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.shape-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 800;
}

.shape-meta strong {
  color: var(--maple-red);
  font-size: 1.45rem;
}

.shape-info {
  margin-top: 10px;
  padding: 12px 14px;
  border-left: 6px solid var(--maple-red);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(211, 17, 17, 0.06);
  line-height: 1.4;
  font-weight: 800;
}

.answer-panel {
  padding: 22px;
}

.prompt h2 {
  margin-bottom: 6px;
  font-size: 1.45rem;
  color: #3a3433;
}

.prompt p {
  margin-bottom: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.answer-form {
  display: grid;
  gap: 14px;
}

.visual-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
}

.tool-toggle {
  min-height: 38px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.tool-toggle.faces.active {
  border-color: #d49b22;
  background: #d49b22;
  color: #fff;
}

.tool-toggle.edges.active {
  border-color: #177ddc;
  background: #177ddc;
  color: #fff;
}

.tool-toggle.vertices.active {
  border-color: var(--maple-red);
  background: var(--maple-red);
  color: #fff;
}

.selection-count {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 800;
  padding-left: 10px;
  border-left: 4px solid var(--maple-red);
}

.visual-tools:not([hidden]) .selection-count {
  padding: 14px 16px;
  border: 2px solid rgba(211, 17, 17, 0.18);
  border-left: 8px solid var(--maple-red);
  border-radius: 14px;
  background: rgba(211, 17, 17, 0.06);
  color: var(--ink);
  font-size: 1.35rem;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.name-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.name-choice {
  min-height: 48px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.name-choice.selected {
  border-color: var(--maple-red);
  background: rgba(211, 17, 17, 0.1);
  color: var(--maple-red-dark);
}

input {
  width: 100%;
  min-height: 76px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: #fff;
  font-size: 2.4rem;
  font-weight: 800;
  text-align: center;
}

input:focus {
  border-color: var(--maple-red);
  outline: 3px solid rgba(211, 17, 17, 0.16);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 10px;
  margin-top: 4px;
}

.primary,
.secondary {
  min-height: 50px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 900;
}

.primary {
  border: 0;
  color: #fff;
  background: var(--maple-red);
  box-shadow: 0 8px 18px rgba(211, 17, 17, 0.2);
}

.secondary {
  border: 1px solid rgba(211, 17, 17, 0.22);
  color: var(--ink);
  background: #fff;
}

.next-button {
  white-space: nowrap;
}

.feedback,
.hint {
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  line-height: 1.45;
  font-weight: 800;
}

.feedback:empty {
  display: none;
}

.feedback.correct {
  color: #15552f;
  background: rgba(47, 125, 74, 0.14);
}

.feedback.try {
  color: #7c1c1c;
  background: rgba(211, 17, 17, 0.1);
}

.hint {
  color: #6d3c00;
  background: rgba(240, 180, 41, 0.22);
}

.study-card {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(211, 17, 17, 0.18);
  border-radius: 16px;
  background: rgba(255, 250, 246, 0.96);
}

.study-card[hidden] {
  display: none;
}

.study-card h3 {
  margin: 0 0 8px;
  color: var(--maple-red-dark);
  font-size: 1rem;
}

.study-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0;
}

.study-card dt {
  color: var(--muted);
  font-weight: 900;
}

.study-card dd {
  margin: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(38, 35, 35, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.result-modal {
  width: min(520px, 100%);
  padding: 24px;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 28px 90px rgba(38, 35, 35, 0.28);
}

.result-modal h2 {
  margin: 0 0 10px;
  color: var(--maple-red);
}

.result-modal ul {
  margin: 12px 0 0;
  padding-left: 20px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 14px 0;
    align-items: start;
  }

  .topbar {
    align-items: flex-start;
  }

  .stage-grid {
    grid-template-columns: 1fr;
  }

  .shape-card {
    min-height: min(72vw, 440px);
  }

  .answer-panel {
    padding: 16px;
  }
}

@media (max-width: 460px) {
  .topbar {
    flex-direction: column;
  }

  .mode-row {
    width: 100%;
  }

  .mode-button {
    flex: 1;
    min-width: 0;
  }

  .actions {
    grid-template-columns: 1fr 1fr;
  }

  .next-button {
    grid-column: 1 / -1;
  }
}
