/* 도시 탐방대 — 디자인 토큰(교육·초등 레시피: 하늘 primary · 초록 보조 · 노랑 강조). 글자·터치는 전부 DOM, 월드만 캔버스. */
:root {
  --primary: 199 89% 34%;            /* 하늘(까치 깃털 파랑) — 흰 글자 대비 ≥ 4.5 */
  --primary-foreground: 0 0% 100%;
  --accent: 43 96% 56%;              /* 탐방대 모자 노랑 */
  --accent-foreground: 222 47% 11%;
  --secondary: 142 64% 30%;          /* 초록 */
  --secondary-foreground: 0 0% 100%;
  --background: 205 60% 97%;
  --foreground: 222 47% 11%;
  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;
  --muted: 205 30% 92%;
  --muted-foreground: 215 20% 35%;
  --border: 205 25% 80%;
  --destructive: 0 72% 42%;
  --destructive-foreground: 0 0% 100%;
  --bronze: 28 58% 38%;
  --silver: 215 12% 40%;
  --gold: 40 90% 34%;
  --ring: 199 89% 40%;
  --radius: 1rem;
  --shadow: 0 6px 20px hsl(215 40% 20% / 0.18);
  --font: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Noto Sans CJK KR', 'Malgun Gothic', system-ui, sans-serif;
  --fs: 16px;
  --z-labels: 10; --z-hud: 20; --z-panel: 40; --z-toast: 60; --z-boot: 80;
}
.dark {
  --background: 215 30% 12%; --foreground: 205 40% 96%; --card: 215 28% 18%; --card-foreground: 205 40% 96%;
  --muted: 215 20% 24%; --muted-foreground: 205 20% 78%; --border: 215 20% 32%;
  --primary: 199 89% 34%; --primary-foreground: 0 0% 100%; --accent: 43 96% 56%; --accent-foreground: 222 47% 11%;
  --secondary: 142 64% 30%; --secondary-foreground: 0 0% 100%; --destructive: 0 72% 42%; --destructive-foreground: 0 0% 100%;
  --bronze: 28 58% 38%; --silver: 215 12% 40%; --gold: 40 90% 34%; --ring: 199 89% 55%;
}
html.bigtext { --fs: 20px; }
html.board { --fs: 22px; }                     /* 전자칠판 */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: hsl(var(--background)); color: hsl(var(--foreground)); font-family: var(--font); font-size: var(--fs); -webkit-text-size-adjust: 100%; }
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; height: 100dvh; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; outline: none; }
#labels { position: absolute; inset: 0; pointer-events: none; z-index: var(--z-labels); overflow: hidden; }
#hud { position: absolute; inset: 0; pointer-events: none; z-index: var(--z-hud); padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
#hud .ptr, #hud button, #hud .btn { pointer-events: auto; }
#panel { position: absolute; inset: 0; z-index: var(--z-panel); display: flex; align-items: center; justify-content: center; background: hsl(215 40% 12% / 0.45); padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
#panel.clear { background: transparent; pointer-events: none; }
#panel.clear > * { pointer-events: auto; }
#toast { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); z-index: var(--z-toast); pointer-events: none; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: hsl(var(--card)); color: hsl(var(--card-foreground)); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); font-weight: 700; animation: pop .25s ease-out; max-width: 86vw; text-align: center; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 버튼 */
.btn { min-height: 48px; min-width: 48px; padding: 10px 18px; border-radius: var(--radius); border: 2px solid transparent; font: inherit; font-weight: 800; cursor: pointer; background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); box-shadow: var(--shadow); display: inline-flex; align-items: center; justify-content: center; gap: 8px; touch-action: manipulation; }
.btn.alt { background: hsl(var(--card)); color: hsl(var(--card-foreground)); border-color: hsl(var(--border)); }
.btn.accent { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.btn.green { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn.round { border-radius: 999px; width: 56px; height: 56px; padding: 0; font-size: 1.4em; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .choice:focus-visible, .tab:focus-visible, .cell:focus-visible { outline: 3px solid hsl(var(--ring)); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }

/* HUD */
.hud-tl { position: absolute; left: max(10px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); display: flex; gap: 8px; align-items: center; }
.hud-tr { position: absolute; right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); display: flex; gap: 8px; align-items: flex-start; }
.hud-bl { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.hud-br { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
.hud-tc { position: absolute; left: 50%; top: max(10px, env(safe-area-inset-top)); transform: translateX(-50%); max-width: min(560px, 60vw); }
.chip { background: hsl(var(--card) / 0.94); color: hsl(var(--card-foreground)); border-radius: 999px; padding: 6px 14px; font-weight: 800; box-shadow: var(--shadow); display: inline-flex; gap: 6px; align-items: center; min-height: 44px; }
.mission { background: hsl(var(--card) / 0.96); color: hsl(var(--card-foreground)); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); font-weight: 700; line-height: 1.35; text-align: center; }
.mission small { display: block; color: hsl(var(--muted-foreground)); font-weight: 600; margin-top: 2px; }
.mission .hint { color: hsl(var(--primary)); }
.compass { width: 84px; height: 84px; border-radius: 50%; background: hsl(var(--card) / 0.95); box-shadow: var(--shadow); position: relative; cursor: pointer; }
.compass .rose { position: absolute; inset: 0; transition: transform .05s linear; }
.compass .n { position: absolute; left: 50%; top: 4px; transform: translateX(-50%); font-weight: 900; color: hsl(var(--destructive)); font-size: 17px; }
.compass .needle { position: absolute; left: 50%; top: 12px; width: 0; height: 0; margin-left: -8px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 24px solid hsl(var(--destructive)); }
.compass .needle.s { top: auto; bottom: 12px; border-bottom: 0; border-top: 24px solid hsl(var(--muted-foreground)); }
.compass .d { position: absolute; font-size: 16px; font-weight: 800; color: hsl(var(--muted-foreground)); }
.scalebar { background: hsl(var(--card) / 0.95); border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); font-weight: 800; font-size: 16px; }
.scalebar .bar { height: 8px; border: 2px solid hsl(var(--foreground)); border-top: 0; margin-top: 4px; }
.legend { background: hsl(var(--card) / 0.95); border-radius: 12px; padding: 6px 10px; box-shadow: var(--shadow); font-size: 16px; max-width: 46vw; }
.legend .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; border: 1px solid hsl(var(--border)); flex: none; }
.dots { display: flex; gap: 6px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: hsl(var(--muted)); border: 2px solid hsl(var(--border)); }
.dots i.on { background: hsl(var(--accent)); border-color: hsl(var(--gold)); }
.dots i.kk { border-radius: 4px; }
.layers { display: flex; flex-direction: column; gap: 6px; }
.stick { position: absolute; width: 120px; height: 120px; border-radius: 50%; background: hsl(var(--card) / 0.35); border: 2px solid hsl(var(--card) / 0.8); pointer-events: none; }
.stick i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: hsl(var(--card) / 0.9); box-shadow: var(--shadow); }

