@font-face {
  font-family: "Galmuri";
  src: url("/static/fonts/galmuri11.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --blue: #1565c0;
  --blue-d: #0b3c7a;
  --red: #e64935;        /* art-direction: vehicle */
  --red-d: #b71c1c;
  --yellow: #ffc842;     /* art-direction: gold */
  --yellow-d: #ff8f00;
  --cream: #f8e8d0;      /* art-direction: cream */
  --ink: #1a2b45;
  --panel: rgba(255, 252, 247, 0.96);
  --sky: #84c9ff;        /* art-direction: sky */
  --grass: #8bcb89;
  --water: #56badd;
  --rail: #53606d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b1e3a;
  font-family: "Galmuri", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  touch-action: none;
  image-rendering: pixelated;
}

#scene-root { position: fixed; inset: 0; z-index: 0; }
#scene-root canvas { display: block; width: 100% !important; height: 100% !important; }

/* ===== 화면 공통 ===== */
.screen {
  position: fixed; inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.screen.active { display: flex; }
#screen-game.active { display: block; pointer-events: none; }
#screen-game.active .touch-btn,
#screen-game.active .btn-skip { pointer-events: auto; }

/* ===== 버튼 (픽셀 스타일: 각진 테두리 + 하드 섀도우) ===== */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 18px;
  border: 3px solid #1a2b45;
  border-radius: 4px;
  padding: 14px 26px;
  cursor: pointer;
  color: #fff;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.35), inset 0 3px 0 rgba(255,255,255,0.3);
  transition: transform .06s, box-shadow .06s;
  letter-spacing: 0.5px;
  image-rendering: pixelated;
}
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 rgba(0,0,0,0.35), inset 0 3px 0 rgba(255,255,255,0.3); }
.btn-primary { background: var(--yellow); color: #5b3a00; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.btn-secondary { background: var(--blue); }
.btn-icon { background: linear-gradient(#64b5f6, var(--blue)); padding: 12px 16px; font-size: 22px; }

/* ===== 타이틀 화면 (레퍼런스 레이아웃: 상단 로고 / 하단 버튼) ===== */
#screen-title {
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 64px) 16px calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(rgba(11,30,58,0.15), rgba(11,30,58,0.0) 35%, rgba(11,30,58,0.45));
}
.title-top { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
/* 레퍼런스: 나무판 위에 올라간 입체 로고 */
.logo {
  display: flex; flex-direction: column; line-height: 0.92;
  background: linear-gradient(#a06a3c, #7a4a24);
  border: 4px solid #3a2410; border-radius: 6px;
  padding: 14px 26px 18px;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.4), inset 0 3px 0 rgba(255,255,255,0.18);
  position: relative;
}
.logo::before {
  content: ""; position: absolute; inset: 6px; border-radius: 3px;
  border: 2px dashed rgba(255,255,255,0.22); pointer-events: none;
}
.logo-top {
  font-size: clamp(46px, 13vw, 84px); font-weight: 700; letter-spacing: 6px;
  font-family: "Galmuri", "Arial Black", sans-serif;
  color: #7cd3ff;
  -webkit-text-stroke: 2px #103f7a; paint-order: stroke fill;
  text-shadow: 3px 4px 0 #0b3c7a;
}
.logo-bottom {
  font-size: clamp(54px, 16vw, 100px); font-weight: 700; letter-spacing: 6px;
  font-family: "Galmuri", "Arial Black", sans-serif;
  color: #ffcf45;
  -webkit-text-stroke: 2px #6b3f00; paint-order: stroke fill;
  text-shadow: 3px 4px 0 #7a4a00;
  margin-top: 4px;
}
.crown { -webkit-text-stroke: 0; text-shadow: 2px 2px 0 #7a4a00; }
.tagline {
  color: #fff; font-weight: 700; font-size: clamp(13px, 4vw, 19px); line-height: 1.4;
  background: var(--blue); padding: 9px 20px; border-radius: 4px;
  border: 3px solid #1a2b45; box-shadow: 4px 4px 0 rgba(0,0,0,0.3); margin: 0;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}
.btn-big { width: min(340px, 86vw); font-size: 24px; padding: 18px 20px; border-radius: 20px; }
.chev { font-weight: 900; }
.disclaimer { color: #e3f0ff; font-size: 11px; margin: 4px 0 0; max-width: 320px; line-height: 1.4; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }

/* 지역 나무 표지판 (레퍼런스: 명동/강촌) */
.place-sign {
  position: absolute; top: 46%;
  background: linear-gradient(#caa472, #a07a48);
  color: #4a2e12; font-weight: 700; font-size: 16px;
  padding: 7px 14px; border-radius: 4px; border: 3px solid #3a2410;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.3), inset 0 2px 0 rgba(255,255,255,0.25);
  z-index: 9; pointer-events: none; text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}
.place-sign.left { left: 10px; transform: rotate(-4deg); }
.place-sign.right { right: 10px; transform: rotate(4deg); }

/* 레퍼런스 상단 바: 좌(닭갈비) / 우(별점+설정) */
.top-bar {
  position: absolute; top: calc(env(safe-area-inset-top) + 14px); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 14px; z-index: 11;
}
.top-right { display: flex; align-items: center; gap: 10px; }
.tb-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(11,30,58,0.62); color: #fff; font-weight: 800; font-size: 16px;
  padding: 5px 6px 5px 14px; border-radius: 20px; border: 2px solid rgba(255,255,255,0.45);
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
}
.tb-chip b { color: var(--yellow); }
.tb-chip.chicken b { color: #ffab91; }
.tb-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(#66bb6a, #388e3c); color: #fff; font-style: normal;
  font-weight: 900; font-size: 16px; border: 2px solid #fff; margin-left: 2px;
}
.tb-gear {
  width: 44px; height: 44px; border-radius: 4px; border: 3px solid #1a2b45;
  background: var(--blue); color: #fff; font-size: 22px;
  cursor: pointer; box-shadow: 4px 4px 0 rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
}
.tb-gear:active { transform: translate(4px, 4px); box-shadow: 0 0 0 rgba(0,0,0,0.3); }

/* ===== 패널 (방법 / 결과) - 픽셀 스타일 ===== */
#screen-how, #screen-result { background: rgba(11,30,58,0.78); }
.panel {
  background: var(--panel); border-radius: 6px; padding: 22px;
  width: min(440px, 92vw); max-height: 88vh; overflow-y: auto;
  border: 4px solid var(--ink); box-shadow: 8px 8px 0 rgba(0,0,0,0.35);
}
.panel h2 { text-align: center; color: var(--blue); margin: 0 0 16px; font-size: 24px; letter-spacing: 1px; }
.how-list { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 12px; }
.how-list li { background: var(--cream); border: 2px solid #c9b48f; border-radius: 4px; padding: 10px 12px; font-size: 13px; line-height: 1.6; }
.how-list b { color: var(--red-d); }
kbd {
  background: #fff; border: 2px solid var(--ink); border-radius: 3px;
  padding: 1px 7px; font-weight: 700; box-shadow: 2px 2px 0 var(--ink); margin: 0 1px;
}
#btn-how-back { display: block; margin: 8px auto 0; }

/* ===== HUD ===== */
.hud-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 8px) 10px 8px; z-index: 11; }
.gauges { display: flex; gap: 10px; }
.gauge { flex: 1; background: rgba(11,30,58,0.65); border: 2px solid #1a2b45; border-radius: 4px; padding: 5px 8px; display: flex; align-items: center; gap: 6px; }
.g-label { font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap; }
.g-bar { flex: 1; height: 12px; background: rgba(0,0,0,0.4); border-radius: 2px; overflow: hidden; border: 2px solid rgba(0,0,0,0.5); }
.g-fill { height: 100%; width: 100%; border-radius: 0; transition: width .2s; }
.g-fill.temp { background: linear-gradient(90deg, #ff7043, #ffca28); }
.g-fill.quality { background: linear-gradient(90deg, #42a5f5, #26c6da); }
.g-val { font-size: 11px; font-weight: 700; color: #fff; width: 40px; text-align: right; }
.hud-info { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 6px; }
.hud-stage { background: var(--red); color: #fff; font-weight: 700; font-size: 12px; padding: 3px 12px; border-radius: 3px; border: 2px solid #1a2b45; }
.hud-time { background: rgba(11,30,58,0.65); color: #fff; font-weight: 700; font-size: 13px; padding: 3px 10px; border-radius: 3px; border: 2px solid #1a2b45; min-width: 60px; text-align: center; }
.hud-shield { background: var(--yellow); color: #5b3a00; font-weight: 700; font-size: 12px; padding: 3px 10px; border-radius: 3px; border: 2px solid #1a2b45; }
.progress-track { margin-top: 8px; height: 10px; background: rgba(0,0,0,0.4); border-radius: 2px; overflow: hidden; border: 2px solid rgba(0,0,0,0.5); }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--yellow), var(--red)); transition: width .25s; }

/* ===== 중앙 메시지 / 팝업 / 배너 ===== */
.center-msg {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; font-size: clamp(28px, 9vw, 56px); font-weight: 900;
  color: #fff; -webkit-text-stroke: 3px var(--blue-d); paint-order: stroke fill;
  z-index: 12; pointer-events: none; opacity: 0; transition: opacity .2s; line-height: 1.1;
}
.center-msg.show { opacity: 1; }
.center-msg .sub { display: block; font-size: 0.42em; margin-top: 8px; -webkit-text-stroke: 2px var(--blue-d); }
.center-msg.pedal { -webkit-text-stroke: 3px var(--red-d); }

.popup {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, 0);
  font-size: 26px; font-weight: 900; color: var(--yellow);
  -webkit-text-stroke: 2px #7a4a00; paint-order: stroke fill;
  z-index: 12; pointer-events: none; opacity: 0;
}
.popup.show { animation: popup-anim 1s ease-out; }
@keyframes popup-anim {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -10px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50px) scale(1); }
}

.stage-banner {
  position: absolute; top: 88px; left: 50%; transform: translate(-50%, 0);
  background: linear-gradient(#a06a3c, #7a4a24); color: #fff;
  border: 3px solid #3a2410;
  padding: 6px 18px; border-radius: 4px; text-align: center;
  z-index: 12; pointer-events: none; opacity: 0; transition: opacity .3s; max-width: 88vw;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3), inset 0 2px 0 rgba(255,255,255,0.15);
}
.stage-banner.show { opacity: 1; }
.stage-banner .s-name { font-size: 16px; font-weight: 900; color: var(--yellow); text-shadow: 0 2px 0 rgba(0,0,0,0.4); }
.stage-banner .s-sub { font-size: 11px; margin-top: 1px; color: #ffd9a8; font-weight: 700; letter-spacing: -0.3px; }
.stage-banner .s-desc { font-size: 11px; margin-top: 2px; color: #ffe8cf; }

/* 랜드마크 안내 토스트 (배너 바로 아래) */
.landmark-toast {
  position: absolute; top: 150px; left: 50%; transform: translate(-50%, 8px);
  background: rgba(11,30,58,0.82); color: #fff; font-weight: 800; font-size: 13px;
  padding: 5px 14px; border-radius: 4px; border: 2px solid var(--yellow);
  z-index: 12; pointer-events: none; opacity: 0;
  transition: opacity .35s, transform .35s; max-width: 86vw;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.3);
}
.landmark-toast.show { opacity: 1; transform: translate(-50%, 0); }
.landmark-toast .lm-pin { color: var(--yellow); }

/* ===== 모바일 조작 버튼 ===== */
.touch-controls {
  position: absolute; bottom: calc(env(safe-area-inset-bottom) + 16px); left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 0 20px; z-index: 11;
}
.touch-btn {
  width: 92px; height: 92px; border-radius: 8px;
  font-size: 40px; font-weight: 700; color: #fff; border: 4px solid #1a2b45;
  background: var(--blue);
  box-shadow: 5px 5px 0 rgba(0,0,0,0.35); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .06s, box-shadow .06s;
  line-height: 1; text-align: center; padding: 0;
}
.touch-btn:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 rgba(0,0,0,0.35); }
.touch-btn.pedal { background: var(--red); font-size: 20px; letter-spacing: -1px; }

.btn-skip { position: absolute; top: calc(env(safe-area-inset-top) + 90px); right: 12px; font-size: 14px; padding: 8px 14px; z-index: 13; background: var(--blue); }

/* 일시정지 버튼 + 오버레이 */
.btn-pause {
  position: absolute; top: calc(env(safe-area-inset-top) + 90px); left: 12px; z-index: 13;
  width: 42px; height: 42px; border-radius: 4px; border: 3px solid #1a2b45;
  background: var(--blue); color: #fff; font-size: 18px; cursor: pointer;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.3); pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
}
.btn-pause:active { transform: translate(4px,4px); box-shadow: 0 0 0 rgba(0,0,0,0.3); }
.pause-overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(11,30,58,0.8); pointer-events: auto;
}
.pause-panel { width: min(320px, 82vw); }
.pause-panel .result-btns { flex-direction: column; }

/* ===== 결과 ===== */
.result-panel { text-align: center; }
.grade { font-size: 88px; font-weight: 900; line-height: 1; margin: 6px 0 14px; -webkit-text-stroke: 6px var(--blue-d); paint-order: stroke fill; }
.grade.S { color: #ffd54f; } .grade.A { color: #81c784; } .grade.B { color: #64b5f6; } .grade.C { color: #e0e0e0; }
.result-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; text-align: left; }
.r-row { display: flex; justify-content: space-between; background: var(--cream); border: 2px solid #c9b48f; padding: 9px 14px; border-radius: 3px; font-size: 14px; font-weight: 700; }
.r-row.detail { background: #eef3fb; border-color: #c3d2e8; font-size: 12px; color: #456; }
.r-row.total { background: var(--blue); border-color: #0b3c7a; color: #fff; font-size: 18px; }
.r-row.best { background: #fff3e0; border-color: #e8cfa0; color: var(--yellow-d); }
.r-row b { font-weight: 700; }
.result-btns { display: flex; gap: 10px; justify-content: center; }
.result-btns .btn { flex: 1; font-size: 15px; padding: 14px 10px; white-space: nowrap; }

/* ===== 로딩 ===== */
.loading {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: #0b1e3a; color: #fff; font-size: 24px; font-weight: 800;
}
.loading.hidden { display: none; }
.hidden { display: none !important; }

/* 데스크톱에서는 터치 버튼을 반투명하게 */
@media (hover: hover) and (pointer: fine) {
  .touch-btn { opacity: 0.55; }
}
