:root {
  color-scheme: dark;
  --bg: #080f2b;
  --surface: #101a40;
  --grid: #18254f;
  --line: #39437b;
  --text: #fff4d9;
  --muted: #aba5e5;
  --accent: #ff6265;
  --block-0: #ff6265;
  --block-1: #ff9a3d;
  --block-2: #27c1d1;
  --block-3: #49d58d;
  --block-4: #9872e3;
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overscroll-behavior: none; background: var(--bg); }
body { color: var(--text); min-width: 320px; touch-action: manipulation; }
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }
svg { width: 1.45rem; height: 1.45rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100dvh; display: grid; place-items: center; overflow: hidden; background: var(--bg); }
.game { width: min(100%, 31rem); min-height: 100dvh; padding: max(1rem, env(safe-area-inset-top)) 1rem max(.7rem, env(safe-area-inset-bottom)); display: grid; grid-template-rows: auto auto 1fr auto auto auto; gap: clamp(.45rem, 1.5dvh, .8rem); }
.game-header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 4rem; }
.game-header h1 { margin: 0; font-size: clamp(2.4rem, 12vw, 3.8rem); line-height: .9; letter-spacing: -.075em; text-shadow: 0 .15rem 0 color-mix(in srgb, var(--text) 28%, transparent); }
.game-header h1 span { color: var(--accent); }
.score-card { display: flex; flex-direction: column; text-transform: uppercase; }
.score-card.right { align-items: flex-end; }
.score-card span { color: var(--muted); font-size: .69rem; font-weight: 900; letter-spacing: .12em; }
.score-card strong { font-size: clamp(1.25rem, 6vw, 1.8rem); font-variant-numeric: tabular-nums; line-height: 1.05; }
.toolbar { display: grid; grid-template-columns: 4rem 1fr 4rem; align-items: center; }
.icon-button { min-height: 3.7rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); display: grid; place-items: center; gap: .1rem; box-shadow: 0 .35rem .7rem rgba(0,0,0,.22); }
.icon-button small { color: var(--muted); font-size: .58rem; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.status-message { text-align: center; margin: 0; color: var(--accent); font-weight: 900; font-size: .9rem; }
.board-wrap { min-height: 0; display: grid; place-items: center; }
.board { width: min(100%, 50dvh); aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr); gap: clamp(3px, 1vw, 5px); padding: clamp(5px, 1.5vw, 8px); background: var(--line); border-radius: 1rem; box-shadow: 0 .75rem 1.5rem rgba(0,0,0,.25), inset 0 1px 0 color-mix(in srgb, var(--text) 12%, transparent); }
.cell { min-width: 0; aspect-ratio: 1; border: 0; padding: 0; border-radius: clamp(.25rem, 1.4vw, .5rem); background: var(--grid); box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 6%, transparent); transition: transform .12s ease, background .12s ease, opacity .12s ease; }
.cell.filled { box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -3px 0 rgba(0,0,0,.13), 0 2px 3px rgba(0,0,0,.18); }
.cell.just-placed { animation: place-cell .18s ease-out; }
.block-0 { background: var(--block-0) !important; }.block-1 { background: var(--block-1) !important; }.block-2 { background: var(--block-2) !important; }.block-3 { background: var(--block-3) !important; }.block-4 { background: var(--block-4) !important; }
.cell.preview { opacity: .78; transform: scale(.88); }
.cell.preview.valid { background: var(--accent); outline: 2px solid var(--text); }
.cell.preview.invalid { background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 4px, transparent 4px, transparent 8px); outline: 2px dashed var(--text); }
.board.is-breaking { pointer-events: none; }
.cell.breaking { animation: break-cell .26s ease-out both; box-shadow: 0 0 1rem currentColor; }
.board.invalid-shake { animation: invalid-shake .22s ease-out; }
.tray { min-height: clamp(6rem, 17dvh, 8rem); display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; padding: .65rem; border: 1px solid var(--line); background: var(--surface); border-radius: 1.35rem; box-shadow: 0 .6rem 1.25rem rgba(0,0,0,.25); }
.piece-slot { min-width: 0; min-height: 5rem; border: 0; background: transparent; border-radius: .9rem; display: grid; place-items: center; touch-action: none; }
.piece-slot.selected { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); outline: 2px solid var(--accent); transform: translateY(-.25rem); }
.piece-slot.used { opacity: .2; }
.piece { --unit: clamp(.86rem, 4.9vw, 1.45rem); position: relative; display: block; width: calc(var(--w) * var(--unit)); height: calc(var(--h) * var(--unit)); }
.piece i { position: absolute; left: calc(var(--x) * var(--unit)); top: calc(var(--y) * var(--unit)); width: calc(var(--unit) - 2px); height: calc(var(--unit) - 2px); border-radius: .3rem; box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -2px 0 rgba(0,0,0,.15), 0 2px 4px rgba(0,0,0,.2); }
.drag-ghost { position: fixed; z-index: 40; left: 0; top: 0; pointer-events: none; opacity: .96; filter: drop-shadow(0 .7rem .7rem rgba(0,0,0,.32)); will-change: transform; }
.instruction { margin: 0; min-height: 1.2rem; color: var(--muted); font-size: .72rem; text-align: center; text-transform: uppercase; font-weight: 900; letter-spacing: .08em; }
.mini-footer { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .68rem; min-height: 2rem; }
.mini-footer button { border: 0; background: transparent; padding: .5rem; display: flex; align-items: center; gap: .35rem; }
.mini-footer svg { width: 1rem; height: 1rem; }

