:root {
  --bg: #0b1d3a;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-line: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #f97316;
  --ok: #16a34a;
  --bad: #dc2626;
  --shadow: 0 18px 50px rgba(2, 6, 23, 0.28);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Pretendard', system-ui, -apple-system, 'Malgun Gothic', sans-serif;
  color: var(--text);
  background: var(--bg);
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
kbd {
  font: 600 11px/1 'Pretendard', sans-serif;
  padding: 3px 6px; border-radius: 6px; margin-left: 6px;
  background: rgba(255, 255, 255, .22);
}

#map { position: fixed; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---------- 상단 ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; padding: 18px 24px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-shadow: 0 1px 8px rgba(0,0,0,.4); }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8); font-weight: 900; font-size: 22px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .5);
}
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: .02em; }
.brand-name b { color: #93c5fd; }
.brand-sub { font-size: 12px; opacity: .8; }

/* 플레이 중 상단: 왼쪽 코스 카드, 오른쪽 기록 칩 (따로 떠 있음) */
.hud { flex: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.hud-trip {
  display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 16px;
  padding: 10px 18px 10px 10px; box-shadow: var(--shadow); border-left: 6px solid var(--accent-2);
}
.hud-exit {
  width: 36px; height: 36px; border: 0; border-radius: 50%; background: #f1f5f9; color: var(--muted);
  font-weight: 800; font-size: 15px;
}
.hud-exit:hover { background: #fee2e2; color: var(--bad); }
.hud-course { font-weight: 800; font-size: 16px; white-space: nowrap; }
.hud-count { font-size: 12px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.hud-stats { display: flex; gap: 8px; }
.chip {
  background: var(--panel); border-radius: 14px; padding: 8px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; min-width: 76px;
}
.chip small { font-size: 11px; color: var(--muted); font-weight: 600; }
.chip b { font-size: 20px; font-variant-numeric: tabular-nums; }
.chip.clock { background: #0f172a; min-width: 128px; }
.chip.clock small { color: #94a3b8; }
.chip.clock b { color: #fbbf24; font-size: 22px; }

/* ---------- 패널 ---------- */
.panel {
  position: fixed; z-index: 5; left: 24px; top: 92px; bottom: 24px; width: 400px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 24px; display: flex; flex-direction: column; backdrop-filter: blur(10px);
}
.panel h1 { margin: 0 0 8px; font-size: 26px; }
.panel h2 { margin: 6px 0 8px; font-size: 26px; }
.muted { color: var(--muted); margin: 0 0 18px; line-height: 1.55; font-size: 14px; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.tab {
  border: 1px solid var(--panel-line); background: #f8fafc; border-radius: 12px;
  padding: 10px 4px; font-weight: 800; font-size: 14px; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tab small { font-weight: 500; font-size: 10.5px; color: var(--muted); }
.tab.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tab.on small { color: #dbeafe; }

.course-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.course {
  text-align: left; border: 1px solid var(--panel-line); background: #fff; border-radius: 14px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; transition: transform .15s, box-shadow .15s;
}
.course:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(37, 99, 235, .15); border-color: #bfdbfe; }
.course b { font-size: 17px; }
.course-route { font-size: 13px; color: #334155; line-height: 1.5; }
.course-meta { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: 14px; }

.detail-tier {
  align-self: flex-start; background: #eff6ff; color: var(--accent); font-weight: 700; font-size: 12px;
  padding: 5px 10px; border-radius: 99px;
}
.route { list-style: none; padding: 0; margin: 0 0 16px; overflow-y: auto; flex: 1; }
.route li { position: relative; padding: 0 0 4px 22px; }
.route li::before {
  content: ''; position: absolute; left: 4px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
}
.route li:not(:last-child)::after {
  content: ''; position: absolute; left: 10px; top: 20px; bottom: -2px; border-left: 2px dashed #93c5fd;
}
.route li b { font-size: 16px; }
.route-leg { display: block; font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.detail-best { background: #f8fafc; border-radius: 12px; padding: 12px 14px; font-size: 14px; color: #334155; margin-bottom: 14px; }
.detail-best b { color: var(--accent); }
.detail-actions { display: flex; gap: 10px; }
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 800; font-size: 16px; }
.btn.primary { flex: 1; background: var(--accent); color: #fff; box-shadow: 0 8px 20px rgba(37, 99, 235, .35); }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { background: #f1f5f9; color: #334155; }
.btn.ghost:hover { background: #e2e8f0; }

/* ---------- 지도 위 표시 ---------- */
.stop { display: flex; align-items: center; gap: 6px; pointer-events: none; }
.stop-dot {
  width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 4px solid #94a3b8;
  box-shadow: 0 2px 6px rgba(0,0,0,.3); flex: none;
}
.stop-label {
  background: rgba(255,255,255,.95); padding: 3px 8px; border-radius: 8px; font-weight: 700; font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2); white-space: nowrap;
}
.stop.current .stop-dot { border-color: var(--accent-2); transform: scale(1.25); }
.stop.current .stop-label { background: var(--accent-2); color: #fff; }
.stop.visited .stop-dot { border-color: var(--accent); background: var(--accent); }
.stop.stamp .stop-dot { animation: stamp .5s ease-out; }
@keyframes stamp { 0% { transform: scale(2.4); } 60% { transform: scale(.85); } 100% { transform: scale(1); } }

.vehicle { width: 40px; height: 40px; display: grid; place-items: center; pointer-events: none; }
.vehicle span {
  font-size: 22px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.35); border: 3px solid var(--accent-2);
}
.vehicle svg { filter: drop-shadow(0 4px 6px rgba(0,0,0,.45)); }

/* ---------- 카운트다운 ---------- */
#countdown {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; pointer-events: none;
  font-size: 140px; font-weight: 900; color: #fff; text-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#countdown.pop { animation: pop .7s ease-out; }
@keyframes pop { 0% { transform: scale(1.8); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1); } }

/* ---------- 타이핑 패널 ---------- */
/* 탑승권 카드: 왼쪽 본권 + 점선 절취선 + 오른쪽 작은 표 */
#typing {
  position: fixed; z-index: 20; left: 32px; bottom: 28px;
  width: min(820px, calc(100vw - 340px));
}
.ticket {
  display: grid; grid-template-columns: 1fr 190px; background: #fffdf7; border-radius: 20px;
  box-shadow: var(--shadow); overflow: hidden; position: relative;
}
.ticket-main { position: relative; padding: 0 28px 20px; }
.ticket-head {
  display: flex; justify-content: space-between; align-items: center; margin: 0 -28px 14px; padding: 10px 28px;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .06em;
}
.ticket[data-type="leg"] .ticket-head { background: var(--accent-2); }
.ticket-step { font-variant-numeric: tabular-nums; opacity: .9; }
.ticket-label { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.t-en { font-size: 13px; color: var(--muted); margin-top: 10px; letter-spacing: .04em; text-transform: uppercase; }

.ticket-stub {
  position: relative; padding: 16px 18px; border-left: 3px dashed #cbd5e1; background: #f8f5ec;
  display: flex; flex-direction: column; gap: 6px;
}
/* 절취선 위아래 반원 홈 */
.ticket-stub::before, .ticket-stub::after {
  content: ''; position: absolute; left: -13px; width: 22px; height: 22px; border-radius: 50%; background: rgba(2, 6, 23, .55);
}
.ticket-stub::before { top: -11px; }
.ticket-stub::after { bottom: -11px; }
.ticket-stub small { font-size: 11px; color: var(--muted); font-weight: 800; letter-spacing: .08em; }
.stub-next { font-weight: 800; font-size: 17px; line-height: 1.35; word-break: keep-all; }
.stub-code {
  margin-top: auto; height: 38px; border-radius: 4px;
  background: repeating-linear-gradient(90deg, #0f172a 0 2px, transparent 2px 4px, #0f172a 4px 7px, transparent 7px 9px, #0f172a 9px 10px, transparent 10px 13px);
  opacity: .8;
}

/* 위: 쳐야 할 글자 (글자는 그대로, 색만 바뀜) */
.t-target { font-size: 40px; font-weight: 900; letter-spacing: .08em; line-height: 1.25; min-height: 50px; }
.ch { display: inline-block; border-radius: 6px; padding: 0 1px; }
.ch.pending { color: #334155; }
.ch.ok { color: #0f766e; }
.ch.now { color: #0f172a; box-shadow: inset 0 -5px 0 #fbbf24; }
.ch.wrong { color: #fff; background: var(--bad); }
.ch.extra { font-size: 20px; vertical-align: middle; margin-left: 6px; padding: 2px 8px; }

/* 아래: 입력칸 */
#inputHost { margin-top: 12px; }
.type-box {
  width: 100%; height: 58px; border: 3px solid #cbd5e1; border-radius: 14px; padding: 0 18px;
  font: 800 28px/1 'Pretendard', 'Malgun Gothic', sans-serif; letter-spacing: .06em; color: var(--text);
  background: #fff; ime-mode: active;
}
.type-box:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, .15); }
.type-box::placeholder { color: #cbd5e1; font-weight: 600; font-size: 18px; letter-spacing: 0; }
#inputHost[data-state="wrong"] .type-box { border-color: var(--bad); box-shadow: 0 0 0 4px rgba(220, 38, 38, .15); animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.finish-time { font-size: 44px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; }

/* 오른쪽 여행 일정표 */
#itinerary {
  position: fixed; z-index: 15; right: 24px; top: 96px; bottom: 28px; width: 260px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 16px;
  display: flex; flex-direction: column;
}
#itinerary h3 { margin: 0 0 10px; font-size: 15px; }
#itList { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#itList li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; color: #94a3b8; font-weight: 700; }
#itList li.leg { padding-left: 22px; font-size: 13px; font-weight: 600; }
#itList li.done { color: #334155; }
#itList li.done.stop .it-icon { background: #0f766e; color: #fff; }
#itList li.now { background: #fff7ed; color: var(--text); outline: 2px solid var(--accent-2); }
.it-icon {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 12px; background: #e2e8f0; color: #64748b;
}
#itList li.leg .it-icon { background: none; font-size: 14px; }
.type-input {
  position: absolute; left: 50%; top: 50%; width: 1px; height: 1px; opacity: 0;
  border: 0; padding: 0; ime-mode: active;
}

/* ---------- 결과 ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(2, 6, 23, .45); }
.modal-box {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow-y: auto;
  background: #fff; border-radius: 22px; padding: 28px; box-shadow: var(--shadow); text-align: center;
}
.result-flag { font-weight: 800; color: var(--accent-2); }
.modal-box h2 { margin: 6px 0 2px; font-size: 22px; }
.result-time { font-size: 54px; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; margin: 6px 0 12px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.result-stats div { background: #f8fafc; border-radius: 12px; padding: 10px; }
.result-stats small { display: block; color: var(--muted); font-size: 12px; }
.result-stats b { font-size: 20px; }
.result-who { margin-bottom: 16px; font-size: 14px; color: #334155; }
.result-who .best { color: var(--accent-2); font-weight: 800; }

/* 출발 전 닉네임 */
.nick { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.nick span { font-weight: 800; font-size: 14px; white-space: nowrap; }
.nick input {
  flex: 1; min-width: 0; height: 46px; border: 2px solid #e2e8f0; border-radius: 12px; padding: 0 14px;
  font: 700 16px 'Pretendard', sans-serif;
}
.nick input:focus { outline: none; border-color: var(--accent); }
.nick span { min-width: 56px; }
.nick-warn { color: var(--bad); font-size: 13px; font-weight: 700; margin: -2px 0 10px; }
.login-help { margin: 0 0 10px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.who {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px;
  background: #eff6ff; border-radius: 12px; padding: 12px 14px; font-size: 14px;
}
.btn.primary:disabled { opacity: .6; cursor: wait; }
.link { border: 0; background: none; color: var(--accent); font-weight: 700; font-size: 13px; text-decoration: underline; padding: 0; }

/* 순위표 (코스 정보 TOP 5, 결과 화면) */
.best-head { font-weight: 800; font-size: 14px; margin-bottom: 6px; }
.best-head small { color: var(--muted); font-weight: 600; margin-left: 4px; }
.mini-board { list-style: none; margin: 0; padding: 0; }
.mini-board li, .board li { display: grid; grid-template-columns: 30px 1fr auto; grid-template-rows: auto auto; padding: 6px 8px; border-radius: 10px; }
.mini-board li .sub { display: none; }
.mini-board li.sep { margin-top: 4px; border-top: 1px dashed #cbd5e1; }
.mini-board li.empty, .board li.empty { display: block; text-align: center; color: var(--muted); font-size: 13px; }
.mini-board li.me, .board li.me { background: #fff7ed; outline: 2px solid var(--accent-2); }
.board-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.board-tabs button { border: 1px solid #e2e8f0; background: #f8fafc; border-radius: 10px; padding: 8px; font-weight: 700; color: #334155; }
.board-tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.my-rank { font-size: 13px; color: #334155; margin: -8px 0 16px; }
.result-who .bad { color: var(--bad); font-weight: 700; }
.modal-box h3 { font-size: 14px; color: var(--muted); text-align: left; margin: 0 0 8px; }
.board { list-style: none; padding: 0; margin: 0 0 18px; text-align: left; }
.board li { display: grid; grid-template-columns: 32px 1fr auto; grid-template-rows: auto auto; padding: 8px 10px; border-radius: 10px; }
.board li:nth-child(odd) { background: #f8fafc; }
.board li.me { background: #fff7ed; outline: 2px solid var(--accent-2); }
.board .rank, .mini-board .rank { grid-row: span 2; font-weight: 900; color: var(--accent); align-self: center; }
.board .nm, .mini-board .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .tm, .mini-board .tm { font-weight: 800; font-variant-numeric: tabular-nums; }
.board .sub { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
.board li.empty { display: block; text-align: center; color: var(--muted); }

/* 좁은 화면 */
@media (max-width: 760px) {
  .panel { left: 12px; right: 12px; width: auto; top: auto; bottom: 12px; max-height: 60vh; }
  #typing { left: 12px; right: 12px; width: auto; bottom: 12px; }
  .ticket { grid-template-columns: 1fr; }
  .ticket-stub, #itinerary { display: none !important; }
  .t-target { font-size: 30px; }
  .hud-course { display: none; }
}
