/* 딴짓 · 폭탄 돌리기 — 옛날 만화 극장: 남색 밤하늘 망점, 노랑·빨강 효과선, 뚱뚱한 글씨 */
:root {
  --night: #1a1430; --night-2: #2a2050; --ink: #1a1420; --paper: #fffaf0;
  --yellow: #ffd23a; --orange: #ff8a2a; --red: #ff3b2a; --sky: #7fd3ff;
  --fat: 'Bagel Fat One', 'Black Han Sans', 'Pretendard Variable', sans-serif;
  --ui: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; touch-action: manipulation; }
body { margin: 0; min-height: 100svh; color: var(--paper); font: 500 16px/1.55 var(--ui); overflow-x: clip;
  background-color: var(--night);
  background-image: radial-gradient(rgba(255,210,58,.12) 1.3px, transparent 1.8px), radial-gradient(ellipse at 50% 35%, var(--night-2), var(--night) 70%);
  background-size: 14px 14px, 100% 100%; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; max-width: 760px; margin: 0 auto; }
.logo { font: 400 20px/1 var(--fat); color: var(--ink); background: var(--yellow); padding: 10px 12px 8px; border-radius: 10px; text-decoration: none; transform: rotate(-4deg); box-shadow: 3px 3px 0 var(--red); }
.chip { appearance: none; min-height: 44px; padding: 0 14px; border: 2px solid var(--paper); border-radius: 999px; background: transparent; font-weight: 700; font-size: 14px; cursor: pointer; }
.chip[aria-pressed="false"] { opacity: .6; }

