/* 반띵 — 피스타치오빛 종이 위에 판초콜릿 하나. 초록은 '양쪽이 같다'에만 씀 */

:root {
  --paper: #EEF1E7;
  --sheet: #F8FAF3;
  --ink: #2A1B14;
  --ink-2: #6B5A50;
  --line: #D5DCC8;

  --choco: #7A4A2E;
  --choco-hi: #9A6442;
  --choco-lo: #4E2B18;
  --choco-ink: #F7E9D3;
  --knife: #FFF8EC;

  --even: #4F7D2E;
  --even-soft: #DCE8CC;
  --on-even: #FFFFFF;
  --miss: #C2412D;

  --tint-a: rgba(255, 244, 225, 0.22);

  --ui: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;

  --s-1: 0.875rem;  /* 14 */
  --s0: 1rem;       /* 16 */
  --s1: 1.125rem;   /* 18 */
  --s2: 1.375rem;   /* 22 */
  --s3: 1.75rem;    /* 28 */
  --s4: 2.75rem;    /* 44 */

  --r-ctl: 12px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17130F;
    --sheet: #211B16;
    --ink: #F1E8DD;
    --ink-2: #B5A699;
    --line: #3A3029;
    --choco: #4B2C1C;
    --choco-hi: #63402B;
    --choco-lo: #2A170D;
    --choco-ink: #EED9BC;
    --knife: #FFE9C2;
    --even: #9CC46F;
    --even-soft: #2C3A20;
    --on-even: #17130F;
    --miss: #F07A62;
    --tint-a: rgba(255, 236, 205, 0.16);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #17130F;
  --sheet: #211B16;
  --ink: #F1E8DD;
  --ink-2: #B5A699;
  --line: #3A3029;
  --choco: #4B2C1C;
  --choco-hi: #63402B;
  --choco-lo: #2A170D;
  --choco-ink: #EED9BC;
  --knife: #FFE9C2;
  --even: #9CC46F;
  --even-soft: #2C3A20;
  --on-even: #17130F;
  --miss: #F07A62;
  --tint-a: rgba(255, 236, 205, 0.16);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: var(--s0);
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: break-word;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--even); outline-offset: 2px; border-radius: 6px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* 머리글 */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 720px; margin: 0 auto; padding: 16px 16px 0;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--ink); text-decoration: none;
  font-size: var(--s2); font-weight: 800; letter-spacing: -0.02em;
}
.top-tools { display: flex; align-items: center; gap: 8px; }
.sound {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent;
  color: var(--ink-2); cursor: pointer;
}
.sound[aria-pressed="true"] .sound-off,
.sound[aria-pressed="false"] .sound-on { display: none; }
.theme { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.theme button {
  border: 0; background: transparent; color: var(--ink-2);
  font-size: var(--s-1); padding: 5px 10px; border-radius: 999px; cursor: pointer;
}
.theme button[aria-checked="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

main { max-width: 720px; margin: 0 auto; padding: 0 16px; overflow-x: hidden; overflow-x: clip; } /* 판의 잡기용 여백이 좁은 화면 밖으로 나가도 가로 스크롤이 생기지 않게 */
.lede {
  max-width: 460px; margin: 20px auto 18px;
  font-size: var(--s1); font-weight: 700; line-height: 1.45; letter-spacing: -0.01em;
  color: var(--ink-2); text-align: center; text-wrap: balance;
}

/* 게임 */
.game { max-width: 460px; margin: 0 auto; }

.hud {
  display: flex; align-items: baseline; justify-content: space-between;
  font-variant-numeric: tabular-nums;
}
.hud p { margin: 0; }
.clock { position: relative; font-size: var(--s3); font-weight: 800; letter-spacing: -0.02em; }
.clock.low { color: var(--miss); }
.tally { display: flex; align-items: baseline; gap: 6px; font-size: var(--s3); font-weight: 800; letter-spacing: -0.02em; }
.unit { font-size: var(--s0); font-weight: 600; color: var(--ink-2); }
.combo {
  align-self: center;
  font-size: var(--s-1); font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--even-soft); color: var(--even);
}
.pop {
  position: absolute; left: calc(100% + 8px); top: 50%;
  font-size: var(--s0); font-weight: 700; white-space: nowrap;
  opacity: 0; transform: translateY(-50%);
}
.pop.gain { color: var(--even); animation: pop 900ms ease-out; }
.pop.loss { color: var(--miss); animation: pop 900ms ease-out; }
@keyframes pop {
  0% { opacity: 0; transform: translateY(-20%); }
  15% { opacity: 1; transform: translateY(-50%); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-110%); }
}

