: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;
    }

    body { overflow: hidden; }

    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);
      border: 2px solid var(--line);
      border-radius: var(--radius);
      background: #ffffff;
      color: var(--ink);
      padding: 0 12px;
      font-weight: 800;
    }

    .app {
      display: grid;
      grid-template-rows: auto auto 1fr;
      height: 100vh;
      height: 100dvh;
      min-width: 320px;
    }

    .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 {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }

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

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

    .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);
    }

    .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(1180px, 100%);
      min-height: 650px;
      margin: 0 auto;
      background: rgba(255, 255, 255, 0.94);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: 14px;
      display: grid;
      grid-template-rows: auto 1fr;
      gap: 12px;
      transform: scale(var(--zoom));
      transform-origin: top center;
    }

    .teacher-strip {
      display: grid;
      grid-template-columns: minmax(300px, 1fr);
      gap: 10px;
      align-items: stretch;
    }

    .info-card {
      border: 2px solid var(--line);
      border-radius: var(--radius);
      background: #ffffff;
      padding: 10px 12px;
      min-height: 76px;
    }

    .info-card strong {
      display: block;
      font-size: 1.08rem;
      line-height: 1.15;
      margin-bottom: 4px;
    }

    .info-card span {
      color: var(--muted);
      font-weight: 700;
      line-height: 1.3;
    }

    .facts-card {
      border-color: #bfe6f6;
      background: #f5fbfe;
    }

    .facts-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(180px, 1fr));
      gap: 6px 14px;
      margin-top: 6px;
      color: var(--ink);
      font-weight: 800;
    }

    .fact {
      min-width: 0;
      line-height: 1.25;
    }

    .formula-block + .formula-block {
      margin-top: 12px;
      padding-top: 10px;
      border-top: 2px solid #d8e2ea;
    }

    .stage-wrap {
      min-height: 0;
      overflow: hidden;
      border: 2px solid #cbd9e3;
      border-radius: var(--radius);
      background: #f9fcfe;
    }

    .stage-scale {
      width: min(1128px, 100%);
      aspect-ratio: 1128 / 640;
      margin: 0 auto;
      position: relative;
    }

    #stageSvg {
      width: 100%;
      height: 100%;
      display: block;
      background:
        radial-gradient(circle at 462px 316px, rgba(20, 155, 215, 0.08), transparent 250px),
        #ffffff;
    }

    .polygon-fill {
      fill: rgba(143, 216, 243, 0.25);
      stroke: #102131;
      stroke-width: 5;
      stroke-linejoin: round;
    }

    .shape-part {
      stroke: #102131;
      stroke-width: 2;
      stroke-linejoin: round;
      opacity: 0.88;
    }

    .construction-line {
      stroke: rgba(16, 33, 49, 0.58);
      stroke-width: 4;
      stroke-dasharray: 10 8;
      stroke-linecap: round;
      fill: none;
    }

    .angle-sector {
      stroke: rgba(16, 33, 49, 0.28);
      stroke-width: 2;
    }

    .arc {
      fill: none;
      stroke-width: 6;
      stroke-linecap: round;
    }

    .part-angle-arc {
      fill: none;
      stroke: rgba(16, 33, 49, 0.62);
      stroke-width: 3;
      stroke-linecap: round;
    }

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

    .angle-label { font-size: 27px; }
    .diagram-label { font-size: 23px; }

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

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

    .challenge-shape {
      fill: rgba(143, 216, 243, 0.34);
      stroke: #1f66c2;
      stroke-width: 5;
      stroke-linejoin: round;
    }

    .challenge-shape.alt {
      fill: rgba(242, 184, 75, 0.34);
      stroke: #c37a00;
    }

    .challenge-shape.third {
      fill: rgba(164, 212, 111, 0.34);
      stroke: #4f8d24;
    }

    .challenge-line {
      stroke: #102131;
      stroke-width: 5;
      stroke-linecap: round;
      fill: none;
    }

    .challenge-arc {
      fill: none;
      stroke: rgba(16, 33, 49, 0.72);
      stroke-width: 4;
      stroke-linecap: round;
    }

    .challenge-ref {
      stroke: #202326;
      stroke-width: 5;
      stroke-linejoin: round;
      stroke-linecap: round;
    }

    .challenge-ref.blue {
      stroke: #3f70c8;
    }

    .challenge-ref-line {
      stroke: #202326;
      stroke-width: 5;
      stroke-linecap: round;
      fill: none;
    }

    .challenge-ref-line.blue {
      stroke: #3f70c8;
    }

    .challenge-ref-arc {
      fill: none;
      stroke: #202326;
      stroke-width: 5;
      stroke-linecap: round;
    }

    .challenge-ref-arc.red {
      stroke: #ff1515;
    }

    .challenge-ref-label {
      font-family: Arial, Helvetica, sans-serif;
      fill: #000000;
      font-size: 40px;
      font-weight: 700;
      text-anchor: middle;
      dominant-baseline: central;
    }

    .challenge-ref-variable {
      font-family: "Times New Roman", Times, serif;
      fill: #000000;
      font-size: 48px;
      font-style: italic;
      font-weight: 700;
      text-anchor: middle;
      dominant-baseline: central;
    }

    .radius-line {
      fill: none;
      stroke: #102131;
      stroke-width: 4;
      stroke-linecap: round;
    }

    .radius-line {
      stroke: rgba(16, 33, 49, 0.28);
      stroke-width: 3;
    }

    .feedback {
      display: none;
      min-height: 58px;
      border: 2px solid var(--line);
      border-radius: var(--radius);
      padding: 10px 12px;
      background: #ffffff;
      font-weight: 800;
      line-height: 1.28;
    }

    .feedback.good {
      border-color: #76b947;
      background: #eef9e8;
      color: #22510f;
    }

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

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

    .instructions-dialog {
      width: min(860px, calc(100vw - 32px));
      max-height: min(780px, 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(780px, 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: 960px) {
      body { overflow: auto; }

      .app {
        height: auto;
        min-height: 100vh;
      }

      .topbar,
      .teacher-strip {
        grid-template-columns: 1fr;
      }

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

      .toolbar { justify-content: start; }
      .challenge-controls { margin-left: 0; justify-content: start; }
      .brand img { width: 116px; }
.workspace { padding: 12px; }
      .tool-surface { min-height: 560px; }
      .menu-panel { left: 0; right: auto; }
      .facts-grid { grid-template-columns: 1fr; }
    }

    @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-wrap {
        overflow: visible;
        border: 0;
      }

      .stage-scale {
        width: 1128px;
        height: 640px;
      }

      .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;
      }
    }
