:root {
  --bg: #eef0f3;
  --card: #ffffff;
  --text: #141821;
  --muted: #6b7180;
  --line: #dcdfe5;
  --navy: #14213d;
  --accent: #00a84d;
  --far: #e5484d;
  --mid: #f2994a;
  --near: #d4a72c;
  --close: #2f9e6e;
  --map-bg: #f7f8fa;
  --map-dot: #ffffff;
  --river: #cfe3f5;
  --edge-opacity: 0.55;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --card: #161b22;
    --text: #eef1f5;
    --muted: #8b93a1;
    --line: #262c36;
    --navy: #0a1426;
    --map-bg: #10151c;
    --map-dot: #10151c;
    --river: #16304a;
    --edge-opacity: 0.6;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header: 역명판 ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--navy);
  color: #fff;
  border-bottom: 6px solid var(--accent);
}
.sign { display: flex; align-items: center; gap: 10px; }
.sign-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 5px solid var(--accent); background: #fff;
}
.sign h1 { margin: 0; font-size: 24px; letter-spacing: 2px; font-weight: 900; }
.sign-no {
  font-size: 13px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
  background: rgba(255,255,255,0.14);
}
.icon {
  width: 36px; height: 36px; flex: none;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.3);
  background: transparent;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.mode-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px;
  background: #fff4d6; color: #6b4e00;
  font-size: 13px; font-weight: 600;
}
.mode-bar button {
  border: 0; background: #6b4e00; color: #fff;
  border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}

main { max-width: 520px; margin: 0 auto; padding: 14px 16px 24px; }

/* ---------- map ---------- */
.map-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px;
  margin-bottom: 12px;
}
.map { display: block; width: 100%; height: auto; background: var(--map-bg); border-radius: 10px; }
.map .river { fill: none; stroke: var(--river); stroke-width: 1.1; stroke-linecap: round; stroke-linejoin: round; }
.map .edge { stroke-width: 0.32; stroke-linecap: round; opacity: var(--edge-opacity); }
.map .dot { fill: var(--map-dot); stroke: var(--muted); stroke-width: 0.07; }
.map .ring { fill: none; stroke-width: 0.35; stroke-dasharray: 0.9 0.6; opacity: 0.9; animation: ring-in 0.6s ease-out both; transform-box: fill-box; transform-origin: center; }
.map .ring-fill { opacity: 0.07; }
.map .gdot { stroke: var(--card); stroke-width: 0.25; }
.map .glabel { font-size: 1.5px; font-weight: 800; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.map .answer { fill: var(--accent); stroke: #fff; stroke-width: 0.3; animation: pop 0.5s ease-out both; transform-box: fill-box; transform-origin: center; }
.map .alabel { font-size: 1.6px; font-weight: 800; fill: var(--text); paint-order: stroke; stroke: var(--map-bg); stroke-width: 0.5px; }
@keyframes ring-in { from { transform: scale(0.2); } to { transform: scale(1); } }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.4); } 100% { transform: scale(1); } }
.map-legend { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); padding: 6px 0 2px; }
.lg { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
.lg.far { background: var(--far); } .lg.mid { background: var(--mid); }
.lg.near { background: var(--near); } .lg.close { background: var(--close); }

/* ---------- guesses ---------- */
.guesses { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.guesses li {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr auto 30px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 50px;
  overflow: hidden;
}
.guesses li.filled { animation: slide-in 0.35s ease-out both; }
.guesses li.empty { background: transparent; border-style: dashed; }
.guesses li::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tone, transparent); }
.g-no {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff;
  background: var(--tone, var(--line));
}
.g-name { font-weight: 800; font-size: 16px; }
.g-lines { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  color: #fff; font-size: 10.5px; font-weight: 800;
  opacity: 0.4;
}
.badge.match { opacity: 1; outline: 2px solid var(--text); outline-offset: 1px; }
.g-dist { font-variant-numeric: tabular-nums; font-weight: 800; text-align: right; color: var(--tone); }
.g-dir { font-size: 22px; text-align: center; display: inline-block; }
.g-dir.arrow { color: var(--tone); font-weight: 900; transition: transform 0.6s cubic-bezier(.2,1.4,.4,1); }
.guesses li.win { border-color: var(--close); background: color-mix(in srgb, var(--close) 14%, var(--card)); }
.tone-far { --tone: var(--far); }
.tone-mid { --tone: var(--mid); }
.tone-near { --tone: var(--near); }
.tone-close, .tone-win { --tone: var(--close); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.hint {
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
  font-size: 14px;
}

/* ---------- input ---------- */
.guess-form { display: flex; gap: 8px; }
.input-wrap { position: relative; flex: 1; }
#input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  font-size: 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--text);
}
#input:focus { outline: none; border-color: var(--accent); }
.guess-form button {
  height: 50px; padding: 0 20px;
  border: 0; border-radius: 12px;
  background: var(--navy); color: #fff;
  font-size: 16px; font-weight: 800;
  cursor: pointer;
}
.guess-form button:disabled, #input:disabled { opacity: 0.4; cursor: default; }
.suggest {
  position: absolute; left: 0; right: 0; bottom: 54px;
  list-style: none; margin: 0; padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  max-height: 240px; overflow-y: auto;
  z-index: 5;
}
.suggest li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.suggest li.active, .suggest li:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.suggest .s-lines { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }
.suggest .badge { opacity: 1; height: 18px; min-width: 18px; font-size: 10px; }
.msg { min-height: 20px; color: var(--far); font-size: 14px; margin: 8px 2px; }

