:root { --bg: #f4f6f8; --board: #ffffff; --ink: #1f2933; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
       background: var(--bg); color: var(--ink); font-family: system-ui, sans-serif;
       touch-action: manipulation; }
main { text-align: center; width: min(100vw - 1.5rem, 420px); padding: 0.5rem 0; }
header { display: flex; gap: 0.25rem 0.5rem; justify-content: center; align-items: center;
         margin-bottom: 0.5rem; font-size: 1.1rem; }
canvas { width: min(100%, 400px);
         /* 353px = vertical chrome (two-row header of about 73px, message, controls, spacing), tuned to this layout */
         width: min(100%, 400px, calc(100dvh - 353px)); height: auto; aspect-ratio: 1;
         background: var(--board); border-radius: 12px; box-shadow: 0 4px 16px rgb(0 0 0 / 12%); }
button { font: inherit; padding: 0.25rem 0.75rem; border-radius: 8px; border: 1px solid #9aa5b1;
         background: #fff; color: var(--ink); cursor: pointer; }
#message { min-height: 1.5rem; margin: 0.5rem 0; font-weight: 600; }
.help { margin: 0.25rem 0 0; color: #52606d; font-size: 0.9rem; }
@media (pointer: coarse) { .help { display: none; } }

.controls { display: flex; justify-content: center; align-items: center; gap: 1.25rem; margin: 0.5rem 0; }
.dpad { display: grid; grid-template: repeat(3, 56px) / repeat(3, 56px); gap: 6px; }
.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down { grid-area: 3 / 2; }
.side { display: grid; gap: 8px; }
.controls button, #mute { min-width: 56px; min-height: 56px; font-size: 1.25rem; padding: 0.25rem 0.75rem;
                   touch-action: manipulation; user-select: none; -webkit-user-select: none;
                   -webkit-tap-highlight-color: transparent; }
.controls button:active, #mute:active { background: #dbe4ee; transform: scale(0.96); }
#mute[aria-pressed="true"] { background: #dbe4ee; }

header { flex-wrap: wrap; }
.scores { flex: 1 0 100%; display: flex; justify-content: center; gap: 1.5rem; }
#difficulty-open, #mute { min-height: 48px; padding: 0.25rem 0.5rem; font-size: 1rem; }
#difficulty-open { flex: 1 1 0; min-width: 0; }
#mute { flex: 0 0 auto; }
#soundtrack-select { flex: 0 1 auto; min-width: 0; min-height: 48px; font-size: 1rem; }
#difficulty-open:disabled { opacity: 0.5; cursor: not-allowed; }
#best-wrap[hidden] { display: none; }

dialog { width: min(100vw - 1rem, 480px); max-height: 90dvh; overflow: auto; border: 1px solid #9aa5b1;
         border-radius: 12px; padding: 1rem; text-align: left; color: var(--ink); background: #fff; }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog h2 { margin: 0 0 0.5rem; }
.picker { display: grid; gap: 0.25rem; font-weight: 600; }
.picker select { min-height: 48px; font: inherit; }
#difficulty-fields details { margin: 0.75rem 0 0; border: 1px solid #d5dce3; border-radius: 8px; padding: 0 0.5rem 0.5rem; }
#difficulty-fields summary { display: flex; align-items: center; gap: 0.5rem; min-height: 44px; font-weight: 600; cursor: pointer; list-style: none; }
#difficulty-fields summary::-webkit-details-marker { display: none; }
#difficulty-fields summary::before { content: "\25B8"; flex: none; width: 1em; }
#difficulty-fields details[open] > summary::before { content: "\25BE"; }
.field { display: grid; gap: 0.15rem; margin: 0.4rem 0; font-size: 0.9rem; }
.field input { width: 100%; box-sizing: border-box; min-height: 44px; font: inherit; padding: 0 0.5rem; }
.field input.locked, .field input[readonly] { background: #eef1f4; color: #52606d; }
.music-reset, .music-randomize, .reroll, .reset-custom { width: 100%; min-height: 44px; margin-top: 0.4rem; font: inherit; }
.music-toggle { display: flex; align-items: center; gap: 0.5rem; min-height: 44px; margin-top: 0.4rem; font-size: 0.9rem; }
.track-picker select { width: 100%; box-sizing: border-box; min-height: 44px; font: inherit; }
.music-toggle input { width: 24px; height: 24px; flex: none; }
.reroll[hidden], .reset-custom[hidden] { display: none; }
.dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; position: sticky; bottom: 0; background: #fff; padding-top: 0.5rem; }
.dialog-actions button { min-height: 48px; }

.field select { width: 100%; box-sizing: border-box; min-height: 44px; font: inherit; }
.color-row { display: flex; gap: 0.5rem; }
.color-row input[type="color"] { flex: none; width: 56px; padding: 2px; }
.color-row input[type="text"] { flex: 1 1 auto; min-width: 0; }
.theme-note { margin: 0.4rem 0 0; font-size: 0.85rem; color: #52606d; }
.theme-note:empty { display: none; }
#difficulty-fields canvas.theme-preview { display: block; width: 100%; height: auto; aspect-ratio: 8 / 3; margin-top: 0.75rem; border-radius: 8px; box-shadow: none; }
.theme-randomize, .theme-reset { width: 100%; min-height: 44px; margin-top: 0.4rem; font: inherit; }
