﻿/* つなぐ！ボランティアめくり — physical cards with permanent kind colours. */
:root {
  color-scheme: light;
  --forest: #174c35;
  --deep: #103a28;
  --cream: #fbf6e8;
  --cream-2: #f1e9d2;
  --paper: #fffdf6;
  --ink: #173529;
  --muted: #3f5a4c;
  --gold: #e7b54c;
  --gold-soft: #f3d98f;
  --coral: #b5432c;
  --focus: #9e3f23;
  --accent: var(--forest);
  --card-name-header: #14452f;
  --card-name-body: #ffd34d;
  --card-action-header: #0e7c86;
  --card-action-body: #e3f2f7;
  --topbar-h: 60px;
  --gutter: clamp(10px, 2.4vw, 32px);
  --radius: 12px;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html { background: var(--cream); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--cream); }
::selection { background: var(--gold); color: var(--deep); }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: fixed; top: 0; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.svg-library, .art-library { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { fill: none; stroke: currentColor; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
/* Japanese line breaking: no small kana / long vowel mark at line start, keep phrases together where "<wbr>" marks them. */
body { line-break: strict; }
h1, h2, p, li { overflow-wrap: anywhere; text-wrap: pretty; }
h1, h2 { text-wrap: balance; }
button, .turn-message, .card-text, .card-band, .sample-text { word-break: keep-all; overflow-wrap: anywhere; text-wrap: balance; }
ruby { white-space: nowrap; ruby-position: over; }
.seg { display: inline-block; max-width: 100%; }
.text-button .seg { text-decoration: underline; text-underline-offset: 4px; }
rt { font-weight: 600; letter-spacing: 0; }
html.no-furigana rt { display: none; }

/* Activity colours (matched cards, progress, A/B panel, end screen only): each one keeps white text at 4.5:1 or more. */
[data-icon="festival"], [data-icon="mochi"], [data-icon="paint"] { --accent: #9a3b1f; }
[data-icon="guide"], [data-icon="globe"] { --accent: #1d5866; }
[data-icon="star"] { --accent: #5b4396; }
[data-icon="sport"] { --accent: #2b4f86; }
[data-icon="heart"] { --accent: #8f2f45; }
[data-icon="shop"] { --accent: #6e4f12; }

/* Buttons: one shape (fully round), one fill per role. */
.primary-button, .secondary-button, .text-button, .choice-button, .toggle-button, .settings-button {
  min-height: 56px; border-radius: 999px; padding: 10px 22px; font-size: 16px; font-weight: 700; line-height: 1.2; touch-action: manipulation;
}
.primary-button { border: 2px solid var(--forest); background: var(--forest); color: #fff; }
.primary-button:hover:not(:disabled) { background: var(--deep); }
.secondary-button { border: 2px solid var(--forest); background: var(--paper); color: var(--forest); }
.secondary-button:hover:not(:disabled), .toggle-button:hover:not(:disabled) { background: #e6efe1; }
.text-button { border: 0; background: none; color: var(--forest); text-decoration: underline; text-underline-offset: 4px; }

/* Shell and top bar */
.shell { min-height: 100vh; min-height: 100dvh; max-width: 1440px; margin: 0 auto; padding: 0 var(--gutter); display: flex; flex-direction: column; }
.topbar { position: relative; z-index: 20; height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 10px; }
.brand { flex: 1; min-width: 0; min-height: 48px; display: flex; align-items: center; gap: 10px; border: 0; padding: 0; background: none; color: var(--forest); font-size: 17px; font-weight: 800; text-align: left; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand strong { font-weight: 800; }
/* Logo 「四ツ目つなぎ」 (màu nằm trong symbol #mark / #mark-full, không dùng nét). */
.logo-mark { display: block; stroke: none; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.start-mark { display: none; }
.settings-button { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 6px 16px; border: 2px solid var(--forest); background: var(--paper); color: var(--forest); }
.settings-button svg { width: 22px; height: 22px; stroke-width: 4; }
.settings-button[aria-expanded="true"] { background: var(--forest); color: #fff; }
.top-actions { display: none; }
.settings-scrim { position: fixed; inset: 0; z-index: 15; background: rgba(12, 38, 27, .42); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.topbar.is-settings-open .top-actions { position: absolute; top: calc(100% - 4px); right: 0; display: grid; gap: 8px; width: min(300px, calc(100vw - 2 * var(--gutter))); padding: 12px; background: var(--paper); border-radius: 16px; box-shadow: 0 12px 32px rgba(16, 58, 40, .22); }
.toggle-button { border: 2px solid var(--forest); background: var(--paper); color: var(--deep); padding: 8px 16px; }
.toggle-button[aria-pressed="true"] { background: #e3eedf; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; }

/* Start screen */
.start-screen { display: grid; grid-template-columns: 1fr; gap: 28px; padding: 18px 0 28px; }
.start-copy h1 { margin: 0 0 16px; color: var(--deep); font-size: clamp(32px, 8.4vw, 64px); line-height: 1.16; letter-spacing: -.02em; }
.lead { margin: 0; font-size: clamp(17px, 1.6vw, 21px); line-height: 1.7; max-width: 36em; }
.start-form { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; margin: 22px 0 0; padding: 0; border: 0; min-width: 0; }
.start-form legend { float: left; width: 100%; margin-bottom: 2px; padding: 0; font-weight: 700; font-size: 16px; }
.player-options { display: flex; gap: 6px; }
.player-options label { position: relative; }
.player-options input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.player-options > label > span { display: grid; place-items: center; min-width: 52px; min-height: 52px; padding: 2px 8px; border: 2px solid var(--forest); border-radius: 999px; background: var(--paper); color: var(--forest); font-weight: 800; font-size: 17px; line-height: 1.1; }
.player-options rt { font-size: .6em; }
.player-options input:checked + span { background: var(--forest); color: #fff; }
.player-options input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.start-form .primary-button { flex: 1 1 220px; max-width: 360px; font-size: 18px; }
.soft-note { margin: 16px 0 0; font-size: 16px; color: var(--muted); }
.event-line { margin: 22px 0 0; font-size: 16px; font-weight: 700; color: var(--forest); }
.how-to { padding: 22px; background: var(--cream-2); border-radius: 20px; }
.how-to h2 { margin: 18px 0 8px; font-size: clamp(22px, 2.4vw, 30px); color: var(--deep); }
.how-to ol { list-style: none; margin: 0; padding: 0; }
.how-to li { display: flex; align-items: flex-start; gap: 14px; padding: 10px 0; }
.how-to li strong { display: block; font-size: 18px; }
.how-to li p { margin: 3px 0 0; line-height: 1.5; }
.step-icon { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--forest); color: var(--gold-soft); }
.step-icon svg { width: 26px; height: 26px; stroke-width: 4; }
.sample-pair { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; max-width: 420px; }
.sample-card { position: relative; min-height: 208px; border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 2px 0 rgba(20,69,47,.25), 0 6px 14px rgba(20,69,47,.12); }
.sample-back { align-items: center; justify-content: center; gap: 6px; border: 3px solid var(--deep); background: var(--forest); }
.sample-back::before { content: ""; position: absolute; inset: 5px; border: 1.5px solid var(--gold-soft); border-radius: 7px; }
.sample-name { background: var(--card-name-body); color: var(--card-name-header); border: 3px solid var(--card-name-header); }
.sample-name .card-band { background: var(--card-name-header); color: white; }
.sample-action { background: var(--card-action-body); color: var(--card-name-header); border: 3px solid var(--card-action-header); }
.sample-action .card-band { background: var(--card-action-header); }
.sample-card .card-band { display: grid; justify-items: center; gap: 2px; padding: 5px 2px; font-size: 12px; }
.sample-card .card-band > svg { width: 28px; height: 28px; }
.sample-card .card-picture { display: none; }
.sample-action .sample-text { position: relative; z-index: 1; }
.sample-text { flex: 1; display: flex; align-items: center; justify-content: center; padding: 4px 6px; text-align: center; font-size: 16px; font-weight: 800; line-height: 1.3; overflow-wrap: normal; }
.sample-text .seg { white-space: nowrap; }
.sample-text rt { font-size: 10px; }

/* Card faces (shared by board and samples) */
.card-band { flex: none; display: flex; align-items: center; gap: 4px; min-height: 26px; padding: 3px 6px; background: var(--forest); color: #fff; font-size: 13px; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.card-band svg { width: 18px; height: 18px; flex: none; stroke-width: 4.4; }
.card-band rt { font-size: .62em; }
.back-medal { position: relative; z-index: 1; flex: none; display: grid; place-items: center; width: var(--medal, 40px); height: var(--medal, 40px); border: 2px solid var(--paper); border-radius: 50%; background: var(--gold-soft); color: var(--forest); }
.back-word { position: relative; z-index: 1; color: var(--paper); font-size: 13px; font-weight: 800; letter-spacing: .12em; line-height: 1; }

/* Game screen: narrow / portrait layout first */
.game-screen { display: grid; grid-template-rows: auto auto auto; gap: 8px; min-height: calc(100dvh - var(--topbar-h)); height: auto; padding: 2px 0 calc(8px + env(safe-area-inset-bottom)); }
.game-status { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "slots score" "message tries"; align-items: center; column-gap: 10px; row-gap: 4px; }
.status-head { display: contents; }
.status-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.score { grid-area: score; margin: 0; display: flex; align-items: baseline; gap: 6px; color: var(--forest); font-size: 15px; font-weight: 700; white-space: nowrap; }
.score strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.progress-slots { grid-area: slots; display: flex; gap: 4px; min-width: 0; margin: 0; padding: 0; list-style: none; }
.progress-slots li { flex: 0 1 28px; min-width: 0; display: grid; place-items: center; aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--forest); background: transparent; color: #fff; }
.progress-slots li.is-filled { background: var(--forest); }
.progress-slots svg { width: 17px; height: 17px; stroke-width: 4.6; }
.turn-message { grid-area: message; margin: 0; font-size: 16px; font-weight: 800; line-height: 1.35; }
.tries { grid-area: tries; margin: 0; font-size: 15px; font-weight: 700; color: var(--muted); white-space: nowrap; }

/* Card identity is permanent: the two kinds keep their colours after matching. */
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(220px, 1fr)); gap: 14px; min-height: 0; padding: 8px; }
.card {
  --kind-header: var(--card-name-header); --kind-body: var(--card-name-body); --card-ink: var(--card-name-header);
  --selected: var(--card-name-body); --hint: #7c5cff; --wrong: #c3323e; --complete: #258452;
  position: relative; min-width: 0; min-height: 64px; height: 100%; border: 0; padding: 0;
  border-radius: 16px; background: var(--kind-header); perspective: 900px; text-align: center;
  box-shadow: 0 2px 0 rgba(20,69,47,.32), 0 10px 24px rgba(20,69,47,.18);
  transition: translate 150ms ease, scale 150ms ease, box-shadow 150ms ease;
  touch-action: manipulation; scroll-margin-block: 110px 90px; container-type: inline-size;
}
.card.is-action { --kind-header: var(--card-action-header); --kind-body: var(--card-action-body); }
.card:disabled { opacity: 1; cursor: default; }
.card-back, .card-front {
  position: absolute; inset: 0; border: 2px solid var(--kind-header); border-radius: inherit; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.card-back {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border-color: #103a28; background: radial-gradient(ellipse at 28% 12%, rgba(255,253,246,.16), transparent 65%), var(--forest);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22); transform: rotateY(0deg);
}
.card-back::before { content: ""; position: absolute; inset: 6px; border: 1.5px solid var(--gold-soft); border-radius: 9px; pointer-events: none; }
.card-back::after { content: ""; position: absolute; inset: 12px; border-radius: 6px; opacity: .15; background-image: radial-gradient(circle at 50% 100%, transparent 10px, #f3d98f 11px, transparent 12px), radial-gradient(circle at 50% 0%, transparent 10px, #f3d98f 11px, transparent 12px); background-size: 32px 23px; pointer-events: none; }
.card .back-medal { --medal: 58px; border-color: var(--gold-soft); box-shadow: 0 3px 8px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.6); }
.back-num { position: static; color: var(--forest); font-size: clamp(24px, 2.1vw, 32px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.card-front { display: flex; flex-direction: column; background: var(--kind-body); color: var(--card-ink); transform: rotateY(-180deg); box-shadow: inset 0 0 0 1px rgba(255,255,255,.55); }
.card-front::after { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(20,69,47,.16); border-radius: 10px; pointer-events: none; }
.card .card-band { justify-content: flex-start; gap: 8px; min-height: 48px; padding: 5px 10px; background: var(--kind-header); color: #fff; font-size: 15px; letter-spacing: 0; line-height: 1.25; writing-mode: horizontal-tb; }
.card .card-band > svg { display: block; width: 32px; height: 32px; flex: none; stroke-width: 3.8; }
.card .card-band rt { font-size: 10px; color: rgba(255,255,255,.88); }
.card-picture { position: relative; flex: none; align-self: center; display: grid; place-items: center; width: 44px; height: 36px; margin: 7px 0 0; border-radius: 50%; background: rgba(255,255,255,.26); }
.card-picture svg { display: block; width: 36px; height: 36px; stroke: none; }
.card.is-action .card-picture { position: absolute; right: 10px; bottom: 14px; margin: 0; opacity: .14; }
.card.is-action:not(.is-matched) .card-picture svg { stroke: var(--kind-header); stroke-width: 3.2; }
.card .card-text {
  position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  padding: 9px 12px 14px; font-size: clamp(15px, 2.2vw, 30px); font-weight: 800; line-height: 1.5;
  letter-spacing: 0; word-break: keep-all; overflow-wrap: normal; text-wrap: balance;
}
.card-text > span { display: block; max-width: 100%; }
.card-text .seg { max-width: none; white-space: nowrap; }
.card-text ruby { display: inline ruby; white-space: nowrap; }
.card-text rt { font-size: max(10px, .44em); font-weight: 600; color: #375c47; }
/* Seven-kana words still fit a card beside the status column on small laptops. */
@container (max-width: 235px) { .card .card-text { font-size: clamp(15px, 10cqi, 23.5px); } }
.card.is-open .card-back { transform: rotateY(180deg); }
.card.is-open .card-front { transform: rotateY(0deg); }
.card.is-open:not(.is-matched):not(.is-wrong) { scale: 1.03; box-shadow: 0 0 0 4px var(--selected), 0 0 0 6px var(--card-ink), 0 12px 24px rgba(20,69,47,.22); z-index: 2; }
.card.is-hint { outline: 4px solid var(--hint); outline-offset: 3px; z-index: 2; }
.hint-ring { position: absolute; inset: -7px; border: 3px solid var(--hint); border-radius: 20px; opacity: 0; pointer-events: none; }
.card.is-hinting .hint-ring { animation: hint-pulse 500ms ease-in-out 2; }
.card.is-wrong { box-shadow: 0 0 0 4px var(--wrong), 0 10px 24px rgba(195,50,62,.2); animation: card-shake 400ms 450ms ease-in-out; z-index: 2; }
.matched-mark, .wrong-mark { position: absolute; top: -8px; right: -7px; z-index: 4; display: none; place-items: center; width: 36px; height: 36px; margin: 0; border: 3px solid var(--paper); border-radius: 50%; background: var(--complete); color: #fff; box-shadow: 0 3px 8px rgba(20,69,47,.22); pointer-events: none; }
.matched-mark svg { width: 24px; height: 24px; stroke-width: 5; }
.wrong-mark { background: var(--wrong); font: 800 23px/1 sans-serif; }
.card.is-wrong .wrong-mark, .card.is-matched .matched-mark { display: grid; }
.card.is-matched { box-shadow: 0 0 0 3px var(--complete), 0 0 18px rgba(37,132,82,.24), 0 8px 20px rgba(20,69,47,.14); }
.card.is-matched .card-front { opacity: .92; }
.card.is-matched .card-front::before { content: ""; position: absolute; inset: auto 0 0; height: 8px; z-index: 2; background: linear-gradient(90deg, var(--card-name-header), #45a96d); }
.card.is-celebrating { animation: pair-pop 500ms 300ms ease both; }
.card.is-celebrating .matched-mark { animation: badge-pop 300ms 300ms cubic-bezier(.2,.7,.3,1.2) both; }
.card-sparkles { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.card-sparkles i { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; border-radius: 2px; background: var(--selected); opacity: 0; --dx: -65px; --dy: -50px; }
.card-sparkles i:nth-child(2) { --dx: 60px; --dy: -60px; background: var(--complete); }
.card-sparkles i:nth-child(3) { --dx: -75px; --dy: 15px; }
.card-sparkles i:nth-child(4) { --dx: 75px; --dy: 20px; background: var(--card-action-header); }
.card-sparkles i:nth-child(5) { --dx: -30px; --dy: 75px; background: var(--card-action-header); }
.card-sparkles i:nth-child(6) { --dx: 35px; --dy: 70px; }
.card.is-celebrating .card-sparkles i { animation: card-sparkle 500ms 300ms ease-out both; }
.card.is-flipping .card-back { animation: flip-back 450ms cubic-bezier(.2,.7,.3,1.2); }
.card.is-flipping .card-front { animation: flip-front 450ms cubic-bezier(.2,.7,.3,1.2); }
.card.is-folding .card-back { animation: flip-back 450ms cubic-bezier(.2,.7,.3,1.2) reverse; }
.card.is-folding .card-front { animation: flip-front 450ms cubic-bezier(.2,.7,.3,1.2) reverse; }
.card:focus-visible { outline: 3px solid var(--card-ink); outline-offset: 7px; z-index: 3; }
@media (hover: hover) and (pointer: fine) {
  .card:hover:not(:disabled) { translate: 0 -4px; box-shadow: 0 3px 0 rgba(20,69,47,.3), 0 16px 30px rgba(20,69,47,.24); z-index: 2; }
  .card.is-open:hover:not(:disabled) { box-shadow: 0 0 0 4px var(--selected), 0 0 0 6px var(--card-ink), 0 16px 30px rgba(20,69,47,.24); }
}
.card:active:not(:disabled) { translate: 0 1px; box-shadow: 0 1px 0 rgba(20,69,47,.3), 0 3px 8px rgba(20,69,47,.16); }
@keyframes flip-back { from { transform: rotateY(0deg); } to { transform: rotateY(180deg); } }
@keyframes flip-front { from { transform: rotateY(-180deg); } to { transform: rotateY(0deg); } }
@keyframes card-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }
@keyframes hint-pulse { 0%,100% { opacity: .3; scale: 1; } 50% { opacity: 1; scale: 1.025; } }
@keyframes pair-pop { 0%,100% { scale: 1; } 35% { scale: 1.04; } }
@keyframes badge-pop { from { scale: .3; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes card-sparkle { 0% { transform: translate(0,0) rotate(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translate(var(--dx),var(--dy)) rotate(135deg); opacity: 0; } }


.game-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; align-items: stretch; }
.game-controls button { min-height: 56px; padding: 6px 8px; font-size: 16px; line-height: 1.15; }
.hint-count { display: inline-grid; place-items: center; min-width: 26px; height: 26px; margin-left: 4px; border-radius: 50%; background: var(--gold); color: var(--deep); font-variant-numeric: tabular-nums; }

/* A/B panel */
.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 12px; background: rgba(12, 38, 27, .8); overflow-y: auto; }
.prompt-panel { width: min(100%, 680px); max-height: calc(100dvh - 24px); overflow-y: auto; padding: clamp(18px, 3.4vw, 36px); background: var(--paper); border-radius: 22px; border-top: 10px solid var(--accent); box-shadow: 0 24px 60px rgba(0, 0, 0, .3); }
.prompt-head { display: flex; align-items: center; gap: 14px; }
.prompt-icon { flex: none; display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; }
.prompt-icon svg { width: 32px; height: 32px; stroke-width: 4; }
.prompt-kicker { margin: 0; font-size: 17px; font-weight: 800; color: var(--forest); }
.prompt-panel h2 { margin: 2px 0 0; font-size: clamp(22px, 3vw, 30px); color: var(--deep); }
.activity-info { margin: 14px 0 0; padding: 12px 14px; background: var(--cream); border-radius: 12px; font-size: 17px; line-height: 1.65; }
.activity-info rt { font-size: .58em; }
.prompt-question { margin: 18px 0 14px; font-size: clamp(21px, 3vw, 30px); font-weight: 800; line-height: 1.4; color: var(--deep); }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-button { min-height: 72px; border: 3px solid var(--forest); background: #eef3e8; color: var(--deep); font-size: 19px; border-radius: 18px; }
.choice-button[aria-pressed="true"] { background: var(--forest); color: #fff; border-color: var(--gold); }
.prompt-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.prompt-actions button { min-width: 128px; }
#pass-button[aria-pressed="true"] { background: var(--cream-2); }

/* End screen */
.end-screen { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; max-width: 760px; width: 100%; margin: 0 auto; padding: 10px 0 18px; text-align: center; }
.celebration { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.celebration > span { position: absolute; top: -24px; width: 18px; height: 18px; color: var(--gold); opacity: 0; }
.celebration svg { display: block; width: 100%; height: 100%; fill: currentColor; stroke: none; }
.celebration > span:nth-child(6n+1) { color: #d9643a; }
.celebration > span:nth-child(6n+2) { color: #e06a8f; }
.celebration > span:nth-child(6n+3) { color: #f0a03c; }
.celebration > span:nth-child(6n+4) { color: #2a8c8c; }
.celebration > span:nth-child(6n+5) { color: #7a5cc4; }
.celebration > span:nth-child(5n) { width: 13px; height: 13px; }
.end-emblem { display: grid; place-items: center; width: 88px; height: 88px; }
.end-emblem svg { width: 100%; height: 100%; }
.end-screen h1 { margin: 0; font-size: clamp(44px, 9vw, 84px); line-height: 1.05; letter-spacing: -.02em; color: var(--forest); }
.end-screen .lead { max-width: 30em; }
.end-icons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 4px 0; padding: 0; list-style: none; }
.end-icons li { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; }
.end-icons svg { width: 24px; height: 24px; stroke-width: 4.2; }
.reward { width: 100%; margin: 4px 0 0; padding: 12px 18px 14px; background: #fbe7b5; color: var(--deep); border-radius: 18px; font-size: 17px; line-height: 1.6; }
.reward rt { color: var(--deep); font-size: max(10px, .55em); }
.reward p { margin: 6px 0 0; }
.reward strong { display: block; font-size: 20px; color: var(--deep); word-break: keep-all; }
.gifts { display: flex; justify-content: center; gap: clamp(14px, 4vw, 28px); margin: 0; padding: 0; list-style: none; }
.gifts li { display: grid; justify-items: center; gap: 2px; font-size: 15px; font-weight: 800; color: var(--deep); line-height: 1.2; }
.gifts svg { width: 46px; height: 46px; padding: 8px; border-radius: 50%; background: var(--paper); color: #b5432c; stroke-width: 4.4; }
.gifts li:nth-child(2) svg { color: #8f2f45; }
.gifts li:nth-child(3) svg { color: var(--forest); }
.end-stats { display: flex; justify-content: center; gap: 22px; margin: 2px 0; font-size: 16px; font-weight: 700; color: var(--muted); }
.end-stats strong { color: var(--forest); font-size: 22px; font-variant-numeric: tabular-nums; }
.end-actions { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(100%, 520px); }

/* Staff */
.staff-screen { max-width: 960px; width: 100%; margin: 0 auto; padding: 16px 0 32px; }
.staff-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.staff-head h1 { margin: 0; font-size: clamp(28px, 4vw, 38px); color: var(--deep); }
.staff-screen > p { line-height: 1.6; }
.staff-pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.staff-pair { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 14px; background: var(--paper); border: 2px solid transparent; border-radius: 14px; font-weight: 700; cursor: pointer; }
.staff-pair:has(input:checked) { border-color: var(--forest); background: #e6efe1; }
.staff-pair input { width: 24px; height: 24px; flex: none; accent-color: var(--forest); }
.staff-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); }
.staff-count { font-weight: 800; color: var(--forest); }
.staff-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 26px; }
.staff-guide { padding: 20px 24px; background: var(--cream-2); border-radius: 18px; line-height: 1.7; }
.staff-guide h2 { margin: 0; font-size: 22px; }
.staff-guide p { margin-bottom: 0; }

/* Phones */
@media (max-width: 560px) {
  :root { --topbar-h: 56px; }
  .brand { font-size: 16px; gap: 8px; }
  .brand-mark { width: 32px; height: 32px; }
  .settings-button { padding: 6px 12px; }
  .how-to { padding: 16px; }
  .end-actions button { padding: 8px 10px; }
  .staff-pairs { grid-template-columns: 1fr; }
  .staff-actions button { width: 100%; }
  .prompt-panel { border-top-width: 8px; }
  .prompt-icon { width: 46px; height: 46px; }
  .prompt-icon svg { width: 26px; height: 26px; }
  .prompt-question { margin: 14px 0 12px; }
  .choice-button { min-height: 60px; font-size: 18px; }
  .end-screen { gap: 8px; }
  .end-emblem { width: 64px; height: 64px; }
  .end-icons li { width: 36px; height: 36px; }
  .end-icons svg { width: 21px; height: 21px; }
  .reward { padding: 10px 12px; font-size: 16px; }
  .reward strong { font-size: 18px; }
  .end-screen .lead { font-size: 16px; line-height: 1.55; }
}
@media (max-width: 420px) {
  .choice-row { grid-template-columns: 1fr; gap: 8px; }
  .progress-slots { gap: 3px; }
  .progress-slots li { width: 25px; height: 25px; }
  .progress-slots svg { width: 15px; height: 15px; }
  .score { font-size: 0; }
  .score strong { font-size: 22px; }
  .back-num { font-size: 20px; }
}
/* Short phones (320x568, iPhone SE in Safari): 16 readable faces with furigana cannot fit in ~400px of height
   (the longest face needs 5-6 lines at 14px). So: a slim sticky status bar on top, sticky buttons at the bottom,
   and the board scrolls a little in between. Card height is fixed so flipping never moves the layout. */
@media (max-width: 359px), (max-height: 640px) and (max-width: 560px) {
  :root { --topbar-h: 48px; }
  .brand-mark { width: 28px; height: 28px; }
  .settings-button { min-height: 44px; }
  .game-screen { height: auto; gap: 6px; padding-top: 0; }
  .game-status { position: sticky; top: 0; z-index: 5; padding: 4px 0 6px; background: var(--cream); row-gap: 2px; }
  .turn-message { font-size: 15px; line-height: 1.25; }
  .tries { font-size: 14px; }
  .end-screen h1 { font-size: 40px; }
  .end-icons li { width: 32px; height: 32px; }
  .end-icons svg { width: 19px; height: 19px; }
  .end-screen .lead { line-height: 1.45; }
  .end-emblem { width: 48px; height: 48px; }
  .gifts svg { width: 38px; height: 38px; padding: 6px; }
  .gifts li { font-size: 14px; }
  .reward { padding: 8px 10px; }
  .reward p { margin-top: 4px; }
}

/* Tablet portrait and larger phones: bigger faces */
@media (min-width: 600px) {
  .back-word { font-size: 17px; }
  .progress-slots li { width: 34px; height: 34px; }
  .progress-slots svg { width: 20px; height: 20px; }
  .turn-message { font-size: 18px; }
  .tries { font-size: 16px; }
  .game-controls { grid-template-columns: repeat(3, minmax(0, 220px)); justify-content: center; gap: 10px; }
  .how-to { padding: 28px; }
}

/* Wide landscape (iPad landscape, laptop): status column + board */
@media (min-width: 900px) and (min-height: 560px) {
  :root { --topbar-h: 72px; }
  .brand { font-size: 20px; }
  .brand-mark { width: 42px; height: 42px; }
  .settings-button { display: none; }
  .top-actions { display: flex; gap: 8px; }
  .toggle-button { min-height: 48px; }
  .start-screen { grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr); align-items: center; gap: clamp(32px, 6vw, 96px); padding: 24px 0 40px; }
  .start-copy h1 { font-size: clamp(40px, 4.6vw, 66px); }
}
@media (min-width: 900px) and (min-height: 560px) and (orientation: landscape) {
  .game-screen { grid-template-columns: minmax(230px, 290px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "status board" "controls board"; column-gap: clamp(20px, 3vw, 44px); row-gap: 14px; padding: 8px 0 20px; }
  .game-status { grid-area: status; align-self: start; display: flex; flex-direction: column; align-items: flex-start; gap: 14px; padding: 22px; background: var(--cream-2); border-radius: 20px; }
  .status-head { display: block; }
  .status-head h1 { position: static; width: auto; height: auto; overflow: visible; clip: auto; white-space: normal; margin: 0 0 6px; font-size: clamp(26px, 2.4vw, 34px); line-height: 1.15; color: var(--deep); }
  .score { font-size: 16px; }
  .score strong { font-size: 34px; }
  .progress-slots { display: grid; grid-template-columns: repeat(4, 34px); gap: 8px; }
  .turn-message { font-size: 19px; }
  .game-controls { grid-area: controls; grid-template-columns: 1fr; align-self: end; justify-content: stretch; }
}

/* Phone held sideways: 4 x 4 board (wider, readable faces) beside a slim status column.
   The kind label runs vertically down the left edge of each face (縦書き) so the text keeps the full card height. */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --topbar-h: 44px; }
  .brand { font-size: 15px; }
  .brand-mark { width: 28px; height: 28px; }
  .settings-button { min-height: 44px; }
  .game-screen { grid-template-columns: 172px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "status board" "controls board"; column-gap: 10px; row-gap: 6px; padding: 0 env(safe-area-inset-right) calc(6px + env(safe-area-inset-bottom)) env(safe-area-inset-left); }
  .game-status { grid-area: status; align-self: start; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
  .progress-slots { display: grid; grid-template-columns: repeat(4, 28px); gap: 5px; }
  .progress-slots li { width: 28px; height: 28px; }
  .turn-message { font-size: 15px; line-height: 1.3; }
  .back-num { font-size: 20px; }
  .game-controls { grid-area: controls; grid-template-columns: 1fr; gap: 4px; }
  .game-controls button { min-height: 44px; font-size: 15px; }
  .start-screen { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); align-items: start; gap: 20px; padding: 6px 0 16px; }
  .start-copy h1 { font-size: 27px; margin-bottom: 4px; line-height: 1.12; }
  .start-copy .lead { font-size: 16px; line-height: 1.5; }
  .start-form { margin-top: 6px; gap: 6px 10px; }
  .player-options > label > span { min-width: 44px; min-height: 44px; }
  .start-form .primary-button { min-height: 48px; flex-basis: 100%; }
  .soft-note { margin-top: 6px; }
  .event-line { margin-top: 2px; font-size: 14px; }
  .how-to { padding: 14px 16px; }
  .sample-pair { display: none; }
  .how-to h2 { margin: 0 0 2px; font-size: 20px; }
  .how-to li { padding: 5px 0; gap: 10px; }
  .how-to li strong { font-size: 16px; }
  .how-to li p { font-size: 15px; }
  .step-icon { width: 38px; height: 38px; }
  .staff-screen { padding-top: 8px; }
  .end-screen { flex-direction: column; gap: 6px; padding: 4px 0 10px; }
  .end-emblem { display: none; }
  .end-screen h1 { font-size: 40px; }
  .reward { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 8px 16px; }
  .reward p { margin: 0; text-align: left; }
  .gifts { gap: 10px; }
  .gifts li { font-size: 14px; }
  .gifts svg { width: 38px; height: 38px; padding: 6px; }
}

/* Reduced motion: no 3D turn, no confetti; state changes are a short fade. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
  .celebration { display: none; }
}
@media (max-width: 380px) {
  .brand { font-size: 15px; gap: 6px; }
  .brand-mark { width: 28px; height: 28px; }
  .settings-button { width: 52px; padding: 0; justify-content: center; }
  .settings-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}

@media (min-width: 600px) and (min-height: 521px) { .card-back { --medal: 54px; gap: 10px; } }
@media (min-width: 900px) and (min-height: 560px) { .card-back { --medal: 62px; } }

@media (min-width: 900px) and (min-height: 560px) { .settings-scrim { display: none; } }
/* Logo lớn ở màn bắt đầu: chỉ khi còn chỗ (tablet/laptop); điện thoại đã có logo ở header ngay trên. */
@media (min-width: 600px) and (min-height: 700px) { .start-mark { display: block; width: 64px; height: 64px; margin: 0 0 18px; } }
@media (min-width: 900px) and (min-height: 560px) and (max-height: 699px) { .start-mark { display: block; width: 52px; height: 52px; margin: 0 0 12px; } }
@media (max-width: 359px) { .end-icons { gap: 4px; } }
@media (max-height: 520px) and (orientation: landscape) {
  .end-screen { justify-content: flex-start; gap: 5px; padding-top: 0; }
  .end-screen h1 { font-size: 34px; }
  .end-screen .lead { font-size: 16px; line-height: 1.4; }
  .end-icons { margin: 0; }
  .end-icons li { width: 34px; height: 34px; }
  .end-icons svg { width: 20px; height: 20px; }
  .reward { margin: 0; padding: 6px 14px; font-size: 16px; line-height: 1.4; }
  .reward strong { font-size: 17px; }
  .end-stats { margin: 0; }
  .end-actions button { min-height: 48px; padding: 6px 12px; }
}
@media (max-width: 359px), (max-height: 640px) and (max-width: 560px) {
  .game-controls { position: sticky; bottom: 0; z-index: 5; padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); background: var(--cream); }
  .game-controls button { min-height: 48px; font-size: 15px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .prompt-panel { padding: 12px 20px 14px; border-top-width: 8px; }
  .prompt-icon { width: 40px; height: 40px; }
  .prompt-icon svg { width: 24px; height: 24px; }
  .prompt-kicker { font-size: 16px; }
  .prompt-panel h2 { font-size: 20px; }
  .activity-info { margin-top: 8px; padding: 6px 12px; font-size: 16px; line-height: 1.55; }
  .prompt-question { margin: 10px 0 8px; font-size: 19px; }
  .choice-button { min-height: 52px; font-size: 18px; }
  .prompt-actions { margin-top: 8px; }
  .prompt-actions button { min-height: 48px; }
}
/* Confetti stays behind the words. */
.celebration { z-index: 0; }
.end-screen > :not(.celebration) { position: relative; z-index: 1; }

/* Phone: 2 × 8 preserves complete words at 15px (four columns leave <90px per face).
   At 390px: 370px board - 16px padding - 12px gap = two 171px cards. */
@media (max-width: 599px) {
  .game-screen { display: grid; grid-template-columns: 1fr; grid-template-rows: auto auto auto; grid-template-areas: none; gap: 8px; height: auto; }
  .game-status { grid-area: auto; position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "slots score" "message tries"; gap: 4px 8px; padding: 8px 0; background: var(--cream); border-radius: 0; }
  .status-head { display: contents; }
  .status-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .board { grid-area: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: 220px; gap: 14px 12px; width: 100%; max-width: none; }
  .card .card-band { min-height: 46px; padding: 5px 8px; font-size: 13px; gap: 6px; }
  .card .card-band > svg { width: 28px; height: 28px; }
  .card .card-text { font-size: 15px; padding: 8px 10px 13px; }
  .card-text rt { font-size: 10px; }
  .card .back-medal { --medal: 54px; }
  .game-controls { grid-area: auto; position: sticky; bottom: 0; z-index: 5; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); background: var(--cream); }
  .game-controls button { min-height: 56px; font-size: 15px; }
  .progress-slots { display: flex; gap: 3px; }
  .turn-message { font-size: 15px; }
}
@media (min-width: 600px) {
  .board { grid-template-rows: repeat(4, minmax(225px, 1fr)); }
}
@media (min-width: 900px) and (min-height: 560px) and (orientation: landscape) {
  .board { grid-area: board; width: 100%; max-width: none; justify-self: stretch; gap: 16px; }
  .game-status { position: sticky; top: 16px; }
  .game-controls { position: sticky; bottom: 16px; }
}
/* Short landscape screens keep a scrolling four-column board with horizontal labels. */
@media (min-width: 600px) and (max-height: 520px) and (orientation: landscape) {
  .game-screen { height: auto; }
  .board { grid-area: board; grid-template-rows: repeat(4, 240px); }
  .game-status { position: sticky; top: 8px; }
  .game-controls { position: sticky; bottom: 8px; }
  .card .card-band { padding-inline: 5px; gap: 4px; font-size: 12px; }
  .card .card-band > svg { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card *, .card::before, .card::after { animation: none !important; transition: none !important; }
  .card { scale: 1 !important; translate: none !important; }
  .card-back, .card-front { transform: none !important; }
  .card:not(.is-open) .card-front, .card.is-open .card-back { opacity: 0; }
  .card-sparkles { display: none; }
  .card.is-celebrating .matched-mark { opacity: 1; scale: 1; }
}
