:root {
  --bg-app: #f4f6f9;
  --bg-card: #ffffff;
  --bg-ocean: #e6f0f8;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Microsoft YaHei", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 20;
}

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

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #e84855, #f9844a);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(232, 72, 85, 0.28);
}

.title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-subtitle {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.2;
}

.map-title-input {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: -6px;
  background: transparent;
  width: 290px;
  max-width: 380px;
  transition: border-color 0.15s, background 0.15s;
}

.map-title-input:hover {
  background: #f8fafc;
  border-color: var(--border-subtle);
}

.map-title-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  min-width: 34px;
  border: none;
  background: transparent;
  padding: 0 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn[data-lang="en"] {
  padding-top: 1px;
}

.lang-btn.active {
  background: #ffffff;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: #f8fafc;
}

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

.btn-ghost-danger:hover {
  background: #fef2f2;
}

/* Workspace Layout */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Map Panel */
.map-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-ocean);
  position: relative;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  z-index: 10;
}

.mode-switch {
  display: inline-flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.mode-btn {
  border: none;
  background: transparent;
  padding: 5px 11px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn.active {
  background: var(--text-main);
  color: #ffffff;
}

.legend-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border-subtle);
  background: #ffffff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}

.legend-pill:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.legend-pill.brush-active {
  border-color: var(--text-main);
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.14);
}

.legend-swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(15, 23, 42, 0.22);
  flex-shrink: 0;
}

.legend-score {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}

.mode-hint-bar {
  padding: 4px 14px;
  font-size: 12px;
  color: #475569;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid rgba(226, 232, 240, 0.7);
}

.map-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

.map-stage.panning {
  cursor: grabbing;
}

.map-stage.brush-cursor {
  cursor: crosshair;
}

.japan-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.inset-box {
  fill: rgba(255, 255, 255, 0.55);
  stroke: #94a3b8;
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke;
}

.inset-label {
  font-size: 13px;
  font-weight: 700;
  fill: #475569;
  pointer-events: none;
}

.muni-path {
  stroke: #94a3b8;
  stroke-width: 0.55;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: all;
  cursor: pointer;
  transition: fill 0.14s ease;
}

.map-stage.brush-cursor .muni-path {
  cursor: crosshair;
}

.pref-path {
  fill: none;
  stroke: #475569;
  stroke-width: 1.25;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.shinkansen-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.14s;
}

.shinkansen-toggle.active {
  border-color: #0d9488;
  color: #0f766e;
  background: #f0fdfa;
}

.shinkansen-swatch {
  display: inline-block;
  width: 18px;
  height: 4px;
  border-radius: 2px;
  background: repeating-linear-gradient(
    90deg,
    #0d9488 0 5px,
    #ffffff 5px 9px
  );
  border: 1px solid rgba(13, 148, 136, 0.7);
}

.land-base-path {
  fill: #ffffff;
  stroke: none;
}

.shinkansen-layer {
  opacity: 0.52;
}

.shinkansen-base {
  fill: none;
  stroke: #0d9488;
  stroke-width: 3;
  stroke-linecap: butt;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.shinkansen-dash {
  fill: none;
  stroke: #ffffff;
  stroke-width: 1.5;
  stroke-dasharray: 6 6;
  stroke-linecap: butt;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.pref-bg-label {
  fill: rgba(51, 65, 85, 0.22);
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
  pointer-events: none;
}

.hover-highlight {
  fill: rgba(15, 23, 42, 0.08);
  stroke: #0f172a;
  stroke-width: 1.8;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.selected-highlight {
  fill: none;
  stroke: #2563eb;
  stroke-width: 2.4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(230, 240, 248, 0.9);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  z-index: 15;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Map Floating Controls */
.map-breadcrumb {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  z-index: 8;
}

.breadcrumb-back {
  border: none;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.breadcrumb-back:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  color: var(--text-muted);
}

.breadcrumb-current {
  font-weight: 700;
  color: var(--text-main);
}

.zoom-controls {
  position: absolute;
  bottom: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
  z-index: 8;
}

.zoom-btn {
  min-width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
}

.zoom-btn:hover {
  background: #f1f5f9;
}

.zoom-reset {
  font-size: 12px;
  font-weight: 600;
  border-left: 1px solid var(--border-subtle);
  border-radius: 0 7px 7px 0;
}

/* Tooltip */
.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
  z-index: 25;
  max-width: 260px;
}

.tooltip-title {
  font-weight: 700;
  font-size: 13px;
}

.tooltip-meta {
  color: #cbd5e1;
  font-size: 11px;
}

.tooltip-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-weight: 600;
}

.tooltip-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Level Popover */
.level-popover {
  position: absolute;
  width: 264px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 10px;
  z-index: 30;
}

.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 8px;
}

.popover-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.popover-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.popover-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
}

