:root {
      --blue: #149bd7;
      --ink: #102131;
      --muted: #5c6b78;
      --paper: #fbfcfe;
      --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;
    }

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

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

  .home-button:hover,
  .home-button:focus-visible {
    background: var(--blue, #149bd7);
    border-color: #8fd8f3;
    color: #06111a;
  }.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 {
      background: var(--blue);
      border-color: #8fd8f3;
      color: #06111a;
    }

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

    .toolbar {
      display: grid;
      grid-template-columns: auto auto minmax(360px, 1fr);
      gap: 12px;
      align-items: center;
      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;
    }

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

    .check-strip {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      align-items: center;
      width: 280px;
      padding: 10px;
      position: absolute;
      top: calc(100% + 6px);
      left: 0;
      z-index: 10;
      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);
    }

    .random-menu,
    .tool-menu {
      position: relative;
    }

    .random-menu summary,
    .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;
    }

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

    .menu-panel {
      width: 310px;
      padding: 10px;
      position: absolute;
      top: calc(100% + 6px);
      right: 0;
      z-index: 10;
      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);
    }

    select,
    input[type="number"] {
      min-height: var(--touch);
      border: 2px solid var(--line);
      border-radius: var(--radius);
      background: #ffffff;
      color: var(--ink);
      padding: 0 12px;
      font-weight: 800;
    }

    input[type="number"] {
      width: 126px;
      font-size: 1.1rem;
    }

    .segmented {
      display: inline-grid;
      grid-auto-flow: column;
      grid-auto-columns: 1fr;
      border: 2px solid var(--line);
      border-radius: var(--radius);
      overflow: hidden;
      background: #ffffff;
    }

    .segmented button {
      min-width: 86px;
      border: 0;
      border-radius: 0;
      background: #ffffff;
    }

    .segmented button + button { border-left: 2px solid var(--line); }

    .segmented button[aria-pressed="true"] {
      background: var(--blue);
      color: #06111a;
    }

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

    .primary {
      background: var(--blue);
      border-color: #0f80b3;
      color: #06111a;
    }

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

    .tool-surface {
      width: min(1160px, 100%);
      min-height: 620px;
      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: 1fr auto;
      gap: 12px;
    }

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

    .stage-scale {
      width: calc(1128px * var(--zoom));
      height: calc(620px * var(--zoom));
      transform-origin: top left;
      position: relative;
    }

    #stageSvg {
      width: 1128px;
      height: 620px;
      transform: scale(var(--zoom));
      transform-origin: top left;
      display: block;
      touch-action: none;
      background:
        radial-gradient(circle at 564px 310px, rgba(20, 155, 215, 0.09), transparent 210px),
        #ffffff;
    }

    .feedback-row {
      display: grid;
      grid-template-columns: minmax(250px, 1fr) minmax(520px, 1.7fr) auto;
      gap: 10px;
      align-items: center;
    }

    .steps {
      display: grid;
      grid-template-columns: repeat(3, minmax(150px, 1fr));
      gap: 8px;
      min-width: 0;
    }

    .step {
      display: grid;
      grid-template-rows: auto auto;
      gap: 6px;
      min-width: 0;
      padding: 8px;
      border: 2px solid var(--line);
      border-radius: var(--radius);
      background: #ffffff;
    }

    .step-title {
      font-size: 0.86rem;
      color: var(--muted);
      font-weight: 800;
      white-space: nowrap;
    }

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

    .feedback {
      min-height: 54px;
      border: 2px solid var(--line);
      border-radius: var(--radius);
      padding: 9px 12px;
      background: #ffffff;
      font-weight: 800;
      line-height: 1.25;
    }

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

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

    .angle-line {
      stroke: #102131;
      stroke-width: 4.5;
      stroke-linecap: round;
    }

    .angle-arm-tip { fill: #102131; }

    .angle-arc {
      fill: none;
      stroke: #e4572e;
      stroke-width: 5;
      stroke-linecap: round;
    }

    .guide-line {
      fill: none;
      stroke: rgba(20, 155, 215, 0.82);
      stroke-width: 4;
      stroke-linecap: round;
      stroke-dasharray: 12 9;
      pointer-events: none;
    }

    .guide-square {
      fill: rgba(20, 155, 215, 0.12);
      stroke: rgba(20, 155, 215, 0.92);
      stroke-width: 3;
      pointer-events: none;
    }

    .protractor-body {
      fill: rgba(143, 216, 243, 0.28);
      stroke: rgba(6, 17, 26, 0.66);
      stroke-width: 2.2;
    }

    .protractor-edge {
      fill: none;
      stroke: rgba(6, 17, 26, 0.72);
      stroke-width: 2.2;
    }

    .protractor-tick {
      stroke: rgba(6, 17, 26, 0.88);
      stroke-linecap: butt;
    }

    .protractor-label {
      fill: rgba(6, 17, 26, 0.92);
      font-family: Arial, Helvetica, sans-serif;
      font-weight: 800;
      text-anchor: middle;
      dominant-baseline: central;
      pointer-events: none;
      user-select: none;
      -webkit-user-select: none;
    }

    .protractor-small-label {
      fill: rgba(6, 17, 26, 0.72);
      font-family: Arial, Helvetica, sans-serif;
      font-weight: 700;
      text-anchor: middle;
      dominant-baseline: central;
      pointer-events: none;
      user-select: none;
      -webkit-user-select: none;
    }

    .protractor-move {
      cursor: grab;
      user-select: none;
      -webkit-user-select: none;
    }

    .protractor-move:active {
      cursor: grabbing;
    }

    .centre-hole {
      fill: rgba(255, 255, 255, 0.64);
      stroke: rgba(6, 17, 26, 0.75);
      stroke-width: 1.8;
    }

    .centre-crosshair {
      stroke: rgba(6, 17, 26, 0.9);
      stroke-width: 1.8;
      stroke-linecap: round;
      pointer-events: none;
    }

    .rotation-handle {
      fill: #ffffff;
      stroke: #0f80b3;
      stroke-width: 4;
      cursor: grab;
    }

    .rotation-handle:active { cursor: grabbing; }

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

    .instructions-dialog {
      width: min(820px, 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: 860px) {
      body { overflow: auto; }

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

      .toolbar,
      .feedback-row {
        grid-template-columns: 1fr;
      }

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

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

      .top-actions { justify-content: start; }
    }

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

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

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

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

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

      .stage-wrap {
        overflow: visible;
        border: 0;
      }

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

      #stageSvg { transform: none; }

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