:root {
  --blue: #149bd7;
  --ink: #102131;
  --muted: #5c6b78;
  --panel: #ffffff;
  --line: #d8e2ea;
  --shadow: 0 12px 32px rgba(15, 33, 49, 0.12);
  --radius: 8px;
  --touch: 48px;
  --zoom: 1;
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: #eef4f8;
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
}

button,
input,
select { font: inherit; }

button {
  min-height: var(--touch);
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-weight: 800;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 2px;
}

select {
  min-height: var(--touch);
  max-width: min(330px, calc(100vw - 36px));
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #071018;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  width: 142px;
  height: auto;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-logo {
  display: inline-flex;
  border-radius: 6px;
}

.brand-logo:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 3px;
}

.title-block { min-width: 0; }

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2.05rem);
  line-height: 1.05;
  font-weight: 800;
}
.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: end;
  flex-wrap: wrap;
}

.icon-button {
  width: var(--touch);
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: #122436;
  color: #ffffff;
  border-color: #263d51;
}

.icon-button:hover,
.icon-button[aria-pressed="true"] {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.home-button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid #263d51;
  border-radius: var(--radius);
  background: #122436;
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.home-button:hover,
.home-button:focus-visible {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.icon {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
  z-index: 3;
  flex-wrap: wrap;
}

.toolbar-left,
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.challenge-controls {
  margin-left: auto;
  justify-content: end;
}

.control-label {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.wide-button {
  min-height: var(--touch);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--line);
  background: #f8fbfd;
  color: var(--ink);
  white-space: nowrap;
}

.wide-button:hover,
.wide-button[aria-pressed="true"],
.primary {
  border-color: #0f80b3;
  background: var(--blue);
  color: #06111a;
}

.tool-menu { position: relative; }

.tool-menu summary {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
  white-space: nowrap;
  user-select: none;
}

.tool-menu summary::-webkit-details-marker { display: none; }

.tool-menu[open] summary,
.tool-menu summary:hover {
  border-color: var(--blue);
  background: #e5f6fc;
}

.menu-panel {
  width: min(440px, calc(100vw - 36px));
  padding: 10px;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.models-menu .menu-panel {
  left: 0;
  right: auto;
}

.check-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  font-weight: 800;
  white-space: nowrap;
}

.check-pill input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.workspace {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px;
  background:
    linear-gradient(#dce8f0 1px, transparent 1px),
    linear-gradient(90deg, #dce8f0 1px, transparent 1px);
  background-size: 34px 34px;
}

.tool-surface {
  width: min(1220px, 100%);
  min-height: 660px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.94);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 14px;
  transform: scale(var(--zoom));
  transform-origin: top center;
}

.stage-panel,
.facts-panel {
  min-width: 0;
  border: 2px solid #cbd9e3;
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}

.stage-panel {
  display: grid;
  grid-template-rows: 1fr;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.shape-heading {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.shape-heading strong {
  font-size: 1.14rem;
  line-height: 1.1;
}

.shape-heading span {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.25;
}

.mode-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 2px solid #bfe6f6;
  border-radius: var(--radius);
  background: #f0f9fd;
  color: #0a5e86;
  font-weight: 900;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 46%, rgba(20, 155, 215, 0.10), transparent 270px),
    #f9fcfe;
  touch-action: none;
}

#shapeSvg {
  width: 100%;
  height: 100%;
  min-height: 560px;
  display: block;
}

.face,
.surface-face {
  stroke: rgba(16, 33, 49, 0.82);
  stroke-width: 2.4;
  stroke-linejoin: round;
  transition: opacity 220ms ease;
}

.surface-face {
  stroke: rgba(143, 216, 243, 0.92);
  stroke-width: 0.8;
}

.face.highlight,
.surface-face.highlight {
  stroke: #d18a00;
  stroke-width: 5;
  fill-opacity: 1;
  filter: drop-shadow(0 0 7px rgba(209, 138, 0, 0.62));
}

.edge-line,
.surface-edge {
  stroke: #102131;
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
}

.surface-edge {
  stroke: rgba(16, 33, 49, 0.18);
  stroke-width: 1.4;
}

.edge-line.highlight,
.surface-edge.highlight {
  stroke: #d25a4b;
  stroke-width: 7;
}

.vertex-dot {
  fill: #ffffff;
  stroke: #102131;
  stroke-width: 3;
}

.vertex-dot.highlight {
  fill: #149bd7;
  stroke: #06111a;
  stroke-width: 4;
}

.shape-label,
.net-label,
.surface-label {
  font-family: Arial, Helvetica, sans-serif;
  fill: #102131;
  font-size: 18px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 5;
  stroke-linejoin: round;
}

.surface-label { font-size: 20px; }

.net-piece {
  stroke: #102131;
  stroke-width: 3;
  stroke-linejoin: round;
  fill-opacity: 0.72;
  transform-box: fill-box;
  transform-origin: center;
  animation: unfoldNet 480ms ease both;
}

.net-edge {
  fill: none;
  stroke: #d25a4b;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 8 7;
}

.net-curve {
  fill: rgba(143, 216, 243, 0.34);
  stroke: #102131;
  stroke-width: 3;
}

@keyframes unfoldNet {
  from { opacity: 0; transform: scale(0.76) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.facts-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
}

.facts-top {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.facts-top h2 {
  margin: 0;
  font-size: 1.08rem;
}

.facts-top p {
  margin: 5px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.28;
}

.facts-table {
  width: 100%;
  border-collapse: collapse;
}

.facts-table[hidden] {
  display: none;
}

.facts-table th,
.facts-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.facts-table th {
  color: var(--muted);
  font-size: 0.86rem;
}

.facts-table td {
  font-size: 1.08rem;
  font-weight: 900;
}

.facts-table tr.active {
  background: #e5f6fc;
}

.note-list {
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.note-card {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #ffffff;
  line-height: 1.32;
}

.note-card strong {
  display: block;
  margin-bottom: 3px;
}

.note-card span,
.note-card li {
  color: var(--muted);
  font-weight: 700;
}

.note-card ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.feedback {
  min-height: 52px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #ffffff;
  font-weight: 800;
  line-height: 1.28;
}

.feedback.good {
  background: #eef9e8;
  color: #22510f;
}

.feedback.try {
  background: #fff8e6;
  color: #6a4300;
}

.print-logo,
.print-copyright { display: none; }

.instructions-dialog {
  width: min(900px, calc(100vw - 32px));
  max-height: min(800px, calc(100vh - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(6, 17, 26, 0.32);
}

.instructions-dialog::backdrop {
  background: rgba(6, 17, 26, 0.5);
}

.instructions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #071018;
  color: #ffffff;
}

.instructions-header h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.15;
}

.instructions-body {
  max-height: calc(min(800px, 100vh - 32px) - 76px);
  overflow: auto;
  padding: 16px 18px 20px;
  line-height: 1.45;
}

.instructions-body h3 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.instructions-body h3:first-child { margin-top: 0; }

.instructions-body p,
.instructions-body ul,
.instructions-body ol {
  margin: 0 0 10px;
}

.instructions-body li { margin-bottom: 6px; }
.instructions-body strong { color: #06111a; }

@media (max-width: 980px) {
  .topbar,
  .tool-surface {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .control-group,
  .challenge-controls {
    justify-content: start;
  }

  .challenge-controls { margin-left: 0; }
  .toolbar { justify-content: start; }
  .brand img { width: 116px; }
.workspace { padding: 12px; }
  .tool-surface { min-height: 0; }
  #shapeSvg { min-height: 470px; }
  .menu-panel { left: 0; right: auto; }
}

@media print {
  @page { size: landscape; }

  body,
  .workspace {
    background: #ffffff;
    overflow: visible;
  }

  .topbar,
  .toolbar,
  .feedback,
  .instructions-dialog {
    display: none;
  }

  .app {
    display: block;
    height: auto;
  }

  .workspace {
    overflow: visible;
    padding: 0;
  }

  .tool-surface {
    width: 100%;
    min-height: 0;
    box-shadow: none;
    border: 1px solid #000000;
    transform: none;
  }

  .stage-panel,
  .facts-panel {
    border-color: #000000;
  }

  .print-logo {
    display: block;
    width: 150px;
    margin-bottom: 12px;
  }

  .print-copyright {
    display: block;
    margin-top: 12px;
    color: #000000;
    font-size: 11pt;
    font-weight: 700;
    text-align: right;
  }
}
