  :root {
    color-scheme: dark;
    --page: #0c1e19;
    --panel: #172e27;
    --edge: #3b6254;
    --leaf: #baf3cd;
    --ink: #edf8f0;
    --muted: #b5ccc1;
    --pad: 12px;
    --gap: 12px;
    --control-height: 52px;
    font-family: "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
    color: var(--ink);
    background: var(--page);
    line-height: 1.45;
    word-break: keep-all;
  }
  *, *::before, *::after { box-sizing: border-box; }
  body {
    margin: 0;
    min-height: 100vh;
    min-height: 100svh;
    display: grid;
    align-items: center;
    padding: var(--pad);
    padding: calc(var(--pad) + env(safe-area-inset-top, 0px))
      calc(var(--pad) + env(safe-area-inset-right, 0px))
      calc(var(--pad) + env(safe-area-inset-bottom, 0px))
      calc(var(--pad) + env(safe-area-inset-left, 0px));
    background: radial-gradient(ellipse at 50% 30%, #233f32, transparent 65%), var(--page);
  }
  button, a { -webkit-tap-highlight-color: transparent; }
  button { font: inherit; }
  a { color: inherit; }
  :focus-visible { outline: 2px solid #fff5bb; outline-offset: 4px; }
  [hidden] { display: none !important; }
  h1, p { margin: 0; }
  .game {
    --available-height: calc(100svh - 2 * var(--pad) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    --board-limit: calc((var(--available-height) - var(--control-height) - var(--gap)) * .75);
    width: min(100%, 480px);
    width: min(100%, 480px, max(158px, var(--board-limit)));
    margin: auto;
    outline: none;
    display: grid;
    gap: var(--gap);
  }
  .stage {
    container: dodge-board / inline-size;
    position: relative;
    isolation: isolate;
    min-width: 0;
    aspect-ratio: 3 / 4;
    background: #142a23;
    border-radius: 8px;
    box-shadow: 0 0 0 1px #527766, 0 18px 65px #06130eb0;
  }
  canvas { display: block; width: 100%; height: 100%; border-radius: inherit; image-rendering: pixelated; }
  .hud {
    position: absolute;
    inset: 0 0 auto;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 8px;
    padding: 11px 12px;
    font-size: .875rem;
  }
  .game[data-mode="playing"] .hud { padding-bottom: 6px; }
  .indicators { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 9px; }
  .score { color: var(--muted); white-space: nowrap; }
  .score-change {
    display: none;
    color: #ffe29a;
    font: 800 .91rem/1.25 ui-monospace, monospace;
    text-align: center;
    padding-inline: 3px;
    border-radius: 4px;
  }
  .game[data-mode="playing"] .score-change { display: inline-block; min-width: 2.15ch; }
  .score-change[data-kind="star"] { background: #ffe29a; color: #342a12; }
  .game[data-mode="playing"] .score strong { font-size: 1.15rem; }
  .slow-frame {
    position: absolute;
    inset: 0;
    border: 3px solid #65d9ef;
    border-radius: inherit;
    box-shadow: inset 0 0 14px #72d7ef55;
    pointer-events: none;
    opacity: 0;
    transition: opacity .18s ease-out;
  }
  .slow-frame[data-active] { opacity: 1; }
  @media (prefers-reduced-motion: reduce) {
    .slow-frame { transition: none; }
  }
  .effect-label {
    position: absolute;
    z-index: 1;
    left: clamp(42px, var(--effect-x), calc(100% - 42px));
    transform: translate(-50%, -100%);
    pointer-events: none;
    font-size: clamp(.95rem, 4cqi, 1.4rem);
    font-weight: 850;
    white-space: nowrap;
    color: #deffe8;
    text-shadow: 0 2px 5px #071711, 0 0 9px #65e8a5;
  }
  .effect-label.star { color: #ffe29a; text-shadow: 0 2px 5px #261d0e, 0 0 8px #e7a534; }
  .effect-label.near-miss {
    left: clamp(58px, var(--effect-x), calc(100% - 58px));
    color: #dcfaff;
    text-shadow: 0 2px 5px #071d26, 0 0 9px #66cfe8;
  }
  .level { color: var(--leaf); white-space: nowrap; font-weight: 750; }
  .level strong { font-family: ui-monospace, monospace; }
  .next-level {
    flex-basis: 100%;
    color: var(--muted);
    font-size: .7rem;
    line-height: 1.2;
  }
  .play-status {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px 5px;
  }
  .play-status:not(:has(> :not([hidden]))) { display: none; }
  .playing-player, .item-readout, .slow-status {
    max-width: 100%;
    padding: 3px 6px;
    border: 1px solid var(--edge);
    border-radius: 4px;
    background: var(--page);
    color: var(--muted);
    font-size: .76rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
    pointer-events: none;
  }
  .playing-player strong { color: var(--ink); }
  .item-readout { color: #ffe29a; font-weight: 700; }
  .slow-status { color: #b1f6ff; background: #133541; border-color: #438896; }
  .slow-status strong { font-variant-numeric: tabular-nums; }
  .slow-progress { display: block; height: 3px; margin-top: 3px; background: #28556a; border-radius: 4px; overflow: hidden; }
  .slow-progress span { display: block; height: 100%; background: #a7f5ff; transform-origin: left; }
  .message .round-breakdown { font-size: .75rem; }
  .level-up {
    position: absolute;
    inset: 100% auto auto 50%;
    width: max-content;
    max-width: calc(100% - 24px);
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 7px 11px;
    border: 1px solid #f8cc76;
    border-radius: 7px;
    color: #ffecbb;
    background: #392d19;
    box-shadow: 0 3px 14px #141005c9;
    font-size: clamp(.9rem, 3vw, 1.1rem);
    font-weight: 800;
    text-align: center;
    pointer-events: none;
  }
  @media (prefers-reduced-motion: no-preference) {
    .level-up-icon { animation: level-up-bounce 550ms ease-out both; }
    .level-up-spark { animation: level-up-spark 650ms ease-out both; }
  }
  @keyframes level-up-bounce {
    0%, 68%, 100% { transform: translateY(0); }
    35% { transform: translateY(-5px) rotate(-12deg); }
    82% { transform: translateY(-2px); }
  }
  @keyframes level-up-spark {
    0% { opacity: .2; transform: scale(.6); }
    45% { opacity: 1; transform: translate(3px, -3px) scale(1.25); }
    100% { opacity: .75; transform: translate(2px, -1px); }
  }
  .pause {
    min-width: 48px;
    min-height: 48px;
    padding: 0 7px;
    border: 1px solid var(--edge);
    border-radius: 4px;
    color: var(--ink);
    background: var(--panel);
    font-size: .82rem;
    font-weight: 750;
    white-space: nowrap;
    cursor: pointer;
  }
  .pause:hover, .pause:active { background: #25473b; }
  .pause { display: inline-flex; gap: 5px; align-items: center; }
  .pause-icon { width: 8px; height: .75rem; border-inline: 2px solid currentColor; }
  .pause kbd {
    padding: 1px 4px;
    border: 1px solid #679281;
    border-radius: 3px;
    color: var(--leaf);
    font: .72rem ui-monospace, monospace;
  }
  .hud-actions { display: flex; align-items: center; gap: 5px; }
  .records-button {
    min-height: 44px;
    padding: 0 7px;
    border: 0;
    border-radius: 4px;
    color: var(--leaf);
    background: transparent;
    font-size: .875rem;
    font-weight: 750;
    cursor: pointer;
    white-space: nowrap;
  }
  .records-button:hover { background: var(--panel); }
  .item-help-short { display: none; }
  @container dodge-board (max-width: 250px) {
    .pause kbd { display: none; }
    .item-help-long { display: none; }
    .item-help-short { display: inline; }
  }
  @container dodge-board (max-width: 196px) {
    .game:not([data-mode="playing"]) .hud-actions { grid-column: 1 / -1; justify-self: end; }
    .game:not([data-mode="playing"]) .overlay { inset-block-start: 88px; }
  }
  .score strong { display: inline-block; transform-origin: left center; color: var(--ink); font: 750 1rem ui-monospace, monospace; }
  .overlay {
    position: absolute;
    inset: 53px 0 8px;
    z-index: 1;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    place-items: center;
    pointer-events: none;
  }
  .message {
    pointer-events: auto;
    width: min(calc(100% - 22px), 312px);
    max-height: 100%;
    min-height: 0;
    display: grid;
    justify-items: center;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
    padding: clamp(10px, 3vw, 18px) clamp(8px, 3vw, 18px);
    text-align: center;
    background: #132820;
    border: 1px solid var(--edge);
    border-top: 4px solid #81c69b;
    border-radius: 5px;
    box-shadow: 0 6px 0 #081a15aa;
  }
  .message-content { min-height: 0; width: 100%; overflow: auto; overscroll-behavior: contain; padding: 3px; }
  .message h1 { font-size: clamp(1.3rem, 5.8vw, 2.6rem); letter-spacing: -.055em; line-height: 1.08; }
  .message p { margin-top: 7px; color: var(--muted); font-size: .875rem; }
  .level-picker {
    margin-top: 8px;
    color: var(--muted);
    text-align: left;
    font-size: .875rem;
  }
  .level-picker strong { color: var(--ink); font-weight: 650; }
  .level-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(44px, 1fr));
    gap: 4px;
    margin-top: 4px;
  }
  .level-option {
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--edge);
    border-radius: 4px;
    color: var(--ink);
    background: var(--panel);
    font: 750 .9rem ui-monospace, monospace;
    cursor: pointer;
  }
  .level-option[aria-pressed="true"] { color: #103322; background: var(--leaf); border-color: var(--leaf); }
  .level-picker p.level-description { margin-top: 4px; font-size: .77rem; }
  .start-player { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 6px; margin-top: 8px; text-align: left; font-size: .875rem; }
  .start-player input {
    min-width: 0;
    width: 100%;
    min-height: 44px;
    padding: 5px 7px;
    border: 1px solid var(--edge);
    border-radius: 4px;
    color: var(--ink);
    background: var(--panel);
    font: inherit;
    font-size: 1rem;
  }
  .action {
    min-height: 48px;
    margin-top: 14px;
    padding: 5px 17px;
    border: 0;
    border-radius: 4px;
    background: var(--leaf);
    color: #103322;
    font-weight: 800;
    box-shadow: inset 0 -3px #7fb896;
    cursor: pointer;
  }
  .action:active { background: #9de2b5; }
  .personal-record { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 8px; margin-top: 7px; font-size: .875rem; }
  .personal-record span { color: var(--leaf); font-weight: 750; }
  #personal-rank:not(:empty) { padding-inline-start: 8px; border-inline-start: 1px solid var(--edge); }
  .message .record-status { font-size: .75rem; }
  .message #result-status[data-record-effect] { font-size: .875rem; font-weight: 800; color: #ffe29a; }
  .message #result-status[data-record-effect="best"] { text-shadow: 0 0 12px #e7a53455; }
  .records-dialog {
    width: min(420px, calc(100% - 24px));
    max-height: calc(100svh - 24px);
    padding: 18px;
    color: var(--ink);
    background: var(--page);
    border: 1px solid var(--edge);
    border-radius: 8px;
  }
  .records-dialog::backdrop { background: #04120dd9; }
  .records-dialog h2 { margin: 0; font-size: 1.35rem; }
  .records-dialog header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .item-help-list { list-style: none; margin: 0; padding: 0; }
  .item-help-list li {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding-block: 9px;
    border-bottom: 1px solid var(--edge);
  }
  .item-help-list canvas { width: 34px; height: 34px; }
  .item-help-list p { color: var(--muted); font-size: .875rem; }
  .nickname-choices { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }
  .nickname-choices .action:disabled { opacity: .65; cursor: wait; }
  .record-form { margin-block: 12px 18px; }
  .record-form label { display: block; margin-bottom: 4px; }
  .record-fields { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
  .records-dialog input {
    min-width: 0;
    min-height: 44px;
    padding: 5px 8px;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--edge);
    border-radius: 4px;
    font: inherit;
  }
  .records-dialog .action { margin: 0; min-height: 44px; font-size: .875rem; padding-inline: 10px; }
  .records-dialog .feedback { margin-top: 6px; color: var(--muted); font-size: .875rem; }
  .records-dialog .feedback:empty { display: none; }
  #records-dialog { width: min(720px, calc(100% - 24px)); overflow: hidden; }
  #records-dialog[open] { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); gap: 8px; }
  #records-close { min-height: 44px; }
  .rank-board {
    display: grid;
    grid-row: 4;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    align-content: start;
    align-items: start;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
  .rank-board:focus-visible { outline-offset: -2px; }
  .rank-table .own-record { background: var(--panel); }
  .rank-table { width: 100%; margin-top: 4px; border-collapse: collapse; table-layout: fixed; text-align: left; }
  .rank-table th, .rank-table td { padding: 6px 4px; border-bottom: 1px solid var(--edge); overflow-wrap: anywhere; }
  .rank-table thead th { color: var(--muted); font-size: .8rem; }
  .rank-table th:first-child { width: 12%; }
  .rank-table th:nth-child(3) { width: 19%; }
  .rank-table th:nth-child(4) { width: 19%; }
  .rank-table th:last-child { width: 28%; }
  .rank-table th:nth-child(n+3), .rank-table td:nth-child(n+3) { text-align: right; }
  .rank-table td:nth-child(3), .rank-table td:nth-child(4) { font-variant-numeric: tabular-nums; }
  .rank-table td:nth-child(3) { color: var(--leaf); }
  .rank-table td:last-child { color: var(--muted); font-size: .8rem; }
  .controls { display: grid; grid-template-columns: repeat(2, minmax(48px, 1fr)); gap: 8px; }
  .direction {
    min-width: 48px;
    min-height: var(--control-height);
    padding: 2px 3px;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--edge);
    border-radius: 5px;
    box-shadow: inset 0 -4px #071711;
    font-size: .9rem;
    font-weight: 750;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  .direction[disabled] { color: var(--muted); cursor: default; }
  .direction[data-held] { background: var(--leaf); color: #103322; box-shadow: inset 0 -2px #79b791; }
  .direction span { margin-inline: 2px; }
  .sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
  }
  @media (orientation: landscape) and (max-height: 500px) {
    .game {
      --board-limit: calc(var(--available-height) * .75);
      width: min(100%, 612px);
      width: min(100%, 612px, calc(max(158px, var(--board-limit)) + 132px));
      grid-template-columns: minmax(0, 1fr) 120px;
      align-items: center;
    }
    .message { padding: 8px 6px; }
    .message .level-buttons { grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }
    .message .start-player { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .message h1 { font-size: clamp(1.25rem, 4vw, 1.75rem); }
    .action { margin-top: 9px; }
  }
