/* 턴폴 포털판 — 앱(E:\tetris turnfall.css)과 같은 디자인, 색 변수는 --tf- (포털 style.css 와 안 겹치게). 어두운 판 하나로 통일하고, 블록 세 색(민트·보라·코랄)과 라임 포인트만 쓴다.
   레이아웃: 기본 = 휴대폰 세로 / 600px 이상 = 태블릿 세로 / 960px 이상 = 넓은 화면 3단 / 낮은 가로 화면 = 판 | 조작 2단 */
@font-face {
  font-family: 'Pretendard';
  src: url('fonts/pretendard.woff2') format('woff2-variations'), url('fonts/pretendard.woff2') format('woff2');
  font-weight: 45 920;
  font-display: swap;
}
:root {
  color-scheme: dark;
  --tf-bg: #0b1014;
  --tf-surface: #131a20;
  --tf-surface-2: #1a232b;
  --tf-surface-3: #222d36;
  --tf-surface-hover: #2a3640;
  --tf-board: #0e151a;
  --tf-border: rgba(255, 255, 255, .07);
  --tf-border-strong: rgba(255, 255, 255, .13);
  --tf-text: #eef3e8;
  --tf-text-muted: #9ba79f;
  --tf-text-subtle: #76827b;
  --tf-brand: #d9f975;
  --tf-brand-hover: #e6ff9a;
  --tf-brand-ink: #1c2a09;
  --tf-brand-subtle: rgba(217, 249, 117, .08);
  --tf-brand-line: rgba(217, 249, 117, .3);
  --tf-mint: #91e5cc;
  --tf-violet: #b8a0ff;
  --tf-coral: #ff8c7e;
  --tf-coral-hover: #ffa194;
  --tf-coral-ink: #3a130c;
  --tf-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35);
  --tf-glow-brand: 0 0 0 1px rgba(217, 249, 117, .5), 0 8px 24px rgba(217, 249, 117, .25);
  --tf-ease: cubic-bezier(.16, 1, .3, 1);
  --tf-stage: min(100%, calc(100dvh - 404px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--tf-bg); overscroll-behavior: none; }
body {
  margin: 0;
  min-height: 100dvh;
  padding: calc(8px + env(safe-area-inset-top, 0px)) env(safe-area-inset-right, 0px) calc(24px + env(safe-area-inset-bottom, 0px)) env(safe-area-inset-left, 0px);
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(217, 249, 117, .07), transparent 60%),
    radial-gradient(90% 50% at 100% 110%, rgba(184, 160, 255, .08), transparent 60%),
    var(--tf-bg);
  background-attachment: fixed;
  color: var(--tf-text);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  line-height: 1.6;
  letter-spacing: -.01em;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
p { max-width: 68ch; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--tf-brand); text-underline-offset: 3px; }
a:hover { color: var(--tf-brand-hover); }
:focus-visible { outline: 2px solid var(--tf-brand); outline-offset: 2px; }
.ic { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[data-pause] rect, [data-play] path { fill: currentColor; stroke: none; }
kbd { font-family: inherit; font-size: 11px; line-height: 1; padding: 4px 6px; border-radius: 4px; background: rgba(255, 255, 255, .06); color: var(--tf-text-subtle); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ── 바탕 배치 (휴대폰 세로) ───────────────────────── */
.turnfall-layout { max-width: 480px; margin: 0 auto; padding: 0 12px; display: flex; flex-direction: column; gap: 12px; }

/* 제목 줄: 글자 로고 + 모드 전환 */
.game-intro { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.intro-heading { min-width: 0; }
.intro-heading h1 { margin: 0; font-size: 22px; line-height: 1; font-weight: 850; letter-spacing: -.04em; white-space: nowrap; }
.intro-heading h1 br { display: none; }
.title-arrow { margin-left: 4px; color: var(--tf-brand); font-weight: 500; }
.eyebrow, .korean-title, .intro-copy, .key-legend { display: none; }
.mode-picker { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--tf-surface); border: 1px solid var(--tf-border); }
.mode-picker > button { display: flex; align-items: center; min-height: 36px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--tf-text-muted); font-size: 13px; font-weight: 600; transition: background .2s var(--tf-ease), color .2s var(--tf-ease); }
.mode-picker > button:hover { color: var(--tf-text); }
.mode-picker > button[aria-pressed="true"] { background: var(--tf-brand); color: var(--tf-brand-ink); }
.mode-picker > button[data-confirm="true"] { box-shadow: inset 0 0 0 2px var(--tf-coral); color: var(--tf-coral); }
.mode-picker small, .mode-dot { display: none; }
.mode-picker > button > span:nth-child(2) { display: contents; }

/* 짧은 퍼즐: 정해진 수 안에서 미리 보고 생각할 수 있는 판 */
.puzzle-panel { display: grid; width: var(--tf-stage); min-width: min(100%, 264px); gap: 6px; margin: 0 auto; padding: 12px 14px; border: 1px solid var(--tf-brand-line); border-radius: 16px; background: var(--tf-brand-subtle); }
.puzzle-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; color: var(--tf-text-muted); }
.puzzle-heading b { color: var(--tf-brand); font-size: 13px; font-variant-numeric: tabular-nums; }
.puzzle-panel select { width: 100%; min-width: 0; min-height: 44px; padding: 8px 30px 8px 10px; border: 1px solid var(--tf-border-strong); border-radius: 10px; background: var(--tf-surface); color: var(--tf-text); font: inherit; font-size: 14px; cursor: pointer; }
.puzzle-panel p { margin: 0; }
.puzzle-rule { color: var(--tf-text); font-size: 13px; line-height: 1.5; }
.puzzle-fine { color: var(--tf-text-muted); font-size: 11px; line-height: 1.6; }
body[data-mode="puzzle"] { --tf-stage: min(100%, calc(100dvh - 616px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px))); }
body[data-mode="puzzle"] .game-stage { min-width: min(100%, 264px); }
body[data-mode="puzzle"] .console-footer { grid-template-columns: minmax(0, 1fr) auto; }
body[data-mode="puzzle"] .hold-button { display: none; }
@media (max-width: 380px) {
  .game-intro { gap: 6px; }
  .intro-heading h1 { font-size: 18px; }
  .mode-picker { padding: 3px; gap: 0; }
  .game-intro .mode-picker > button { padding-inline: 8px; font-size: 12px; }
}

