/* 5초 골목대장 — 옛 딱지 인쇄풍: 갱지 바탕, 먹 외곽선, 어긋난 색 그림자 */
:root {
  --paper: #efe3c2; --paper2: #f7efd8; --ink: #2b2622; --dim: #6f6352;
  --red: #d8433b; --blue: #2f6fb5; --yel: #f2b632; --grn: #4f9a5b;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--paper); color: var(--ink);
  background-image: radial-gradient(rgba(43, 38, 34, 0.07) 1px, transparent 1.2px); background-size: 7px 7px;
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }
[hidden] { display: none !important; }

/* ── 상단 줄 ── */
.topbar { flex: none; height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 8px; padding-top: env(safe-area-inset-top); box-sizing: content-box; border-bottom: 2px solid var(--ink); background: var(--paper2); }
.back-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--ink); background: #fff8e3; color: var(--ink); text-decoration: none; font-size: 0.82rem; font-weight: 800; box-shadow: 2px 2px 0 var(--ink); }
.back-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.total { margin-left: auto; font-weight: 900; }
.tools { display: flex; gap: 8px; }
.mini { position: relative; width: 40px; height: 40px; flex: none; border-radius: 50%; border: 2px solid var(--ink); background: #fff8e3; font-weight: 900; padding: 0; line-height: 1; box-shadow: 2px 2px 0 var(--ink); }
.mini::after { content: ''; position: absolute; inset: -4px; }      /* 누르는 범위만 44px로 넓힌다 */
.mini:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }

/* ── 메뉴·지도 ── */
.screen { flex: 1; overflow-y: auto; padding: 10px 16px 28px; }
.screen > * { max-width: 520px; margin-left: auto; margin-right: auto; }
.logo { text-align: center; margin: 4px auto 12px; }
.logo-art { position: relative; height: 84px; width: 190px; margin: 0 auto; }
.logo-art i { position: absolute; width: 54px; height: 54px; border: 2.5px solid var(--ink); border-radius: 6px; box-shadow: 3px 3px 0 var(--ink); background: linear-gradient(45deg, transparent 47%, var(--ink) 47%, var(--ink) 53%, transparent 53%), linear-gradient(-45deg, transparent 47%, var(--ink) 47%, var(--ink) 53%, transparent 53%), var(--c); animation: flip 2.4s ease-in-out infinite; }
.logo-art i:nth-child(1) { --c: var(--red); left: 12px; top: 22px; transform: rotate(-12deg); }
.logo-art i:nth-child(2) { --c: var(--yel); left: 68px; top: 6px; animation-delay: -0.8s; }
.logo-art i:nth-child(3) { --c: var(--blue); left: 124px; top: 22px; transform: rotate(12deg); animation-delay: -1.6s; }
@keyframes flip { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }
h1 { margin: 6px 0 2px; font-size: 1.9rem; letter-spacing: -0.03em; font-weight: 900; }
h1 span { color: var(--red); }
.tagline { margin: 0 0 8px; color: var(--dim); font-size: 0.88rem; }
.chip { display: inline-block; padding: 3px 12px; border-radius: 999px; border: 2px solid var(--ink); background: var(--yel); font-weight: 900; font-size: 0.82rem; }
.dim { color: var(--dim); } .small { font-size: 0.82rem; }