.popover-close:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

.popover-levels {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.popover-level-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s;
}

.popover-level-btn:hover {
  background: #f1f5f9;
}

.popover-level-btn.active {
  background: #eff6ff;
  border-color: var(--accent);
}

.popover-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

.popover-level-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.popover-level-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.popover-level-desc {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popover-footer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.popover-focus-btn {
  width: 100%;
  padding: 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  background: #ffffff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.popover-focus-btn:hover {
  background: #eff6ff;
}

/* Right Sidebar */
.sidebar {
  width: 375px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-left: 1px solid var(--border-subtle);
  min-height: 0;
}

.stats-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.stats-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stat-block {
  flex: 1;
}

.stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border-subtle);
}

.stat-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.stat-value-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 2px;
}

.stat-big-number {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.progress-track {
  height: 6px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ea8de, #43aa8b, #f9c74f, #f9844a, #e84855);
  transition: width 0.25s ease;
}

.tier-counts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tier-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 7px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  font-size: 11px;
}

.tier-chip-left {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.tier-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #334155;
  font-weight: 600;
}

.tier-chip-count {
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

/* Search */
.search-box {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.search-input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-main);
  background: #f8fafc;
  transition: border-color 0.15s, background 0.15s;
}

.search-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--accent);
}

/* Browser Panel */
.browser-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.browser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-subtle);
}

.back-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 0;
}

.back-btn:hover {
  text-decoration: underline;
}

.browser-header-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.filter-bar {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.filter-chip {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: #ffffff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-chip.active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: #ffffff;
}

.browser-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
}

.region-group {
  margin-bottom: 14px;
}

.region-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 6px 2px;
}

.pref-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.pref-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.14s, background 0.14s;
}

.pref-card:hover {
  border-color: var(--accent);
  background: #f8fafc;
}

.pref-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.pref-card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.pref-card-score {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
}

.pref-card-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* Municipality Row */
.muni-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-bottom: 1px solid #f1f5f9;
}

.muni-row:hover {
  background: #f8fafc;
}

.muni-row-info {
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.muni-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.muni-row-pref {
  font-size: 11px;
  color: var(--text-muted);
}

.mini-level-group {
  display: inline-flex;
  gap: 3px;
  flex-shrink: 0;
}

.mini-level-btn {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  background: #ffffff;
  color: #64748b;
  transition: transform 0.1s;
}

.mini-level-btn:hover {
  transform: scale(1.1);
}

.mini-level-btn.active {
  border-color: rgba(15, 23, 42, 0.45);
  box-shadow: 0 0 0 1.5px rgba(15, 23, 42, 0.2);
}

.empty-state {
  text-align: center;
  padding: 32px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 8px 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 10px;
  color: var(--text-muted);
  background: #f8fafc;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.form-input {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}

.scope-options {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.scope-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.preview-box {
  background: #f1f5f9;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  place-items: center;
  min-height: 240px;
  max-height: 420px;
  overflow: hidden;
}

.preview-status {
  font-size: 13px;
  color: var(--text-muted);
}

.export-preview-img {
  max-width: 100%;
  max-height: 390px;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-subtle);
  background: #f8fafc;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 60;
}

/* Live Map HUD (mirrors Export Share Card header pills) */
.map-score-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: stretch;
  gap: 8px;
  z-index: 8;
}

.hud-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 7px 13px;
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
  text-align: left;
  font-family: inherit;
}