/* 게임기: 점수 · 판 · 에너지/다음/보관 */
.game-stage { width: var(--tf-stage); min-width: min(100%, 264px); margin-inline: auto; }
.game-console { position: relative; padding: 8px; border-radius: 24px; background: linear-gradient(180deg, var(--tf-surface-2), var(--tf-surface)); border: 1px solid var(--tf-border); box-shadow: var(--tf-shadow); }
.console-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 12px 12px; }
.score-group { display: grid; gap: 4px; }
.score-group > span, .console-best > span, .charge-heading > span, .piece-preview > span, .hold-button > span { font-size: 11px; font-weight: 600; letter-spacing: .08em; color: var(--tf-text-subtle); }
.score-group strong { font-size: 32px; line-height: 1; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.console-best { display: flex; align-items: center; gap: 12px; }
.console-best > span { display: grid; justify-items: end; gap: 4px; }
.console-best > span b { color: var(--tf-brand); font-size: 15px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.utility-buttons { display: flex; gap: 8px; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--tf-border); border-radius: 12px; background: var(--tf-surface-3); color: var(--tf-text-muted); transition: background .15s var(--tf-ease), color .15s var(--tf-ease), transform .1s var(--tf-ease); }
.icon-button .ic { width: 20px; height: 20px; }
.icon-button:hover:not(:disabled) { background: var(--tf-surface-hover); color: var(--tf-text); }
.icon-button:active:not(:disabled) { transform: scale(.96); }
.icon-button:disabled { opacity: .35; }
#sound-toggle[aria-pressed="true"] [data-off], #sound-toggle[aria-pressed="false"] [data-on] { display: none; }
#sound-toggle[aria-pressed="false"] { color: var(--tf-text-subtle); }
#pause-toggle[data-state="playing"] [data-play], #pause-toggle[data-state="paused"] [data-pause] { display: none; }
#pause-toggle[data-state="paused"]:not(:disabled) { background: var(--tf-brand); color: var(--tf-brand-ink); border-color: transparent; }

.board-wrap { position: relative; overflow: hidden; width: 100%; aspect-ratio: 1; border-radius: 16px; background: var(--tf-board); box-shadow: inset 0 0 0 1px var(--tf-border), inset 0 2px 12px rgba(0, 0, 0, .4); isolation: isolate; }
#turnfall-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#turnfall-canvas:focus { outline: none; }

/* 연쇄 글자: --level(1~4) 이 클수록 크게 */
.combo-toast { --level: 1; pointer-events: none; position: absolute; z-index: 1; inset: 34% 4% auto; display: grid; justify-items: center; gap: 4px; text-align: center; filter: drop-shadow(0 4px 16px rgba(0, 0, 0, .7)); }
.combo-toast b { font-size: calc(28px + var(--level) * 6px); font-weight: 850; letter-spacing: -.03em; line-height: 1.1; background: linear-gradient(90deg, var(--tf-brand), var(--tf-mint)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.combo-toast small { padding: 4px 12px; border-radius: 999px; background: rgba(12, 18, 22, .8); color: var(--tf-brand); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.combo-toast.is-pop { animation: pop .55s var(--tf-ease); }
@keyframes pop { 0% { opacity: 0; transform: scale(.6) translateY(12px); } 45% { opacity: 1; transform: scale(1.08); } 100% { transform: none; } }
#score { display: inline-block; transform-origin: left center; transition: transform .2s var(--tf-ease), color .2s var(--tf-ease); }
#score.is-bump { transform: scale(1.12); color: var(--tf-brand); }
/* 위험: 블록이 입구 근처까지 찼다 */
.board-wrap::after { content: ''; pointer-events: none; position: absolute; inset: 0; z-index: 1; border-radius: inherit; box-shadow: inset 0 0 0 2px rgba(255, 140, 126, .7), inset 0 24px 48px -16px rgba(255, 140, 126, .35); opacity: 0; transition: opacity .3s var(--tf-ease); }
.board-wrap.is-danger::after { opacity: 1; animation: danger 1.1s ease-in-out infinite; }
@keyframes danger { 50% { opacity: .45; } }

/* 시작 안내: 판 위쪽 빈자리에 — 아래에 준비된 블록이 그대로 보이게 */
.game-overlay { position: absolute; inset: 0; z-index: 3; padding: 24px; display: grid; place-items: start center; padding-top: 40px; background: linear-gradient(180deg, rgba(8, 12, 15, .9) 30%, rgba(8, 12, 15, 0) 62%); }
.game-overlay[data-state="paused"], .game-overlay[data-state="over"] { place-items: center; background: rgba(8, 12, 15, .78); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.overlay-card { width: 100%; max-width: 300px; text-align: center; animation: rise .4s var(--tf-ease); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.overlay-card h2 { margin: 0 0 4px; font-size: 24px; line-height: 1.3; font-weight: 750; letter-spacing: -.03em; white-space: pre-line; }
.overlay-card > p { margin: 0 auto; color: var(--tf-text-muted); font-size: 14px; line-height: 1.6; white-space: pre-line; }
.overlay-score { display: block; margin: 12px 0 4px; color: var(--tf-brand); font-size: 56px; line-height: 1.1; font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums; text-shadow: 0 0 32px rgba(217, 249, 117, .3); }
.game-overlay[data-state="over"] h2 { color: var(--tf-text-muted); font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.game-overlay.is-record h2 { color: var(--tf-brand); }
.game-overlay.is-record .overlay-score { animation: record 1.2s var(--tf-ease); }
@keyframes record { 0% { transform: scale(.6); opacity: 0; } 40% { transform: scale(1.08); opacity: 1; } 100% { transform: none; } }
.start-button { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 52px; margin-top: 16px; padding: 12px 24px; border: 0; border-radius: 14px; background: var(--tf-brand); color: var(--tf-brand-ink); font-size: 16px; font-weight: 750; box-shadow: var(--tf-glow-brand); transition: background .15s var(--tf-ease), transform .1s var(--tf-ease); }
.start-button:hover { background: var(--tf-brand-hover); }
.start-button:active { transform: scale(.98); }
.restart-button { min-height: 44px; margin-top: 8px; padding: 8px 16px; border: 0; border-radius: 12px; background: transparent; color: var(--tf-text-muted); font-size: 14px; }
.restart-button:hover { color: var(--tf-text); }

/* 판이 작은 화면(작은 폰·가로 모드): 안내를 줄여 블록이 더 보이게 */
.board-wrap { container-type: inline-size; }
@container (max-width: 300px) {
  .game-overlay { padding: 16px; }
  .game-overlay[data-state="ready"] { padding-top: 20px; }
  .overlay-card h2 { font-size: 19px; }
  .overlay-card > p { font-size: 13px; }
  .overlay-score { font-size: 44px; margin-top: 8px; }
  .start-button { min-height: 44px; margin-top: 12px; }
  .coach { top: 8px; padding: 4px 12px 4px 4px; gap: 8px; }
  .coach-step { width: 24px; height: 24px; }
  .coach p { font-size: 12px; }
}

/* 첫 판 안내: 판 위쪽에 한 줄 — 판을 가리지 않는다 */
.coach { pointer-events: none; position: absolute; z-index: 2; top: 12px; left: 50%; display: flex; align-items: center; gap: 12px; width: max-content; max-width: calc(100% - 24px); padding: 8px 16px 8px 8px; border-radius: 999px; background: rgba(12, 18, 22, .92); border: 1px solid var(--tf-brand-line); box-shadow: 0 8px 24px rgba(0, 0, 0, .45); transform: translateX(-50%); animation: coach-in .35s var(--tf-ease); }
@keyframes coach-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translateX(-50%); } }
.coach-step { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--tf-brand); color: var(--tf-brand-ink); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.coach p { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.4; }
.coach b { color: var(--tf-brand); font-weight: 700; }
/* 안내가 가리키는 버튼: 맥박처럼 빛난다 */
.is-coached:not(:disabled) { position: relative; animation: coach-pulse 1.4s var(--tf-ease) infinite; }
@keyframes coach-pulse { 0%, 100% { box-shadow: var(--tf-glow-brand); } 50% { box-shadow: 0 0 0 4px rgba(217, 249, 117, .55), 0 0 32px rgba(217, 249, 117, .45); } }

.console-footer { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 16px; padding: 12px 8px 4px 12px; }
.charge-heading { white-space: nowrap; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.charge-heading b { color: var(--tf-brand); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.charge-pips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 8px 0 4px; }
.charge-pips > span { height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .08); transition: background .3s var(--tf-ease), box-shadow .3s var(--tf-ease); }
.charge-pips > .is-full { background: var(--tf-brand); box-shadow: 0 0 12px rgba(217, 249, 117, .4); }
.charge-pips > .is-pop { animation: pip .45s var(--tf-ease); }
@keyframes pip { 0% { transform: scaleY(1); } 35% { transform: scale(1.15, 1.8); box-shadow: 0 0 20px rgba(217, 249, 117, .8); } 100% { transform: none; } }
.charge-indicator { margin: -4px -8px; padding: 4px 8px; border-radius: 12px; }
.charge-indicator.is-coached { animation: coach-pulse 1.4s var(--tf-ease) infinite; }
#turn-progress { display: block; width: 100%; height: 3px; appearance: none; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .06); overflow: hidden; color: rgba(217, 249, 117, .55); }
#turn-progress::-webkit-progress-bar { background: rgba(255, 255, 255, .06); }
#turn-progress::-webkit-progress-value { background: rgba(217, 249, 117, .55); border-radius: 999px; }
#turn-progress::-moz-progress-bar { background: rgba(217, 249, 117, .55); }
.piece-preview { display: grid; gap: 4px; }
#next-canvas { display: block; width: 90px; height: 29px; }
.hold-button { display: grid; gap: 4px; width: 60px; padding: 6px 8px; border: 1px solid var(--tf-border); border-radius: 12px; background: var(--tf-surface-3); text-align: left; transition: background .15s var(--tf-ease), transform .1s var(--tf-ease); }
.hold-button:hover:not(:disabled) { background: var(--tf-surface-hover); }
.hold-button:disabled { opacity: .45; }
#hold-canvas { display: block; width: 42px; height: 28px; }

/* 조작 버튼 */
.game-controls { margin-top: 12px; }
.turn-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.turn-control { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 16px; border: 1px solid var(--tf-brand-line); border-radius: 16px; background: var(--tf-brand-subtle); color: var(--tf-text); text-align: left; touch-action: manipulation; -webkit-user-select: none; user-select: none; transition: background .2s var(--tf-ease), color .2s var(--tf-ease), box-shadow .2s var(--tf-ease), transform .1s var(--tf-ease); }
.turn-icon { display: grid; place-items: center; color: var(--tf-brand); }
.turn-icon .ic { width: 28px; height: 28px; }
.turn-control > span:nth-child(2) { flex: 1; display: grid; gap: 2px; min-width: 0; }
.turn-control b { font-size: 15px; font-weight: 700; line-height: 1.3; }
.turn-control small { color: var(--tf-text-muted); font-size: 12px; line-height: 1.3; }
.turn-control:hover:not(:disabled) { background: rgba(217, 249, 117, .14); }
/* 이 방향으로 돌리면 연쇄가 난다 → 꽉 찬 라임으로 "지금 누르세요" */
.turn-control[data-chain="true"]:not(:disabled) { background: var(--tf-brand); border-color: transparent; color: var(--tf-brand-ink); box-shadow: var(--tf-glow-brand); }
.turn-control[data-chain="true"]:not(:disabled) .turn-icon, .turn-control[data-chain="true"]:not(:disabled) small { color: var(--tf-brand-ink); }
.turn-control[data-chain="true"]:not(:disabled) small { opacity: .75; font-weight: 600; }
.turn-control:disabled { opacity: .4; }
.block-controls { display: grid; grid-template-columns: 1fr 1fr 1fr 1.7fr; gap: 8px; margin-top: 8px; }
.block-control { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 60px; padding: 8px; border: 1px solid var(--tf-border); border-radius: 16px; background: var(--tf-surface-2); color: var(--tf-text); touch-action: none; -webkit-user-select: none; user-select: none; transition: background .15s var(--tf-ease), transform .1s var(--tf-ease); }
.block-control > small { font-size: 11px; color: var(--tf-text-subtle); line-height: 1; }
.block-control:hover:not(:disabled) { background: var(--tf-surface-3); }
.block-control:disabled { opacity: .4; }
.block-control--drop { flex-direction: row; gap: 12px; border-color: transparent; background: var(--tf-coral); color: var(--tf-coral-ink); }
.block-control--drop > span { display: grid; gap: 2px; font-size: 15px; font-weight: 750; line-height: 1.2; text-align: left; }
.block-control--drop small { font-size: 11px; font-weight: 600; letter-spacing: .08em; opacity: .6; }
.block-control--drop:hover:not(:disabled) { background: var(--tf-coral-hover); }
.turn-control:active:not(:disabled), .block-control:active:not(:disabled), .hold-button:active:not(:disabled) { transform: scale(.97); }
/* 가운데 단이 좁을 때(낮은 PC 화면): 키 표시를 빼고 글자가 꺾이지 않게 */
.game-stage { container-type: inline-size; }
@container (max-width: 400px) {
  .turn-control { gap: 8px; padding-inline: 12px; }
  .turn-control kbd { display: none; }
  .turn-control b, .block-control--drop > span { white-space: nowrap; }
  .block-control--drop { gap: 8px; }
}
.game-status { min-height: 20px; margin: 12px auto 0; text-align: center; font-size: 13px; color: var(--tf-text-subtle); line-height: 1.5; }
/* 입구가 막혀 판 돌리기를 기다릴 때: 멈춘 게 아니라는 것을 크게 알린다 */
.game-status.is-alert { padding: 8px 12px; border-radius: 12px; background: var(--tf-brand); color: var(--tf-brand-ink); font-size: 14px; font-weight: 700; box-shadow: var(--tf-glow-brand); }

/* 기록 · 설명 */
.game-sidebar { margin-top: 12px; display: grid; gap: 16px; }
.session-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.session-metrics > div { display: grid; gap: 4px; padding: 12px 16px; border-radius: 16px; background: var(--tf-surface); border: 1px solid var(--tf-border); }
.session-metrics dt { font-size: 12px; color: var(--tf-text-subtle); }
.session-metrics dd { display: flex; align-items: baseline; gap: 4px; margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.session-metrics small { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--tf-text-subtle); }
.save-panel { display: grid; gap: 4px; }
.save-panel > span { font-size: 11px; font-weight: 600; letter-spacing: .08em; color: var(--tf-text-subtle); }
.save-panel p { margin: 0; font-size: 13px; color: var(--tf-text-muted); }
.save-panel button { justify-self: start; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--tf-brand); font-size: 13px; }
.save-panel button:hover { color: var(--tf-brand-hover); }
.overlay-card .overlay-note { margin-top: 8px; color: var(--tf-brand); font-size: 13px; }
.guide-fine { margin: 0; font-size: 12px; line-height: 1.8; color: var(--tf-text-subtle); }
.noscript { padding: 24px; text-align: center; }

/* 키 높이가 낮은 휴대폰: 버튼을 조금 낮춰 판을 지킨다 */
@media (max-height: 760px) and (max-width: 599px) {
  :root { --tf-stage: min(100%, calc(100dvh - 358px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px))); }
  .game-intro { min-height: 44px; }
  .console-header { padding: 4px 4px 8px 8px; }
  .score-group strong { font-size: 26px; }
  .console-footer { padding-top: 8px; }
  .turn-control { min-height: 52px; padding-block: 4px; }
  .turn-icon .ic { width: 24px; height: 24px; }
  .block-control { min-height: 52px; }
  .block-control > small { display: none; }
  .game-controls, .game-status { margin-top: 8px; }
  .icon-button { width: 40px; height: 40px; }
  .mode-picker > button { min-height: 32px; padding: 0 12px; }
  .turn-control { min-height: 48px; }
  .turn-control small { font-size: 11px; }
  .block-control { min-height: 48px; }
  /* 안내 줄은 경고일 때만 (판을 한 줄이라도 더 키운다) */
  .game-status:not(.is-alert) { display: none; }
  .block-control--drop { gap: 8px; }
  .block-control--drop > span { white-space: nowrap; }
  .block-control--drop small { display: none; }
}

/* ── 태블릿 세로 ───────────────────────── */
@media (min-width: 600px) {
  :root { --tf-stage: min(100%, calc(100dvh - 432px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px))); }
  body { padding-top: calc(24px + env(safe-area-inset-top, 0px)); }
  .turnfall-layout { max-width: 640px; padding: 0 24px; gap: 16px; }
  .intro-heading h1 { font-size: 28px; }
  .game-stage { min-width: 420px; }
  #next-canvas { width: 120px; height: 38px; }
  .hold-button { width: 72px; }
  #hold-canvas { width: 54px; height: 36px; }
}

/* ── 넓은 가로 화면 3단: 소개 | 게임 | 기록 (세로로 긴 태블릿은 1단) ───────────────────────── */
@media (min-width: 960px) and (min-height: 600px) and (min-aspect-ratio: 6/5) {
  :root { --tf-stage: clamp(320px, min(100dvh - 380px, 100vw - 600px), 560px); }
  body { padding-top: calc(32px + env(safe-area-inset-top, 0px)); }
  .turnfall-layout { max-width: 1280px; padding: 0 40px; display: grid; grid-template-columns: minmax(220px, 1fr) var(--tf-stage) minmax(200px, .9fr); align-items: start; gap: 48px; }
  .game-stage { min-width: 320px; }
  .game-intro { display: block; padding-top: 24px; }
  .eyebrow { display: flex; align-items: center; gap: 8px; margin: 0 0 24px; font-size: 11px; font-weight: 600; letter-spacing: .16em; color: var(--tf-brand); opacity: .8; }
  .eyebrow > span { width: 6px; height: 6px; border-radius: 50%; background: var(--tf-brand); }
  .intro-heading h1 { font-size: clamp(56px, 6vw, 84px); line-height: .92; letter-spacing: -.06em; }
  .intro-heading h1 br { display: inline; }
  .korean-title { display: block; margin: 16px 0 0; font-size: 12px; letter-spacing: .3em; color: var(--tf-text-subtle); }
  .intro-copy { display: block; margin: 32px 0 12px; font-size: 24px; line-height: 1.5; font-weight: 700; letter-spacing: -.03em; }
  .intro-copy em { font-style: normal; color: var(--tf-brand); }
  .mode-picker { display: grid; gap: 8px; margin-top: 32px; padding: 0; border: 0; border-radius: 0; background: none; }
  .mode-picker > button { min-height: 64px; padding: 12px 16px; gap: 12px; border-radius: 16px; background: var(--tf-surface); border: 1px solid var(--tf-border); text-align: left; }
  .mode-picker > button > span:nth-child(2) { display: grid; gap: 2px; flex: 1; }
  .mode-picker > button b { font-size: 15px; color: var(--tf-text); }
  .mode-picker small { display: block; font-size: 12px; font-weight: 400; color: var(--tf-text-muted); }
  .mode-picker > button[aria-pressed="true"] { background: var(--tf-brand-subtle); border-color: var(--tf-brand-line); color: var(--tf-text); }
  .mode-dot { display: block; width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--tf-text-subtle); }
  [aria-pressed="true"] > .mode-dot { background: var(--tf-brand); border-color: var(--tf-brand); box-shadow: 0 0 0 4px rgba(217, 249, 117, .15); }
  .key-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 32px 0 0; padding-top: 24px; border-top: 1px solid var(--tf-border); }
  .key-legend > div { display: flex; align-items: center; gap: 8px; }
  .key-legend dt { display: flex; gap: 4px; }
  .key-legend dd { margin: 0; font-size: 13px; color: var(--tf-text-muted); }
  .key-legend kbd { min-width: 24px; text-align: center; }
  .game-sidebar { margin-top: 0; padding-top: 24px; gap: 24px; }
  .session-metrics { grid-template-columns: 1fr; }
  .session-metrics > div { display: flex; align-items: center; justify-content: space-between; }
}
@media (min-width: 960px) and (min-height: 600px) and (min-aspect-ratio: 6/5) and (pointer: coarse) { .key-legend { display: none; } }

