:root {
  color-scheme: light;
  --paper: #f3f1eb;
  --ink: #18211f;
  --ink-soft: #65716a;
  --line: #d8d7cc;
  --forest: #235848;
  --forest-dark: #173d34;
  --clay: #c76443;
  --gold: #d6b36c;
  --white: #fffefa;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at 1px 1px, rgba(24, 33, 31, .04) 1px, transparent 0) 0 0 / 18px 18px, var(--paper);
  color: var(--ink);
}
button { font: inherit; }
button:focus-visible { outline: 3px solid #d88e64; outline-offset: 3px; }
.shell { width: min(960px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 44px; }
.topbar { height: 70px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 8px); gap: 3px; transform: rotate(-8deg); }
.brand-mark i { width: 8px; height: 8px; display: block; background: var(--forest); border-radius: 50%; }
.brand-mark i:nth-child(2) { background: var(--clay); }
.brand-mark i:nth-child(3) { background: var(--gold); }
.brand-name { font-family: 'Hiragino Mincho ProN', 'Yu Mincho', serif; font-size: 17px; font-weight: 700; letter-spacing: .04em; }
.topbar-note, .eyebrow, .card-label, .board-topline { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: .09em; }
.topbar-note { color: var(--ink-soft); font-size: 12px; }
.heading-row { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 28px 0 22px; }
.eyebrow { margin: 0 0 7px; color: var(--forest); font-size: 12px; font-weight: 700; }
h1 { margin: 0; font: 700 clamp(32px, 5vw, 50px)/1.15 ui-monospace, 'SFMono-Regular', Consolas, monospace; letter-spacing: -.06em; }
h1 span { margin-left: 7px; font: 600 clamp(17px, 2.5vw, 24px)/1.3 'Hiragino Mincho ProN', 'Yu Mincho', serif; letter-spacing: .02em; }
.intro { margin: 9px 0 0; color: var(--ink-soft); font-size: 15px; }
.heading-actions { display: flex; gap: 8px; padding-bottom: 4px; }
.quiet-button { min-height: 38px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); color: var(--forest-dark); cursor: pointer; white-space: nowrap; }
.quiet-button:hover:not(:disabled) { border-color: var(--forest); }
.quiet-button:disabled { opacity: .45; cursor: default; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 20px; align-items: start; }
.board-card { padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,254,250,.82); box-shadow: 0 12px 34px rgba(33, 44, 39, .06); }
.board-topline { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--ink-soft); font-size: 11px; }
.board-topline strong { color: var(--forest); font-family: system-ui, sans-serif; font-size: 12px; letter-spacing: 0; }
.arena { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 355px) minmax(0, 1fr); gap: 8px; align-items: stretch; }
.character-card { display: flex; flex-direction: column; justify-content: end; min-width: 0; min-height: 0; margin: 0; overflow: hidden; border-radius: 14px; background: #e7ece5; }
.character-gamer { background: #e1eeed; }
.character-strategist { background: #f0e9df; }
.character-card img { display: block; width: 100%; height: 0; min-height: 0; flex: 1; object-fit: cover; object-position: center 24%; }
.character-card figcaption { display: grid; gap: 2px; min-height: 72px; padding: 10px 8px; text-align: center; }
.character-card figcaption strong { color: var(--forest-dark); font-size: 13px; white-space: nowrap; }
.character-card figcaption span { color: var(--ink-soft); font-size: 10px; line-height: 1.3; }
.board-frame { position: relative; width: min(100%, 355px); margin: 0 auto; padding: 9px; border-radius: 14px; background: linear-gradient(135deg, #235848, #173d34); box-shadow: inset 0 3px 10px rgba(0,0,0,.18), 0 12px 22px rgba(23,61,52,.16); }
.board { display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(12, 1fr); gap: 3px; aspect-ratio: 7 / 12; touch-action: none; user-select: none; -webkit-user-select: none; }
.cell { display: grid; place-items: center; min-width: 0; min-height: 0; border-radius: 6px; background: rgba(255,255,255,.095); color: var(--ink); font: 800 clamp(18px, 3.2vw, 27px)/1 ui-monospace, 'SFMono-Regular', Consolas, monospace; box-shadow: inset 0 1px 0 rgba(255,255,255,.06); }
.cell.has-number, .mini-number { box-shadow: inset 0 2px 0 rgba(255,255,255,.37), inset 0 -3px 0 rgba(0,0,0,.09), 0 2px 2px rgba(4,20,17,.16); }
.cell.is-ghost { background: rgba(240,196,91,.11); outline: 2px dashed rgba(255,255,255,.52); outline-offset: -4px; }
.cell.is-match { position: relative; z-index: 1; outline: 3px solid #fff6c8; outline-offset: -2px; animation: match-pulse .5s ease-in-out infinite alternate; }
.board.is-bursting .cell.is-match { animation: match-burst .22s ease-in forwards; }
@keyframes match-pulse { from { filter: brightness(1); box-shadow: 0 0 8px rgba(240,196,91,.45); } to { filter: brightness(1.28); box-shadow: 0 0 24px rgba(240,196,91,.95); } }
@keyframes match-burst { to { opacity: 0; transform: scale(1.32); filter: brightness(1.9); } }
.value-1 { background: #c9e4d5; }
.value-2 { background: #a4d4cd; }
.value-3 { background: #f0d994; }
.value-4 { background: #e6b88c; }
.value-5 { background: #d9b7ad; }
.value-6 { background: #bfc7dd; }
.value-7 { background: #f0c45b; color: #44310b; }
.board-overlay { position: absolute; inset: 9px; display: grid; place-items: center; padding: 18px; border-radius: 6px; background: rgba(12,38,31,.83); color: white; text-align: center; }
.board-overlay[hidden] { display: none; }
.clear-callout { position: absolute; z-index: 3; top: 20px; left: 50%; display: grid; gap: 2px; max-width: calc(100% - 30px); padding: 9px 14px; border: 2px solid #fff3bb; border-radius: 13px; background: #f0c45b; color: #173d34; box-shadow: 0 5px 22px rgba(7,30,24,.38); text-align: center; transform: translateX(-50%); pointer-events: none; }
.clear-callout[hidden] { display: none; }
.clear-callout strong { font: 900 18px/1.1 ui-monospace, monospace; white-space: nowrap; }
.clear-callout span { font-size: 12px; font-weight: 700; line-height: 1.3; }
.overlay-panel { max-width: 260px; }
.overlay-kicker { margin: 0 0 8px; color: #f0c45b; font: 700 11px ui-monospace, monospace; letter-spacing: .16em; }
.overlay-panel h2 { margin: 0; font: 600 25px/1.35 'Hiragino Mincho ProN', 'Yu Mincho', serif; }
.overlay-panel p:not(.overlay-kicker) { margin: 12px 0 21px; color: #e0e9df; font-size: 14px; line-height: 1.7; }
.primary-button { min-height: 46px; padding: 10px 22px; border: 0; border-radius: 11px; background: #f0c45b; color: #173d34; font-weight: 800; cursor: pointer; }
.primary-button:hover { background: #f8d47d; }
.touch-controls { display: grid; grid-template-columns: repeat(4, 1fr) 1.6fr; gap: 7px; margin-top: 12px; }
.touch-controls button { min-height: 54px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: #f7f6f0; color: var(--forest-dark); font-size: 21px; font-weight: 700; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.touch-controls button:active { transform: translateY(1px); background: #e6ebdf; }
.touch-controls .drop-button { background: var(--forest); border-color: var(--forest); color: white; font-size: 13px; }
.clear-feedback { min-height: 37px; margin: 10px 0 0; padding: 8px 11px; border: 1px solid #d7e2d3; border-radius: 10px; background: #eef4e9; color: var(--forest-dark); font-size: 12px; font-weight: 650; line-height: 1.5; }
.clear-feedback.is-live { border-color: #f2d17b; background: #f0c45b; color: #173d34; font-size: 14px; font-weight: 850; box-shadow: 0 4px 16px rgba(240,196,91,.32); animation: feedback-pop .28s ease-out; }
@keyframes feedback-pop { from { transform: scale(.97); } to { transform: scale(1); } }
.gesture-hint { margin: 10px 1px 0; color: var(--ink-soft); font-size: 12px; line-height: 1.55; }
.side-panel { display: grid; gap: 12px; }
.score-card, .next-card, .rule-card { padding: 18px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,254,250,.82); }
.score-card { color: white; border-color: #173d34; background: linear-gradient(135deg, #235848, #173d34); }
.card-label { display: block; color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.score-card .card-label { color: #c9d8ca; }
.score-card > strong { display: block; margin: 7px 0 13px; font: 700 39px/1 ui-monospace, monospace; letter-spacing: -.05em; }
.score-meta { display: flex; justify-content: space-between; gap: 10px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.2); color: #d7e6dc; font-size: 13px; }
.score-meta b { color: white; }
.level-progress { height: 6px; margin-top: 16px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.19); }
.level-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: #f0c45b; transition: width .18s ease; }
.level-note { display: flex; justify-content: space-between; gap: 8px; margin: 7px 0 0; color: #d7e6dc; font-size: 11px; line-height: 1.3; }
.level-note span:last-child { white-space: nowrap; }
.next-card { display: flex; align-items: center; justify-content: space-between; }
.next-pair { display: flex; align-items: center; gap: 5px; min-height: 43px; }
.mini-number { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 7px; font: 800 21px ui-monospace, monospace; }
.rule-card h2 { margin: 0 0 10px; font: 600 20px 'Hiragino Mincho ProN', 'Yu Mincho', serif; }
.rule-card p { margin: 0 0 10px; color: var(--ink-soft); font-size: 14px; line-height: 1.65; }
.rule-card p strong { color: var(--ink); }
.rule-example { display: flex; align-items: center; gap: 7px; margin: 14px 0; }
.rule-example span, .rule-example em { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; background: #f0d994; color: var(--ink); font: 800 18px ui-monospace, monospace; font-style: normal; }
.rule-example span:nth-of-type(2) { background: #e6b88c; }
.rule-example em { background: #c9e4d5; }
.rule-example b { color: var(--ink-soft); font-size: 13px; }
.rule-card .controls-note { margin-bottom: 0; padding-top: 11px; border-top: 1px solid var(--line); font-size: 12px; }
@media (max-width: 700px) {
  .topbar { height: 62px; }
  .heading-row { align-items: start; flex-direction: column; margin: 21px 0 18px; }
  .heading-actions { align-self: stretch; }
  .heading-actions button { flex: 1; }
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: 1fr 1fr; }
  .rule-card { grid-column: 1 / -1; }
  .board-card { padding: 12px; }
  .arena { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .character-card { flex-direction: row; align-items: center; min-height: 74px; max-height: 74px; }
  .character-card img { width: 68px; height: 74px; flex: none; object-position: center 16%; }
  .character-card figcaption { min-height: 0; padding: 6px 4px; text-align: left; }
  .character-card figcaption strong { font-size: 12px; }
  .character-card figcaption span { font-size: 9px; }
  .board-frame { grid-column: 1 / -1; grid-row: 2; }
  .touch-controls { position: sticky; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 2; padding: 6px; margin: 8px -6px 0; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,254,250,.97); box-shadow: 0 8px 20px rgba(23,61,52,.15); }
}
@media (max-width: 430px) {
  h1 span { display: inline-block; margin-left: 4px; }
  .intro { font-size: 14px; }
  .board-frame { width: min(100%, 305px); }
  .cell { font-size: 19px; }
  .touch-controls { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .touch-controls button { min-height: 54px; }
  .touch-controls .drop-button { font-size: 14px; }
  .character-card img { width: 59px; }
  .character-card figcaption span { display: none; }
  .score-card, .next-card, .rule-card { padding: 14px; }
  .score-card > strong { font-size: 31px; }
  .score-meta { display: grid; gap: 2px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .cell.is-match, .board.is-bursting .cell.is-match { animation: none; }
  .clear-feedback.is-live { animation: none; }
}

/* Story battle */
[hidden] { display: none !important; }
.shell { width: min(1080px, calc(100% - 32px)); }
.brand { color: inherit; text-decoration: none; }
.brand:hover .brand-name, .brand:focus-visible .brand-name { text-decoration: underline; }
.analytics-consent { padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); font-size: 12px; line-height: 1.6; }
.analytics-consent p { margin: 7px 0 11px; color: var(--ink-soft); }
.analytics-consent a { color: var(--forest); }
.consent-actions { display: flex; gap: 7px; }
.consent-actions button { flex: 1; min-height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #e8eee5; color: var(--forest-dark); cursor: pointer; }
.analytics-state { margin: 0 4px; color: var(--ink-soft); font-size: 11px; }
.heading-actions { flex-wrap: wrap; justify-content: flex-end; }
.heading-actions .is-selected { border-color: var(--forest); background: #e7eee7; font-weight: 800; }
.campaign-banner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 1.15fr); gap: 10px 22px; padding: 16px 20px; margin-bottom: 12px; border: 1px solid #c9d5ca; border-radius: 17px; background: linear-gradient(125deg, #eaf0e8, #f6f1e2); }
.stage-heading { display: grid; align-content: center; gap: 3px; }
.stage-heading span:first-child { color: var(--forest); font: 800 12px ui-monospace, monospace; letter-spacing: .08em; }
.stage-heading strong { font: 700 22px/1.2 'Hiragino Mincho ProN', 'Yu Mincho', serif; }
.stage-heading span:last-child { color: var(--ink-soft); font-size: 12px; }
.battle-meters { display: grid; gap: 9px; }
.battle-meters > div > span { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 3px; font-size: 12px; color: var(--forest-dark); }
.battle-meters b { font-weight: 800; }
.meter { height: 9px; overflow: hidden; border-radius: 99px; background: #d1d7ce; }
.meter i { display: block; width: 0; height: 100%; border-radius: inherit; background: #d3a95b; transition: width .2s ease; }
.enemy-meter i { background: #bd705e; }
.battle-brief { grid-column: 1 / -1; margin: 0; padding-top: 8px; border-top: 1px solid #cbd7ca; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.stage-map { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.stage-map summary { padding: 10px 15px; color: var(--forest-dark); font-size: 12px; font-weight: 700; cursor: pointer; }
.stage-buttons { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; padding: 0 12px 12px; }
.stage-buttons button { min-height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #f6f6ef; color: var(--ink-soft); font: 700 12px ui-monospace, monospace; cursor: pointer; }
.stage-buttons button.is-current { border-color: var(--forest); background: var(--forest); color: white; }
.stage-buttons button.is-cleared { background: #e3efdf; color: var(--forest-dark); }
.stage-buttons button:disabled { opacity: .42; cursor: default; }
.mode-story .arena { grid-template-columns: minmax(0, 1fr) minmax(0, 355px) minmax(132px, 1fr); }
.mode-story .character-strategist, .mode-solo .enemy-card { display: none; }
.enemy-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-width: 0; padding: 8px; border: 1px solid #d4d8c9; border-radius: 13px; background: #f4f1e8; }
.enemy-portrait { width: 100%; aspect-ratio: 1; border-radius: 9px; background: #e8dbc5 url('./assets/enemy-sheet.png') no-repeat; background-size: 300% 200%; box-shadow: inset 0 0 0 1px rgba(54,41,31,.16); }
.portrait-0 { background-position: 0% 0%; }
.portrait-1 { background-position: 50% 0%; }
.portrait-2 { background-position: 100% 0%; }
.portrait-3 { background-position: 0% 100%; }
.portrait-4 { background-position: 50% 100%; }
.portrait-5 { background-position: 100% 100%; }
.enemy-kicker { color: var(--clay); font: 800 10px ui-monospace, monospace; letter-spacing: .08em; }
.enemy-card > strong { color: var(--forest-dark); font-size: 14px; }
.enemy-board { display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(12, 1fr); gap: 1px; width: min(100%, 110px); aspect-ratio: 7 / 12; padding: 3px; border-radius: 7px; background: var(--forest-dark); }
.enemy-cell { display: grid; place-items: center; min-width: 0; min-height: 0; border-radius: 2px; background: rgba(255,255,255,.1); color: #26352b; font: 800 9px/1 ui-monospace, monospace; }
.enemy-cell.value-1 { background: #c9e4d5; }
.enemy-cell.value-2 { background: #a4d4cd; }
.enemy-cell.value-3 { background: #f0d994; }
.enemy-cell.value-4 { background: #e6b88c; }
.enemy-cell.value-5 { background: #d9b7ad; }
.enemy-cell.value-6 { background: #bfc7dd; }
.enemy-cell.value-7 { background: #f0c45b; color: #44310b; }
.enemy-cell.is-match { outline: 1px solid white; filter: brightness(1.35); }
.value-8, .enemy-cell.value-8 { background: #aeb8b0; color: #43534a; }
.enemy-meta { margin: 4px 0 0; color: var(--ink-soft); font-size: 10px; text-align: center; }
.incoming-line { margin: 12px 0 0; color: #e9d7b8; font-size: 12px; }
.incoming-line b { color: white; }
.touch-controls { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, 52px); }
.touch-controls [data-control="left"] { grid-column: 1; grid-row: 1; }
.touch-controls [data-control="down"] { grid-column: 2; grid-row: 1; }
.touch-controls [data-control="right"] { grid-column: 3; grid-row: 1; }
.touch-controls [data-control="rotate"] { grid-column: 4; grid-row: 1; }
.touch-controls [data-control="drop"] { grid-column: 4; grid-row: 2; }
.touch-controls .drop-button { background: var(--gold); border-color: #bea05e; color: var(--forest-dark); font-size: 13px; }
.story-overlay { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(10,31,26,.74); }
.story-dialogue { width: min(100%, 510px); padding: 20px; border: 2px solid #e0d5b8; border-radius: 22px; background: var(--white); box-shadow: 0 22px 65px rgba(0,0,0,.35); }
.dialogue-top { display: flex; justify-content: space-between; color: var(--forest); font: 800 11px ui-monospace, monospace; letter-spacing: .08em; }
.story-dialogue h2 { margin: 8px 0 12px; font: 700 24px 'Hiragino Mincho ProN', 'Yu Mincho', serif; }
.dialogue-portraits { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; max-width: 360px; margin: 0 auto 14px; }
.dialogue-portraits img, .dialogue-portraits .enemy-portrait { width: 100%; height: 128px; object-fit: cover; object-position: center 20%; aspect-ratio: auto; border-radius: 12px; background-color: #e5e8de; }
.dialogue-portraits span { color: var(--clay); font: 900 18px ui-monospace, monospace; }
.dialogue-line { min-height: 104px; padding: 13px 15px; border-radius: 13px; background: #eaf0e8; }
.dialogue-line strong { color: var(--forest); font-size: 13px; }
.dialogue-line p { margin: 6px 0 0; color: var(--ink); font-size: 16px; line-height: 1.55; }
.dialogue-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 700px) {
  .heading-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; gap: 5px; }
  .heading-actions .quiet-button { padding: 7px 3px; font-size: 11px; }
  .campaign-banner { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .stage-heading { grid-template-columns: auto 1fr auto; align-items: baseline; gap: 8px; }
  .stage-heading strong { font-size: 18px; }
  .stage-heading span:last-child { text-align: right; }
  .battle-meters { grid-template-columns: 1fr 1fr; gap: 8px; }
  .battle-brief { font-size: 11px; }
  .stage-buttons { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .mode-story .arena { grid-template-columns: minmax(0, 1fr) 104px; align-items: start; }
  .mode-story .character-gamer { grid-column: 1 / -1; grid-row: 1; }
  .mode-story .board-frame { grid-column: 1; grid-row: 2; width: 100%; }
  .mode-story .enemy-card { grid-column: 2; grid-row: 2; min-height: 100%; padding: 5px 3px; }
  .mode-story .enemy-portrait { max-width: 90px; }
  .mode-story .enemy-board { width: min(100%, 88px); }
  .enemy-card > strong { font-size: 12px; }
  .touch-controls { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, 49px); }
  .touch-controls button { min-height: 49px; }
}
@media (max-width: 430px) {
  .mode-story .cell { font-size: 16px; }
  .mode-story .character-gamer { justify-content: flex-start; }
  .dialogue-portraits img, .dialogue-portraits .enemy-portrait { height: 106px; }
  .story-dialogue { padding: 16px; }
  .story-dialogue h2 { font-size: 21px; }
}