.btn { word-break: keep-all; padding: 10px 16px; border-radius: 12px; border: 2px solid var(--ink); background: #fff8e3; font-weight: 900; box-shadow: 3px 3px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.go { background: var(--red); color: #fff; }
.btn.wide { width: 100%; }
.big { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 15px 14px; margin-bottom: 14px; font-size: 1.15rem; }
.big small { font-size: 0.8rem; font-weight: 700; opacity: 0.9; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.mode { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 12px; border-radius: var(--r); border: 2px solid var(--ink); background: #fff8e3; box-shadow: 3px 3px 0 var(--ink); min-height: 84px; }
.mode:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.mode .mi { font-size: 1.5rem; line-height: 1; }
.mode b { font-size: 0.98rem; word-break: keep-all; }
.mode small { color: var(--dim); font-size: 0.76rem; line-height: 1.3; word-break: keep-all; }
.mode.c1 { background: #ffe1d6; } .mode.c2 { background: #fff0bf; } .mode.c3 { background: #dcefd9; } .mode.c4 { background: #d9e7f6; }
.mode.c5 { background: #eadcf5; grid-column: 1 / -1; min-height: 72px; }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.links .btn { font-size: 0.9rem; padding: 10px 8px; }

.map-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.map-head h2 { margin: 0; font-size: 1.2rem; flex: 1; }
.hoods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.hood { padding: 6px 2px; min-height: 44px; border-radius: 10px; border: 2px solid var(--ink); background: #fff8e3; font-weight: 800; font-size: 0.76rem; line-height: 1.2; word-break: keep-all; overflow: hidden; }
.hood.on { background: var(--ink); color: var(--paper); }
.gates { position: relative; display: flex; flex-direction: column-reverse; gap: 10px; padding: 6px 0; }
.gates::before { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 26px; translate: -50% 0; background: repeating-linear-gradient(0deg, rgba(43, 38, 34, 0.12) 0 8px, transparent 8px 16px); border-radius: 13px; }
.gate { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--r); border: 2px solid var(--ink); background: #fff8e3; box-shadow: 3px 3px 0 var(--ink); text-align: left; width: 78%; }
.gate:nth-child(even) { align-self: flex-end; }
.gate:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.gate .gn { width: 40px; height: 40px; flex: none; border-radius: 8px 8px 2px 2px; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 900; background: var(--blue); color: #fff; }
.gate.boss { width: 100%; background: #ffe1d6; padding: 14px; }
.gate.boss .gn { width: 50px; height: 50px; background: var(--red); font-size: 1.4rem; }
.gate b { display: block; } .gate small { color: var(--dim); font-size: 0.76rem; }
.gate .gs { margin-left: auto; font-size: 0.95rem; letter-spacing: 1px; white-space: nowrap; }
.gate.next { outline: 3px dashed var(--red); outline-offset: 3px; }

/* ── 놀이 화면 ── */
#play { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hud { flex: none; height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 10px; background: var(--paper2); border-bottom: 2px solid var(--ink); }
.h-lives { display: flex; gap: 4px; min-width: 76px; }
.mb { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--ink); background: radial-gradient(circle at 35% 30%, #fff 0 18%, var(--blue) 22%); }
.mb.off { background: transparent; opacity: 0.35; }
.mb.up { animation: mbup 0.7s ease-out; }
@keyframes mbup { 0% { scale: 0.3; box-shadow: 0 0 0 0 var(--yel); } 40% { scale: 1.7; box-shadow: 0 0 0 6px var(--yel); } 100% { scale: 1; box-shadow: 0 0 0 0 transparent; } }
.h-count { font-weight: 900; font-size: 0.95rem; white-space: nowrap; }
.h-speed { margin-left: auto; font-weight: 800; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sunbar { position: relative; flex: none; height: 28px; overflow: hidden; border-bottom: 2px solid var(--ink); background: linear-gradient(90deg, #a8d8f0, #f8e3a0 55%, #f3a45c); }
.dusk { position: absolute; inset: 0; background: linear-gradient(90deg, #f0a35e, #d8593b 60%, #5b4a7a); opacity: 0; }
.sun { position: absolute; top: 4px; left: 0; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%; border: 2px solid var(--ink); background: var(--yel); box-shadow: 0 0 0 4px rgba(242, 182, 50, 0.35); }
.hill { position: absolute; right: -14px; bottom: -22px; width: 70px; height: 40px; border-radius: 50%; background: var(--ink); opacity: 0.55; }

#stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; touch-action: none; overflow: hidden; }
.board { position: relative; flex: none; width: 100px; height: 130px; background: #dcc798; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); overflow: hidden; }
#cv { display: block; width: 100%; height: 100%; touch-action: none; }
.rest { flex: 1; min-height: 46px; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--dim); font-weight: 900; font-size: 1rem; pointer-events: none; text-align: center; padding: 0 12px; }
.rest small { font-weight: 700; font-size: 0.74rem; opacity: 0.85; }

/* 지시 카드: pop(가운데 크게 떴다가 0.3초 뒤 위로 줄어들어 장면을 비운다) → tag(위쪽 작은 꼬리표) */
.cue { position: absolute; left: 50%; top: 42%; translate: -50% -50%; width: max-content; max-width: 92%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 20px; border: 3px solid var(--ink); border-radius: 16px; background: #fff8e3; box-shadow: 5px 5px 0 var(--ink); text-align: center; pointer-events: none; transition: top 0.16s, scale 0.16s, padding 0.16s; z-index: 3; }
.cue small { font-weight: 800; font-size: 0.78rem; color: var(--dim); }
.cue b { font-size: clamp(40px, 12vw, 54px); line-height: 1.05; font-weight: 900; color: var(--red); letter-spacing: -0.04em; word-break: keep-all; }
.cue b.long { font-size: clamp(27px, 8vw, 38px); }
.cue span { font-weight: 800; font-size: 0.9rem; }
.cue.pop { animation: cuepop 0.52s ease-out forwards; }
.cue.pop.boss { animation: pop 0.22s ease-out; }
@keyframes pop { from { scale: 1.6; opacity: 0; } to { scale: 1; opacity: 1; } }
@keyframes cuepop { 0% { scale: 1.6; opacity: 0; top: 42%; } 22% { scale: 1; opacity: 1; top: 42%; } 56% { scale: 1; top: 42%; } 100% { scale: 0.7; top: 14%; opacity: 0.94; } }
.cue.demo { top: 13%; padding: 8px 14px; }
.cue.demo b { font-size: 26px; }
.cue.tag { top: 0; translate: -50% 0; padding: 3px 12px; border-width: 0 2px 2px; border-radius: 0 0 12px 12px; box-shadow: none; flex-direction: row; gap: 8px; opacity: 0.92; }
.cue.tag small, .cue.tag span { display: none; }
.cue.tag b, .cue.tag b.long { font-size: 17px; letter-spacing: 0; }

.bossbar { flex: none; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 5px; max-width: 100%; padding: 3px 10px; border: 2px solid var(--ink); border-radius: 14px; background: #ffe1d6; color: var(--ink); font-weight: 900; font-size: 0.78rem; white-space: nowrap; pointer-events: none; }
.bossbar .bdots { display: inline-flex; align-items: center; gap: 5px; }
.bossbar i { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--ink); background: transparent; }
.bossbar i { flex: none; }
.bossbar i.w { background: var(--grn); } .bossbar i.l { background: var(--red); } .bossbar i.c { outline: 2px solid var(--yel); }

/* 판정 도장 */
.stamp { position: absolute; left: 50%; top: 40%; translate: -50% -50%; rotate: -8deg; width: max-content; max-width: 94%; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 4; animation: stamp 0.14s ease-out; }
.stamp b { padding: 6px 22px; border: 5px solid currentColor; border-radius: 14px; font-size: clamp(38px, 12vw, 56px); font-weight: 900; letter-spacing: -0.03em; background: rgba(255, 248, 227, 0.86); white-space: nowrap; }
.stamp.ok { color: var(--red); } .stamp.great { color: var(--red); } .stamp.bad { color: var(--blue); rotate: 6deg; }
.stamp.great b { box-shadow: 0 0 0 4px var(--yel); }
.stamp small { rotate: 8deg; max-width: 280px; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 10px; background: #fff8e3; color: var(--ink); font-weight: 800; font-size: 0.82rem; text-align: center; word-break: keep-all; }
.stamp.bad small { rotate: -6deg; }
.stamp small:empty { display: none; }
@keyframes stamp { from { scale: 2.2; opacity: 0.2; } to { scale: 1; opacity: 1; } }
.banner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: rgba(242, 182, 50, 0.9); font-weight: 900; z-index: 5; pointer-events: none; text-align: center; }
.banner b { font-size: clamp(42px, 13vw, 60px); color: var(--red); letter-spacing: -0.04em; animation: zoom 0.5s ease-in-out infinite alternate; text-shadow: 3px 3px 0 var(--ink); }
.banner span { font-size: 1.1rem; }
@keyframes zoom { from { scale: 0.92; } to { scale: 1.08; } }
.veil { position: absolute; inset: 0; background: var(--paper); background-image: radial-gradient(rgba(43, 38, 34, 0.1) 1px, transparent 1.2px); background-size: 7px 7px; z-index: 6; display: grid; place-items: center; font-size: 84px; font-weight: 900; color: var(--red); }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(43, 38, 34, 0.55); }
.sheet { width: 100%; max-width: 400px; max-height: 92dvh; overflow-y: auto; padding: 18px; border: 3px solid var(--ink); border-radius: 18px; background: var(--paper2); box-shadow: 6px 6px 0 var(--ink); text-align: center; }
.sheet h2 { margin: 0 0 6px; font-size: 1.35rem; }
.sheet p { margin: 6px 0; }
.sheet .stars { font-size: 2.2rem; letter-spacing: 4px; margin: 6px 0; }
.sheet .stars .off { opacity: 0.22; filter: grayscale(1); }
.rows { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.rows > div { padding: 8px 4px; border: 2px solid var(--ink); border-radius: 10px; background: #fff8e3; }
.rows b { display: block; font-size: 1.25rem; } .rows span { font-size: 0.74rem; color: var(--dim); }
.grid5 { display: flex; justify-content: center; gap: 6px; margin: 10px 0; }
.grid5 span { flex: 1; min-width: 0; max-width: 60px; padding: 6px 0 4px; border: 2px solid var(--ink); border-radius: 10px; background: #fff8e3; font-size: 1.25rem; display: flex; flex-direction: column; align-items: center; }
.grid5 small { font-size: 0.58rem; font-weight: 800; color: var(--dim); white-space: nowrap; letter-spacing: -0.04em; }
.newcards { margin: 8px 0; padding: 8px; border: 2px dashed var(--ink); border-radius: 10px; background: #fff0bf; font-weight: 800; font-size: 0.86rem; }
.fails { margin: 8px 0; font-size: 0.84rem; color: var(--dim); }
.acts { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.acts.row { flex-direction: row; } .acts.row .btn { flex: 1; }
.help { text-align: left; }
.help ol, .help ul { margin: 6px 0 10px; padding-left: 20px; font-size: 0.88rem; line-height: 1.5; }
.help li b { color: var(--red); }
.noscript { text-align: center; padding: 30px; }

/* ── 보조 화면: 연습장·딱지 도감·기록·돌려 하기 ── */
.textbtn { display: block; min-height: 44px; margin: 8px auto 0; padding: 10px 16px; border: 0; background: none; color: var(--dim); font-weight: 800; font-size: 0.86rem; text-decoration: underline; }
.sec { margin: 16px auto 8px; font-size: 1rem; }
.pgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pcard { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 7px; border-radius: 12px; border: 2px solid var(--ink); background: #fff8e3; box-shadow: 2px 2px 0 var(--ink); min-width: 0; }
.pcard:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.pcard b { font-size: 0.8rem; line-height: 1.2; max-width: 100%; word-break: keep-all; text-align: center; }
.pcard small { font-size: 0.68rem; line-height: 1.25; color: var(--dim); max-width: 100%; word-break: keep-all; text-align: center; }
.pcard.lock { background: #e9dfc6; opacity: 0.75; } .pcard.none { background: #f1e8cf; }
.cardcv { display: block; flex: none; margin: 0 auto; }
.seg { display: flex; gap: 6px; margin: 10px 0; }
.seg button { flex: 1; min-width: 0; padding: 8px 2px; border-radius: 10px; border: 2px solid var(--ink); background: #fff8e3; font-weight: 900; font-size: 0.9rem; }
.seg button small { display: block; font-size: 0.64rem; font-weight: 700; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button.on { background: var(--ink); color: var(--paper); } .seg button.on small { color: #d8cdb0; }
.needs { list-style: none; margin: 10px 0; padding: 0; text-align: left; font-size: 0.84rem; }
.needs li { padding: 6px 8px 6px 30px; margin-bottom: 5px; border: 2px solid var(--ink); border-radius: 10px; background: #fff8e3; position: relative; opacity: 0.8; }
.needs li::before { content: "○"; position: absolute; left: 9px; font-weight: 900; }
.needs li.got { background: #dcefd9; opacity: 1; } .needs li.got::before { content: "✓"; color: var(--grn); }
.needs b { margin-right: 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.8rem; background: #fff8e3; border: 2px solid var(--ink); }
.tbl th, .tbl td { padding: 6px 4px; border-bottom: 1px solid rgba(43, 38, 34, 0.25); text-align: center; }
.tbl th { background: var(--yel); font-size: 0.72rem; } .tbl td:first-child, .tbl th:first-child { text-align: left; padding-left: 8px; }
.tbl small { color: var(--dim); }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dashed rgba(43, 38, 34, 0.3); text-align: left; font-weight: 800; }
.setrow .btn { min-width: 84px; padding: 8px 10px; }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px auto 14px; }
.names label { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border: 2px solid var(--ink); border-radius: 10px; background: #fff8e3; font-size: 1.1rem; }
.names input { flex: 1; min-width: 0; width: 100%; border: 0; background: none; font: inherit; font-weight: 900; font-size: 1rem; color: var(--ink); user-select: text; -webkit-user-select: text; outline: none; }
.handoff { text-align: center; padding-top: 10px; }
.handoff .who { font-size: 4.2rem; line-height: 1.1; }
.handoff h2 { margin: 2px 0 6px; font-size: 1.7rem; }
.plist { margin: 12px auto 16px; display: flex; flex-direction: column; gap: 6px; }
.plist > div { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border: 2px solid var(--ink); border-radius: 10px; background: #fff8e3; font-weight: 800; }
.plist > div span:last-child { display: flex; gap: 4px; align-items: center; }
.plist .cur { background: #fff0bf; box-shadow: 3px 3px 0 var(--ink); } .plist .out { opacity: 0.45; text-decoration: line-through; }
.side, .pc-keys { display: none; }
/* 가로로 든 휴대폰 안내(모달보다 위) */
.rotate { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 12px; background: var(--paper); background-image: radial-gradient(rgba(43, 38, 34, 0.1) 1px, transparent 1.2px); background-size: 7px 7px; }
.rotate .sheet { max-width: 360px; }

@media (min-width: 700px) {
  .screen { padding-top: 18px; }
  .board { border-top: 0; }
}
@media (max-height: 620px) { .logo-art { display: none; } h1 { font-size: 1.5rem; } }
@media (prefers-reduced-motion: reduce) { .logo-art i, .banner b { animation: none; } }

/* ── PC(넓은 화면): 놀이판을 가운데 두고 왼쪽에 지시·요령, 오른쪽에 조작·키 안내 ── */
@media (min-width: 860px) and (min-height: 560px) {
  #stage { flex-direction: row; justify-content: center; align-items: center; gap: 20px; }
  .board { border-top: 2px solid var(--ink); }
  .side, .rest { flex: none; width: 200px; min-height: 0; padding: 14px; border: 2px solid var(--ink); border-radius: var(--r); background: var(--paper2); box-shadow: 3px 3px 0 var(--ink); pointer-events: none; }
  .side { display: flex; flex-direction: column; gap: 6px; text-align: left; }
  .side small { font-weight: 800; color: var(--dim); font-size: 0.88rem; }
  .side b { font-size: 1.6rem; line-height: 1.15; color: var(--red); word-break: keep-all; }
  .side span { font-size: 0.94rem; line-height: 1.5; word-break: keep-all; }
  .rest { gap: 8px; color: var(--ink); font-size: 1.05rem; word-break: keep-all; }
  .rest small { font-size: 0.88rem; }
  .pc-keys { display: block; color: var(--dim); }
}
/* 큰 모니터: 놀이판이 커지는 만큼 양옆 안내도 키운다 */
@media (min-width: 1500px) and (min-height: 900px) {
  #stage { gap: 28px; }
  .side, .rest { width: 260px; padding: 20px; }
  .side small { font-size: 1.02rem; }
  .side b { font-size: 2.1rem; }
  .side span { font-size: 1.1rem; }
  .rest { font-size: 1.25rem; }
  .rest small { font-size: 1.02rem; }
  .bossbar { font-size: 0.95rem; }
}