/* ── 낮은 가로 화면(휴대폰 가로): 판 | 조작 ───────────────────────── */
@media (orientation: landscape) and (max-height: 560px) {
  body { padding: calc(8px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px)); }
  .turnfall-layout { max-width: none; padding: 0; display: grid; grid-template-columns: auto minmax(240px, 360px); grid-template-areas: "console intro" "console controls" "console status"; grid-template-rows: auto 1fr auto; justify-content: center; align-items: start; gap: 8px 24px; }
  .game-stage { display: contents; }
  .game-console { grid-area: console; width: calc(100dvh - 144px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); min-width: 220px; }
  .console-header { padding: 4px 4px 8px 8px; }
  .score-group strong { font-size: 24px; }
  .console-footer { padding-top: 8px; gap: 12px; }
  .game-intro { grid-area: intro; }
  .game-controls { grid-area: controls; margin: 0; align-self: center; }
  .turn-control, .block-control { min-height: 52px; }
  .block-controls { grid-template-columns: repeat(3, 1fr); }
  .block-control--drop { grid-column: 1 / -1; }
  .game-status { grid-area: status; margin: 0; }
  .game-sidebar { display: none; }
  .game-status:not(.is-alert) { display: none; }
  .charge-heading > span { display: none; }
  .charge-heading { justify-content: flex-start; }
  #next-canvas { width: 72px; height: 24px; }
  .hold-button { width: 52px; padding: 4px 6px; }
  #hold-canvas { width: 36px; height: 24px; }
}

