/* 오늘의 지뢰밭 60초 — 자체 팔레트(초록 들판 칸 + 코랄 강조). 폰트는 기기 글꼴, 한글 폴백 Noto Sans KR. */
:root {
  --bg: #f2f6fb; --surface: #ffffff; --ink: #142031; --muted: #56657a; --line: #dbe3ee;
  --tile: #2fae78; --tile-hi: #3cc489; --tile-flag: #2fae78;
  --open: #ffffff; --open-line: #e3eaf3;
  /* 대비(WCAG): 채움색+흰 글자 5.24:1, 글자색은 배경 위 4.5:1 이상. 채움(--accent)과 글자용(--*-text)을 나눈다. */
  --accent: #c9351a; --accent-ink: #ffffff; --accent-soft: #ffe7e0; --accent-text: #c9351a;
  --hit: #c92a3c; --low: #c92a3c; --ok: #2fae78; --ok-text: #147049; --low-text: #c92a3c;
  --n1: #13867d; --n2: #6a43d4; --n3: #cf2f79; --n4: #b86e00; --n5: #0b6f8f; --n6: #9a2c9e; --n7: #2c3a4e; --n8: #6a7a90;
  --cell: 40px; --r: 10px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1620; --surface: #16212e; --ink: #e8eef6; --muted: #9aa8ba; --line: #253447;
    --tile: #2a9a6b; --tile-hi: #33b07c; --open: #1b2736; --open-line: #243345;
    --accent: #c9351a; --accent-soft: #3a2320; --accent-text: #ff8a6e; --ok-text: #2fae78; --low-text: #ff6b7a;
    --n1: #4fd1c2; --n2: #a58bff; --n3: #ff6fae; --n4: #ffb547; --n5: #56c2f0; --n6: #e27be6; --n7: #d6deea; --n8: #9aa8ba;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
html.playing, html.playing body { overflow: hidden; overscroll-behavior: none; height: 100dvh; }
button, a { font: inherit; }
[hidden] { display: none !important; }

/* ── 배치: 기본 = 좁은 화면(세로 1열). 넓은 화면(≥1024px, 폴드 펼침 1,100·카톡 1,066 포함) = 좌 60% 판 + 우 40% 패널 ── */
.app { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); gap: 12px; }
.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.panel { width: 100%; max-width: 560px; }
@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: 60% 40%; align-items: center; padding: 24px 0; gap: 0; height: 100dvh; }
  .stage { justify-self: center; padding: 0 24px; }
  .panel { justify-self: start; padding: 0 40px 0 8px; max-width: 440px; }
}
@media (max-width: 1023px) { body.big .app { padding-left: 8px; padding-right: 8px; } } /* 큰 판(12·14칸)은 좁은 화면에서 좌우 여백을 줄여 가로 넘침 0 */
body[data-screen="start"] .hud, body[data-screen="start"] .modebar, body[data-screen="start"] .panel-play { display: none; }
body[data-screen="play"] .panel-start { display: none; }
body[data-screen="result"] .app { display: none; }
@media (max-width: 1023px) { body[data-screen="play"] .panel-play { display: none; } }
body[data-screen="play"] .app { height: 100dvh; min-height: 0; justify-content: center; }

/* ── 상단 바: 남은 시간 · 남은 지뢰 · 점수 + 시간 막대 ── */
.hud { width: calc(var(--cell) * var(--cols, 9)); display: grid; grid-template-columns: auto 1fr 1fr; align-items: end; gap: 4px 16px; }
.hud-time { display: flex; align-items: baseline; gap: 2px; }
.hud-time b { font-size: 32px; line-height: 1; font-variant-numeric: tabular-nums; font-weight: 800; transition: color .3s; }
.hud-time span { color: var(--muted); font-size: 14px; }
.hud-item { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--muted); }
.hud-item b { font-size: 20px; color: var(--ink); font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 99px; overflow: hidden; background: color-mix(in srgb, var(--line) 60%, transparent); }
.bar i { display: block; height: 100%; background: var(--ok); transform-origin: left center; transform: scaleX(1); transition: background-color .3s; }
body.low .hud-time b { color: var(--low-text); }
body.low .bar i { background: var(--low); }

