  :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;
    width: min(100%, max(158px, var(--board-limit)));
    justify-self: center;
    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 {
    container: dodge-message / inline-size;
    min-height: 0;
    width: 100%;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 3px;
  }
  .message-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; text-align: start; }
  #language-switch { flex: none; margin-inline-start: auto; }
  .message h1 {
    font-size: clamp(1.05rem, 16cqi, 2.6rem);
    letter-spacing: -.055em;
    line-height: 1.08;
    white-space: nowrap;
  }
  .message h1:lang(en) { font-size: clamp(1.05rem, 11.5cqi, 2rem); }
  .message p { margin-top: 7px; color: var(--muted); font-size: .875rem; }
  .message :is(#description, .round-breakdown, .level-description) { text-wrap: balance; }
  .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;
  }
  .start-player input::placeholder { font-size: .85rem; }
  .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; }
  .message-actions { margin-top: 14px; max-width: 100%; }
  .message-actions .action { margin: 0; }
  .game[data-mode="ended"] .message-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }
  .game[data-mode="ended"] .message-actions button { padding-inline: 5px; font-size: .875rem; text-wrap: balance; }
  #results-open { border: 1px solid var(--edge); background: var(--panel); white-space: normal; }
  .personal-record { margin: 7px 0 0; font-size: .875rem; }
  .personal-record dd { margin: 0; color: var(--leaf); font-weight: 750; }
  .game[data-mode="ready"] .personal-record > div { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 7px; }
  .game[data-mode="ended"] .personal-record { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
  .game[data-mode="ended"] .personal-record > div { padding: 5px 2px; border: 1px solid var(--edge); border-radius: 4px; }
  .game[data-mode="ended"] .personal-record > div:first-child { background: var(--panel); }
  .game[data-mode="ended"] .personal-record dt { color: var(--muted); font-size: .75rem; text-wrap: balance; }
  .game[data-mode="ended"] .personal-record dd { font-size: 1.15rem; overflow-wrap: anywhere; }
  .message .result-progress p { margin-top: 4px; font-size: .75rem; }
  .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); }
  .rank-table td:nth-child(2) { overflow-wrap: anywhere; text-wrap: balance; word-break: normal; }
  .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; text-wrap: balance; }
  .rank-personal {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 4px;
    color: var(--leaf);
    background: var(--panel);
    font-size: .875rem;
  }
  @media (max-width: 380px) {
    #records-dialog { padding-inline: 11px; }
    .rank-table th, .rank-table td { padding-inline: 3px; }
    .rank-table th:first-child { width: max(13%, 36px); }
    .rank-table th:nth-child(3), .rank-table th:nth-child(4) { width: max(14%, 37px); }
    .rank-table th:last-child { width: 27%; }
    .rank-table td:not(:last-child) { font-size: .875rem; }
  }
  .controls { display: grid; grid-template-columns: repeat(2, minmax(48px, 1fr)); gap: 8px; }
  .direction {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    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;
    white-space: nowrap;
    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; }
  .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; }
    .direction { gap: 3px; font-size: .8rem; }
    .action { margin-top: 9px; }
  }
  .challenge-status {
    max-width: 100%;
    padding: 3px 6px;
    border: 1px solid #9b8049;
    border-radius: 4px;
    background: var(--page);
    color: #ffe29a;
    font-size: .76rem;
    font-weight: 750;
    line-height: 1.2;
  }
  .challenge-targets {
    position: absolute;
    inset: auto 0 2% 0;
    pointer-events: none;
  }
  .challenge-target {
    position: absolute;
    bottom: 0;
    display: grid;
    justify-items: center;
    width: var(--target-width);
    transform: translateX(-50%);
    color: #fff1be;
    text-shadow: 0 1px 3px #04120d, 0 0 4px #04120d;
    font: 800 clamp(.65rem, 3cqi, .85rem)/1.2 system-ui, sans-serif;
    white-space: nowrap;
  }
  .challenge-target::after {
    content: '';
    width: 100%;
    height: 6px;
    border: 1px solid #ffdc72;
    border-radius: 3px;
    background: #3e321a;
  }
  .challenge-target[data-kind="door"]::after { height: 8px; border-style: dashed; }
  .challenge-target[data-kind="door"][data-open]::after { border-style: solid; background: #fff1be; }
  .challenge-target[data-kind="moving"]::after { border-radius: 99px; }
  .challenge-help { margin-top: 12px; font-size: .875rem; }
  .challenge-help summary { min-height: 44px; align-content: center; color: var(--leaf); cursor: pointer; }
  .challenge-help dl { margin: 0; }
  .challenge-help dt { margin-top: 6px; font-weight: 750; }
  .challenge-help dd { margin: 0; color: var(--muted); }

.clip-dialog { max-width: 420px; }
#clip-settings { margin: 8px 0 0; min-inline-size: 0; padding: 0; border: 0; font-size: .875rem; }
#clip-settings legend { padding: 0; font-weight: 700; }
.clip-highlight-title { color: var(--leaf); font-weight: 750; }
.clip-option { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.clip-name-option { flex-wrap: wrap; row-gap: 4px; }
#clip-player-name { min-width: 0; color: var(--leaf); overflow-wrap: anywhere; }
.clip-option input { min-height: auto; }
.clip-dialog video {
  display: block;
  width: auto;
  max-width: 100%;
  height: min(46svh, 420px);
  margin: 0 auto;
  background: var(--page);
}
.clip-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.clip-actions a { display: inline-flex; align-items: center; text-underline-offset: 3px; }
.clip-actions button:disabled { opacity: .6; cursor: wait; }
.clip-choices { display: grid; gap: 6px; margin: 10px 0; }
.clip-choices .records-button, .clip-choice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 8px;
  text-align: left;
  overflow-wrap: anywhere;
}
.clip-choice { border: 1px solid var(--line, var(--muted)); border-radius: 6px; }
.clip-choice input { flex: none; min-height: auto; }
.clip-choices .records-button[aria-pressed="true"], .clip-choice:has(input:checked) {
  border-color: var(--leaf);
  color: var(--leaf);
}
.clip-choice-length { white-space: nowrap; margin-inline-start: auto; color: var(--muted); }
.clip-diagnostics { position: absolute; inset: 8px 8px auto auto; z-index: 5; max-width: min(92vw, 540px); padding: 8px; background: var(--page); }
.clip-diagnostics pre { max-height: 55svh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 540px) {
  .clip-dialog[data-mode="compose"] video { display: none; }
}
.clip-panel { min-width: 0; }
.clip-dialog.clip-multiple { max-width: 660px; }
@media (min-width: 670px) {
  .clip-multiple .clip-layout {
    display: grid;
    grid-template-columns: minmax(0, 210px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }
}
