:root {
    color-scheme: light;
    --ink: #303f40;
    --muted: #6d7977;
    --accent: #356c65;
    --line: #e2e5df;
    --paper: #fffdf8;
    --c1: #baace3;
    --c2: #efa6a0;
    --c3: #8dcabd;
    --c4: #edca7b;
    --c5: #9fbde5;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: radial-gradient(ellipse at 10% 0, #e8eee6, transparent 55%), #f6f4ee;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
    -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
button:focus-visible, summary:focus-visible { outline: 3px solid #b56f4b; outline-offset: 3px; }
.game-wallet { color: var(--ink); background: #f1eee5; border-radius: 20px; }
.game-wallet__value { color: var(--ink); }

.block-shell { padding: 22px 18px max(30px, env(safe-area-inset-bottom)); }
.block-game { max-width: 420px; margin: auto; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .12em; }
h1 { display: flex; align-items: center; gap: 9px; margin: 6px 0 0; font-size: 25px; font-weight: 800; letter-spacing: .025em; }
.brand-mark { flex: 0 0 28px; width: 28px; height: 28px; transform: rotate(-7deg); }
.slow-label { display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0; font-size: 10px; color: #577269; }
.slow-label svg { width: 14px; height: 14px; }
.score-strip {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
    align-items: center;
    padding: 13px 6px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--paper);
    box-shadow: 0 3px 0 #e9e8df, 0 8px 24px #33443d04;
}
.score-strip > div { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.score-strip > div + div { border-left: 1px solid var(--line); }
.score-strip span { color: var(--muted); font-size: 10px; font-weight: 600; }
.score-strip strong { max-width: 100%; font-size: clamp(16px, 5.8vw, 24px); font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.score-strip > div:first-child strong { color: #2f6a5d; font-size: clamp(23px, 7.8vw, 32px); letter-spacing: -.035em; }
.companion { display: flex; align-items: center; gap: 10px; min-height: 100px; padding: 6px 4px 4px; }
.companion img { flex-shrink: 0; width: 80px; height: 88px; object-fit: cover; object-position: center top; border: 2px solid var(--paper); border-radius: 14px; background: #eeeee4; box-shadow: 0 2px 7px #52634b18; }
.companion > div { position: relative; flex: 1; padding: 9px 13px; border: 1px solid #e7e4d9; border-radius: 4px 14px 14px 14px; background: #fffdf8; }
.companion span { color: #6b7771; font-size: 10px; font-weight: 600; }
.companion p { margin: 4px 0 0; color: #455a51; font-size: 12px; font-weight: 600; line-height: 1.6; }
.board-wrap { position: relative; padding: 6px; border: 1px solid #bdc9bd; border-radius: 22px; background: #d9e1d6; box-shadow: 0 5px 0 #c2cec1, 0 14px 26px #283f3610; }
.block-board {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 4px;
    padding: 9px;
    border: 1px solid #2a4543;
    border-radius: 16px;
    background: #344f4c;
    box-shadow: inset 0 2px 5px #152c3540;
    touch-action: none;
    user-select: none;
}
.cell { position: relative; aspect-ratio: 1; min-width: 0; padding: 0; border: 0; border-radius: 5px; background: #435e5a; box-shadow: inset 0 1px 2px #132c3020; transition: background-color .12s, box-shadow .12s; }
.cell.filled, .mini-cell.filled { background: linear-gradient(145deg, #ffffff18, #00000006), var(--tile); box-shadow: inset 0 2px 0 #ffffff70, inset 0 -3px 0 #293c4324, 0 1px 1px #132c3018; }
.cell.filled::after { content: ""; position: absolute; inset: 4px; border: 1px solid #ffffff30; border-radius: 3px; pointer-events: none; }
.cell.preview { background: var(--tile); opacity: .7; outline: 2px solid #fffdf0; outline-offset: -2px; }
.cell.invalid { background: repeating-linear-gradient(135deg, #9e555b 0 5px, #b76b70 5px 10px); outline: 2px dashed #ffe0dc; outline-offset: -2px; }
.cell.will-clear { box-shadow: inset 0 0 0 2px #fff8d2, 0 0 9px #fff5c870; filter: brightness(1.14); }
.cell:focus-visible { z-index: 1; outline-color: #fff1bd; outline-offset: 1px; }
.cell.just-placed { animation: settle .23s ease-out; }
.block-board.is-over { opacity: .75; }

.tray-heading { display: flex; align-items: center; justify-content: space-between; margin: 22px 3px 10px; font-size: 11px; color: var(--muted); }
.tray-heading > span:first-child { color: #445b51; font-weight: 700; }
#combo { font-size: 10px; }
#combo.is-combo { color: #956329; font-weight: 700; }
.piece-tray { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.piece-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 90px;
    border: 1px solid #dedfd4;
    border-radius: 15px;
    background: #fffdf8;
    box-shadow: 0 3px 0 #e4e4d9;
    touch-action: none;
    user-select: none;
    transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.piece-button[aria-pressed="true"] { border-color: #4f8171; background: #e9f1e7; box-shadow: inset 0 0 0 1px #4f8171, 0 3px 0 #bdcebd; }
.piece-button.is-blocked { background: #efeee7; box-shadow: 0 2px 0 #e3e2d9; }
.piece-button.is-blocked .mini-shape { opacity: .4; }
.piece-button:disabled { border-style: dashed; background: #eeeee6; box-shadow: none; }
.piece-button:disabled:empty::after { content: "✓"; color: #9ca99a; font-size: 20px; }
.mini-shape { display: grid; gap: 3px; pointer-events: none; }
.mini-cell { width: 16px; height: 16px; border-radius: 3px; }
.instructions { margin: 13px 4px 9px; text-align: center; font-size: 11px; color: var(--muted); line-height: 1.8; }
.bottom-actions { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.help { max-width: 78%; color: var(--muted); font-size: 11px; }
.help summary { display: list-item; padding: 10px 0; cursor: pointer; }
.help p { line-height: 1.9; }
.text-button { padding: 10px 6px; border: 0; background: transparent; color: #63746a; font-size: 11px; white-space: nowrap; }
.text-button:disabled { opacity: .4; }
.cast-picker { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 13px; padding-top: 16px; border-top: 1px solid #dfe2d8; }
.cast-picker > span { color: var(--muted); font-size: 10px; font-weight: 600; }
#castPicker { display: flex; gap: 7px; }
.cast-choice { width: 42px; height: 42px; padding: 3px; overflow: hidden; border: 1px solid #e0e2d7; border-radius: 50%; background: #eeeee4; transition: background-color .15s, box-shadow .15s; }
.cast-choice[aria-pressed="true"] { border-color: #668c70; background: #fffdf8; box-shadow: 0 0 0 3px #dce7d8; }
.cast-choice img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top; border-radius: 50%; }
.storage-notice { color: #95523d; font-size: 11px; line-height: 1.7; }
.celebration { position: absolute; z-index: 2; top: 40%; left: 0; width: 100%; text-align: center; color: #fffbdc; font-size: clamp(22px, 7vw, 30px); font-weight: 800; text-shadow: 0 2px 12px #193934, 0 0 4px #193934; pointer-events: none; }
.celebration.is-active { animation: celebrate .9s ease-out both; }
.drag-ghost { position: fixed; z-index: 20; opacity: .94; filter: drop-shadow(0 6px 5px #1a362e40); pointer-events: none; }
.drag-ghost .mini-cell { width: var(--ghost-cell); height: var(--ghost-cell); border-radius: 5px; }

.block-dialog { width: min(360px, calc(100% - 36px)); padding: 0; border: 1px solid #fffdf8; border-radius: 24px; color: var(--ink); background: var(--paper); box-shadow: 0 24px 80px #15362e30; }
.block-dialog::backdrop { background: #1c393b85; backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.dialog-content { padding: 32px 26px 24px; text-align: center; }
.dialog-content .eyebrow { color: #668573; font-size: 9px; }
.dialog-content h2 { margin: 14px 0 10px; font-size: 24px; }
.dialog-content p { color: var(--muted); font-size: 12px; line-height: 1.8; }
.result-score { display: block; margin: 22px 0; color: #336a58; font-size: 58px; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
#coinMessage { color: #96712f; font-weight: 600; }
.primary-button { width: 100%; min-height: 48px; margin: 10px 0 5px; border: 1px solid #356b5d; border-radius: 13px; color: #fffdf8; background: #3f7766; box-shadow: 0 3px 0 #2e584d; font-size: 13px; font-weight: 700; }
.primary-button:active { box-shadow: 0 1px 0 #2e584d; transform: translateY(2px); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@keyframes settle { from { transform: scale(.8); } to { transform: scale(1); } }
@keyframes celebrate { 0% { opacity: 0; transform: translateY(12px) scale(.85); } 25% { opacity: 1; transform: translateY(0) scale(1.05); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-18px); } }
@media (hover: hover) {
    .piece-button:not(:disabled):hover { border-color: #88a895; }
    .cast-choice:hover { background: #fffdf8; }
    .primary-button:hover { background: #326a59; }
}
@media (max-width: 360px) {
    .block-shell { padding: 16px 12px max(26px, env(safe-area-inset-bottom)); }
    .heading { margin-bottom: 14px; }
    h1 { font-size: 22px; gap: 6px; }
    .brand-mark { flex-basis: 24px; width: 24px; height: 24px; }
    .slow-label { font-size: 9px; }
    .board-wrap { padding: 5px; border-radius: 18px; }
    .block-board { gap: 3px; padding: 7px; border-radius: 13px; }
    .companion { min-height: 92px; }
    .companion img { width: 72px; height: 80px; }
    .companion > div { padding: 8px 10px; }
    .companion p { font-size: 11px; }
    .piece-button { height: 78px; }
    .mini-cell { width: 14px; height: 14px; }
    .cast-choice { width: 36px; height: 36px; }
    #castPicker { gap: 6px; }
    .instructions { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    .celebration.is-active { opacity: 1; }
}

/* Compact puzzle layout: keep the board and three pieces together on phones. */
.block-shell { padding-top: 10px; }
.score-strip { padding-block: 8px; }
.companion { min-height: 84px; }
.companion img { width: 64px; height: 72px; }
.tray-heading { margin: 12px 3px 6px; }
.piece-button { height: 86px; border-color: #dedfd480; background: #fffdf880; box-shadow: 0 2px 0 #e4e4d966; }
.mini-cell { width: 19px; height: 19px; }
@media (max-width: 360px) {
    .block-shell { padding-top: 8px; }
    .piece-tray { gap: 6px; }
    .piece-button { height: 80px; }
    .mini-cell { width: 16px; height: 16px; }
}
@media (max-height: 740px) {
    .block-shell { padding-top: 6px; }
    .score-strip { padding-block: 5px; }
    .score-strip > div { gap: 2px; }
    .companion { min-height: 64px; gap: 8px; padding-block: 4px; }
    .companion img { width: 48px; height: 56px; }
    .companion > div { padding: 5px 9px; }
    .companion p { margin-top: 2px; font-size: 11px; line-height: 1.4; }
    .tray-heading { margin-top: 8px; }
    .piece-button { height: 78px; }
    .mini-cell { width: 16px; height: 16px; }
}
