:root {
  --paper: #f5f5f0;
  --surface: #ffffff;
  --surface-soft: #fafaf5;
  --line: #d9ddd2;
  --text: #26312b;
  --muted: #6d766e;
  --quake: #c63d32;
  --quake-soft: #fff2ee;
  --volcano: #6f4bb3;
  --divergent: #2f9d69;
  --convergent: #d97a20;
  --transform: #2879b8;
  --focus: #176b87;
  --shadow: 0 10px 28px rgba(42, 52, 44, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background: var(--cnsa-bg, #16213e);
  color: var(--cnsa-text, #fff);
  font-family: var(--cnsa-font, "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  display: grid;
  grid-template-columns: minmax(264px, 20vw) 1fr;
  grid-template-rows: var(--cnsa-bar-h, 48px) 56px 1fr;
  grid-template-areas:
    "bar bar"
    "header header"
    "sidebar map";
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--cnsa-accent-1, #00d2ff);
  outline-offset: 2px;
}

#app-header {
  grid-area: header;
  background: rgba(14, 22, 44, 0.62);
  backdrop-filter: var(--cnsa-blur, blur(12px));
  -webkit-backdrop-filter: var(--cnsa-blur, blur(12px));
  border-bottom: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px 0 20px;
  z-index: 1100;
}

#app-header h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: var(--cnsa-accent, linear-gradient(90deg, #00d2ff, #3a7bd5));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  flex: 0 0 auto;
  white-space: nowrap;
}

#last-updated {
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 13px;
  min-width: 0;
  white-space: nowrap;
}

#sidebar {
  grid-area: sidebar;
  background: rgba(14, 22, 44, 0.5);
  backdrop-filter: var(--cnsa-blur, blur(12px));
  -webkit-backdrop-filter: var(--cnsa-blur, blur(12px));
  border-right: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  padding: 18px;
  overflow-y: auto;
  z-index: 1000;
}

#map {
  grid-area: map;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #eef1ea;
}

.panel-section {
  border-bottom: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  padding: 0 0 18px;
  margin: 0 0 18px;
}

.panel-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.panel-title {
  color: var(--cnsa-text, #fff);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  color: var(--cnsa-text, #fff);
  cursor: pointer;
  font-size: 14px;
}

.layer-toggle + .layer-toggle {
  margin-top: 6px;
}

.layer-toggle span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.layer-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--cnsa-accent-1, #00d2ff);
}

.layer-mark {
  width: 14px;
  height: 14px;
  display: inline-block;
  flex: 0 0 auto;
}

.layer-mark.plate {
  border-top: 3px solid var(--convergent);
}

.layer-mark.volcano {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 14px solid var(--volcano);
}

.layer-mark.quake {
  border-radius: 999px;
  background: var(--quake);
}

.plate-types {
  margin: 6px 0 4px 26px;
  padding: 8px 10px;
  border-left: 2px solid var(--cnsa-border-strong, rgba(255, 255, 255, 0.26));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plate-type-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  font-size: 13px;
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  cursor: pointer;
}

.plate-type-toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--cnsa-accent-1, #00d2ff);
}

.plate-swatch {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
  flex: 0 0 auto;
}

.plate-swatch.divergent {
  background: #2f9d69;
}

.plate-swatch.convergent {
  background: #d97a20;
}

.plate-swatch.transform {
  background: #2879b8;
}

.volcano-swatch {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  display: inline-block;
  flex: 0 0 auto;
}

.volcano-swatch.recent {
  border-left-width: 7px;
  border-right-width: 7px;
  border-bottom: 14px solid #c0392b;
}

.volcano-swatch.modern {
  border-left-width: 5px;
  border-right-width: 5px;
  border-bottom: 11px solid #e67e22;
}

.volcano-swatch.historical {
  border-left-width: 4px;
  border-right-width: 4px;
  border-bottom: 9px solid #8e7cc3;
}

.range-group + .range-group {
  margin-top: 20px;
}

.range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--cnsa-text, #fff);
  font-weight: 700;
}