.hud-card-dark {
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(6px);
}

.hud-card-light {
  background: rgba(255, 255, 255, 0.94);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: border-color 0.14s, transform 0.12s;
}

.hud-card-light:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.hud-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  opacity: 0.72;
  line-height: 1.2;
}

.hud-value-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 1px;
}

.hud-number {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.hud-unit {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.75;
}

/* Bottom Live 6-Tier Summary Bar (mirrors Export Card bottom legend) */
.bottom-stats-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.bottom-stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 7px 10px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color 0.14s, background 0.14s, transform 0.12s;
}

.bottom-stat-card:hover {
  border-color: var(--border-strong);
  background: #ffffff;
  transform: translateY(-1px);
}

.bottom-stat-card.active {
  border-color: var(--accent);
  background: #eff6ff;
}

.bottom-stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.bottom-stat-name-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.bottom-stat-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bottom-stat-pts {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.bottom-stat-bottom {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
}

.bottom-stat-count {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.bottom-stat-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Sidebar Tabs */
.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: #f8fafc;
}

.sidebar-tab {
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  border-radius: 8px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.14s;
}

.sidebar-tab.active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: #ffffff;
}

.marked-group {
  margin-bottom: 12px;
}

.marked-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: #f8fafc;
  border-radius: 7px;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
}

.marked-group-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.marked-group-right {
  font-size: 11px;
  color: var(--text-muted);
}

.marked-tier-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.marked-tier-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.marked-tier-chip.active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: #ffffff;
}

/* Leaderboard Button & Modal */
.btn-leaderboard {
  background: #fffbeb;
  color: #b45309;
  border-color: #fde68a;
}

.btn-leaderboard:hover {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

.lb-modal-card {
  max-width: 560px;
}

.lb-header-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lb-total-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 999px;
}

.lb-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lb-submit-card {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lb-my-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.lb-my-score-label {
  font-weight: 600;
  color: var(--text-muted);
}

.lb-my-score-value {
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.lb-submit-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.lb-name-input {
  flex: 1;
  min-width: 0;
}

.lb-submit-btn {
  flex-shrink: 0;
  padding: 0 16px;
}

.lb-feedback {
  font-size: 12px;
  font-weight: 600;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 7px 10px;
  line-height: 1.45;
}

.lb-feedback.is-info {
  color: #0369a1;
  background: #f0f9ff;
  border-color: #bae6fd;
}

.lb-my-rank-banner {
  font-size: 12.5px;
  font-weight: 700;
  color: #1e40af;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 7px 10px;
}

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

.lb-list-subtitle {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.lb-refresh-btn {
  padding: 4px 10px;
  font-size: 12px;
}

.lb-list-wrap {
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: #ffffff;
  max-height: 360px;
  overflow-y: auto;
}

.lb-status-box {
  padding: 28px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.lb-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  z-index: 1;
}

.lb-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
  vertical-align: middle;
}

.lb-table tbody tr:last-child td {
  border-bottom: none;
}

.lb-table tbody tr.is-me {
  background: #eff6ff;
}

.lb-col-rank {
  width: 54px;
  text-align: center !important;
}

.lb-col-visited {
  width: 78px;
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted) !important;
}

.lb-col-score {
  width: 84px;
  text-align: right !important;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.lb-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-muted);
  background: #f1f5f9;
}

.lb-rank-badge.rank-1 {
  background: #fef3c7;
  color: #b45309;
}

.lb-rank-badge.rank-2 {
  background: #e2e8f0;
  color: #334155;
}

.lb-rank-badge.rank-3 {
  background: #ffedd5;
  color: #c2410c;
}