/* ---------- result ---------- */
.result {
  margin-top: 4px;
  padding: 18px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: center;
  animation: slide-in 0.4s ease-out both;
}
.result-title { font-size: 21px; font-weight: 900; margin: 0 0 4px; }
.result-answer { margin: 0 0 12px; color: var(--muted); }
.share-preview {
  margin: 0 auto 14px;
  padding: 10px 14px;
  display: inline-block;
  text-align: left;
  background: var(--bg);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.result-actions { display: grid; gap: 8px; }
.primary, .secondary, .ghost {
  display: block; width: 100%;
  height: 50px;
  border-radius: 12px;
  font-size: 16px; font-weight: 800;
  cursor: pointer;
}
.primary { border: 0; background: var(--accent); color: #fff; }
.secondary { border: 0; background: linear-gradient(90deg, #f58529, #dd2a7b, #8134af); color: #fff; }
.ghost { border: 1.5px solid var(--line); background: transparent; color: var(--text); }
.next { margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.next b { font-variant-numeric: tabular-nums; color: var(--text); }
.foot { text-align: center; color: var(--muted); font-size: 11px; padding: 0 16px 24px; }

/* ---------- dialogs ---------- */
dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0; border-radius: 18px;
  padding: 20px;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog h3 { font-size: 15px; margin: 16px 0 8px; }
dialog ul { padding-left: 18px; line-height: 1.6; font-size: 15px; margin: 0 0 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; }
.stats b { display: block; font-size: 24px; }
.stats span { font-size: 12px; color: var(--muted); }
.dist { display: grid; gap: 4px; margin-bottom: 16px; }
.dist-row { display: grid; grid-template-columns: 16px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.dist-bar { background: var(--muted); color: #fff; text-align: right; padding: 2px 6px; border-radius: 4px; min-width: 22px; font-weight: 700; }
.dist-bar.today { background: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 오늘의 역 이야기 ---------- */
.wiki {
  text-align: left;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}
.wiki h3 { margin: 0 0 6px; font-size: 14px; }
.wiki p { margin: 0 0 6px; }
.wiki a { color: var(--accent); font-weight: 700; text-decoration: none; font-size: 13px; }

/* ---------- 하드 모드 토글 ---------- */
.toggle {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px; margin: 0 0 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  cursor: pointer;
}
.toggle input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: #e5484d; flex: none; }
.toggle span { display: grid; gap: 2px; font-size: 15px; }
.toggle small { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.toggle:has(input:disabled) { opacity: 0.55; cursor: default; }