@media (pointer: coarse) { kbd { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .game-overlay { -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ── 포털에만 있는 것: 머리말 · 꼬리말 · 계정 단추 · 랭킹 ───────────────────────── */
.site-header { max-width: 1280px; height: 64px; margin: 0 auto; padding: 0 40px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 4px; color: var(--tf-text); font-size: 17px; font-weight: 850; letter-spacing: -.04em; text-decoration: none; }
.brand:hover { color: var(--tf-text); }
.brand span { color: var(--tf-text-subtle); font-weight: 450; }
.brand i { margin-left: 4px; color: var(--tf-brand); font-size: 22px; font-style: normal; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--tf-text-muted); font-size: 13px; text-decoration: none; }
.back-link:hover { color: var(--tf-text); }
.site-header .acct__login { min-height: 40px; padding: 8px 16px; border: 1px solid var(--tf-border-strong); border-radius: 999px; background: var(--tf-surface-3); color: var(--tf-text); font-size: 13px; font-weight: 600; }
.site-header .acct__login:hover { background: var(--tf-surface-hover); }
.site-header .acct__me { min-height: 40px; padding: 4px 12px 4px 4px; border-color: var(--tf-border-strong); background: var(--tf-surface-2); color: var(--tf-text); font-size: 13px; }
.site-header .acct__me:hover { background: var(--tf-surface-3); }
.site-header .acct__avatar { width: 30px; height: 30px; font-size: 13px; }
.site-footer { max-width: 1280px; margin: 32px auto 0; padding: 24px 40px; display: flex; justify-content: space-between; gap: 16px; color: var(--tf-text-subtle); font-size: 12px; }
.site-footer a { color: var(--tf-text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--tf-text); }
.save-panel button { min-height: 44px; }

.rank-board { box-sizing: border-box; max-width: 640px; margin: 32px auto 0; padding: 24px; border-radius: 24px; background: var(--tf-surface); border: 1px solid var(--tf-border); color: var(--tf-text); }
.rank-board .eyebrow { display: block; margin: 0 0 4px; font-size: 11px; font-weight: 600; letter-spacing: .16em; color: var(--tf-brand); opacity: .8; }
.rank-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.rank-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.rank-head > span { flex: none; font-size: 12px; color: var(--tf-text-subtle); }
.rank-mine { margin: 8px 0 0; font-size: 14px; font-weight: 600; color: var(--tf-brand); }
.rank-list { list-style: none; margin: 16px 0 0; padding: 0; }
.rank-list li { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 8px; align-items: center; min-height: 44px; padding: 0 12px; border-top: 1px solid var(--tf-border); font-size: 14px; }
.rank-list li:nth-child(-n+3) b { color: var(--tf-brand); }
.rank-list li.is-me { border-radius: 12px; border-top-color: transparent; background: var(--tf-brand-subtle); box-shadow: inset 0 0 0 1px var(--tf-brand-line); }
.rank-list b, .rank-list strong { font-variant-numeric: tabular-nums; }
.rank-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tf-text-muted); }
.rank-list .rank-empty { display: block; padding: 16px 12px; color: var(--tf-text-subtle); }
.rank-login { display: block; width: 100%; min-height: 48px; margin-top: 16px; border: 0; border-radius: 14px; background: var(--tf-brand); color: var(--tf-brand-ink); font-size: 15px; font-weight: 700; cursor: pointer; transition: background .15s var(--tf-ease); }
.rank-login:hover { background: var(--tf-brand-hover); }
.rank-login[hidden] { display: none; }
.rank-fine { max-width: 68ch; margin: 16px 0 0; font-size: 12px; color: var(--tf-text-subtle); }