.stage { max-width: 760px; margin: 0 auto; padding: 0 16px 20px; min-height: calc(100svh - 64px); display: flex; flex-direction: column; }
.bomb-wrap { position: relative; flex: 1 1 auto; min-height: 220px; }
#bomb { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 문제 카드 */
.card { display: none; position: relative; margin: 4px auto 0; width: min(100%, 420px); background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 18px; padding: 12px 16px 14px; text-align: center; box-shadow: 6px 6px 0 var(--red); transform: rotate(-1.5deg); }
body[data-state="run"] .card, body[data-state="paused"] .card, body[data-state="ready"] .card { display: block; }
/* 판이 도는 동안은 화면을 고정: 폰을 돌리다 손가락이 스쳐도 설명서가 올라오지 않게 */
body[data-state="run"], body[data-state="paused"], body[data-state="ready"], body[data-state="boom"] { overflow: hidden; overscroll-behavior: none; }
body[data-state="run"] .guide, body[data-state="paused"] .guide, body[data-state="ready"] .guide, body[data-state="boom"] .guide { display: none; }
.card.flip { animation: flip .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes flip { from { transform: rotate(-1.5deg) scale(.82) rotateX(70deg); } }
.c-kind { display: inline-block; font: 400 15px/1 var(--fat); background: var(--ink); color: var(--yellow); padding: 6px 10px 4px; border-radius: 8px; }
.c-kind[hidden] { display: none; }
.c-big { display: grid; place-items: center; min-height: 2.1em; margin: 6px 0 2px; font: 400 clamp(40px, 13vw, 64px)/1.05 var(--fat); letter-spacing: .04em; word-break: keep-all; }
.c-sub { display: block; font-size: 14px; font-weight: 600; color: #5a4a50; }
.c-skip { position: absolute; right: 4px; top: 2px; appearance: none; border: 0; background: none; color: #6a5a60; font-size: 13px; font-weight: 700; min-height: 44px; padding: 0 6px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
body[data-mode="chain"] .c-skip, body[data-mode="none"] .c-skip, body[data-state="ready"] .c-skip { display: none; }
.c-skip:disabled { opacity: .35; cursor: default; text-decoration: none; }
.c-ans { appearance: none; margin-top: 4px; min-height: 40px; padding: 0 10px; border: 2px dashed #b9a9b0; border-radius: 10px; background: none; color: #5a4a50; font-size: 13px; font-weight: 700; cursor: pointer; }
.c-ans[hidden] { display: none; }

/* 설정 */
.setup { display: none; background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 22px 22px 18px 18px; padding: 16px 16px 18px; box-shadow: 0 8px 0 rgba(0,0,0,.35); }
body[data-state="setup"] .setup { display: block; }
.setup h1 { margin: 0; font: 400 clamp(36px, 11vw, 48px)/1 var(--fat); color: var(--red); text-shadow: 3px 3px 0 var(--ink); letter-spacing: -.01em; }
.lede { margin: 6px 0 12px; font-size: 15px; font-weight: 600; color: #4a3a40; word-break: keep-all; }
.opt { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 8px; margin-top: 8px; }
.opt > span { font: 400 15px/1 var(--fat); color: #6a5a60; }
.seg { display: flex; gap: 6px; }
.seg button { appearance: none; flex: 1; min-width: 0; min-height: 48px; padding: 0 2px; white-space: nowrap; border: 3px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); font-weight: 800; font-size: clamp(12px, 3.6vw, 15px); letter-spacing: -.02em; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; box-shadow: 0 3px 0 var(--ink); }
.seg button small { font-size: 11px; font-weight: 600; color: #6a5a60; margin-top: 2px; }
.seg [aria-checked="true"] { background: var(--yellow); transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.pen { margin-top: 10px; font-size: 14px; }
.pen summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; gap: 4px; list-style: none; }
.pen summary::-webkit-details-marker { display: none; }
.pen[open] summary span { display: inline-block; transform: rotate(45deg); }
.note { margin: 8px 0 0; font-size: 12.5px; color: #6a5a60; text-align: center; }
.pen label { display: block; font-size: 13px; color: #6a5a60; margin-bottom: 4px; }
.pen textarea { width: 100%; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: 16px; resize: vertical; background: #fff; color: var(--ink); }
.go { appearance: none; display: block; width: 100%; margin-top: 12px; min-height: 60px; border: 4px solid var(--ink); border-radius: 16px; background: var(--red); color: #fff; font: 400 26px/1 var(--fat); cursor: pointer; box-shadow: 0 6px 0 var(--ink); text-shadow: 2px 2px 0 var(--ink); }
.go:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }

/* 진행 */
.play { display: none; padding-bottom: env(safe-area-inset-bottom); }
body[data-state="run"] .play, body[data-state="paused"] .play { display: block; }
.pass { appearance: none; display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 96px; border: 4px solid var(--ink); border-radius: 22px; background: var(--yellow); color: var(--ink); font: 400 clamp(26px, 8vw, 34px)/1 var(--fat); cursor: pointer; box-shadow: 0 8px 0 var(--ink); -webkit-tap-highlight-color: transparent; user-select: none; }
.pass:active, .pass.hit { transform: translateY(5px); box-shadow: 0 3px 0 var(--ink); }
.pass.hit { animation: hit .25s ease-out; }
@keyframes hit { 40% { background: #fff; } }
body[data-state="paused"] .pass { opacity: .5; pointer-events: none; }
.play-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 26px; font-weight: 700; }
.play-meta b { font: 800 28px/1 var(--ui); color: var(--yellow); font-variant-numeric: tabular-nums; }
.mini.armed { background: var(--red); border-color: var(--red); color: #fff; }
.mini { appearance: none; min-height: 44px; padding: 0 14px; border: 2px solid currentColor; border-radius: 10px; background: transparent; font-weight: 700; font-size: 14px; cursor: pointer; }

/* 폭발 */
.flash { position: fixed; inset: -40px; z-index: 70; pointer-events: none; display: grid; place-items: center; opacity: 0; background: radial-gradient(circle, #fff 0 20%, var(--yellow) 40%, var(--orange) 65%, var(--red)); }
.flash b { font: 400 min(42vw, 260px)/1 var(--fat); color: var(--red); -webkit-text-stroke: 8px var(--ink); paint-order: stroke fill; transform: rotate(-8deg); }
.flash.go { animation: boom 1.1s ease-out forwards; }
@keyframes boom { 0% { opacity: 1; filter: brightness(2); } 12% { opacity: 1; filter: none; } 70% { opacity: 1; } 100% { opacity: 0; } }
.flash.go b { animation: pow .6s cubic-bezier(.2,1.8,.4,1); }
@keyframes pow { from { transform: rotate(-8deg) scale(.2); } }
body[data-state="boom"] .stage { animation: shake .5s; }
@keyframes shake { 20% { transform: translate(-10px, 6px); } 40% { transform: translate(8px, -8px); } 60% { transform: translate(-6px, 4px); } 80% { transform: translate(4px, -2px); } }

/* 결과 */
.result { position: fixed; inset: 0; z-index: 80; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; overflow-y: auto; padding: 16px; background: rgba(26,20,48,.82); }
.result[hidden] { display: none; }
.r-in { min-width: 0; width: min(100%, 420px); background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 22px; padding: 18px 16px; text-align: center; box-shadow: 8px 8px 0 var(--red); }
.r-in h2 { margin: 0; font: 400 clamp(40px, 12vw, 54px)/1 var(--fat); color: var(--red); text-shadow: 3px 3px 0 var(--ink); }
.r-stats { display: flex; justify-content: center; gap: 18px; margin: 12px 0 2px; font-weight: 700; }
.r-stats b { font: 400 28px/1 var(--fat); }
.r-best { margin: 0 0 10px; font-size: 13px; color: #6a5a60; }
.r-best:empty { display: none; }
.r-stats + .r-best:empty + .r-pen { margin-top: 10px; }
.r-pen { background: var(--yellow); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 12px 12px; display: grid; gap: 4px; justify-items: center; }
.r-pen small { font-weight: 700; color: #6a4a20; }
.r-pen b { font: 400 22px/1.3 var(--fat); word-break: keep-all; overflow-wrap: anywhere; max-width: 100%; }
.r-pen .mini[hidden] { display: none; }
.r-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.btn { appearance: none; min-height: 50px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); font-weight: 800; font-size: 15px; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90; margin: 0; padding: 12px 16px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; font-weight: 700; width: max-content; max-width: calc(100vw - 32px); text-align: center; }
.toast[hidden] { display: none; }

/* 설명서 */
.guide { position: relative; max-width: 760px; margin: 24px auto 0; padding: 28px 20px 40px; background: var(--paper); color: var(--ink); border-top: 6px solid var(--yellow); content-visibility: auto; contain-intrinsic-size: auto 1800px; }
.guide h2 { font: 400 25px/1.3 var(--fat); margin: 28px 0 10px; color: var(--ink); word-break: keep-all; }
.guide section:first-of-type h2 { margin-top: 8px; }
.guide p, .guide li, .guide dd { word-break: keep-all; }
.guide ol { padding-left: 1.3em; }
.faq dl { margin: 0; }
.faq dt { font-weight: 800; margin-top: 14px; }
.faq dd { margin: 4px 0 0; color: #4a3a40; }
.others { padding-left: 1.1em; }
.cols { columns: 2 14em; column-gap: 28px; padding-left: 1.4em; }
.cols li { break-inside: avoid; }
.tags { line-height: 1.9; color: #4a3a40; }
.ex { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(15em, 1fr)); gap: 6px 20px; }
.ex b { display: inline-block; min-width: 2.6em; font: 400 18px/1 var(--fat); color: var(--red); }
.others a { font-weight: 800; color: var(--ink); display: inline-block; padding: 8px 0; }
.site-foot { margin-top: 32px; font-size: 14px; display: flex; gap: 8px; }
.site-foot a { color: #5a4a50; display: inline-block; padding: 12px 0; }

/* 가로로 눕힌 폰: 폭탄 | 카드·버튼 두 칸 */
@media (orientation: landscape) and (max-height: 520px) {
  .stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); grid-template-rows: auto auto 1fr; gap: 8px 20px; min-height: calc(100svh - 64px); }
  .bomb-wrap { grid-column: 1; grid-row: 1 / 4; min-height: 0; }
  .card { grid-column: 2; grid-row: 1; margin: 0; width: 100%; padding: 8px 12px 10px; }
  .c-big { font-size: clamp(30px, 9vh, 44px); }
  .setup, .play { grid-column: 2; grid-row: 2 / 4; }
  body[data-state="setup"] .setup { grid-row: 1 / 4; padding: 10px 14px; }
  .setup h1 { font-size: 30px; } .lede { margin: 2px 0 4px; font-size: 13px; }
  .c-big { min-height: 1.15em; } .c-ans { min-height: 34px; margin-top: 2px; }
  .pass { min-height: 60px; } .play-meta { margin-top: 10px; } .play-meta .mini { min-height: 40px; }
}
@media (min-width: 900px) {
  .top { max-width: 1080px; }
  .c-big { font-size: clamp(64px, 7vw, 120px); }
  .stage { display: grid; grid-template-columns: minmax(0, 1fr) 420px; grid-template-rows: 1fr auto auto 1fr; gap: 16px 32px; max-width: 1080px; min-height: calc(100svh - 70px); }
  .bomb-wrap { grid-column: 1; grid-row: 1 / 5; min-height: 520px; }
  .card { grid-column: 2; grid-row: 2; margin: 0; width: 100%; }
  .setup, .play { grid-column: 2; grid-row: 3; }
  body[data-state="setup"] .setup { grid-row: 1 / 5; align-self: center; }
}
@media (prefers-reduced-motion: reduce) { .card.flip, .flash.go b, body[data-state="boom"] .stage, .pass.hit { animation: none; } .flash.go { animation: boomsoft .6s ease-out forwards; } }
@keyframes boomsoft { 0%, 50% { opacity: 1; } 100% { opacity: 0; } }