.bar { height: 6px; margin: 8px 0 14px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: var(--even); border-radius: inherit; transform-origin: left; transition: background-color 200ms; }
.bar.low i { background: var(--miss); }

.stage { position: relative; }
.game.live .stage { touch-action: none; }
.board {
  display: block; width: 100%; height: auto; max-width: none;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.board.playing { cursor: crosshair; }
.tray { fill: var(--choco-lo); }
.stop-hi { stop-color: var(--choco-hi); }
.stop-base { stop-color: var(--choco); }
.cell rect.face { fill: url(#piece); }
.cell rect.rim { fill: none; stroke: rgba(255, 240, 220, 0.14); stroke-width: 2; }
.cell text {
  fill: var(--choco-ink); font-family: var(--ui); font-weight: 800; font-size: 50px;
  text-anchor: middle; dominant-baseline: central; pointer-events: none;
}
.cell rect.tint { fill: transparent; transition: fill 120ms; }
/* 고른 칸은 양쪽 모두 같은 모습 (밝게 + 크림 테두리). 두 쪽은 칼선으로만 나눈다 */
.cell.a rect.tint, .cell.b rect.tint { fill: var(--tint-a); }
.cell.a rect.rim, .cell.b rect.rim { stroke: var(--knife); stroke-opacity: 0.85; stroke-width: 3; }
.cell.empty rect.face, .cell.empty rect.rim { display: none; }
.cell.empty rect.tint { fill: transparent; }
.cell.empty.a rect.tint, .cell.empty.b rect.tint { fill: var(--tint-a); fill-opacity: 0.5; }
.knife {
  stroke: var(--knife); stroke-width: 10; stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(255, 230, 190, 0.6));
}

/* 성공한 칸이 쪼개지며 사라짐 */
.cell { transform-box: fill-box; transform-origin: center; transition: transform 240ms cubic-bezier(.3, 0, .6, 1), opacity 240ms; }
.cell.gone { transform: scale(0.4) rotate(8deg); opacity: 0; }
.board.shake { animation: shake 300ms; }
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

/* 시작 · 결과 화면: 판 위에 겹침 */
.overlay {
  position: absolute; inset: -6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-radius: 14px;
}
.overlay[hidden] { display: none; }
.overlay h2 { margin: 0 0 14px; font-size: var(--s2); font-weight: 800; letter-spacing: -0.02em; }
.rules { margin: 0 0 22px; padding: 0; list-style: none; counter-reset: r; text-align: left; }
.rules li { counter-increment: r; display: flex; gap: 10px; align-items: baseline; margin: 6px 0; }
.rules li::before {
  content: counter(r); flex: none; display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 999px;
  background: var(--choco); color: var(--choco-ink); font-size: 13px; font-weight: 700;
}
.final { margin: 0; font-size: var(--s4); font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.final-sub { margin: 4px 0 0; font-weight: 600; color: var(--ink-2); }
.final-bonus { margin: 4px 0 0; font-size: var(--s-1); font-weight: 700; color: var(--even); }
.best { margin: 10px 0 20px; font-size: var(--s-1); color: var(--ink-2); }
.best.new { color: var(--even); font-weight: 700; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn {
  min-height: 48px; padding: 0 22px; border-radius: var(--r-ctl);
  border: 1px solid var(--line); background: var(--sheet); color: var(--ink);
  font-weight: 700; cursor: pointer;
}
.btn-main { border-color: var(--choco); background: var(--choco); color: var(--choco-ink); }
.btn:active { transform: translateY(1px); }

/* 저울 */
.scale {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 16px; font-variant-numeric: tabular-nums;
}
.pan {
  min-width: 64px; padding: 6px 12px; border-radius: var(--r-ctl);
  text-align: center; font-size: var(--s2); font-weight: 800;
  border: 1px solid var(--line); color: var(--ink-2);
}
.pan.filled { background: var(--choco); border-color: transparent; color: var(--choco-ink); }
.scale.even .pan { background: var(--even); color: var(--on-even); }
.beam { width: 96px; height: 36px; flex: none; }
.fulcrum { fill: var(--ink-2); }
.beam-bar { fill: var(--ink); }
.scale.even .beam-bar { fill: var(--even); }
#beam { transform-origin: 60px 20px; transform-box: view-box; transition: transform 220ms cubic-bezier(.3, 1.4, .5, 1); }
.goal { margin: 10px 0 0; text-align: center; font-size: var(--s-1); color: var(--ink-2); }
/* 저울과 목표는 플레이 중에만 (자리는 그대로 두어 화면이 흔들리지 않게) */
.game:not(.live) .scale, .game:not(.live) .goal { visibility: hidden; }

/* 설명 글 */
.guide { max-width: 40rem; margin: 88px auto 0; }
.guide + .guide { margin-top: 56px; }
.guide h2 { margin: 0 0 16px; font-size: var(--s3); font-weight: 800; line-height: 1.3; letter-spacing: -0.02em; }
.guide p, .guide li { line-height: 1.8; }
.guide ul { margin: 0; padding-left: 1.2em; }
.guide li { margin-bottom: 8px; }
.guide li::marker { color: var(--choco); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding-left: 44px; margin-bottom: 18px; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 2px;
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--choco); color: var(--choco-ink); font-weight: 800; font-size: var(--s-1);
  box-shadow: inset 0 -3px 0 var(--choco-lo);
}
.steps strong { display: block; font-size: var(--s1); }
.faq details { border-top: 1px solid var(--line); }
.faq details:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 2px; font-weight: 700; cursor: pointer; list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: ""; flex: none; width: 10px; height: 10px;
  border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2);
  transform: rotate(45deg) translateY(-3px); transition: transform 160ms;
}
.faq details[open] summary::after { transform: rotate(-135deg) translateY(-1px); }
.faq details p { margin: 0 0 18px; padding: 0 2px; color: var(--ink-2); }

/* 광고 칸: 주석 처리된 ins 만 있으면 자리도 차지하지 않음. ins.adsbygoogle 을 풀면 나타남 */
.ad { display: none; }
.ad-inline:has(ins.adsbygoogle) { display: block; }
.ad-slot { overflow: hidden; }
.ad-inline { max-width: 40rem; min-height: 100px; margin: 72px auto 0; }

/* 바닥글 */
.foot {
  max-width: 40rem; margin: 96px auto 0; padding: 28px 16px 56px;
  border-top: 1px solid var(--line); font-size: var(--s-1); color: var(--ink-2);
}
.foot p { margin: 0 0 12px; }
.foot nav { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; }
.foot-tools span { font-weight: 600; color: var(--ink); }
.foot a { color: var(--ink-2); }
.foot a:hover { color: var(--choco); }

/* 게임 중 조작 줄: 난이도 바꾸기(누르면 새로 시작) + 다시 하기. 시작·결과 화면에서는 자리만 남김 */
.controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px 0 12px; }
.game:not(.live) .controls { visibility: hidden; }
.restart {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  font-size: var(--s-1); font-weight: 700; padding: 0 14px; border-radius: 999px; cursor: pointer;
}
.level.level-mini { margin: 0; padding: 2px; }
.level.level-mini button { min-height: 32px; padding: 0 12px; font-size: var(--s-1); }