@media (max-width: 599px) {
  .site-header { height: 52px; padding: 0 16px; gap: 8px; }
  .brand { font-size: 14px; }
  .brand i { font-size: 18px; }
  .header-actions { gap: 8px; }
  .back-link { font-size: 12px; }
  .site-header .acct__name { display: none; }
  .site-header .acct__me { padding: 4px; }
  .site-footer { padding: 24px 16px; }
  .rank-board { margin: 24px 12px 0; padding: 16px; }
}
/* 넓은 화면은 머리말(64px)만큼 판을 줄여 조작 버튼까지 한 화면에 */
@media (min-width: 960px) and (min-height: 600px) and (min-aspect-ratio: 6/5) {
  :root { --tf-stage: clamp(320px, min(100dvh - 444px, 100vw - 600px), 560px); }
}
@media (orientation: landscape) and (max-height: 560px) {
  .site-header, .site-footer, .rank-board { display: none; }
}

/* 넓은 화면의 퍼즐 목표는 판 오른쪽에 두어 기존 조작 높이를 유지한다. */
@media (min-width: 960px) and (min-height: 600px) and (min-aspect-ratio: 6/5) {
  body[data-mode="puzzle"] { --tf-stage: clamp(320px, min(100dvh - 444px, 100vw - 600px), 560px); }
  body[data-mode="puzzle"] .turnfall-layout { grid-template-areas: "intro stage puzzle" "intro stage sidebar"; grid-template-rows: auto 1fr; row-gap: 12px; }
  body[data-mode="puzzle"] .game-intro { grid-area: intro; }
  body[data-mode="puzzle"] .game-stage { grid-area: stage; }
  body[data-mode="puzzle"] .puzzle-panel { grid-area: puzzle; width: 100%; min-width: 0; margin: 0; }
  body[data-mode="puzzle"] .game-sidebar { grid-area: sidebar; }
}
@media (orientation: landscape) and (max-height: 560px) {
  body[data-mode="puzzle"] .turnfall-layout { grid-template-areas: "console intro" "console puzzle" "console controls" "console status"; grid-template-rows: auto auto 1fr auto; }
  .puzzle-panel { grid-area: puzzle; width: auto; min-width: 0; margin: 0; padding: 8px 10px; gap: 4px; }
  .puzzle-rule { font-size: 12px; }
  .puzzle-fine { font-size: 10px; line-height: 1.4; }
  body[data-mode="puzzle"] .turn-control, body[data-mode="puzzle"] .block-control { min-height: 44px; }
}