/* ── 판 ── */
.grid-wrap { touch-action: none; }
.grid { display: grid; grid-auto-rows: var(--cell); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.row { display: grid; grid-template-columns: repeat(var(--cols, 9), var(--cell)); grid-auto-rows: var(--cell); }
#rStatus:focus { outline: none; }
.cell { width: var(--cell); height: var(--cell); margin: 0; padding: 0; border: 2px solid transparent; background-clip: padding-box; border-radius: var(--r); background-color: var(--tile); color: var(--ink); display: grid; place-items: center; font-weight: 800; font-size: calc(var(--cell) * .5); line-height: 1; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; transition: background-color .18s ease, transform .12s ease; }
.cell:focus-visible { outline: 3px solid var(--accent-text); outline-offset: -2px; }
@media (hover: hover) { body[data-screen="play"] .cell[data-s="c"]:hover, body[data-screen="play"] .cell[data-s="f"]:hover { background-color: var(--tile-hi); } }
.cell[data-s="c"]:active { transform: scale(.94); }
.cell[data-s="o"] { background-color: var(--open); box-shadow: inset 0 0 0 1px var(--open-line); cursor: default; }
.cell[data-s="h"] { background-color: var(--hit); color: #fff; }
.cell svg { width: 62%; height: 62%; }
.n1 { color: var(--n1); } .n2 { color: var(--n2); } .n3 { color: var(--n3); } .n4 { color: var(--n4); }
.n5 { color: var(--n5); } .n6 { color: var(--n6); } .n7 { color: var(--n7); } .n8 { color: var(--n8); }
@media (prefers-reduced-motion: no-preference) {
  .cell.pop { animation: pop .28s cubic-bezier(.16, 1, .3, 1) both; animation-delay: var(--d, 0ms); }
  .cell.plant svg { animation: plant .22s cubic-bezier(.16, 1, .3, 1) both; }
  .bar i { transition: background-color .3s, transform .2s linear; }
}
@keyframes pop { from { transform: scale(.7); opacity: .2; } to { transform: scale(1); opacity: 1; } }
@keyframes plant { from { transform: translateY(-30%) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* 시작 화면 미리보기: 닫힌 칸은 조금 옅게 */
body[data-screen="start"] .cell[data-s="c"] { opacity: .88; }

/* ── 열기/깃발 토글 ── */
.modebar { display: grid; grid-template-columns: 1fr 1fr; width: calc(var(--cell) * var(--cols, 9)); max-width: 100%; padding: 4px; border-radius: 99px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.modebar button { min-height: 44px; border: 0; border-radius: 99px; background: transparent; color: var(--muted); font-weight: 700; font-size: 16px; cursor: pointer; transition: background-color .2s, color .2s; touch-action: manipulation; }
.modebar button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.modebar button[data-mode="flag"][aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.modebar button:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }

/* ── 시작 화면 토글: 판 종류(오늘의 판·연습 판) 한 줄 + 연습 판일 때만 난이도 3단 한 줄 ── */
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 0 0 12px; max-width: 320px; border-radius: 99px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.pick button { min-height: 44px; border: 0; border-radius: 99px; background: transparent; color: var(--muted); font-weight: 800; font-size: 16px; cursor: pointer; touch-action: manipulation; transition: background-color .2s, color .2s; }
.pick button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.pick button:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }
.pick-level { grid-template-columns: repeat(3, 1fr); border-radius: 22px; }
.pick-level button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 2px; border-radius: 18px; line-height: 1.15; }
.pick-level small { font-size: 11px; font-weight: 700; opacity: .9; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pick-note { margin: 0 0 16px; font-size: 14px; line-height: 1.5; color: var(--muted); }

/* ── 패널 ── */
h1 { font-size: clamp(28px, 4.2vw, 44px); line-height: 1.15; letter-spacing: -0.02em; margin: 4px 0 6px; font-weight: 800; }
h1 em { font-style: normal; color: var(--accent-text); }
.sub { margin: 0 0 20px; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 28px; border-radius: 99px; border: 0; font-weight: 800; font-size: 18px; cursor: pointer; text-decoration: none; touch-action: manipulation; transition: transform .12s ease, background-color .2s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn-main { background: var(--accent); color: var(--accent-ink); }
.btn-sub { background: var(--ink); color: var(--bg); }
#btnPractice { background: #147049; color: #fff; } /* 채움 #147049 + 흰 글자 대비 6.5:1(라이트·다크 공통) */
.btn-link { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
#btnStart { width: 100%; max-width: 320px; }
.rules { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 10px; line-height: 1.55; color: var(--muted); font-size: 15px; }
.rules b { color: var(--ink); margin-right: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; gap: 24px; margin: 0 0 16px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.note, .play-tip { font-size: 13px; color: var(--muted); line-height: 1.6; margin: 0 0 8px; }

/* ── 결과 화면 ── */
.result { min-height: 100dvh; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.result-inner { max-width: 1000px; margin: 0 auto; display: grid; gap: 24px; }
@media (min-width: 1024px) { .result-inner { grid-template-columns: 60% 1fr; align-items: center; column-gap: 40px; padding-top: 24px; } }
.res-status { margin: 0; font-weight: 700; color: var(--muted); }
.res-status.clear { color: var(--ok-text); }
.res-status.mine { color: var(--low-text); }
.res-score { margin: 4px 0; display: flex; align-items: baseline; gap: 6px; }
.res-score b { font-size: clamp(56px, 10vw, 88px); line-height: 1; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.res-safe { margin: 0 0 16px; color: var(--muted); }
.res-safe b { color: var(--ink); }
.mini { display: grid; grid-template-columns: repeat(var(--cols, 9), 1fr); gap: 4px; width: min(100%, 300px); }
.mini i { aspect-ratio: 1; border-radius: 5px; background: var(--line); }
.mini i.o { background: var(--tile); }
.mini i.h { background: var(--hit); }
.res-actions { display: grid; gap: 10px; align-content: start; max-width: 360px; width: 100%; }
.next { margin: 8px 0 0; color: var(--muted); }
.next b { color: var(--ink); font-variant-numeric: tabular-nums; }
.res-rec { margin: 0; color: var(--muted); font-size: 14px; }
.toast { min-height: 1.4em; margin: 0; font-weight: 700; color: var(--ok-text); }
.copybox { width: 100%; height: 12em; font: 14px/1.4 var(--font); border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 10px; }
/* 광고 자리: 요약 격자와 150px 이상 떨어진 맨 아래 한 줄(넓은 화면에서도 두 열 아래) */
.ad-slot { grid-column: 1 / -1; margin-top: 150px; min-height: 100px; }
@media (prefers-reduced-motion: no-preference) {
  .result:not([hidden]) .res-score b { animation: rise .5s cubic-bezier(.16, 1, .3, 1) both; }
  .result:not([hidden]) .mini i { animation: pop .3s cubic-bezier(.16, 1, .3, 1) both; animation-delay: calc(var(--k, 0) * 6ms); }
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