/* 난이도 고르기 */
.level { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-bottom: 8px; background: var(--sheet); }
.level button {
  border: 0; background: transparent; color: var(--ink-2); font-weight: 700;
  padding: 8px 18px; border-radius: 999px; cursor: pointer; min-height: 40px;
}
.level button[aria-checked="true"] { background: var(--choco); color: var(--choco-ink); }
.level-note { margin: 0 0 18px; font-size: var(--s-1); color: var(--ink-2); min-height: 1.6em; }
.link-btn { margin-top: 14px; border: 0; background: transparent; color: var(--ink-2); font-size: var(--s-1); text-decoration: underline; cursor: pointer; padding: 6px; }

/* 쉬움·보통 연습: 나눌 수 있으면 칼선 자리를 점선으로 */
.knife.preview { stroke-dasharray: 2 16; stroke-opacity: 0.9; }
/* 쉬움: 오래 못 찾으면 자를 수 있는 칸들이 통통 튐 (테두리는 '고른 칸'과 '탭할 칸'에만 씀) */
.cell.hint { animation: nudge 1100ms ease-in-out infinite; }
@keyframes nudge { 0%, 60%, 100% { transform: translateY(0); } 25% { transform: translateY(-7%); } 40% { transform: translateY(2%); } }

@media (prefers-reduced-motion: reduce) {
  .cell { transition: opacity 200ms; }
  .cell.hint { animation: none; }
  .cell.hint rect.tint { fill: var(--tint-a); }
  .cell.gone { transform: none; }
  #beam { transition: none; }
  .board.shake { animation: none; }
}

@media (max-width: 380px) {
  .theme button { padding: 5px 8px; }
  .brand { font-size: var(--s1); }
}
