:root {
  --paper-bg: #fbf7ee;
  --paper-card: #fffdf8;
  --paper-alt: #f4ecdc;
  --ink: #3a2d24;
  --ink-soft: #6e5846;
  --ink-muted: #8f7a68;
  --terracotta: #d95d39;
  --terracotta-dark: #b84727;
  --matcha: #4d7c5b;
  --mustard: #e09f3e;
  --indigo: #3b5b78;
  --border-ink: #5c4b3c;
  --shadow-sketch: 4px 4px 0px #cbbba4;
  --shadow-sketch-sm: 2px 2px 0px #cbbba4;
  --font-display: "Zen Maru Gothic", "Noto Sans TC", sans-serif;
  --font-hand: "Klee One", "Zen Maru Gothic", cursive, sans-serif;
  --font-body: "Noto Sans TC", -apple-system, BlinkMacSystemFont, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--paper-bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
}

.paper-grain-defs {
  position: fixed;
  width: 0;
  height: 0;
  pointer-events: none;
}

.paper-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
  filter: url(#paper-texture);
  opacity: 0.7;
}

.page-wrapper {
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px 20px 44px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Sketchy Hand-Drawn Borders & Cards */
.sketch-header,
.filter-ribbon,
.map-board,
.spot-detail-card,
.spot-list-section {
  background: var(--paper-card);
  border: 2px solid var(--border-ink);
  border-radius: 18px 22px 19px 24px / 22px 18px 23px 19px;
  box-shadow: var(--shadow-sketch);
}

/* Header */
.sketch-header {
  padding: 22px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  background-image: radial-gradient(circle at 92% 18%, rgba(224, 159, 62, 0.14) 0%, transparent 45%),
                    radial-gradient(circle at 8% 85%, rgba(77, 124, 91, 0.12) 0%, transparent 45%);
}

.station-stamp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border: 1.8px dashed var(--terracotta);
  border-radius: 999px;
  background: #fff5f0;
  margin-bottom: 8px;
}

.stamp-jp {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--terracotta);
}

.stamp-main {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.sketch-header h1 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.subtitle {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.96rem;
  max-width: 62ch;
}

.passport-summary-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--paper-alt);
  border: 2px solid var(--border-ink);
  border-radius: 16px;
  box-shadow: var(--shadow-sketch-sm);
}

.passport-stat {
  text-align: center;
  min-width: 64px;
}

.stat-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.passport-stat strong {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--terracotta);
}

.stat-unit {
  font-size: 0.76rem;
  color: var(--ink-soft);
  margin-left: 2px;
}

.passport-divider {
  width: 1.5px;
  height: 32px;
  background: #cbbba4;
}

/* Hand-Drawn Buttons */
.sketch-btn {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 9px 16px;
  border: 2px solid var(--border-ink);
  border-radius: 12px 14px 11px 13px;
  background: var(--paper-card);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sketch-sm);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
}

.sketch-btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0px #b8a58b;
}

.sketch-btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0px #b8a58b;
}

.btn-terracotta {
  background: var(--terracotta);
  color: #fffdf8;
}

.btn-terracotta:hover {
  background: var(--terracotta-dark);
}

.btn-primary {
  background: var(--matcha);
  color: #fffdf8;
}

.btn-primary.in-pocket {
  background: var(--indigo);
}

.btn-stamp {
  background: #fff3eb;
  color: var(--terracotta);
  border-style: dashed;
}

.btn-stamp.stamped {
  background: var(--terracotta);
  color: #ffffff;
  border-style: solid;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}

/* Filter Ribbon */
.filter-ribbon {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.route-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.route-tab {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  padding: 7px 14px;
  border: 1.8px solid var(--border-ink);
  border-radius: 999px;
  background: var(--paper-bg);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s ease;
}

.route-tab:hover {
  background: var(--paper-alt);
  color: var(--ink);
}

.route-tab.active {
  background: var(--ink);
  color: var(--paper-card);
  box-shadow: var(--shadow-sketch-sm);
}

.filter-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 12px;
  border: 1.5px solid #bfa98e;
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink-soft);
  cursor: pointer;
}

.chip.active {
  background: var(--mustard);
  border-color: var(--border-ink);
  color: var(--ink);
}

.search-box input {
  width: 270px;
  max-width: 100%;
  padding: 7px 13px;
  border: 1.8px solid var(--border-ink);
  border-radius: 12px;
  background: #ffffff;
  font-family: inherit;
  font-size: 0.86rem;
  color: var(--ink);
}

.search-box input:focus {
  outline: none;
  border-color: var(--terracotta);
}

/* Main Grid */
.main-grid {
  display: grid;
  grid-template-columns: 1.48fr 1fr;
  gap: 20px;
  align-items: start;
}

/* Map Board */
.map-board {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  display: inline-block;
}

.dot-station {
  background: var(--terracotta);
}

.dot-food {
  background: var(--mustard);
}

.line-dashed {
  width: 20px;
  height: 0;
  border-top: 2.5px dashed var(--terracotta);
  display: inline-block;
}

.map-zoom-controls {
  display: inline-flex;
  gap: 6px;
}

.icon-btn {
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border: 1.8px solid var(--border-ink);
  border-radius: 8px;
  background: var(--paper-bg);
  font-family: var(--font-display);
  font-weight: 900;
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--paper-alt);
}

