    *,
    *::before,
    *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0
    }

    :root {
      /* Canonical text sizes — unified across menu, level select and tutorial.
         --fs-name : titles (game name, level name, tutorial slide title)
         --fs-desc : body   (descriptions, level specs, records, tutorial body) */
      --fs-name: 1.04rem;
      --fs-desc: .79rem;
      --shadow: 0 1px 2px rgba(43, 38, 30, .06), 0 8px 24px rgba(43, 38, 30, .08);
      --shadow-lift: 0 2px 4px rgba(43, 38, 30, .08), 0 16px 40px rgba(43, 38, 30, .14);
      --bg: #e7e0cf;
      --surf: #f3eee2;
      --surf2: #e1d9c5;
      --surf3: #d2c8af;
      --level-bg: rgba(236, 229, 212, .74);
      --acc: #7c6244;
      --acc2: #7d9b8e;
      --acc3: #b5485a;
      --on-acc: #fff;
      --danger: #b5485a;
      --ok: #5f8a6a;
      --text: #2b2a26;
      --text2: #6f6a5c;
      --text3: #a59d8b;
      --bdr: rgba(43, 42, 38, .08);
      --bdr2: rgba(43, 42, 38, .17);
      --accfade: rgba(124, 98, 68, .20);
      --dangerbdr: rgba(181, 72, 90, .25);
      --dim: rgba(231, 224, 207, .96);
      --dim2: rgba(43, 42, 38, .34);
      --overlay: rgba(231, 224, 207, .96);
      --scrim: rgba(43, 42, 38, .34);
      --radius: 10px;
      --accent-rgb: 124, 98, 68;
      --danger-rgb: 181, 72, 90;
      --ok-rgb: 95, 138, 106;
      --c-gold-rgb: 184, 146, 63;
      --font-display: 'Zen Kaku Gothic New', sans-serif;
      --font-mono: 'Martian Mono', monospace;
      --zen-rgb: 43, 42, 38;
      --zen-a: .05;
      --ribbon-1: #d8b75c;
      --ribbon-2: #b8923f;
      --ribbon-text: #2b2520;
      --safe-t: env(safe-area-inset-top, 0px);
      --safe-b: env(safe-area-inset-bottom, 0px);
      --safe-l: env(safe-area-inset-left, 0px);
      --safe-r: env(safe-area-inset-right, 0px);
      --btn-h: 36px;
    }

    /* ═══════════════════════════════════════════════════════════════
       DARK TATAMI — the same room by lamplight (行灯)
       ═══════════════════════════════════════════════════════════════ */
    html[data-theme="dark"] {
      --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .4);
      --shadow-lift: 0 2px 4px rgba(0, 0, 0, .35), 0 18px 46px rgba(0, 0, 0, .55);
      --bg: #1b1915;
      --surf: #262320;
      --surf2: #2f2b25;
      --surf3: #3b352d;
      --level-bg: rgba(43, 39, 34, .72);
      --acc: #82a7c4;
      --acc2: #93b89e;
      --acc3: #d28c9b;
      --on-acc: #15130f;
      --danger: #d2788a;
      --ok: #8fbf9e;
      --text: #ece5d6;
      --text2: #b3aa97;
      --text3: #7c7464;
      --bdr: rgba(236, 229, 214, .07);
      --bdr2: rgba(236, 229, 214, .16);
      --accfade: rgba(130, 167, 196, .22);
      --dangerbdr: rgba(210, 120, 138, .25);
      --dim: rgba(20, 18, 15, .96);
      --dim2: rgba(0, 0, 0, .55);
      --overlay: rgba(27, 25, 21, .95);
      --scrim: rgba(0, 0, 0, .55);
      --accent-rgb: 130, 167, 196;
      --danger-rgb: 210, 120, 138;
      --ok-rgb: 143, 191, 158;
      --c-gold-rgb: 214, 184, 120;
      --zen-rgb: 236, 229, 214;
      --zen-a: .04;
      --ribbon-1: #e6c474;
      --ribbon-2: #c69f4e;
      --ribbon-text: #1b1610;
    }

    html,
    body {
      width: 100%;
      height: 100%;
      overflow: hidden;
      background: var(--bg);
      color: var(--text);
      font-family: 'Zen Kaku Gothic New', sans-serif;
      -webkit-tap-highlight-color: transparent;
      user-select: none;
      -webkit-user-select: none
    }

    #app {
      position: fixed;
      inset: 0;
      overflow: hidden;
      padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l)
    }

    .screen {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      transition: opacity .25s, transform .25s;
      overflow: hidden
    }

    .screen.hidden {
      opacity: 0;
      pointer-events: none;
      transform: translateY(8px)
    }

    /* ── Home ── */
    #home-screen {
      justify-content: flex-start;
      padding: 1rem 1.2rem 1.5rem;
      gap: .55rem;
      background: var(--bg);
      overflow-y: auto
    }

    .logo-wrap {
      text-align: center;
      cursor: pointer
    }

    .logo-svg {
      display: block;
      margin: 0 auto .55rem
    }

    .logo-title {
      font-size: 2.3rem;
      font-weight: 800;
      letter-spacing: -.04em;
      line-height: 1;
      text-transform: uppercase;
      background: linear-gradient(135deg, var(--acc2), var(--acc));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text
    }

    .logo-sub {
      font-size: .65rem;
      color: var(--text3);
      letter-spacing: .2em;
      text-transform: uppercase;
      margin-top: .3rem;
      font-weight: 600
    }

    .level-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: .45rem;
      width: 100%;
      max-width: 340px;
      margin-top: 15px
    }

    .level-btn {
      background: var(--level-bg);
      border: 1.5px solid var(--bdr2);
      border-radius: var(--radius);
      padding: .6rem .5rem;
      cursor: pointer;
      text-align: center;
      color: var(--text);
      transition: border-color .15s, background .15s, box-shadow .2s;
      -webkit-tap-highlight-color: transparent
    }

    .level-btn.active {
      box-shadow: 0 0 10px var(--acc);
      border-color: var(--acc);
      background: rgba(var(--accent-rgb), .12)
    }

    .level-name {
      font-weight: 700;
      font-size: var(--fs-name);
      margin: .05rem 0
    }

    .level-size {
      font-size: var(--fs-desc);
      color: var(--text2)
    }

    .level-rec {
      font-size: var(--fs-desc);
      color: var(--acc2);
      margin-top: .18rem;
      opacity: .85
    }

    /* ═══════════════════════════════════════════════════════════════
     *  Level select — "Path of Puzzles" (mode stations along a path)
     * ═══════════════════════════════════════════════════════════════ */
    .lvl-hero { display: flex; align-items: center; gap: 12px; cursor: pointer; }
    .lvl-mark { width: 52px; height: 52px; flex: none; color: var(--game-acc, var(--acc)); display: grid; place-items: center; }
    .lvl-mark svg { width: 52px; height: 52px; }
    .lvl-hero-txt { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
    .lvl-kanji { font-weight: 900; font-size: 1.4rem; letter-spacing: .04em; }
    .lvl-kanji .lvl-k1 { color: var(--text); }
    .lvl-kanji .lvl-k2 { color: var(--game-acc, var(--acc)); }
    .lvl-name { font-weight: 900; font-size: 1.4rem; letter-spacing: .02em; margin-top: 2px;
      background: linear-gradient(95deg, var(--text), var(--game-acc, var(--acc)));
      -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
    .lvl-tag { font-family: 'Martian Mono', monospace; font-size: .5rem; letter-spacing: .18em; text-transform: uppercase; color: var(--text3); margin-top: 6px; }

    .lvl-select { display: flex; flex-direction: column; align-items: stretch; width: 100%; max-width: 419px; margin-top: 16px; }
    /* the exact mockup-B toggle */
    .lvl-toggle { align-self: center; display: inline-flex; background: var(--surf2); border: 1px solid var(--bdr2); border-radius: 999px; padding: 3px; margin: 4px 0 20px; }
    .lvl-diff { font-family: 'Martian Mono', monospace; font-size: .6rem; letter-spacing: .08em; text-transform: uppercase; padding: 6px 20px; border-radius: 999px; color: var(--text3); font-weight: 500; background: none; border: none; cursor: pointer; transition: color .18s; }
    .lvl-diff.on { background: var(--game-acc, var(--acc)); color: #fff; }

    .lvl-path { position: relative; display: flex; flex-direction: column; gap: 14px; padding-left: 22px; }
    .lvl-path::before { content: ''; position: absolute; left: 8px; top: 12px; bottom: 12px; border-left: 2px dotted var(--game-acc-line, var(--bdr2)); }
    /* border / shadow / hover exactly match the main-menu game cards (.tablet) */
    .lvl-station { position: relative; display: block; text-align: left; width: 100%; font-family: inherit; color: inherit;
      background: color-mix(in srgb, var(--surf2) 55%, transparent);
      border: 1px solid var(--bdr2); border-radius: 18px; box-shadow: var(--shadow); padding: 15px 16px; cursor: pointer;
      transition: background .2s ease, transform .16s ease, box-shadow .2s ease, border-color .2s; -webkit-tap-highlight-color: transparent; }
    .lvl-station:active { transform: translateY(0) scale(.995); }
    .lvl-main { display: flex; align-items: center; gap: 13px; }
    .lvl-stone { position: absolute; left: -14px; top: 35px; width: 13px; height: 13px; border-radius: 50%;
      background: var(--surf); border: 2.5px solid var(--game-acc, var(--acc)); transform: translate(-50%, -50%); overflow: hidden; }
    .lvl-stone.half::after { content: ''; position: absolute; inset: 0; background: var(--game-acc, var(--acc)); clip-path: inset(0 50% 0 0); }
    .lvl-stone.full { background: var(--game-acc, var(--acc)); }
    .lvl-badge { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center;
      color: var(--game-acc, var(--acc)); background: var(--game-acc-soft, var(--surf2)); border: 1px solid var(--game-acc-line, var(--bdr2)); }
    .lvl-badge svg { width: 23px; height: 23px; }
    .lvl-badge .lvl-uni { font-size: 1.2rem; line-height: 1; color: var(--game-acc, var(--acc)); }
    .lvl-info { flex: 1; min-width: 0; }
    .lvl-mode { font-weight: 700; font-size: var(--fs-name); color: var(--text); }
    .lvl-desc { font-size: var(--fs-desc); color: var(--text2); line-height: 1.4; margin-top: 3px;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .lvl-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
    .lvl-stars { font-size: .68rem; color: var(--gold, #b8923f); letter-spacing: 1px; line-height: 1; white-space: nowrap; }
    .lvl-stars .o { color: var(--text3); opacity: .5; }
    .lvl-time { font-family: 'Martian Mono', monospace; font-size: .58rem; color: var(--text3); }

    /* footer split by a centre divider: Continue label (centred, left) · New button (fills right) */
    .lvl-foot { display: flex; align-items: center; margin-top: 13px; padding-top: 12px; border-top: 1px dashed var(--bdr2); }
    .lvl-cont-label { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 5px; font-size: .72rem; font-weight: 700; color: var(--game-acc, var(--acc)); }
    .lvl-cont-label small { font-family: 'Martian Mono', monospace; font-weight: 500; opacity: .8; font-size: .82em; }
    .lvl-foot-div { flex: none; align-self: stretch; width: 0; border-left: 1px dashed var(--bdr2); margin: 0 10px; }
    .lvl-new { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; font-family: inherit; font-size: .68rem; font-weight: 700; padding: 9px; border-radius: 10px;
      border: 1.5px solid var(--game-acc, var(--acc)); background: transparent; color: var(--game-acc, var(--acc)); cursor: pointer; }

    @media (hover: hover) and (pointer: fine) {
      .lvl-station:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--game-acc, var(--acc)); background: color-mix(in srgb, var(--surf2) 80%, transparent); }
      .lvl-new:hover { background: var(--game-acc-soft, transparent); }
    }

    .level-rec.empty {
      color: var(--text3)
    }

    .home-btn-row {
      display: flex;
      gap: .5rem;
      width: 100%;
      max-width: 340px
    }

    .btn-primary {
      flex: 1;
      padding: .78rem .4rem;
      background: var(--acc);
      color: #fff;
      border: none;
      border-radius: var(--radius);
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .85rem;
      font-weight: 700;
      cursor: pointer;
      transition: opacity .15s, transform .15s;
      white-space: nowrap
    }

    .btn-primary:active {
      transform: scale(.97);
      opacity: .88
    }

    .btn-primary:disabled {
      opacity: .3;
      cursor: default;
      transform: none
    }

    .btn-secondary {
      flex: 1;
      padding: .78rem .4rem;
      background: transparent;
      color: var(--text2);
      border: 1.5px solid var(--bdr2);
      border-radius: var(--radius);
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .85rem;
      font-weight: 600;
      cursor: pointer;
      transition: background .15s, transform .15s;
      white-space: nowrap
    }

    .btn-secondary:active {
      transform: scale(.97);
      background: var(--surf)
    }

    .btn-secondary:disabled {
      opacity: .28;
      cursor: default;
      transform: none
    }

    .install-banner {
      display: none;
      align-items: center;
      gap: .5rem;
      width: 100%;
      max-width: 340px;
      background: var(--surf2);
      border: 1px solid var(--bdr2);
      border-radius: var(--radius);
      padding: .5rem .8rem;
      cursor: pointer
    }

    .install-banner.visible {
      display: flex
    }

    .install-banner .ib-icon {
      font-size: 1.1rem
    }

    .install-banner .ib-text {
      flex: 1;
      font-size: .7rem;
      color: var(--text2);
      line-height: 1.4
    }

    .install-banner .ib-cta {
      font-size: .68rem;
      font-weight: 700;
      color: var(--acc2);
      background: var(--accfade);
      border: 1px solid var(--bdr2);
      border-radius: 6px;
      padding: .2rem .5rem;
      white-space: nowrap
    }

    /* ── Game screen ── */
    #game-screen {
      justify-content: flex-start;
      padding: 0;
      background: var(--bg)
    }

    .game-header {
      width: 100%;
      display: flex;
      align-items: center;
      padding: .32rem .6rem;
      gap: .4rem;
      border-bottom: 1px solid var(--bdr);
      flex-shrink: 0;
      background: var(--surf)
    }

    .icon-btn {
      width: var(--btn-h);
      height: var(--btn-h);
      border-radius: 8px;
      border: 1px solid var(--bdr2);
      background: var(--surf2);
      color: var(--text);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: transform .12s
    }

    .icon-btn:active {
      transform: scale(.9)
    }

    .icon-btn svg {
      width: 15px;
      height: 15px
    }

    .header-center {
      flex: 1;
      min-width: 0;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      gap: .6rem
    }

    .header-titles {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      text-align: right;
      gap: .02rem;
      min-width: 0
    }

    .header-game-name {
      font-size: .92rem;
      font-weight: 700;
      letter-spacing: .01em;
      line-height: 1.1;
      color: var(--text)
    }

    .header-actions {
      display: flex;
      align-items: center;
      gap: .35rem;
      flex-shrink: 0
    }

    .header-center .timer {
      font-size: 1.05rem;
      text-align: left;
      flex-shrink: 0
    }

    .header-div {
      flex: none;
      width: 1px;
      height: 20px;
      background: var(--bdr2);
      opacity: .8
    }

    .header-label {
      font-size: .56rem;
      font-weight: 700;
      letter-spacing: .11em;
      text-transform: uppercase;
      color: var(--text3);
      text-align: right
    }

    .timer {
      font-family: 'Martian Mono', monospace;
      font-size: 1.12rem;
      font-weight: 500;
      color: var(--text);
      letter-spacing: .04em;
      line-height: 1
    }

    .timer.warn {
      color: var(--acc3)
    }

    .progress-wrap {
      width: 100%;
      height: 2px;
      background: var(--surf3);
      flex-shrink: 0
    }

    .progress-fill {
      height: 100%;
      background: linear-gradient(90deg, var(--acc), var(--acc2));
      transition: width .2s
    }

    .mode-banner {
      display: none;
      width: 100%;
      padding: .3rem .8rem;
      border-bottom: 1px solid var(--bdr);
      font-size: .7rem;
      font-weight: 700;
      letter-spacing: .06em;
      text-align: center;
      flex-shrink: 0;
      color: var(--text2);
      background: var(--surf2)
    }

    .mode-banner.visible {
      display: block
    }

    .canvas-wrap {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 0;
      min-width: 0;
      overflow: hidden
    }

    #game-canvas {
      touch-action: none;
      cursor: pointer;
      display: block
    }

    .pad-row {
      display: none;
      width: 100%;
      padding: .3rem .6rem 0;
      gap: .3rem;
      flex-shrink: 0;
      background: var(--surf)
    }

    .pad-row.visible {
      display: flex
    }

    .pad-btn {
      flex: 1;
      height: 40px;
      border-radius: 8px;
      border: 1px solid var(--bdr2);
      background: var(--surf2);
      color: var(--text);
      cursor: pointer;
      font-family: 'Martian Mono', monospace;
      font-size: .95rem;
      font-weight: 500;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: transform .1s, background .1s;
      min-width: 0;
      padding: 0
    }

    .pad-btn:active {
      transform: scale(.9);
      background: var(--surf3)
    }

    .toolbar {
      width: 100%;
      display: flex;
      align-items: center;
      padding: .32rem .6rem;
      border-top: 1px solid var(--bdr);
      background: var(--surf);
      flex-shrink: 0;
      gap: .35rem
    }

    #game-screen .toolbar {
      border-top: none
    }

    .pad-row+.toolbar {
      border-top: none
    }

    .tool-btn {
      flex: 1;
      height: var(--btn-h);
      border-radius: 8px;
      border: 1px solid var(--bdr2);
      background: var(--surf2);
      color: var(--text2);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: .22rem;
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .65rem;
      font-weight: 600;
      white-space: nowrap;
      transition: transform .12s
    }

    .tool-btn:active {
      transform: scale(.93)
    }

    .tool-btn svg {
      width: 13px;
      height: 13px;
      flex-shrink: 0
    }

    .tool-btn.danger {
      color: var(--danger);
      border-color: var(--dangerbdr)
    }

    .tool-btn.accent,
    .tool-btn.success {
      color: var(--acc2);
      border-color: var(--bdr2)
    }

    /* ── Pause ── */
    #pause-screen {
      background: var(--dim);
      justify-content: center;
      align-items: center;
      gap: 1.1rem;
      padding: 2rem;
      z-index: 10
    }

    .pause-icon {
      width: 58px;
      height: 58px;
      border-radius: 50%;
      background: var(--surf);
      border: 1px solid var(--bdr2);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.55rem
    }

    .pause-title {
      font-size: 1.45rem;
      font-weight: 800
    }

    /* language + light/dark toggle — same buttons, same top-right corner
       placement as the menu (index.html)'s .top bar */
    .pause-toggles {
      position: absolute;
      top: 14px;
      right: 14px;
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .lang-mini {
      font-family: var(--font-mono);
      font-size: .66rem;
      font-weight: 700;
      letter-spacing: .12em;
      color: var(--text3);
      background: none;
      border: none;
      padding: 4px 3px;
      cursor: pointer;
      transition: color .2s
    }

    .lang-mini:hover {
      color: var(--text)
    }

    .theme-mini {
      color: var(--text3);
      background: none;
      border: none;
      padding: 4px;
      display: grid;
      place-items: center;
      transition: color .2s
    }

    .theme-mini:hover {
      color: var(--text)
    }

    .theme-mini svg {
      width: 19px;
      height: 19px
    }

    .btn-full {
      display: block;
      width: 100%;
      max-width: 200px;
      padding: .78rem;
      background: var(--acc);
      color: #fff;
      border: none;
      border-radius: var(--radius);
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .9rem;
      font-weight: 700;
      cursor: pointer;
      margin-bottom: .45rem;
      transition: opacity .15s, transform .15s;
      text-align: center
    }

    .btn-ico {
      width: 15px;
      height: 15px;
      vertical-align: -3px;
      margin-right: 6px
    }

    .btn-full:active {
      transform: scale(.97);
      opacity: .88
    }

    .btn-full.outline {
      background: transparent;
      color: var(--text2);
      border: 1.5px solid var(--bdr2);
      font-size: .84rem
    }

    .btn-full.outline:active {
      background: var(--surf)
    }

    /* ── Win ── */
    #win-screen {
      background: var(--bg);
      justify-content: center;
      align-items: center;
      gap: .75rem;
      padding: 1.8rem 1.2rem;
      z-index: 10
    }

    .win-stars {
      display: flex;
      gap: .3rem;
      font-size: 1.65rem
    }

    .win-time {
      font-family: 'Martian Mono', monospace;
      font-size: .84rem;
      color: var(--text2)
    }

    .win-time span {
      font-size: 1.45rem;
      font-weight: 500;
      color: var(--acc2)
    }

    .win-record {
      font-size: .68rem;
      color: var(--acc3);
      font-weight: 700;
      letter-spacing: .05em;
      text-transform: uppercase
    }

    /* ── Share sheet ── */
    .url-box {
      width: 100%;
      background: var(--surf);
      border: 1px solid var(--bdr2);
      border-radius: var(--radius);
      padding: .78rem;
      display: flex;
      align-items: center;
      gap: .5rem
    }

    .url-text {
      flex: 1;
      font-family: 'Martian Mono', monospace;
      font-size: .58rem;
      color: var(--text2);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap
    }

    .copy-btn {
      background: var(--acc);
      color: #fff;
      border: none;
      border-radius: 7px;
      padding: .33rem .68rem;
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .68rem;
      font-weight: 700;
      cursor: pointer;
      flex-shrink: 0
    }

    .copy-btn:active {
      transform: scale(.92)
    }

    .sheet {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      background: var(--surf);
      border-top: 1px solid var(--bdr2);
      padding: .8rem 1rem 1.2rem;
      z-index: 22;
      transform: translateY(101%);
      transition: transform .3s cubic-bezier(.16, 1, .3, 1);
      border-radius: 16px 16px 0 0
    }

    .sheet.open {
      transform: translateY(0)
    }

    .sheet-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: .6rem
    }

    .sheet-title {
      font-weight: 700;
      font-size: .88rem
    }

    .sheet-close {
      width: 24px;
      height: 24px;
      border-radius: 50%;
      background: var(--surf3);
      border: none;
      color: var(--text2);
      cursor: pointer;
      font-size: .85rem;
      display: flex;
      align-items: center;
      justify-content: center
    }

    .btn-outline {
      display: block;
      width: 100%;
      padding: .68rem;
      background: transparent;
      color: var(--text2);
      border: 1.5px solid var(--bdr2);
      border-radius: var(--radius);
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .82rem;
      font-weight: 600;
      cursor: pointer;
      transition: background .15s;
      margin: 0
    }

    .btn-outline:active {
      background: var(--surf)
    }

    /* ── Dimmer & toast ── */
    .dimmer {
      position: absolute;
      inset: 0;
      background: var(--dim2);
      z-index: 18;
      opacity: 0;
      pointer-events: none;
      transition: opacity .2s
    }

    .dimmer.visible {
      opacity: 1;
      pointer-events: auto
    }

    .toast-msg {
      position: fixed;
      bottom: 4.5rem;
      left: 50%;
      transform: translateX(-50%) translateY(12px);
      background: var(--surf3);
      color: var(--text);
      padding: .42rem .95rem;
      border-radius: 16px;
      font-size: .76rem;
      font-weight: 600;
      opacity: 0;
      transition: all .2s;
      pointer-events: none;
      z-index: 100;
      white-space: nowrap;
      border: 1px solid var(--bdr2)
    }

    .toast-msg.visible {
      opacity: 1;
      transform: translateX(-50%) translateY(0)
    }

    /* ── Home header with tutorial button ── */
    .home-header-row {
      display: flex;
      width: 100%;
      max-width: 419px;
      padding-left: 22px;
      justify-content: space-between;
      margin-bottom: -.1rem;
    }

    .tutorial-open-btn {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      border: 1px solid var(--bdr2);
      background: var(--surf2);
      color: var(--text2);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: transform .12s, background .12s;
    }

    .tutorial-open-btn:active {
      transform: scale(.9);
      background: var(--surf3);
    }

    .tutorial-open-btn svg {
      width: 15px;
      height: 15px;
    }

    /* ── Tutorial overlay ── */
    #tutorial-screen {
      background: var(--bg);
      justify-content: flex-start;
      align-items: stretch;
      z-index: 30;
      padding: 0;
    }

    .tutorial-header {
      width: 100%;
      display: flex;
      align-items: center;
      padding: .5rem .8rem;
      border-bottom: 1px solid var(--bdr);
      background: var(--surf);
      flex-shrink: 0;
      gap: .5rem;
    }

    .tutorial-title {
      flex: 1;
      font-size: .78rem;
      font-weight: 700;
      letter-spacing: .1em;
      text-transform: uppercase;
      color: var(--text2);
      text-align: center;
    }

    .tutorial-close-btn {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      border: 1px solid var(--bdr2);
      background: var(--surf2);
      color: var(--text2);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: .9rem;
      flex-shrink: 0;
      transition: transform .12s;
    }

    .tutorial-close-btn:active {
      transform: scale(.9);
    }

    .tutorial-carousel {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      overflow: hidden;
      position: relative;
    }

    .tutorial-slides {
      display: flex;
      width: 100%;
      height: 100%;
      transition: transform .35s cubic-bezier(.4, 0, .2, 1);
    }

    .tutorial-slide {
      min-width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: .8rem 1.2rem 0;
      gap: .7rem;
    }

    .tutorial-canvas-wrap {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      flex: 1;
      min-height: 0;
    }

    .tutorial-canvas {
      display: block;
    }

    .tutorial-desc {
      width: 100%;
      text-align: center;
    }

    .tutorial-step-label {
      font-size: .56rem;
      font-weight: 700;
      letter-spacing: .14em;
      text-transform: uppercase;
      color: var(--acc2);
      margin-bottom: .28rem;
    }

    .tutorial-step-title {
      font-size: var(--fs-name);
      color: var(--text);
      margin-bottom: .3rem;
    }

    .tutorial-desc .tutorial-step-title { font-weight: 700; }   /* match the menu game-name weight */

    .tutorial-step-body {
      font-size: var(--fs-desc);
      color: var(--text2);
      margin-bottom: .3rem;
      line-height: 1.4;
    }

    .tutorial-step-body strong {
      color: var(--acc2);
      font-weight: 700;
    }

    .tutorial-nav {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: .65rem 1rem .8rem;
      flex-shrink: 0;
      border-top: 1px solid var(--bdr);
      background: var(--surf);
    }

    .tutorial-nav-btn {
      height: 34px;
      padding: 0 1rem;
      border-radius: 8px;
      border: 1px solid var(--bdr2);
      background: var(--surf2);
      color: var(--text2);
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-size: .72rem;
      font-weight: 700;
      cursor: pointer;
      transition: transform .12s, opacity .12s;
      display: flex;
      align-items: center;
      gap: .3rem;
    }

    .tutorial-nav-btn:active {
      transform: scale(.93);
    }

    .tutorial-nav-btn:disabled {
      opacity: .25;
      pointer-events: none;
    }

    .tutorial-nav-btn.primary {
      background: var(--acc);
      color: #fff;
      border-color: transparent;
    }

    .tutorial-dots {
      display: flex;
      gap: .38rem;
      align-items: center;
    }

    .tutorial-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--surf3);
      transition: background .2s, transform .2s;
    }

    .tutorial-dot.active {
      background: var(--acc2);
      transform: scale(1.35);
    }

    /* ===== shared interaction/win-screen layer (was per-game) ===== */
    body {
      -webkit-font-smoothing: antialiased;
    }

    .logo-title,
    .pause-title,
    .tutorial-step-title,
    .win-stars {
      font-family: 'Zen Kaku Gothic New', sans-serif;
      font-weight: 900;
    }

    .logo-title {
      letter-spacing: -.01em;
    }

    .logo-sub {
      letter-spacing: .26em;
    }

    .level-btn {
      box-shadow: 0 1px 2px rgba(43, 42, 38, .05);
    }

    .level-btn.active {
      box-shadow: 0 0 15px 1px rgba(var(--accent-rgb), .5), 0 3px 11px rgba(var(--accent-rgb), .14);
      background: rgba(var(--accent-rgb), .1);
    }

    .btn-primary {
      box-shadow: 0 2px 9px rgba(124, 98, 68, .22);
    }

    .tool-btn,
    .btn-secondary,
    .icon-btn {
      box-shadow: 0 1px 2px rgba(43, 42, 38, .04);
    }

    /* ═══ Motion & micro-interactions ═══════════════════════════════ */
    :root {
      --ease-out: cubic-bezier(.22, 1, .36, 1);
      --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
    }

    /* Screen crossfade — a touch softer and with a gentle scale */
    .screen {
      transition: opacity .34s var(--ease-out), transform .34s var(--ease-out);
    }

    .screen.hidden {
      opacity: 0;
      transform: translateY(12px) scale(.992);
      pointer-events: none;
    }

    /* Staggered entrance for menu-like screens */
    @keyframes riseIn {
      from {
        opacity: 0;
        transform: translateY(14px);
      }

      to {
        opacity: 1;
        transform: none;
      }
    }

    #home-screen.anim-in>*,
    #win-screen.anim-in>*,
    #pause-screen.anim-in>* {
      animation: riseIn .5s var(--ease-out) both;
    }

    #home-screen.anim-in>*:nth-child(1) {
      animation-delay: .02s;
    }

    #home-screen.anim-in>*:nth-child(2) {
      animation-delay: .07s;
    }

    #home-screen.anim-in>*:nth-child(3) {
      animation-delay: .12s;
    }

    #home-screen.anim-in>*:nth-child(4) {
      animation-delay: .17s;
    }

    #home-screen.anim-in>*:nth-child(5) {
      animation-delay: .22s;
    }

    #home-screen.anim-in>*:nth-child(6) {
      animation-delay: .27s;
    }

    #win-screen.anim-in>*:nth-child(1) {
      animation-delay: .02s;
    }

    #win-screen.anim-in>*:nth-child(2) {
      animation-delay: .07s;
    }

    #win-screen.anim-in>*:nth-child(3) {
      animation-delay: .12s;
    }

    #win-screen.anim-in>*:nth-child(4) {
      animation-delay: .18s;
    }

    #win-screen.anim-in>*:nth-child(5) {
      animation-delay: .23s;
    }

    #win-screen.anim-in>*:nth-child(6) {
      animation-delay: .28s;
    }

    #win-screen.anim-in>*:nth-child(n+7) {
      animation-delay: .33s;
    }

    #pause-screen.anim-in>*:nth-child(2) {
      animation-delay: .05s;
    }

    #pause-screen.anim-in>*:nth-child(3) {
      animation-delay: .10s;
    }

    #pause-screen.anim-in>*:nth-child(4) {
      animation-delay: .15s;
    }

    #pause-screen.anim-in>*:nth-child(5) {
      animation-delay: .20s;
    }

    /* Logo tiles settle into place */
    @keyframes tileIn {
      from {
        opacity: 0;
        transform: scale(.7);
      }

      to {
        opacity: 1;
        transform: none;
      }
    }

    .logo-tile {
      transform-box: fill-box;
      transform-origin: center;
      animation: tileIn .55s var(--ease-spring) both;
      animation-delay: calc(.06s * var(--i) + .1s);
    }

    .logo-svg {
      overflow: visible;
    }


    /* Board entrance */
    @keyframes boardReveal {
      from {
        opacity: 0;
        filter: blur(7px);
      }

      to {
        opacity: 1;
        filter: blur(0);
      }
    }

    #game-canvas.board-reveal {
      animation: boardReveal .45s var(--ease-out) both;
    }

    /* Win stars pop in one by one */
    @keyframes starPop {
      0% {
        opacity: 0;
        transform: scale(.2) rotate(-22deg);
      }

      60% {
        transform: scale(1.18) rotate(4deg);
      }

      100% {
        opacity: 1;
        transform: none;
      }
    }

    .win-star {
      display: inline-block;
      color: var(--text3);
      animation: starPop .52s var(--ease-spring) both;
      animation-delay: calc(.12s * var(--i) + .1s);
    }

    .win-star.fill {
      color: rgba(var(--c-gold-rgb), 1);
      text-shadow: 0 1px 7px rgba(var(--c-gold-rgb), .5);
    }

    @keyframes ribbonIn {
      0% {
        opacity: 0;
        transform: rotate(45deg) translateY(-26px);
      }

      60% {
        opacity: 1;
      }

      100% {
        opacity: 1;
        transform: rotate(45deg) translateY(0);
      }
    }

    .win-ribbon {
      animation: ribbonIn .6s var(--ease-out) .35s both;
    }

    /* Buttons — visually responsive press + desktop hover lift */
    .level-btn,
    .tool-btn,
    .icon-btn,
    .btn-primary,
    .btn-secondary,
    .btn-full,
    .copy-btn,
    .btn-outline {
      transition: transform .16s var(--ease-spring), box-shadow .2s var(--ease-out),
        background .2s var(--ease-out), border-color .2s var(--ease-out), opacity .2s var(--ease-out);
      will-change: transform;
    }

    .level-btn:active,
    .tool-btn:active,
    .icon-btn:active,
    .btn-primary:active,
    .btn-secondary:active,
    .btn-full:active,
    .copy-btn:active,
    .btn-outline:active {
      transform: scale(.94);
    }

    .icon-btn:active {
      transform: scale(.88);
    }

    @media (hover: hover) and (pointer: fine) {
      .level-btn:hover {
        border-color: var(--acc);
        transform: translateY(-2px);
        box-shadow: 0 6px 16px rgba(124, 98, 68, .14);
      }

      .tool-btn:hover,
      .icon-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(43, 42, 38, .12);
        border-color: var(--acc);
      }

      .btn-primary:hover {
        transform: translateY(-1px);
        box-shadow: 0 6px 18px rgba(124, 98, 68, .32);
      }

      .btn-secondary:hover,
      .btn-full.outline:hover,
      .btn-outline:hover {
        transform: translateY(-1px);
        border-color: var(--acc);
        color: var(--acc);
      }

      .btn-full:not(.outline):hover {
        transform: translateY(-1px);
        box-shadow: 0 6px 18px rgba(124, 98, 68, .30);
      }

      .copy-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(124, 98, 68, .22);
      }
    }

    /* Keyboard focus polish */
    .level-btn:focus-visible,
    .tool-btn:focus-visible,
    .icon-btn:focus-visible,
    .btn-primary:focus-visible,
    .btn-secondary:focus-visible,
    .btn-full:focus-visible,
    .copy-btn:focus-visible,
    .btn-outline:focus-visible {
      outline: none;
      box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .38);
    }

    /* Active difficulty selection feels deliberate */
    .level-btn.active {
      transform: translateY(-1px);
    }

    .tutorial-dot {
      transition: transform .3s var(--ease-spring), background .3s var(--ease-out);
    }

    /* Smoother progress fill + timer warn pulse */
    .progress-fill {
      transition: width .38s var(--ease-out);
    }

    @keyframes timerWarn {

      0%,
      100% {
        opacity: 1;
      }

      50% {
        opacity: .55;
      }
    }

    .timer.warn {
      animation: timerWarn 1.4s ease-in-out infinite;
    }

    /* Toast: spring up instead of a plain fade */
    .toast-msg {
      transition: opacity .28s var(--ease-out), transform .32s var(--ease-spring);
    }

    @media (prefers-reduced-motion: reduce) {

      *,
      *::before,
      *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
      }
    }

    /* ═══ Zen background — faint seigaiha (青海波) wave ripples ═══════ */
    body {
      background-color: var(--bg);
      background-image:
        radial-gradient(circle at 50% 50%,
          rgba(var(--zen-rgb), 0) 0 30%, rgba(var(--zen-rgb), var(--zen-a)) 30% 31.5%,
          rgba(var(--zen-rgb), 0) 31.5% 53%, rgba(var(--zen-rgb), var(--zen-a)) 53% 54.5%,
          rgba(var(--zen-rgb), 0) 54.5% 76%, rgba(var(--zen-rgb), var(--zen-a)) 76% 77.5%,
          rgba(var(--zen-rgb), 0) 77.5%),
        radial-gradient(circle at 50% 50%,
          rgba(var(--zen-rgb), 0) 0 30%, rgba(var(--zen-rgb), var(--zen-a)) 30% 31.5%,
          rgba(var(--zen-rgb), 0) 31.5% 53%, rgba(var(--zen-rgb), var(--zen-a)) 53% 54.5%,
          rgba(var(--zen-rgb), 0) 54.5% 76%, rgba(var(--zen-rgb), var(--zen-a)) 76% 77.5%,
          rgba(var(--zen-rgb), 0) 77.5%);
      background-size: 68px 68px;
      background-position: 0 0, 34px 34px;
      background-repeat: repeat;
      transition: background-color .4s ease;
    }

    /* Let the body pattern show through the screens (board canvas stays opaque) */
    #home-screen,
    #game-screen,
    #win-screen,
    #tutorial-screen {
      background: transparent;
    }

    /* Ease surfaces when switching light/dark */
    .game-header,
    .toolbar,
    .mode-banner,
    .level-btn,
    .btn-primary,
    .btn-secondary,
    .btn-full,
    .tool-btn,
    .icon-btn,
    .pause-icon,
    .tutorial-open-btn,
    .progress-wrap {
      transition: background-color .4s ease, color .4s ease, border-color .4s ease;
    }

    /* ═══ Win-screen redesign (board snapshot + stars + ribbon) ═══════ */
    .home-header-row {
      justify-content: space-between;
    }

    .pause-scheme {
      position: absolute;
      top: calc(var(--safe-t) + 16px);
      right: 16px;
      width: 40px;
      height: 40px;
      border: none;
      background: none;
      color: var(--text3);
      display: grid;
      place-items: center;
      cursor: pointer;
      transition: color .2s, transform .12s;
    }

    .pause-scheme:hover {
      color: var(--text);
    }

    .pause-scheme:active {
      transform: scale(.9);
    }

    .pause-scheme svg {
      width: 24px;
      height: 24px;
    }

    #win-screen {
      justify-content: flex-start;
      align-items: center;
      gap: .5rem;
      padding: 1.2rem;
      overflow-y: auto;
      background: transparent;
    }

    #win-screen::before,
    #win-screen::after {
      content: '';
      flex: 1 0 0;
      min-height: 0;
    }

    #win-screen>* {
      flex-shrink: 0;
    }

    #win-screen .logo-sub#win-meta {
      margin-bottom: .15rem;
    }

    .win-board-frame {
      position: relative;
      overflow: hidden;
      width: min(68vw, 40vh, 262px);
      aspect-ratio: 1 / 1;
      border: 3px solid var(--bdr2);
      box-shadow: 0 12px 30px var(--scrim);
      line-height: 0;
      margin: .15rem 0 .35rem;
      background: var(--surf);
    }

    .win-board-img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
      user-select: none;
      -webkit-user-drag: none;
    }

    .win-ribbon {
      position: absolute;
      top: 30px;
      right: -50px;
      width: 184px;
      transform: rotate(45deg);
      background: linear-gradient(135deg, var(--ribbon-1), var(--ribbon-2));
      color: var(--ribbon-text);
      text-align: center;
      padding: 7px 0;
      font-family: var(--font-mono);
      font-size: .6rem;
      font-weight: 700;
      letter-spacing: .12em;
      text-transform: uppercase;
      box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
      border-top: 1px solid rgba(255, 255, 255, .42);
      border-bottom: 1px solid rgba(0, 0, 0, .14);
    }

    .win-ribbon[hidden] {
      display: none;
    }

    .win-ribbon span {
      display: inline-block;
    }

    #win-screen .win-stars {
      display: flex;
      gap: .35rem;
      font-size: 1.9rem;
      line-height: 1;
      margin-top: .1rem;
    }

    .win-time-row {
      display: flex;
      align-items: baseline;
      gap: .45rem;
      font-family: var(--font-mono);
    }

    .win-time-label {
      font-size: .64rem;
      letter-spacing: .16em;
      color: var(--text3);
      transform: translateY(-1px);
    }

    .win-time-val {
      font-size: 1.2rem;
      font-weight: 400;
      color: var(--acc2);
      letter-spacing: .02em;
    }

    .win-hints {
      font-family: var(--font-mono);
      font-size: .64rem;
      letter-spacing: .03em;
      color: var(--text3);
    }

    .win-hints[hidden] {
      display: none;
    }

    #win-screen>.btn-full {
      margin-top: .45rem;
    }

    #win-screen .btn-full {
      max-width: 320px;
    }

    .win-btn-row {
      display: flex;
      gap: .5rem;
      width: 100%;
      max-width: 320px;
    }

    .win-btn-row .btn-full {
      flex: 1 1 0;
      width: auto;
      max-width: none;
      min-width: 0;
    }

    /* ===== logo-entrance keyframes (shared) ===== */
    @keyframes lp-pop {
      0% {
        opacity: 0;
        transform: scale(.2)
      }

      60% {
        opacity: 1;
        transform: scale(1.18)
      }

      100% {
        opacity: 1;
        transform: scale(1)
      }
    }

    @keyframes lp-fade {
      0% {
        opacity: 0
      }

      100% {
        opacity: 1
      }
    }

    @keyframes lp-draw {
      0% {
        stroke-dashoffset: 100
      }

      100% {
        stroke-dashoffset: 0
      }
    }

    @keyframes lp-drop {
      0% {
        opacity: 0;
        transform: translateY(-9px) scale(.6)
      }

      60% {
        opacity: 1;
        transform: translateY(0) scale(1.08)
      }

      100% {
        opacity: 1;
        transform: scale(1)
      }
    }

    @keyframes lp-rise {
      0% {
        opacity: 0;
        transform: translateY(7px) scale(.72)
      }

      100% {
        opacity: 1;
        transform: translateY(0) scale(1)
      }
    }

    @keyframes lp-grow {
      0% {
        opacity: 0;
        transform: scale(.35)
      }

      100% {
        opacity: 1;
        transform: scale(1)
      }
    }
    /* ═══════════════════════════════════════════════════════════════
     *  Menu entrance: hero + cards rise-and-fade in (once, on load)
     * ═══════════════════════════════════════════════════════════════ */
    .wrap.anim-in .hero { animation: riseIn .5s var(--ease-out) both; }
    .wrap.anim-in .way { animation: riseIn .55s var(--ease-out) both; }
    .wrap.anim-in .way:nth-child(1) { animation-delay: .04s }
    .wrap.anim-in .way:nth-child(2) { animation-delay: .10s }
    .wrap.anim-in .way:nth-child(3) { animation-delay: .16s }
    .wrap.anim-in .way:nth-child(4) { animation-delay: .22s }
    .wrap.anim-in .way:nth-child(5) { animation-delay: .28s }
    .wrap.anim-in .way:nth-child(6) { animation-delay: .34s }
    .wrap.anim-in .way:nth-child(7) { animation-delay: .40s }
    .wrap.anim-in .way:nth-child(n+8) { animation-delay: .46s }

    @media (prefers-reduced-motion: reduce) {
      .wrap.anim-in .hero, .wrap.anim-in .way { animation: none }
    }