.range-value {
  color: var(--cnsa-accent-1, #00d2ff);
  font-weight: 800;
  white-space: nowrap;
}

.range-input {
  width: 100%;
  height: 28px;
  accent-color: var(--cnsa-accent-1, #00d2ff);
}

.range-scale {
  display: flex;
  justify-content: space-between;
  color: var(--cnsa-text-dimmer, rgba(255, 255, 255, 0.5));
  font-size: 11px;
  margin-top: 6px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.segmented button {
  min-height: 40px;
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  border-radius: var(--cnsa-radius-sm, 10px);
  background: var(--cnsa-surface, rgba(255, 255, 255, 0.08));
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.18s var(--cnsa-ease, ease);
}

.segmented button:hover {
  background: var(--cnsa-surface-strong, rgba(255, 255, 255, 0.16));
  color: #fff;
}

.segmented button.active {
  border-color: transparent;
  background: var(--cnsa-accent, linear-gradient(90deg, #00d2ff, #3a7bd5));
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 130, 200, 0.32);
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.preset-button,
.action-button {
  width: 100%;
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  border-radius: var(--cnsa-radius-sm, 10px);
  background: var(--cnsa-surface, rgba(255, 255, 255, 0.08));
  color: var(--cnsa-text, #fff);
  cursor: pointer;
  text-align: left;
  transition: all 0.18s var(--cnsa-ease, ease);
}

.preset-button {
  padding: 10px 12px;
  min-height: 40px;
}

.preset-button:hover {
  background: var(--cnsa-surface-strong, rgba(255, 255, 255, 0.16));
  border-color: var(--cnsa-border-strong, rgba(255, 255, 255, 0.26));
}

.preset-button span,
.preset-button small {
  display: block;
}

.preset-button span {
  font-size: 13px;
  font-weight: 800;
}

.preset-button small {
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 11px;
  line-height: 1.35;
  margin-top: 2px;
}

.action-button {
  margin-top: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: none;
  background: var(--cnsa-accent, linear-gradient(90deg, #00d2ff, #3a7bd5));
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 130, 200, 0.32);
}

.action-button:hover {
  filter: brightness(1.07);
}

.action-button.secondary {
  margin-top: 6px;
  background: var(--cnsa-surface, rgba(255, 255, 255, 0.08));
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  box-shadow: none;
}

.action-button.secondary:hover {
  color: #fff;
  background: var(--cnsa-surface-strong, rgba(255, 255, 255, 0.16));
}

.mission-card {
  background: var(--cnsa-surface, rgba(255, 255, 255, 0.08));
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  border-radius: var(--cnsa-radius-sm, 10px);
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--cnsa-text, #fff);
}

.depth-mini {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 11px;
}

.depth-mini span,
.map-key div {
  display: flex;
  align-items: center;
  gap: 7px;
}

.map-key {
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 12px;
  line-height: 1.9;
}

.depth-dot {
  width: 12px;
  height: 12px;
  display: inline-block;
  border-radius: 999px;
  flex: 0 0 auto;
  box-sizing: border-box;
}

.depth-dot.shallow {
  background: #d84a3a;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.depth-dot.intermediate {
  background: rgba(240, 164, 58, 0.18);
  border: 3px solid #f0a43a;
}

.depth-dot.deep {
  background: transparent;
  border: 2px solid #2879b8;
}

.mini-triangle {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 12px solid #7a56c2;
  display: inline-block;
  flex: 0 0 auto;
}

.mini-triangle.recent {
  border-left-width: 7px;
  border-right-width: 7px;
  border-bottom: 14px solid #c0392b;
}

.mini-triangle.modern {
  border-left-width: 5px;
  border-right-width: 5px;
  border-bottom: 11px solid #e67e22;
}

.mini-triangle.historical {
  border-left-width: 4px;
  border-right-width: 4px;
  border-bottom: 9px solid #8e7cc3;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: var(--cnsa-surface, rgba(255, 255, 255, 0.08));
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  border-radius: var(--cnsa-radius-sm, 10px);
  padding: 10px;
}

.stat-label {
  display: block;
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 11px;
  margin-bottom: 4px;
}

.stat-value {
  display: block;
  color: var(--cnsa-accent-1, #00d2ff);
  font-size: 18px;
  line-height: 1;
  font-weight: 800;
}

#timeline-control {
  position: absolute;
  top: calc(var(--cnsa-bar-h, 48px) + 70px);
  right: 16px;
  min-width: 246px;
  background: rgba(14, 22, 44, 0.82);
  backdrop-filter: var(--cnsa-blur, blur(12px));
  -webkit-backdrop-filter: var(--cnsa-blur, blur(12px));
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  border-radius: var(--cnsa-radius, 16px);
  box-shadow: var(--cnsa-shadow-lg, 0 24px 48px rgba(0, 0, 0, 0.4));
  padding: 12px;
  color: var(--cnsa-text, #fff);
  z-index: 1000;
  display: none;
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--cnsa-accent, linear-gradient(90deg, #00d2ff, #3a7bd5));
  color: #fff;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 130, 200, 0.32);
}

.icon-button[data-playing="true"] {
  background: var(--cnsa-surface-strong, rgba(255, 255, 255, 0.16));
  box-shadow: none;
}

.timeline-meta {
  flex: 1;
  min-width: 0;
}

.timeline-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 12px;
  margin-bottom: 6px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--cnsa-accent, linear-gradient(90deg, #00d2ff, #3a7bd5));
  transition: width 120ms linear;
}

.timeline-speed {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.speed-button {
  flex: 1;
  min-height: 32px;
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  background: var(--cnsa-surface, rgba(255, 255, 255, 0.08));
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 12px;
  padding: 4px 0;
  border-radius: var(--cnsa-radius-sm, 10px);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}

.speed-button:hover {
  background: var(--cnsa-surface-strong, rgba(255, 255, 255, 0.16));
  color: #fff;
}

.speed-button.active {
  background: var(--cnsa-accent, linear-gradient(90deg, #00d2ff, #3a7bd5));
  color: #fff;
  border-color: transparent;
}

#legend {
  position: absolute;
  left: calc(max(264px, 20vw) + 16px);
  bottom: 18px;
  width: 230px;
  background: rgba(14, 22, 44, 0.82);
  backdrop-filter: var(--cnsa-blur, blur(12px));
  -webkit-backdrop-filter: var(--cnsa-blur, blur(12px));
  border: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
  border-radius: var(--cnsa-radius, 16px);
  box-shadow: var(--cnsa-shadow-lg, 0 24px 48px rgba(0, 0, 0, 0.4));
  padding: 14px;
  color: var(--cnsa-text, #fff);
  z-index: 1000;
  display: none;
}

.legend-title {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--cnsa-text, #fff);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--cnsa-text-dim, rgba(255, 255, 255, 0.72));
  font-size: 12px;
  min-height: 24px;
}

.legend-line {
  width: 24px;
  height: 0;
  border-top: 4px solid;
  border-radius: 999px;
}

.legend-line.divergent {
  border-color: var(--divergent);
}

.legend-line.convergent {
  border-color: var(--convergent);
}

.legend-line.transform {
  border-color: var(--transform);
}

.legend-line.default {
  border-color: #8a9088;
}

.volcano-icon {
  background: transparent;
  border: 0;
}

.leaflet-container {
  font-family: inherit;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--cnsa-radius-sm, 10px);
  box-shadow: var(--cnsa-shadow-lg, 0 24px 48px rgba(0, 0, 0, 0.4));
}

.leaflet-popup-content {
  margin: 12px;
}

.popup-card {
  min-width: 210px;
}

.popup-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
}

.popup-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #38433c;
  font-size: 12px;
  line-height: 1.6;
}

.popup-row b {
  color: var(--muted);
  font-weight: 700;
}

#toast-root {
  position: absolute;
  top: calc(var(--cnsa-bar-h, 48px) + 66px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(520px, calc(100vw - 32px));
  background: rgba(14, 22, 44, 0.92);
  backdrop-filter: var(--cnsa-blur, blur(12px));
  -webkit-backdrop-filter: var(--cnsa-blur, blur(12px));
  color: var(--cnsa-text, #fff);
  border: 1px solid var(--cnsa-border-strong, rgba(255, 255, 255, 0.26));
  border-left: 3px solid var(--cnsa-accent-1, #00d2ff);
  border-radius: var(--cnsa-radius-sm, 10px);
  box-shadow: var(--cnsa-shadow-lg, 0 24px 48px rgba(0, 0, 0, 0.4));
  padding: 12px 15px;
  font-size: 13px;
  pointer-events: auto;
}

.skeleton-line {
  height: 12px;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06));
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}

.skeleton-line.short {
  width: 72%;
  margin-top: 10px;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }

  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: var(--cnsa-bar-h, 48px) 50px auto 1fr;
    grid-template-areas:
      "bar"
      "header"
      "sidebar"
      "map";
  }

  #app-header {
    padding: 0 12px;
  }

  #app-header h1 {
    font-size: 17px;
  }

  #last-updated {
    font-size: 10.5px;
    line-height: 1.25;
    white-space: normal;
    text-align: right;
  }

  #sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--cnsa-border, rgba(255, 255, 255, 0.12));
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    max-height: 38vh;
    padding: 12px;
  }

  .panel-section {
    margin: 0;
    padding: 0;
    border-bottom: 0;
  }

  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .preset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #timeline-control {
    top: auto;
    right: 12px;
    bottom: 12px;
    min-width: min(280px, calc(100vw - 24px));
  }

  #legend {
    left: 12px;
    bottom: 76px;
  }
}

@media (max-width: 520px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .panel-title {
    margin-bottom: 8px;
  }

  .layer-toggle {
    min-height: 40px;
  }

  #legend {
    width: min(220px, calc(100vw - 24px));
  }
}
