:root {
  --bg: #f6f3ee;
  --card: #fff;
  --ink: #1f2328;
  --muted: #6b7078;
  --line: #e7e2da;
  --accent: #ff6b4a;
  --route: #ff6b4a;
  --follow: #7b5cd6;
  --ok: #2bb673;
  --danger: #e5484d;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(30, 25, 20, .14);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #e9e5de; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
h2 { font-size: 20px; margin: 4px 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

#app {
  max-width: 480px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); position: relative; overflow: hidden; box-shadow: 0 0 40px rgba(0,0,0,.08);
}
.topbar {
  height: 52px; flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; margin: 0; }
.brand { font-weight: 800; color: var(--accent); font-size: 14px; }
.rec-badge { justify-self: end; color: var(--danger); font-size: 12px; font-weight: 700; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .35; } }

main { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; overflow-y: auto; }
.view.active { display: block; }
#view-map { overflow: hidden; }
#map { position: absolute; inset: 0; z-index: 0; background: #ddd; }

.panel {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 1;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
}
#idle-panel { display: flex; align-items: center; gap: 10px; }
.char-chip {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--bg);
  border-radius: 12px; padding: 4px 10px 4px 4px; text-align: left; line-height: 1.25;
}
.char-avatar { display: grid; place-items: center; width: 40px; height: 50px; }
.sim-toggle { font-size: 13px; line-height: 1.2; display: flex; gap: 6px; align-items: flex-start; flex: 1; min-width: 0; white-space: nowrap; }
.sim-toggle input { margin-top: 2px; }

.locate-btn {
  position: absolute; top: 12px; right: 12px; z-index: 1; width: 44px; height: 44px; border: 0;
  border-radius: 12px; background: var(--card); box-shadow: var(--shadow); color: #2f7bf6;
  display: grid; place-items: center;
}
.locate-btn svg { width: 22px; height: 22px; }
.banner {
  position: absolute; top: 12px; left: 12px; right: 64px; z-index: 1;
  background: var(--follow); color: #fff; border-radius: 12px; padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow); font-size: 14px;
}
.banner .btn-text { color: #fff; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats div { background: var(--bg); border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: var(--muted); }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.btn, .btn-primary, .btn-danger {
  border: 0; border-radius: 12px; padding: 12px 14px; font-weight: 700; font-size: 15px;
}
.btn { background: var(--bg); border: 1px solid var(--line); }
.btn.on { background: #ffece7; border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary.big { padding: 16px 22px; font-size: 17px; border-radius: 14px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-text { background: none; border: 0; padding: 6px 0; font-weight: 600; color: var(--muted); }
.btn-text.danger { color: var(--danger); }
.wide { width: 100%; margin-top: 10px; }

/* Tab bar */
.tabbar {
  flex: none; display: flex; background: var(--card); border-top: 1px solid var(--line);
  height: calc(60px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 12px; color: var(--muted);
}
.tabbar button.on { color: var(--accent); font-weight: 700; }
.tabbar svg { width: 22px; height: 22px; }

/* Sheet */
.sheet { position: absolute; inset: 0; z-index: 1000; background: rgba(20, 16, 12, .42); display: flex; align-items: flex-end; }
.sheet-body {
  background: var(--card); width: 100%; max-height: 90%; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}
.mini { height: 200px; border-radius: 14px; overflow: hidden; margin: 10px 0; z-index: 0; position: relative; }
.field { display: block; margin: 14px 0 0; }
.field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.field input, .field select, #f-newlist {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
#f-newlist { margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.sheet .row { margin-top: 18px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1; }

.badge { display: inline-block; background: #fff1e0; color: #b75a14; border-radius: 6px; padding: 2px 7px; font-size: 11px; font-weight: 700; }
.badge.gray { background: #eceae6; color: var(--muted); }

/* Character select */
.char-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.char-card {
  border: 2px solid var(--line); background: var(--bg); border-radius: 14px; padding: 12px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700; font-size: 14px;
}
.char-card.on { border-color: var(--accent); background: #fff4f1; }
.char-card span { display: flex; flex-direction: column; line-height: 1.2; }
.char-card small { font-weight: 500; font-size: 11px; color: var(--muted); }

/* Character SVG + walking */
.char-marker, .print-icon { background: none; border: 0; }
.char-marker svg { filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .22)); }
.print-icon svg { opacity: .9; }
.char-svg .leg, .char-svg .body, .char-svg .arm { transform-box: fill-box; }
.char-svg .leg { transform-origin: 50% 100%; }
.char-svg .body { transform-origin: 50% 100%; }
.char-svg .arm.l { transform-origin: 80% 10%; }
.char-svg .arm.r { transform-origin: 20% 10%; }
.walking .char-svg .leg.l { animation: step .34s ease-in-out infinite alternate; }
.walking .char-svg .leg.r { animation: step .34s ease-in-out infinite alternate-reverse; }
.walking .char-svg .body { animation: waddle .68s ease-in-out infinite; }
.walking .char-svg .arm.l { animation: swing .34s ease-in-out infinite alternate; }
.walking .char-svg .arm.r { animation: swing .34s ease-in-out infinite alternate-reverse; }
.walking .char-svg .shadow { animation: shadow .34s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes step { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes waddle {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  25%, 75% { transform: translateY(-2.5px) rotate(0); }
  50% { transform: translateY(0) rotate(4deg); }
}
@keyframes swing { from { transform: rotate(18deg); } to { transform: rotate(-18deg); } }
@keyframes shadow { to { transform: scaleX(.88); } }

/* Lists & cards */
.pad { padding: 16px; }
.sec-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.list-card, .course-card {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.list-card p, .course-card p { margin: 3px 0 0; }
.list-thumbs { display: flex; gap: 4px; min-width: 64px; }
.thumb { flex: none; background: #f1ede6; border-radius: 10px; }
.cc-body { min-width: 0; flex: 1; }
.cc-body b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; line-height: 1.6; }
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }

.profile {
  display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px;
}
.profile .grow { flex: 1; min-width: 0; }
.profile p { margin: 2px 0 0; }
.hint { margin: 6px 2px 0; }
.field em { font-style: normal; font-weight: 500; }
.pick { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.pick-row {
  display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg);
}
.pick-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.pick-row span { flex: 1; font-weight: 600; }
.inline-add input { flex: 2; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); min-width: 0; }
.code-box {
  margin: 12px 0 8px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line);
  font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; user-select: all;
}
.toast {
  position: absolute; left: 50%; bottom: 84px; transform: translate(-50%, 20px); z-index: 2000;
  background: rgba(31, 35, 40, .92); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
