:root{color-scheme:light;box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}html{scroll-padding-top:env(safe-area-inset-top,0px)}body{margin:0;padding:0;font:14px -apple-system,BlinkMacSystemFont,sans-serif;background:#faf9f5;color:#141413}img{max-width:100%}[hidden]:not([hidden=until-found i]){display:none!important}

  :root {
    /* Layout: a HUD bar over the stage; the 3D puzzle fills the stage and the ring dial sits under it on phones, beside it when wide. */
    --bg: #f4f1ea;
    --bg-hi: #fbf9f4;
    --bg-deep: #e8e1d3;
    --card: #fffdf8;
    --ink: #26221f;
    --on-ink: #ffffff;
    --muted: #776e63;
    --faint: #a39a8d;
    --line: #ddd5c7;
    --chip: #ece6da;
    --accent: #6c47ff;
    --accent-soft: #eee9ff;
    --on-accent: #ffffff;
    --good: #1c8a4a;
    --good-soft: #dff3e6;
    --warn: #e0452f;
    --prize: #fff1bf;
    --prize-ink: #7a5200;
    --scrim: rgba(244, 241, 234, .72);
    --scrim-soft: rgba(244, 241, 234, .6);
    --body: #221f1d;
    --shadow: 0 14px 34px rgba(38, 34, 31, .16), 0 2px 8px rgba(38, 34, 31, .08);
    --shadow-sm: 0 1px 0 rgba(0, 0, 0, .04), 0 4px 12px rgba(38, 34, 31, .10);
    --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #191715; --bg-hi: #221f1c; --bg-deep: #100f0e; --card: #26231f; --ink: #f2ede5; --on-ink: #1a1816;
      --muted: #a79d90; --faint: #7b7368; --line: #3b3631; --chip: #312d29; --accent: #9178ff; --accent-soft: #2d2550;
      --on-accent: #ffffff; --good: #45c27a; --good-soft: #1d3a29; --warn: #ff6a52; --prize: #4a3b12; --prize-ink: #ffd878;
      --scrim: rgba(25, 23, 21, .74); --scrim-soft: rgba(25, 23, 21, .6); --body: #0d0c0b;
      --shadow: 0 14px 34px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .3);
      --shadow-sm: 0 1px 0 rgba(255, 255, 255, .03), 0 4px 12px rgba(0, 0, 0, .35);
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --bg: #191715; --bg-hi: #221f1c; --bg-deep: #100f0e; --card: #26231f; --ink: #f2ede5; --on-ink: #1a1816;
    --muted: #a79d90; --faint: #7b7368; --line: #3b3631; --chip: #312d29; --accent: #9178ff; --accent-soft: #2d2550;
    --on-accent: #ffffff; --good: #45c27a; --good-soft: #1d3a29; --warn: #ff6a52; --prize: #4a3b12; --prize-ink: #ffd878;
    --scrim: rgba(25, 23, 21, .74); --scrim-soft: rgba(25, 23, 21, .6); --body: #0d0c0b;
    --shadow: 0 14px 34px rgba(0, 0, 0, .45), 0 2px 8px rgba(0, 0, 0, .3);
    --shadow-sm: 0 1px 0 rgba(255, 255, 255, .03), 0 4px 12px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
  body {
    position: fixed; inset: 0; overflow: hidden;
    font-family: var(--font);
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  }
  button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-appearance: none; appearance: none; }
  button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
  [hidden] { display: none !important; }

  #app {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: radial-gradient(130% 75% at 50% 0%, var(--bg-hi) 0%, var(--bg) 55%, var(--bg-deep) 100%);
  }

  /* ---------- HUD ---------- */
  #hud { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 14px 2px; min-height: 62px; }
  #hud.off { display: none; }
  .icon-btn {
    flex: none; width: 46px; height: 46px; border-radius: 15px; border: 0; padding: 0;
    background: var(--card); box-shadow: var(--shadow-sm);
    display: grid; place-items: center; transition: transform .12s ease, opacity .2s ease;
  }
  .icon-btn:active { transform: scale(.93); }
  .icon-btn:disabled { opacity: .32; cursor: default; }
  .icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
  .hud-mid { flex: 1; min-width: 0; text-align: center; }
  #timer { font-size: 31px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .01em; line-height: 1; }
  #timer.idle { color: var(--faint); }
  #timer.done { color: var(--good); }
  #timer.label { font-size: 22px; letter-spacing: 0; }
  #hudSub { margin-top: 4px; font-size: 12.5px; font-weight: 700; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

  /* ---------- Stage ---------- */
  #stage {
    flex: 1; min-height: 0; position: relative; display: grid;
    grid-template-columns: 100%; grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "coach" "view" "dial";
  }
  #stage.landscape {
    grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "coach dial" "view dial";
  }
  #viewWrap { grid-area: view; position: relative; min-height: 0; min-width: 0; }
  canvas { display: block; width: 100%; height: 100%; touch-action: none; }
  #viewHint {
    position: absolute; left: 14px; right: 14px; top: 2px; text-align: center;
    font-size: 11.5px; font-weight: 700; color: var(--faint); pointer-events: none; transition: opacity .4s;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .title-mode #viewHint, .title-mode #viewTools { opacity: 0; pointer-events: none; }
  @media (max-width: 440px) { #zoomHint { display: none; } }
  #viewTools { position: absolute; left: 14px; right: 14px; bottom: 6px; display: flex; gap: 6px; justify-content: center; }
  .pill {
    border: 0; border-radius: 99px; padding: 7px 14px; min-height: 34px; font-size: 13.5px; font-weight: 800; white-space: nowrap;
    background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); transition: transform .12s ease, opacity .2s;
  }
  .pill:active { transform: scale(.95); }
  .pill:disabled { opacity: .4; cursor: default; }
  .pill.strong { background: var(--ink); color: var(--on-ink); }

  /* ---------- Ring dial ---------- */
  #dialPanel { grid-area: dial; position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 0 14px 6px; }
  #stage.landscape #dialPanel { padding: 6px 14px 10px 4px; }
  .dial-bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 42px; }
  #dialWrap { flex: 1; min-height: 0; position: relative; }
  .mini-btn {
    flex: none; width: 36px; height: 36px; border: 0; border-radius: 11px; padding: 0;
    background: var(--card); box-shadow: var(--shadow-sm); font-size: 19px; font-weight: 800; line-height: 1;
    display: grid; place-items: center; transition: transform .12s ease, opacity .2s;
  }
  .mini-btn.wide { width: 46px; font-size: 21px; }
  .mini-btn:active { transform: scale(.93); }
  .mini-btn:disabled { opacity: .35; cursor: default; }
  .picker { display: flex; align-items: center; gap: 6px; min-width: 0; }
  .pick-label { min-width: 74px; text-align: center; line-height: 1.05; }
  .pick-label b { display: block; font-size: 15px; font-weight: 800; white-space: nowrap; }
  .pick-label small { display: block; font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 2px; }
  .seg button {
    border: 0; background: transparent; border-radius: 9px; padding: 6px 11px; min-height: 32px;
    font-size: 13.5px; font-weight: 800; color: var(--muted); transition: background .15s, color .15s;
  }
  .seg button[aria-checked="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }
  .seg button:disabled { opacity: .45; cursor: default; }

  /* ---------- Tutorial coach ---------- */
  #coach {
    grid-area: coach; margin: 2px 14px 4px; padding: 12px 14px 12px; background: var(--card);
    border-radius: 18px; box-shadow: var(--shadow); display: none;
  }
  #coach.show { display: block; animation: pop .28s ease-out; }
  #stage.landscape #coach { margin: 4px 8px 4px 14px; max-width: 480px; }
  .coach-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
  .coach-step { flex: none; font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--accent); background: var(--accent-soft); padding: 3px 8px; border-radius: 99px; }
  .coach-title { font-weight: 800; font-size: 16.5px; }
  #coachText { margin: 0; font-size: 14.5px; line-height: 1.38; color: var(--ink); opacity: .86; }
  #coachText b { opacity: 1; }
  #coach.success .coach-step { background: var(--good-soft); color: var(--good); }
  .coach-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
  .coach-actions:empty { display: none; }

  /* ---------- Buttons ---------- */
  .btn {
    border: 0; border-radius: 16px; padding: 12px 18px; font-weight: 800; font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
    transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
  }
  .btn:active { transform: scale(.97); }
  .btn.primary { background: var(--ink); color: var(--on-ink); box-shadow: 0 8px 18px rgba(38, 34, 31, .24); }
  .btn.accent { background: var(--accent); color: var(--on-accent); box-shadow: 0 8px 18px rgba(108, 71, 255, .28); }
  .btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
  .btn.big { width: 100%; min-height: 56px; font-size: 18.5px; border-radius: 18px; }
  .btn.small { padding: 9px 15px; font-size: 14.5px; border-radius: 12px; min-height: 42px; }
  .btn svg { width: 20px; height: 20px; fill: currentColor; }

  /* ---------- Overlays ---------- */
  .overlay {
    position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: calc(14px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom));
    background: var(--scrim);
    -webkit-backdrop-filter: blur(2.5px); backdrop-filter: blur(2.5px);
    transition: opacity .25s ease; overflow-y: auto;
  }
  .overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
  .card {
    width: 100%; max-width: 400px; background: var(--card); border-radius: 26px; box-shadow: var(--shadow);
    padding: 22px 20px 18px; text-align: center; margin: auto 0;
  }
  .overlay:not(.hidden) .card { animation: pop .3s ease-out; }
  @keyframes pop { from { transform: translateY(10px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

  /* Title: the live puzzle spins above the menu card */
  #titleScreen { justify-content: flex-end; -webkit-backdrop-filter: none; backdrop-filter: none; background: none; }
  #stage.landscape ~ #titleScreen { justify-content: center; background: var(--scrim-soft); }
  .title-card { padding-top: 18px; margin: 0; }
  .brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
  .logo { width: 50px; height: 50px; flex: none; }
  .title-card h1 { margin: 0; font-size: clamp(25px, 8vw, 34px); font-weight: 900; letter-spacing: -.025em; line-height: 1; white-space: nowrap; }
  .tagline { margin: 8px auto 14px; max-width: 320px; color: var(--muted); font-size: 14.5px; line-height: 1.38; font-weight: 600; text-wrap: balance; }
  .menu { display: grid; gap: 8px; }
  .diff { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .diff button {
    border: 0; background: var(--chip); border-radius: 13px; padding: 7px 2px; min-height: 48px;
    font-weight: 800; font-size: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    transition: background .15s, color .15s, transform .12s;
  }
  .diff button:active { transform: scale(.95); }
  .diff button small { font-size: 11px; font-weight: 700; color: var(--muted); }
  .diff button[aria-checked="true"] { background: var(--ink); color: var(--on-ink); }
  .diff button[aria-checked="true"] small { color: var(--on-ink); opacity: .72; }
  .best-line { font-size: 13.5px; color: var(--muted); font-weight: 700; min-height: 18px; margin: 2px 0 2px; font-variant-numeric: tabular-nums; }
  .best-line b { color: var(--ink); }
  .badge { font-size: 11.5px; font-weight: 800; color: var(--on-accent); background: var(--accent); padding: 3px 8px; border-radius: 99px; letter-spacing: .02em; }
  .title-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 12px; margin-top: 8px; font-size: 13.5px; font-weight: 700; }
  .title-foot a, .title-foot button { color: var(--muted); text-decoration: none; background: none; border: 0; padding: 6px 4px; white-space: nowrap; }

  /* Results */
  .result-kicker { font-weight: 900; font-size: 14px; letter-spacing: .16em; text-transform: uppercase; color: var(--good); }
  .result-time { font-size: 60px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.05; margin: 6px 0 2px; }
  .result-caption { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
  .result-meta { color: var(--muted); font-weight: 700; font-size: 15px; margin-top: 8px; }
  .result-best { margin: 14px 0 16px; font-weight: 800; font-size: 14.5px; background: var(--chip); border-radius: 12px; padding: 9px 10px; font-variant-numeric: tabular-nums; }
  .result-best.new { background: var(--prize); color: var(--prize-ink); }
  .stack { display: grid; gap: 10px; }

  /* Confirm and help */
  .confirm-card h2, .help-card h2 { margin: 4px 0 6px; font-size: 22px; text-wrap: balance; }
  .confirm-card p { margin: 0 0 16px; color: var(--muted); font-weight: 600; }
  .help-card { max-width: 440px; text-align: left; }
  .help-card h2 { text-align: center; }
  .help-list { margin: 10px 0 12px; padding: 0; list-style: none; display: grid; gap: 9px; }
  .help-list li { font-size: 14px; line-height: 1.4; color: var(--muted); font-weight: 600; }
  .help-list b { color: var(--ink); }
  .facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0 0 14px; }
  .fact { background: var(--chip); border-radius: 12px; padding: 7px 4px 6px; text-align: center; }
  .fact b { display: block; font-size: 17px; font-weight: 900; font-variant-numeric: tabular-nums; }
  .fact small { display: block; font-size: 10.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  kbd {
    font-family: inherit; font-size: 12px; font-weight: 800; color: var(--ink); background: var(--chip);
    border-radius: 6px; padding: 1px 6px; box-shadow: inset 0 -1px 0 var(--line);
  }
  .help-note { margin: 0 0 14px; font-size: 12.5px; line-height: 1.4; color: var(--muted); font-weight: 600; }

  /* Toast */
  #toast {
    position: absolute; left: 50%; top: 4px; z-index: 12; transform: translate(-50%, -6px);
    background: var(--ink); color: var(--on-ink); padding: 9px 15px; border-radius: 99px; font-size: 14px; font-weight: 700;
    opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
    width: max-content; max-width: calc(100% - 32px); text-align: center; line-height: 1.3;
    box-shadow: 0 8px 20px rgba(38, 34, 31, .22);
  }
  #toast.show { opacity: 1; transform: translate(-50%, 0); }

  @media (max-height: 600px) {
    .logo { width: 40px; height: 40px; }
    .title-card h1 { font-size: 28px; }
    .tagline { margin-bottom: 10px; font-size: 13.5px; }
    .btn.big { min-height: 48px; font-size: 17px; }
    .diff button { min-height: 42px; }
    .result-time { font-size: 46px; }
    .card { padding: 14px 16px 12px; }
  }
  @media (max-height: 500px) {
    .tagline { display: none; }
    .brand { margin-bottom: 10px; }
  }
  @media (max-width: 360px) {
    .diff button { font-size: 12.5px; }
    .pick-label { min-width: 62px; }
    .seg button { padding: 6px 8px; }
    .mini-btn.wide { width: 40px; }
  }
  @media (prefers-reduced-motion: reduce) {
    .overlay:not(.hidden) .card, #coach.show { animation: none; }
  }

/* Collection integration: failure controls remain outside the inert game. */
#loadingNotice,#loadFailure,body>noscript{position:fixed;z-index:100;inset:16px 16px auto;margin:auto;max-width:520px;padding:18px;border:2px solid var(--accent);border-radius:16px;background:var(--card);color:var(--ink);text-align:center;box-shadow:var(--shadow)}
#loadingNotice{pointer-events:none}#loadFailure p{margin:0 0 12px}#loadFailure button{min-height:44px}
#titleCard .puzzle-picker{--muted:#655e54;--ink:#26221f;--card:#fffdf8;--accent:#6c47ff}

/* Every dial, segmented, help and free-play action has a 44px touch target. */
.mini-btn { width:44px; height:44px; min-width:44px; min-height:44px; }
.pill,.seg button,.btn.small,.diff button { min-height:44px; min-width:44px; }
.dial-bar { min-height:50px; }