/* ── 설정 창: 어썸 계정 · 소리 · 첫 판 안내 · 의견 보내기 (모든 게임 공통 문구, 포털 docs/GAME-ACCOUNT-FEEDBACK.md) ── */
.settings-sheet { width: min(100% - 32px, 400px); max-height: calc(100dvh - 32px); margin: auto; padding: 24px; border: 1px solid var(--tf-border-strong); border-radius: 24px; background: var(--tf-surface); color: var(--tf-text); box-shadow: var(--tf-shadow); overflow-y: auto; }
.settings-sheet::backdrop { background: rgba(8, 12, 15, .72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.settings-sheet[open] { animation: rise .3s var(--tf-ease); }
.settings-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.settings-head h2 { margin: 0; font-size: 20px; font-weight: 750; letter-spacing: -.02em; }
.settings-group { display: grid; gap: 12px; padding: 16px 0; border-top: 1px solid var(--tf-border); }
.settings-group h3 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--tf-text-subtle); }
.account-row { display: flex; align-items: center; gap: 12px; }
.account-avatar { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--tf-surface-3); color: var(--tf-text-muted); }
.account-avatar .ic { width: 20px; height: 20px; }
.account-who { display: grid; gap: 2px; min-width: 0; }
.account-who b { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-who small { font-size: 13px; line-height: 1.5; color: var(--tf-text-muted); }
.account-login { min-height: 48px; border: 0; border-radius: 14px; background: var(--tf-brand); color: var(--tf-brand-ink); font-size: 15px; font-weight: 700; transition: background .15s var(--tf-ease), transform .1s var(--tf-ease); }
.account-login:hover:not(:disabled) { background: var(--tf-brand-hover); }
.account-login:disabled, .account-login[data-loading] { opacity: .6; }
.account-logout { justify-self: start; min-height: 44px; padding: 0 16px; border: 1px solid var(--tf-border-strong); border-radius: 12px; background: transparent; color: var(--tf-text-muted); font-size: 14px; transition: background .15s var(--tf-ease), color .15s var(--tf-ease); }
.account-logout:hover:not(:disabled) { background: var(--tf-surface-2); color: var(--tf-text); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; }
.settings-row > span { display: grid; gap: 2px; }
.settings-row b { font-size: 15px; font-weight: 600; }
.settings-row small { font-size: 12px; color: var(--tf-text-subtle); }
.switch { position: relative; flex: none; width: 52px; height: 32px; padding: 0; border: 0; border-radius: 999px; background: var(--tf-surface-3); transition: background .2s var(--tf-ease); }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--tf-text-muted); transition: transform .2s var(--tf-ease), background .2s var(--tf-ease); }
.switch[aria-checked="true"] { background: var(--tf-brand); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--tf-brand-ink); }
.settings-button { flex: none; min-height: 40px; padding: 0 16px; border: 1px solid var(--tf-border-strong); border-radius: 12px; background: var(--tf-surface-2); color: var(--tf-text); font-size: 13px; font-weight: 600; transition: background .15s var(--tf-ease); }
.settings-button:hover:not(:disabled) { background: var(--tf-surface-3); }
.settings-button:disabled { max-width: 160px; border-color: transparent; background: transparent; color: var(--tf-brand); white-space: normal; text-align: right; }
.settings-feedback { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; margin-top: 8px; border: 1px solid var(--tf-brand-line); border-radius: 14px; background: var(--tf-brand-subtle); color: var(--tf-text); font-size: 15px; font-weight: 600; transition: background .15s var(--tf-ease); }
.settings-feedback .ic { width: 20px; height: 20px; color: var(--tf-brand); }
.settings-feedback:hover { background: rgba(217, 249, 117, .14); }
.settings-fine { margin: 12px 0 0; font-size: 12px; line-height: 1.6; color: var(--tf-text-subtle); }
