/* 모내기 웹 게임 공통 스타일 (시간 맞추기 · 음 맞추기) */
* { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font-family: inherit; }
[hidden] { display: none !important; }

.app { position: relative; max-width: 440px; margin: 0 auto; height: 100vh; height: 100dvh; box-sizing: border-box; display: flex; flex-direction: column;
  padding: calc(8px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom)); }

/* 위쪽 줄 */
.top { display: flex; align-items: center; gap: 4px; min-height: 52px; padding: 0 2px; }
.brand { font: 400 22px/1 var(--font-display); padding-left: 6px; color: inherit; text-decoration: none; }
.top__title { font-size: 15px; font-weight: 700; }
.spacer { flex: 1; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--ink); cursor: pointer; border-radius: 50%; }
.icon-btn svg { width: 22px; height: 22px; }
.sound-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px 0 10px; border: 0; border-radius: var(--radius-pill); background: var(--paper-raised); box-shadow: inset 0 0 0 1.5px var(--line); color: var(--ink); font: 600 13px/1 var(--font-sans); cursor: pointer; }
.sound-btn svg { width: 18px; height: 18px; }
.sound-btn .ico-off { display: none; }
.sound-btn[aria-pressed="false"] .ico-on { display: none; }
.sound-btn[aria-pressed="false"] .ico-off { display: block; }
.sound-btn[aria-pressed="false"] { color: var(--ink-muted); }
.icon-btn:focus-visible, .sound-btn:focus-visible, .stage:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* 화면 */
.view { flex: 1; min-height: 0; display: none; flex-direction: column; gap: 14px; }
.view.is-on { display: flex; }
.muted { color: var(--ink-muted); }

/* 무대: 다크가 기본이라 무대도 어두워요. data-theme="light"를 켠 화면에서만 무대를 밝게 바꿔요
   --stage-ink / --stage-bg 는 캔버스·반투명 선에 쓰는 '글자색 / 바탕색' RGB 예요 */
:root { --stage-ink: 255, 255, 255; --stage-bg: var(--stage-rgb); }
:root[data-theme="light"] :is(.stage, .game) {
  --stage: #FFFFFF; --stage-raised: #ECEFE7; --on-stage: var(--ink); --on-stage-muted: var(--ink-muted);
  --sprout: #17752F; --grain: #A86A00; --p1: #D4336B; --stage-ink: 18, 22, 19; --stage-bg: 255, 255, 255;
  --shadow-stage: 0 0 0 1.5px var(--line), 0 18px 36px -24px rgba(18, 22, 19, 0.22);
}
.stage { position: relative; flex: 1; min-height: 0; box-sizing: border-box; padding: 24px; background: var(--stage); color: var(--on-stage);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-stage); overflow: hidden; }
.cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.num { position: relative; font: 500 13px/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--on-stage-muted); }

/* 소개 */
.stage--intro { flex: none; height: min(46vh, 400px); }
.qmark { position: absolute; top: 20px; right: 24px; font: 400 40px/1 var(--font-pixel); color: var(--on-stage-muted); }
.intro-copy h1 { margin: 4px 0 8px; font: 400 40px/44px var(--font-display); letter-spacing: -0.02em; }
.intro-copy p { margin: 0; font-size: 16px; line-height: 24px; }
.intro-copy p.muted { margin-top: 8px; font-size: 13px; line-height: 18px; }
.intro-copy b { color: var(--ink); }
.intro-foot { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.best-pill { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-pill); background: var(--paper-raised); box-shadow: inset 0 0 0 1.5px var(--line); font-size: 13px; font-weight: 600; }
.best-pill b { font: 600 13px/1 var(--font-mono); color: var(--sprout-strong); }
.wide { width: 100%; box-sizing: border-box; }

/* 플레이 무대 */
.stage--play { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; cursor: default; transition: box-shadow var(--dur-ui) var(--ease-out); }
.stage--play.is-ready { cursor: pointer; box-shadow: var(--shadow-stage), inset 0 0 0 3px rgba(255, 111, 145, 0.35); animation: kk-ready 1.4s var(--ease-out) infinite; }
.stage--play.is-holding { box-shadow: var(--shadow-stage), inset 0 0 0 3px rgba(255, 111, 145, 0.9); animation: none; }
@keyframes kk-ready { 50% { box-shadow: var(--shadow-stage), inset 0 0 0 3px rgba(255, 111, 145, 0.85); } }

.layer { position: absolute; inset: 0; padding: 56px 24px 24px; display: flex; flex-direction: column; }
.sound-pill { position: absolute; top: 16px; right: 16px; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: var(--radius-pill); background: var(--stage-raised); font: 600 12px/1 var(--font-sans); }
.sound-pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--grain); opacity: 0.3; }
.sound-pill i.is-tick { animation: kk-tick 260ms var(--ease-out); }
@keyframes kk-tick { from { opacity: 1; transform: scale(1.8); } to { opacity: 0.3; transform: none; } }