/* 월드 라벨(R.project) */
.lbl { position: absolute; transform: translate(-50%, -100%); white-space: nowrap; font-weight: 800; font-size: 14px; padding: 3px 9px; border-radius: 999px; background: hsl(var(--card) / 0.92); color: hsl(var(--card-foreground)); box-shadow: 0 2px 6px hsl(215 40% 20% / 0.25); }
.lbl.gu { background: transparent; box-shadow: none; color: hsl(215 40% 20%); text-shadow: 0 0 3px #fff, 0 0 6px #fff; font-size: 15px; }
.lbl.bronze { border: 2px solid hsl(var(--bronze)); } .lbl.silver { border: 2px solid hsl(var(--silver)); } .lbl.gold { border: 2px solid hsl(var(--gold)); background: hsl(48 100% 92%); }
.lbl.ptr { pointer-events: auto; cursor: pointer; }
.edge { position: absolute; width: 44px; height: 44px; margin: -22px; border-radius: 50%; background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); display: grid; place-items: center; font-weight: 900; box-shadow: var(--shadow); }
.arrow2d { position: absolute; width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent; border-bottom: 40px solid hsl(var(--accent)); filter: drop-shadow(0 2px 3px hsl(0 0% 0% / .4)); margin: -20px -14px; }

/* 카드·패널 */
.card { background: hsl(var(--card)); color: hsl(var(--card-foreground)); border-radius: 22px; box-shadow: var(--shadow); width: min(640px, 100%); max-height: calc(100dvh - 24px); overflow: auto; padding: 18px; position: relative; }
.card.wide { width: min(980px, 100%); }
.card h2 { margin: 0 0 8px; font-size: 1.35em; }
.card h3 { margin: 12px 0 6px; font-size: 1.1em; }
.card p { line-height: 1.55; margin: 6px 0; }
.card .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.card .close { position: absolute; right: 10px; top: 10px; }
.kkachi-say { display: flex; gap: 12px; align-items: flex-start; }
.kkachi-say img { width: 72px; height: 72px; flex: none; }
.bubble { background: hsl(var(--muted)); border-radius: 16px; padding: 10px 14px; line-height: 1.5; font-weight: 600; }
.choices { display: grid; gap: 10px; margin-top: 12px; }
.choice { min-height: 52px; text-align: left; padding: 12px 16px; border-radius: 14px; border: 2px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--card-foreground)); font: inherit; font-weight: 700; cursor: pointer; }
.choice.dim { opacity: .35; text-decoration: line-through; cursor: default; }
.choice.ok { border-color: hsl(var(--secondary)); background: hsl(142 60% 92%); }
.choice .no { font-weight: 900; margin-right: 8px; color: hsl(var(--primary)); }
.explain { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: hsl(48 100% 94%); color: hsl(var(--foreground)); font-weight: 600; }
.stars { color: hsl(var(--gold)); font-size: 1.2em; letter-spacing: 2px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tab { min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 2px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--card-foreground)); font: inherit; font-weight: 800; cursor: pointer; }
.tab[aria-selected="true"] { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: hsl(var(--primary)); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.cell { border-radius: 14px; border: 3px solid hsl(var(--border)); background: hsl(var(--muted)); padding: 6px; text-align: center; font-weight: 700; font-size: 16px; min-height: 120px; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: flex-start; cursor: pointer; color: hsl(var(--card-foreground)); font-family: inherit; }
.cell img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: hsl(var(--card)); }
.cell .ph { width: 100%; aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; font-size: 30px; background: hsl(var(--card)); }
.cell.locked { opacity: .55; } .cell.bronze { border-color: hsl(var(--bronze)); } .cell.silver { border-color: hsl(var(--silver)); } .cell.gold { border-color: hsl(var(--gold)); background: hsl(48 100% 92%); }
.meter { height: 12px; border-radius: 999px; background: hsl(var(--muted)); overflow: hidden; }
.meter i { display: block; height: 100%; background: hsl(var(--secondary)); }
.sim { width: 100%; aspect-ratio: 16/7; background: hsl(var(--muted)); border-radius: 14px; display: block; }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.subway { width: 100%; height: min(62dvh, 560px); background: hsl(var(--card)); border-radius: 14px; touch-action: none; display: block; }
.title-screen { text-align: center; }
.title-screen .logo { font-size: 2.1em; font-weight: 900; color: hsl(var(--primary)); margin: 6px 0; }
.boot { position: absolute; inset: 0; z-index: var(--z-boot); display: grid; place-items: center; background: hsl(var(--background)); }
.boot-card { width: min(420px, 86vw); text-align: center; }
.boot-title { font-size: 1.8em; font-weight: 900; color: hsl(var(--primary)); margin-bottom: 14px; }
.boot-bar { height: 14px; border-radius: 999px; background: hsl(var(--muted)); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: hsl(var(--primary)); transition: width .2s; }
.boot-msg { margin-top: 10px; color: hsl(var(--muted-foreground)); font-weight: 700; }
.fade { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 35; transition: opacity .6s; }
.fade.on { opacity: 1; }
@media (max-width: 1000px) { .hud-tc { top: calc(max(10px, env(safe-area-inset-top)) + 58px); max-width: calc(100vw - 210px); } }   /* 태블릿: 좌상 칩 줄 아래로(겹침 — e2e-screens 실측) */
@media (max-width: 600px) { .hud-tc { max-width: 92vw; top: calc(max(10px, env(safe-area-inset-top)) + 96px); } .compass { width: 76px; height: 76px; } .legend { display: none; } .legend.show { display: block; }
  .hud-br { flex-direction: column; flex-wrap: nowrap; max-width: none; } .hud-br .btn.round { width: 50px; height: 50px; } }   /* 폰: 오른쪽 아래 단추를 세로로 — 축척 막대와 겹쳤다 */