.scrim { position: fixed; inset: 0; z-index: 20; display: flex; justify-content: center; align-items: flex-end; padding: 1rem; background: rgba(2, 5, 17, .72); backdrop-filter: blur(8px); }
.sheet { width: min(100%, 29rem); max-height: calc(100dvh - 2rem); overflow: auto; padding: 1.15rem; border: 2px solid var(--line); border-radius: 1.5rem; background: var(--surface); box-shadow: 0 1rem 3rem rgba(0,0,0,.45); animation: sheet-in .22s ease-out; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .7rem; }
.sheet h2 { margin: 0; color: var(--text); font-size: 1.75rem; letter-spacing: -.04em; }
.sheet-head button { width: 2.75rem; height: 2.75rem; border: 0; border-radius: .8rem; background: transparent; color: var(--muted); }
.palette-list { display: grid; gap: .55rem; }
.palette-option { width: 100%; min-height: 4.1rem; display: grid; grid-template-columns: 1fr auto 1.3rem; align-items: center; gap: .7rem; padding: .65rem .75rem; border: 1px solid transparent; border-radius: 1rem; background: var(--bg); text-align: left; }
.palette-option.active { border: 2px solid var(--accent); }
.palette-option > span:first-child { font-weight: 800; }
.palette-option b { color: var(--accent); }
.swatches { display: flex; gap: .25rem; }
.swatches i { width: clamp(1.1rem, 6vw, 1.6rem); aspect-ratio: 1; border-radius: .35rem; box-shadow: inset 0 1px rgba(255,255,255,.25); }
.centered { text-align: center; align-self: center; }
.centered > p { color: var(--muted); line-height: 1.5; }
.primary-button, .secondary-button, .danger-button { width: 100%; min-height: 3.5rem; margin-top: .75rem; border-radius: 1rem; border: 1px solid var(--line); display: flex; justify-content: center; align-items: center; gap: .6rem; font-weight: 900; }
.primary-button { border: 0; background: var(--accent); color: #101326; box-shadow: inset 0 2px rgba(255,255,255,.2), 0 .45rem .9rem rgba(0,0,0,.22); }
.secondary-button { background: var(--bg); }
.danger-button { background: transparent; color: var(--accent); }
.solid-danger { background: var(--accent); color: #101326; border-color: transparent; }
.settings-list { display: grid; }
.setting { min-height: 4.5rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-bottom: 1px solid var(--line); }
.setting span { display: grid; gap: .2rem; text-align: left; }
.setting small { color: var(--muted); }
.setting input { position: absolute; opacity: 0; }
.setting > i { width: 3rem; height: 1.7rem; border-radius: 1rem; background: var(--grid); border: 1px solid var(--line); position: relative; flex: none; }
.setting > i::after { content: ''; position: absolute; width: 1.25rem; height: 1.25rem; border-radius: 50%; background: var(--muted); top: .17rem; left: .2rem; transition: .18s ease; }
.setting input:checked + i { background: var(--accent); }
.setting input:checked + i::after { background: var(--text); transform: translateX(1.3rem); }
.setting input:focus-visible + i { outline: 3px solid var(--text); }
.tutorial-art { height: 7rem; display: grid; grid-template-columns: repeat(4, 2.4rem); grid-template-rows: repeat(2, 2.4rem); justify-content: center; align-content: center; gap: .25rem; }
.tutorial-art span { border-radius: .45rem; background: var(--accent); box-shadow: inset 0 2px rgba(255,255,255,.2); }
.tutorial-art span:nth-child(2), .tutorial-art span:nth-child(5) { background: var(--block-2); }
.tutorial-art span:nth-child(3), .tutorial-art span:nth-child(6) { background: var(--block-3); }
.tutorial-art b { align-self: center; color: var(--muted); font-size: 1.5rem; }
.results h2 { color: var(--accent); }
.result-score { display: flex; justify-content: space-between; align-items: baseline; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.result-score strong { color: var(--text); font-size: 2.5rem; }
.results dl { margin: 0; }
.results dl div { display: flex; justify-content: space-between; padding: .85rem 0; border-bottom: 1px solid var(--line); }
.results dd { margin: 0; font-weight: 900; }
.rotate-notice { display: none; position: fixed; inset: 0; z-index: 50; background: var(--bg); place-content: center; text-align: center; gap: .5rem; padding: 2rem; }
.rotate-notice span { color: var(--muted); }

@keyframes place-cell { from { transform: scale(.65); opacity: .5; } 70% { transform: scale(1.06); } }
@keyframes break-cell { 0% { transform: scale(1); opacity: 1; } 45% { transform: scale(1.2) rotate(5deg); opacity: 1; } 100% { transform: scale(.15) rotate(18deg); opacity: 0; } }
@keyframes invalid-shake { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-.4rem); } 65% { transform: translateX(.4rem); } }
@keyframes sheet-in { from { transform: translateY(2rem); opacity: 0; } }
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
@media (orientation: landscape) and (max-height: 600px) { .rotate-notice { display: grid; } }
@media (min-width: 40rem) { .game { min-height: min(100dvh, 58rem); border-inline: 1px solid var(--line); } .scrim { align-items: center; } }
@media (max-height: 690px) { .game { gap: .35rem; } .board { width: min(100%, 43dvh); } .tray { min-height: 5.2rem; } .piece-slot { min-height: 4rem; } .instruction { font-size: .62rem; } }
@media (max-width: 350px) { .instruction { font-size: .56rem; letter-spacing: .055em; white-space: nowrap; } }