.lb-name-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  word-break: break-word;
}

.lb-me-pill {
  font-size: 10px;
  font-weight: 700;
  color: #1d4ed8;
  background: #dbeafe;
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .lb-submit-form {
    flex-direction: column;
  }
  .lb-submit-btn {
    height: 36px;
  }
}

@media (max-width: 960px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .map-title-input {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .topbar-actions {
    gap: 6px;
  }
  .workspace {
    flex-direction: column;
    overflow: visible;
  }
  .map-panel {
    height: 68vh;
    min-height: 460px;
  }
  .map-score-hud {
    top: 8px;
    right: 8px;
    gap: 5px;
  }
  .hud-card {
    padding: 5px 9px;
  }
  .hud-number {
    font-size: 16px;
  }
  .bottom-stats-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 10px;
  }
  .sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    height: 520px;
  }
}

@media (max-width: 640px) {
  .level-popover {
    position: fixed;
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: 12px;
    width: auto;
    max-height: 75vh;
    overflow-y: auto;
    z-index: 45;
  }
}

/* Footprint (GPX / CSV) Import Button & Modal */
.btn-footprint {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.btn-footprint:hover {
  background: #d1fae5;
  border-color: #34d399;
  color: #065f46;
}

.fp-modal-card {
  max-width: 680px;
}

.fp-header-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fp-privacy-badge {
  font-size: 11px;
  font-weight: 700;
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 2px 8px;
  border-radius: 999px;
}

.fp-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fp-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  background: #f8fafc;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}

.fp-dropzone:hover,
.fp-dropzone:focus-visible,
.fp-dropzone.drag-over {
  border-color: var(--accent);
  background: #eff6ff;
  outline: none;
}

.fp-drop-icon {
  color: var(--accent);
  margin-bottom: 2px;
}

.fp-drop-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.fp-drop-hint {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 480px;
  line-height: 1.45;
}

.fp-files-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
}

.fp-files-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.fp-file-chip {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fp-file-chip-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fp-file-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fp-file-size {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.fp-file-chip-sub {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
}

.fp-files-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fp-btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.fp-progress-box {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fp-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.fp-progress-pct {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 800;
}

.fp-progress-track {
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.fp-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #10b981);
  border-radius: 999px;
  transition: width 0.12s ease;
}

.fp-message-box {
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 9px;
  padding: 8px 11px;
  line-height: 1.45;
}

.fp-message-box.is-error {
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.fp-message-box.is-warn {
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
}

.fp-rules-card {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fp-rules-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.fp-preset-group {
  display: inline-flex;
  background: #e2e8f0;
  padding: 2px;
  border-radius: 8px;
  gap: 2px;
}

.fp-preset-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.14s;
}

.fp-preset-btn.active {
  background: #ffffff;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.fp-rules-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.fp-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-main);
  cursor: pointer;
}

.fp-link-btn {
  border: none;
  background: transparent;
  padding: 2px 4px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

.fp-link-btn:hover {
  text-decoration: underline;
}

.fp-custom-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.fp-threshold-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px 9px;
}

.fp-threshold-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.3;
}

.fp-threshold-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fp-num-input {
  width: 72px;
  padding: 4px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.fp-unit {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.fp-result-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fp-summary-banner {
  font-size: 12.5px;
  font-weight: 700;
  color: #1e40af;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 9px;
  padding: 8px 11px;
}

.fp-tier-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.fp-preview-list {
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: #ffffff;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fp-preview-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  transition: background 0.12s;
}

.fp-preview-row:hover {
  background: #f8fafc;
}

.fp-preview-row.is-excluded {
  opacity: 0.48;
}

.fp-preview-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.fp-preview-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fp-preview-reason {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fp-merge-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

@media (max-width: 640px) {
  .fp-custom-grid {
    grid-template-columns: 1fr;
  }
  .fp-preview-row {
    flex-direction: column;
    align-items: flex-start;
  }
}