.mission .ptitle { font-weight: 900; color: hsl(var(--primary)); }
.card label.row { min-height: 44px; }   /* 설정의 체크·슬라이더 줄 전체가 터치 타깃(20 px 이던 것 — D28) */
.card label.row input[type=checkbox] { width: 26px; height: 26px; }
.card label.row input[type=range] { flex: 1; min-height: 32px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* 찾아가기 오버레이(하늘) */
.navcircle { position: absolute; left: 0; top: 0; border-radius: 50%; border: 4px dashed hsl(var(--accent)); background: hsl(var(--accent) / 0.12); animation: kk-pulse 1.2s ease-in-out infinite; }
.edge.goal { left: 0; top: 0; pointer-events: none; animation: kk-bounce 0.9s ease-in-out infinite; }
.tapring { position: absolute; left: 0; top: 0; width: 36px; height: 36px; margin: -18px; border-radius: 50%; border: 4px solid hsl(var(--card)); box-shadow: 0 0 0 3px hsl(215 40% 20% / 0.5); animation: kk-ring 0.9s ease-out forwards; }
.arrow2d { left: 0; top: 0; transform-origin: 50% 100%; }
.flash { position: fixed; inset: 0; background: #fff; z-index: var(--z-toast); pointer-events: none; animation: kk-flash 0.35s ease-out forwards; }
@keyframes kk-pulse { 50% { opacity: 0.55; } }
@keyframes kk-bounce { 50% { margin-top: -30px; } }
@keyframes kk-ring { from { opacity: 1; } to { opacity: 0; width: 80px; height: 80px; margin: -40px; } }
@keyframes kk-flash { from { opacity: 0.9; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .navcircle, .edge.goal, .tapring { animation: none; } }
:root.reduced .navcircle, :root.reduced .edge.goal, :root.reduced .tapring { animation: none; }

/* 글자 하한 16 px(GDD D28) — 브라우저 기본 small(0.83em)이 13 px 로 떨어졌다 */
small { font-size: max(16px, 0.85em); }
/* 수첩 꾸미기(해금제) — 표지 띠 색만 바꾼다(가독성 토큰은 그대로) */
.nb-theme { border-top: 10px solid hsl(var(--primary)); }
.nb-theme.nb1 { border-top-color: #3d8fd6; } .nb-theme.nb2 { border-top-color: #b5563a; } .nb-theme.nb3 { border-top-color: #e0a52a; }