.cue { position: absolute; left: 0; right: 0; top: 64px; margin: 0; padding: 0 20px; text-align: center; pointer-events: none; }
.cue__big { display: block; font: 400 40px/44px var(--font-display); }
.cue__sub { display: block; margin-top: 6px; font: 500 15px/22px var(--font-sans); color: var(--on-stage-muted); }
.cue.is-warn .cue__sub { color: var(--grain); }

.scorebox { position: absolute; top: 56px; right: 28px; left: 28px; text-align: right; pointer-events: none; }
.score { font: 400 88px/0.9 var(--font-pixel); letter-spacing: -0.03em; color: var(--sprout); display: inline-block; font-variant-numeric: tabular-nums; }
.score.is-pop, .total__v.is-pop { animation: kk-pop 420ms var(--ease-pop); }
@keyframes kk-pop { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
.comment, .total__comment, .total__best { opacity: 0; transform: translateY(6px); transition: opacity 260ms var(--ease-out), transform 260ms var(--ease-out); }
.comment.is-in, .total__comment.is-in, .total__best.is-in { opacity: 1; transform: none; }
.score__of { font: 500 15px/1 var(--font-mono); color: var(--on-stage-muted); margin-left: 4px; }
.comment { margin: 12px 0 0; font: 400 20px/26px var(--font-display); }
@keyframes kk-in { from { transform: translateY(12px) scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }

.tags { position: absolute; left: 0; right: 0; bottom: 18px; display: flex; justify-content: center; gap: 56px; pointer-events: none; }
.tag { display: grid; gap: 2px; text-align: center; }
.tag__k { display: inline-flex; align-items: center; justify-content: center; gap: 5px; font: 600 12px/16px var(--font-sans); color: var(--on-stage-muted); }
.tag__v { font: 600 18px/22px var(--font-mono); font-variant-numeric: tabular-nums; }
.tag__v.muted { color: var(--on-stage-muted); }
.tag__mark { width: 14px; height: 14px; }
.ring-ico { width: 12px; height: 12px; border-radius: 50%; border: 2px dashed rgba(var(--stage-ink), 0.7); box-sizing: border-box; }

.foot { min-height: 64px; display: flex; flex-direction: column; justify-content: center; }
.caption { margin: 0; text-align: center; font-size: 13px; line-height: 18px; color: var(--ink-muted); }
.result-row { display: flex; align-items: center; gap: 12px; padding: 0 4px; }
.err { flex: 1; display: grid; gap: 2px; min-width: 0; }
.err__v { font: 600 17px/22px var(--font-mono); font-variant-numeric: tabular-nums; }
.err__k { font-size: 13px; line-height: 18px; color: var(--ink-muted); }

/* 최종 결과 */
.stage--total { flex: none; padding: 28px 24px 28px; text-align: center; }
.total { margin: 36px 0 0; }
.total__v { display: inline-block; font: 400 96px/0.9 var(--font-pixel); letter-spacing: -0.03em; color: var(--sprout); font-variant-numeric: tabular-nums; }
.total__of { font: 500 17px/1 var(--font-mono); color: var(--on-stage-muted); margin-left: 4px; }
.total__comment { margin: 14px 0 0; font: 400 24px/30px var(--font-display); }
.total__best { margin: 6px 0 0; font: 500 13px/18px var(--font-sans); color: var(--on-stage-muted); }
.total__best b { font: 600 13px/1 var(--font-mono); color: var(--on-stage); }
.total__best.is-new { color: var(--grain); }
.cells-wrap { display: flex; flex-direction: column; gap: 10px; }
.label { font-size: 13px; font-weight: 600; color: var(--ink-muted); }
.hint { font-size: 12px; line-height: 16px; color: var(--ink-muted); }
.cells { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0 10px; border-radius: var(--radius-md); background: var(--paper-raised); box-shadow: inset 0 0 0 1.5px var(--line); }
.cell__n { font: 500 12px/1 var(--font-mono); color: var(--ink-muted); }
.cell__bar { position: relative; width: 8px; height: clamp(56px, 14vh, 132px); border-radius: 4px; background: var(--line); }
.cell__bar i { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 4px; background: var(--sprout); transform-origin: bottom; animation: kk-bar 700ms var(--ease-out) both; }
@keyframes kk-bar { from { transform: scaleY(0); } }
.cell__pts { font: 600 15px/1 var(--font-mono); font-variant-numeric: tabular-nums; }
.cell__err { font: 500 12px/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink-muted); }
.total-side { display: contents; } /* PC에서만 오른쪽 단으로 묶여요 */
.total-foot { margin-top: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row .mn-btn { flex: 1; }

/* 알림: 디자인 시스템 mn-toast 처럼 흰 알약, 아래 버튼(폰 76px · PC 88px) 위 16px */
.toast { position: absolute; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: inline-flex; align-items: center; min-height: 44px; box-sizing: border-box; padding: 0 var(--space-4); border-radius: var(--radius-pill); background: var(--contrast); color: var(--on-contrast); font: 600 14px/20px var(--font-sans); white-space: nowrap; box-shadow: var(--shadow-float); }

@media (max-height: 700px) {
  .stage--intro { height: 38vh; }
  .intro-copy h1 { font-size: 32px; line-height: 36px; }
  .score { font-size: 72px; }
  .total__v { font-size: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  .score.is-pop, .total__v.is-pop, .cell__bar i, .sound-pill i.is-tick, .stage--play.is-ready { animation: none !important; }
}
@media (prefers-reduced-motion: reduce) { .comment, .total__comment, .total__best { transition: none; } }

/* PC (시간·음·블록 맞추기). 폭 960px·높이 620px 이상이면 2단으로 넓혀요.
   가격 맞추기는 price/style.css 에 따로 있어요 (data-game 이 없어서 여기 규칙은 안 닿아요) */
@media (min-width: 960px) and (min-height: 620px) {
  .app[data-game] { max-width: 1000px; height: min(100dvh, 900px); margin-top: max(0px, calc((100dvh - 900px) / 2)); padding: 16px 28px 28px; }
  .app[data-game] .top { min-height: 56px; margin-bottom: 4px; }

  /* 소개: 왼쪽 무대, 오른쪽 설명·시작 */
  .app[data-game] #vIntro.is-on { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-template-rows: 1fr auto auto 1fr; column-gap: 48px; row-gap: 22px; }
  .app[data-game] #vIntro > .stage--intro { grid-column: 1; grid-row: 1 / -1; align-self: center; height: min(100%, 540px); }
  .app[data-game] #vIntro > .intro-copy { grid-column: 2; grid-row: 2; }
  .app[data-game] #vIntro > .intro-foot { grid-column: 2; grid-row: 3; margin-top: 0; }
  .app[data-game] .intro-copy h1 { font-size: 52px; line-height: 56px; margin-bottom: 12px; }
  .app[data-game] .intro-copy p { font-size: 18px; line-height: 27px; }
  .app[data-game] .intro-copy p.muted { font-size: 14px; line-height: 20px; }
  .app[data-game] .qmark { top: 26px; right: 30px; font-size: 52px; }

  /* 플레이: 무대를 넓게, 아래 줄은 가운데에 */
  .app[data-game] .foot { align-items: center; min-height: 72px; }
  .app[data-game] .result-row { width: 100%; max-width: 560px; box-sizing: border-box; }
  .app[data-game] .caption { font-size: 14px; }
  .app[data-game] .stage--play .num, .app[data-game] .stage--total .num { font-size: 14px; }
  .app[data-game] .cue { top: 84px; }
  .app[data-game] .cue__big { font-size: 52px; line-height: 56px; }
  .app[data-game] .cue__sub { font-size: 17px; line-height: 24px; }
  .app[data-game] .scorebox { top: 64px; left: 44px; right: 44px; }
  .app[data-game] .score { font-size: 112px; }
  .app[data-game] .comment { font-size: 24px; line-height: 30px; }
  .app[data-game] .tags { bottom: 28px; gap: 72px; }
  .app[data-game] .tag__k { font-size: 13px; }
  .app[data-game] .tag__v { font-size: 22px; line-height: 28px; }
  .app[data-game] .tags--play { gap: 12px; }
  .app[data-game] .tag--btn { max-width: 220px; padding: 12px 10px; }
  /* 블록 맞추기: 판이 세로로 길어서 무대를 가운데 한 단으로 */
  .app[data-game="blocks"] #vPlay.is-on { width: 100%; max-width: 620px; margin: 0 auto; }

  /* 결과: 왼쪽 점수와 버튼, 오른쪽 기록 */
  .app[data-game] #vTotal.is-on { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; column-gap: 28px; row-gap: 14px; }
  .app[data-game] #vTotal > .stage--total { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; justify-content: center; padding: 28px; }
  .app[data-game] #vTotal > .total-foot { grid-column: 1; grid-row: 2; margin: 0; }
  .app[data-game] .total-side { grid-column: 2; grid-row: 1 / -1; display: flex; flex-direction: column; justify-content: center; gap: 16px; min-height: 0; }
  .app[data-game] .stage--total .num { position: absolute; top: 26px; left: 28px; }
  .app[data-game] .total { margin: 0; }
  .app[data-game] .total__v { font-size: 120px; }
  .app[data-game] .total__comment { font-size: 28px; line-height: 34px; margin-top: 18px; }
  .app[data-game] .total__best { font-size: 14px; }
  .app[data-game] .cells { gap: 10px; }
  .app[data-game] .cell { padding: 16px 0 14px; gap: 8px; }
  .app[data-game] .cell__bar { width: 10px; height: clamp(120px, 28vh, 260px); border-radius: 5px; }
  .app[data-game] .cell__pts { font-size: 17px; }
  .app[data-game] .cell__err { font-size: 13px; }
  .app[data-game] .stats { gap: 10px; }
  .app[data-game] .stat { padding: 24px 0 20px; }
  .app[data-game] .stat__v { font-size: 28px; }
  .app[data-game] .stat__k { font-size: 13px; }
  .app[data-game] .label { font-size: 14px; }
  .app[data-game] .hint { font-size: 13px; line-height: 18px; }

  /* 랭킹: 한 단을 가운데에 */
  .app[data-game] #vRank.is-on { width: 100%; max-width: 560px; margin: 0 auto; }
  .app[data-game] .toast { bottom: 104px; }
}
@media (min-width: 960px) and (min-height: 620px) and (max-height: 759px) {
  .app[data-game] { padding: 10px 28px 18px; }
  .app[data-game] .top { min-height: 48px; margin-bottom: 0; }
  .app[data-game] .intro-copy h1 { font-size: 44px; line-height: 48px; }
  .app[data-game] .score { font-size: 96px; }
  .app[data-game] .total__v { font-size: 100px; }
  .app[data-game] .cue { top: 64px; }
}

/* 아주 작은 폰 (320×568 급): 소개 그림이 자리를 양보하고, 그래도 넘치면 밀어서 봐요 → 시작 버튼이 늘 닿아요 */
@media (max-width: 959px) and (max-height: 620px) {
  #vIntro { overflow-y: auto; }
  #vIntro > .stage--intro { flex: 0 1 auto; min-height: 124px; }
  #vIntro > .intro-copy, #vIntro > .intro-foot { flex-shrink: 0; }
  .intro-copy h1 { font-size: 28px; line-height: 32px; margin-bottom: 6px; }
  .intro-copy p { font-size: 15px; line-height: 22px; }
}
/* 한글은 낱말 가운데에서 줄이 바뀌지 않게 */
.intro-copy, .caption, .total__comment, .total__best, .hint, .cue, .err__k, .comment { word-break: keep-all; overflow-wrap: anywhere; }

/* 폰: 게임 무대를 카드로 묶지 않고 화면 전체를 한 면으로 써요 (넓은 화면은 그대로 카드)
   무대 바탕이 곧 화면 바탕이라 테두리·그림자·옆 여백이 없어요. 둥근 모서리는 맞음·틀림 테두리 띠에만 남아요 */
:root { --game-bg: var(--stage); }
:root[data-theme="light"] { --game-bg: #FFFFFF; }
@media (max-width: 480px) {
  body:has(.stage) { background: var(--game-bg); }
  .app:has(.stage) { max-width: none; background: var(--game-bg); }
  /* 화면(view)을 먼저 양끝까지 넓혀 두어야, 밀어 보는 화면에서도 무대가 옆으로 넘치지 않아요 */
  .app:has(.stage) .view { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
  :root .app .stage { --shadow-stage: 0 0 0 0 transparent; margin-left: -12px; margin-right: -12px; border-radius: 24px; background: var(--game-bg); }
  .stage:focus-visible { outline-offset: -3px; }
  .stage--total { padding-top: 12px; padding-bottom: 20px; }
  .total { margin-top: 28px; }
}

/* 위쪽 '모내기' 글자
   홈: 바로 아래 슬로건에 이름이 또 나와서 글자만 있는 윗줄은 접어요 (다른 것이 들어오면 다시 보여요)
   앱으로 연 게임 화면: 이미 모내기 안이라 글자 대신 홈으로 가는 화살표만 둬요 (웹은 공유 링크로 온 사람이 어디인지 알게 글자 유지) */
.top:has(> .brand:first-child + .spacer:last-child) { min-height: 12px; }
.top > span.brand:first-child:has(+ .spacer:last-child) { display: none; }
html.is-app .top a.brand { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 0; }
html.is-app .top a.brand::before { content: ""; width: 22px; height: 22px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 5l-7 7 7 7'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 5l-7 7 7 7'/%3E%3C/svg%3E") center / contain no-repeat; }
html.is-app .top a.brand:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