.text-btn {
  font-size: 0.78rem;
}

.svg-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 960 / 680;
  background: #fdf9f0;
  border: 2px solid #cbbba4;
  border-radius: 16px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}

.svg-viewport:active {
  cursor: grabbing;
}

#tainanMapSvg {
  width: 100%;
  height: 100%;
  display: block;
}

/* SVG Interactive Pin Styles */
.food-pin-group {
  cursor: pointer;
  transition: transform 0.18s ease;
}

.food-pin-group:hover .pin-bubble {
  fill: #fff1d6;
  stroke: var(--terracotta);
  stroke-width: 2.6;
}

.food-pin-group.is-selected .pin-bubble {
  fill: var(--terracotta);
  stroke: var(--ink);
  stroke-width: 2.6;
}

.food-pin-group.is-selected .pin-label-bg {
  fill: var(--ink);
}

.food-pin-group.is-selected .pin-label-text {
  fill: #fffdf8;
}

.food-pin-group.is-dimmed {
  opacity: 0.25;
}

.walk-route-line {
  fill: none;
  stroke: #d95d39;
  stroke-width: 2.4;
  stroke-dasharray: 6 5;
  stroke-linecap: round;
  opacity: 0.45;
  transition: opacity 0.2s ease, stroke-width 0.2s ease;
}

.walk-route-line.active-route {
  opacity: 1;
  stroke-width: 3.8;
  stroke: #c84624;
}

.walk-route-line.dimmed-route {
  opacity: 0.12;
}

.map-floating-card {
  position: absolute;
  z-index: 15;
  pointer-events: none;
  background: rgba(58, 45, 36, 0.94);
  color: #fffdf8;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  box-shadow: 0 6px 14px rgba(58, 45, 36, 0.25);
  transform: translate(-50%, -122%);
  white-space: nowrap;
}

.map-footnote {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
  text-align: center;
}

/* Sidebar Panel */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.spot-detail-card {
  padding: 20px;
  background: linear-gradient(180deg, #fffdf8 0%, #fbf5e8 100%);
}

.detail-badge-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.route-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: #e6f0e8;
  color: var(--matcha);
  border: 1.4px solid var(--matcha);
}

.walk-time-pill {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: #fff0e6;
  color: var(--terracotta);
  border: 1.4px solid var(--terracotta);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.detail-emoji {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: #ffffff;
  border: 2px solid var(--border-ink);
  box-shadow: var(--shadow-sketch-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  flex-shrink: 0;
}

.detail-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 900;
}

.detail-area {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.detail-desc {
  margin: 0 0 12px;
  font-size: 0.92rem;
  color: var(--ink);
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.meta-box {
  background: #ffffff;
  border: 1.5px solid #d8c8b2;
  border-radius: 10px;
  padding: 8px 10px;
}

.meta-title {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.meta-value {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink);
}

.detail-tip-box {
  background: #f5eedf;
  border-left: 4px solid var(--mustard);
  padding: 8px 12px;
  border-radius: 6px 10px 10px 6px;
  font-size: 0.84rem;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Spot List Section */
.spot-list-section {
  padding: 16px 18px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.list-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 900;
}

#visibleCountLabel {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.spot-cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.spot-mini-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1.8px solid #d5c4ac;
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.14s ease;
}

.spot-mini-card:hover {
  border-color: var(--border-ink);
  background: #fdf8ee;
}

.spot-mini-card.active {
  border-color: var(--terracotta);
  background: #fff4ed;
  box-shadow: var(--shadow-sketch-sm);
}

.mini-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mini-icon {
  font-size: 1.35rem;
  flex-shrink: 0;
}

.mini-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}

.mini-stamp-tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--terracotta);
  color: #ffffff;
}

.mini-sub {
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-walk {
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--matcha);
  background: #eef6f0;
  padding: 3px 8px;
  border-radius: 8px;
  flex-shrink: 0;
}

/* Footer */
.sketch-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 4px 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(58, 45, 36, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: 100%;
  max-width: 540px;
  background: var(--paper-card);
  border: 2.5px solid var(--border-ink);
  border-radius: 20px;
  padding: 22px 24px;
  box-shadow: 6px 6px 0px #5c4b3c;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 900;
}

.close-modal-btn {
  width: 32px;
  height: 32px;
  border: 1.8px solid var(--border-ink);
  border-radius: 8px;
  background: var(--paper-alt);
  font-weight: 900;
  cursor: pointer;
}

.passport-stats-banner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--paper-alt);
  border: 1.8px solid var(--border-ink);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.82rem;
  text-align: center;
}

.passport-stats-banner strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--terracotta);
}

.passport-list {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.passport-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: #ffffff;
  border: 1.5px solid #d5c4ac;
  border-radius: 10px;
}

.passport-empty {
  text-align: center;
  padding: 26px 12px;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* Toast */
.toast-box {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  background: var(--ink);
  color: var(--paper-card);
  border: 1.5px solid var(--mustard);
  padding: 9px 15px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: var(--shadow-sketch-sm);
}

/* Responsive */
@media (max-width: 980px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .spot-cards-list {
    max-height: none;
  }
}

@media (max-width: 600px) {
  .detail-meta-grid {
    grid-template-columns: 1fr;
  }

  .passport-stats-banner {
    grid-template-columns: 1fr;
  }
}
