:root {
      color-scheme: dark;
      --paper: #f2eee4;
      --muted: rgba(242, 238, 228, 0.62);
      --dim: rgba(242, 238, 228, 0.38);
      --charcoal: #131917;
      --panel: #202825;
      --line: rgba(242, 238, 228, 0.2);
      --coral: #ff735f;
      --amber: #e7bb58;
      --mint: #73d9b0;
      --sky: #6bb9d2;
      --safe-top: env(safe-area-inset-top, 0px);
      --safe-bottom: env(safe-area-inset-bottom, 0px);
    }

    * {
      box-sizing: border-box;
      -webkit-tap-highlight-color: transparent;
      letter-spacing: 0;
    }

    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
      overflow: hidden;
      background: var(--charcoal);
      color: var(--paper);
      font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", ui-sans-serif, system-ui, sans-serif;
      touch-action: none;
      user-select: none;
    }

    button {
      font: inherit;
    }

    .app {
      position: fixed;
      inset: 0;
      min-width: 320px;
      min-height: 320px;
      overflow: hidden;
      isolation: isolate;
    }

    canvas {
      position: absolute;
      inset: 0;
      display: block;
      width: 100%;
      height: 100%;
    }

    .hud {
      position: absolute;
      z-index: 4;
      top: calc(13px + var(--safe-top));
      left: clamp(14px, 3.6vw, 34px);
      right: clamp(14px, 3.6vw, 34px);
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
      align-items: center;
      min-height: 58px;
      gap: 14px;
      pointer-events: none;
    }

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

    .brand-mark {
      position: relative;
      width: 30px;
      height: 34px;
      flex: 0 0 auto;
      border: 2px solid rgba(242, 238, 228, 0.86);
      border-radius: 5px;
      background: #28312e;
      box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.16);
    }

    .brand-mark::before {
      position: absolute;
      top: 5px;
      left: 6px;
      right: 6px;
      height: 4px;
      content: "";
      border-radius: 1px;
      background: var(--coral);
      box-shadow: 0 7px 0 rgba(242, 238, 228, 0.22);
    }

    .brand-mark::after {
      position: absolute;
      right: -5px;
      bottom: 5px;
      width: 13px;
      height: 6px;
      content: "";
      border-radius: 1px;
      background: var(--amber);
      transform: rotate(-8deg);
      box-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
    }

    .brand-copy {
      display: grid;
      min-width: 0;
      line-height: 1;
    }

    .brand-name {
      overflow: hidden;
      color: var(--paper);
      font-size: 15px;
      font-weight: 900;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .brand-sub {
      margin-top: 5px;
      color: var(--dim);
      font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
      font-size: 10px;
      font-weight: 800;
      white-space: nowrap;
    }

    .score-stack {
      display: grid;
      justify-items: center;
      gap: 3px;
    }

    .scoreboard {
      display: flex;
      align-items: baseline;
      justify-content: center;
      min-width: 112px;
      gap: 6px;
      color: var(--paper);
      font-variant-numeric: tabular-nums;
    }

    .scoreboard::before,
    .scoreboard::after {
      width: 18px;
      height: 1px;
      content: "";
      background: var(--line);
    }

    .score-value {
      min-width: 34px;
      text-align: center;
      font-size: clamp(28px, 5.3vmin, 48px);
      font-weight: 950;
      line-height: 1;
    }

    .score-unit {
      color: var(--muted);
      font-size: 11px;
      font-weight: 800;
      white-space: nowrap;
    }

    .composure {
      display: flex;
      align-items: center;
      min-height: 13px;
      gap: 7px;
      color: rgba(242, 238, 228, 0.52);
      font-size: 11px;
      font-weight: 850;
      line-height: 1;
      white-space: nowrap;
      opacity: 1;
      transition: color 180ms ease, opacity 180ms ease;
    }

    .composure.is-hidden {
      opacity: 0;
    }

    .composure-dots {
      display: flex;
      gap: 4px;
    }

    .composure-dots i {
      display: block;
      width: 6px;
      height: 6px;
      border: 1px solid rgba(242, 238, 228, 0.34);
      border-radius: 50%;
      background: transparent;
      transition: background 140ms ease, border-color 140ms ease, box-shadow 180ms ease;
    }

    .composure[data-value="1"] .composure-dots i:nth-child(1),
    .composure[data-value="2"] .composure-dots i:nth-child(1),
    .composure[data-value="2"] .composure-dots i:nth-child(2),
    .composure[data-value="3"] .composure-dots i {
      border-color: var(--mint);
      background: var(--mint);
    }

    .composure.is-dnd {
      color: var(--mint);
    }

    .composure.is-dnd .composure-dots i {
      border-color: var(--mint);
      background: var(--mint);
      box-shadow: 0 0 8px rgba(115, 217, 176, 0.72);
    }

    .run-meta {
      justify-self: end;
      display: grid;
      justify-items: end;
      gap: 4px;
      font-variant-numeric: tabular-nums;
    }

    .clock {
      color: var(--paper);
      font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
      font-size: 14px;
      font-weight: 850;
    }

    .best {
      color: var(--dim);
      font-size: 11px;
      font-weight: 800;
      white-space: nowrap;
    }

    .best span {
      color: var(--amber);
      font-size: 13px;
      font-variant-numeric: tabular-nums;
    }

    .story-panel {
      position: absolute;
      z-index: 3;
      top: 48%;
      left: 50%;
      width: min(84vw, 660px);
      transform: translate(-50%, -50%);
      text-align: center;
      pointer-events: none;
      opacity: 1;
      transition: opacity 180ms ease, transform 180ms ease;
    }

    .story-panel.is-hidden {
      opacity: 0;
      transform: translate(-50%, -46%);
    }

    .story-kicker {
      display: inline-flex;
      align-items: center;
      gap: 10px;
      margin: 0 0 16px;
      color: var(--amber);
      font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
      font-size: 12px;
      font-weight: 850;
    }

    .story-kicker::before,
    .story-kicker::after {
      width: 22px;
      height: 1px;
      content: "";
      background: currentColor;
      opacity: 0.7;
    }

    .story-title {
      margin: 0;
      color: var(--paper);
      font-size: clamp(48px, 10vw, 94px);
      font-weight: 950;
      line-height: 0.96;
      text-shadow: 0 8px 30px rgba(0, 0, 0, 0.32);
    }

    .story-copy {
      max-width: 560px;
      margin: 18px auto 0;
      color: rgba(242, 238, 228, 0.82);
      font-size: clamp(16px, 2.4vw, 19px);
      font-weight: 650;
      line-height: 1.75;
      text-wrap: balance;
    }

    .story-result {
      margin-top: 16px;
      color: var(--muted);
      font-size: 13px;
      font-weight: 800;
    }

    .story-result strong {
      color: var(--mint);
      font-variant-numeric: tabular-nums;
    }

    .toast {
      --toast-accent: var(--mint);
      position: absolute;
      z-index: 5;
      top: calc(clamp(104px, 16vh, 132px) + var(--safe-top));
      left: 50%;
      display: grid;
      width: min(86vw, 470px);
      min-height: 62px;
      align-content: center;
      padding: 11px 16px 12px;
      border: 1px solid rgba(242, 238, 228, 0.18);
      border-left: 4px solid var(--toast-accent);
      border-radius: 5px;
      background: rgba(19, 25, 23, 0.94);
      box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
      transform: translate(-50%, -10px);
      opacity: 0;
      pointer-events: none;
      transition: opacity 160ms ease, transform 180ms ease;
    }

    .toast.is-showing {
      transform: translate(-50%, 0);
      opacity: 1;
    }

    .toast strong {
      color: var(--paper);
      font-size: 15px;
      font-weight: 900;
      line-height: 1.3;
    }

    .toast span {
      margin-top: 4px;
      color: rgba(242, 238, 228, 0.74);
      font-size: 14px;
      font-weight: 650;
      line-height: 1.55;
      text-wrap: balance;
    }

    .toast.is-incoming {
      background: rgba(25, 31, 29, 0.95);
    }

    .toast.is-release {
      border-left-color: var(--mint);
      background: rgba(18, 30, 26, 0.95);
    }

    .echo {
      --echo-accent: var(--mint);
      position: absolute;
      z-index: 5;
      right: 0;
      bottom: calc(clamp(118px, 19vh, 154px) + var(--safe-bottom));
      left: 0;
      display: grid;
      place-items: center;
      padding-inline: 14px;
      opacity: 0;
      transform: translateY(7px);
      pointer-events: none;
      transition: opacity 180ms ease, transform 180ms ease;
    }

    .echo.is-showing {
      opacity: 1;
      transform: translateY(0);
    }

    .echo span {
      display: inline-block;
      max-width: min(88vw, 620px);
      padding: 7px 12px 8px;
      border-top: 1px solid var(--echo-accent);
      border-bottom: 1px solid rgba(242, 238, 228, 0.12);
      background: rgba(18, 24, 22, 0.78);
      color: rgba(242, 238, 228, 0.92);
      font-size: 14px;
      font-weight: 750;
      line-height: 1.6;
      text-align: center;
      text-wrap: balance;
      text-shadow: 0 2px 10px rgba(0, 0, 0, 0.36);
    }

    .action-dock {
      position: absolute;
      z-index: 6;
      right: 0;
      bottom: calc(14px + var(--safe-bottom));
      left: 0;
      display: grid;
      place-items: center;
      pointer-events: none;
    }

    .escape-button {
      position: relative;
      width: clamp(102px, 18vmin, 126px);
      height: clamp(74px, 13vmin, 90px);
      padding: 0;
      border: 0;
      border-radius: 7px;
      outline: none;
      background: #6f2923;
      box-shadow:
        0 9px 0 #4d1c18,
        0 13px 28px rgba(0, 0, 0, 0.42),
        0 0 0 1px rgba(255, 255, 255, 0.08);
      cursor: pointer;
      pointer-events: auto;
      transition: transform 80ms ease, box-shadow 80ms ease;
    }

    .escape-button::before {
      position: absolute;
      inset: 7px;
      border: 1px solid rgba(255, 238, 218, 0.22);
      border-radius: 5px;
      content: "";
      pointer-events: none;
    }

    .escape-button:active,
    .escape-button.is-pressed {
      transform: translateY(7px);
      box-shadow:
        0 2px 0 #4d1c18,
        0 6px 17px rgba(0, 0, 0, 0.34),
        0 0 0 1px rgba(255, 255, 255, 0.08);
    }

    .key-face {
      position: absolute;
      inset: 8px;
      display: grid;
      place-content: center;
      border-radius: 4px;
      background: linear-gradient(180deg, #ff816d 0%, #e65347 100%);
      box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.32),
        inset 0 -4px 0 rgba(104, 24, 19, 0.24);
      color: #fff8ec;
      text-align: center;
      transition: background 180ms ease, color 180ms ease;
    }

    .app.is-dnd .key-face {
      background: linear-gradient(180deg, #91e8c5 0%, #4fb68f 100%);
      color: #10231c;
    }

    .key-code {
      display: block;
      font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
      font-size: clamp(25px, 5vmin, 36px);
      font-weight: 950;
      line-height: 0.95;
    }

    .key-label {
      display: block;
      margin-top: 5px;
      font-size: 11px;
      font-weight: 900;
      line-height: 1;
    }

    .vignette,
    .grain {
      position: fixed;
      inset: 0;
      pointer-events: none;
    }

    .vignette {
      z-index: 7;
      background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.18), transparent 18%, transparent 80%, rgba(0, 0, 0, 0.16)),
        linear-gradient(180deg, rgba(0, 0, 0, 0.12), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.18));
    }

    .grain {
      z-index: 8;
      opacity: 0.07;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150' viewBox='0 0 150 150'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='150' height='150' filter='url(%23n)' opacity='.58'/%3E%3C/svg%3E");
      mix-blend-mode: soft-light;
    }

    @media (max-width: 560px) {
      .hud {
        gap: 6px;
      }

      .brand {
        gap: 7px;
      }

      .brand-mark {
        width: 26px;
        height: 30px;
      }

      .brand-name {
        font-size: 13px;
      }

      .brand-sub,
      .best-label {
        display: none;
      }

      .scoreboard::before,
      .scoreboard::after {
        width: 8px;
      }

      .scoreboard {
        min-width: 88px;
        gap: 4px;
      }

      .score-unit {
        font-size: 10px;
      }

      .clock {
        font-size: 12px;
      }

      .composure {
        gap: 5px;
        font-size: 10px;
      }

      .composure-dots {
        gap: 3px;
      }

      .composure-dots i {
        width: 5px;
        height: 5px;
      }

      .story-panel {
        top: 46%;
        width: min(88vw, 520px);
      }

      .story-copy {
        max-width: 330px;
      }
    }

    @media (max-height: 590px) {
      .story-panel {
        top: 45%;
      }

      .story-kicker {
        margin-bottom: 9px;
      }

      .story-title {
        font-size: clamp(42px, 12vh, 66px);
      }

      .story-copy {
        margin-top: 11px;
        font-size: 14px;
        line-height: 1.55;
      }

      .story-result {
        margin-top: 9px;
      }

      .toast {
        min-height: 56px;
        padding-block: 9px 10px;
      }
    }

    @media (max-height: 590px) and (min-width: 561px) {
      .toast {
        top: calc(88px + var(--safe-top));
        left: 68%;
        width: min(55vw, 430px);
      }
    }

    @media (prefers-reduced-motion: reduce) {
      .story-panel,
      .toast,
      .echo,
      .escape-button {
        transition: none;
      }
    }
