:root {
  --bg: #0b0f17;
  --land: #151b28;
  --coast: #28324a;
  --fg: #e6edf3;
  --muted: #8b96a8;
  --shallow: #f2a33c;
  --mid: #e0592a;
  --deep: #4d9de0;
  --accent: #f2a33c;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  max-width: 100%;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

img, canvas {
  max-width: 100%;
}

button {
  font-family: inherit;
  color: inherit;
  background: var(--land);
  border: 1px solid var(--coast);
  border-radius: 6px;
  min-height: 40px;
  min-width: 40px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
button:hover {
  border-color: var(--muted);
}
button.active,
button:active {
  background: var(--coast);
  border-color: var(--accent);
  color: var(--fg);
}
button.primary {
  background: var(--mid);
  border-color: var(--mid);
  color: #fff;
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  height: 40px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--coast);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--coast);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

label {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
}
input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

h1, h2 {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0 0 6px;
}
p {
  margin: 0 0 10px;
  line-height: 1.7;
}

/* -------------------- ヘッダー -------------------- */
.site-header {
  padding: 16px 16px 0;
  text-align: center;
}
.site-header h1 {
  font-size: clamp(20px, 5vw, 28px);
  letter-spacing: 0.02em;
}
.subtitle {
  color: var(--muted);
  font-size: 13px;
  max-width: 46em;
  margin: 0 auto 12px;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--bg);
  padding: 6px 4px;
  border-bottom: 1px solid var(--coast);
}
.tabs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 6px 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border-radius: 6px;
  white-space: nowrap;
}
.tabs a.active {
  color: var(--fg);
  background: var(--land);
  border: 1px solid var(--coast);
}

/* -------------------- メイン -------------------- */
#app {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px;
}

.map-stack {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 70vh;
  min-height: 260px;
  background: var(--bg);
  overflow: hidden;
  border-radius: 8px;
  touch-action: none;
}
.map-stack.hidden {
  display: none;
}
.map-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#base { z-index: 1; pointer-events: none; }
#pts  { z-index: 2; pointer-events: none; }
#ov   { z-index: 3; pointer-events: auto; touch-action: none; }

.loading-indicator {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 5;
  font-size: 11px;
  color: var(--muted);
  background: rgba(11, 15, 23, 0.7);
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
}
.loading-indicator.done:empty {
  display: none;
}

.counter {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 5;
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  background: rgba(11, 15, 23, 0.7);
  padding: 4px 10px;
  border-radius: 4px;
  pointer-events: none;
}

.view-panel {
  padding: 14px 4px 24px;
}

.view-note {
  color: var(--muted);
  font-size: 12.5px;
}

/* -------------------- 百年再生 -------------------- */
.year-display {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: clamp(36px, 10vw, 64px);
  line-height: 1;
  text-align: center;
  margin: 4px 0 8px;
}

.timeline-wrap {
  position: relative;
  padding-top: 14px;
  margin-bottom: 4px;
  overflow: hidden;
}
.named-ticks {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 12px;
  pointer-events: none;
}
.named-tick {
  position: absolute;
  top: 0;
  width: 3px;
  height: 10px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin-left: -1.5px;
  background: var(--accent);
  border: none;
  border-radius: 1px;
  pointer-events: auto;
  cursor: pointer;
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0;
}
#play-toggle {
  font-size: 16px;
  min-width: 48px;
}
.speed-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}
.minmag-label {
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
}
.depth-toggles {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot-shallow { background: var(--shallow); }
.dot-mid { background: var(--mid); }
.dot-deep { background: var(--deep); }

/* -------------------- 断面 -------------------- */
.controls-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.btn-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.note {
  color: var(--muted);
  font-size: 12.5px;
}
.section-info {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.section-plot-wrap {
  width: 100%;
  height: 260px;
  background: var(--bg);
  border: 1px solid var(--coast);
  border-radius: 6px;
  overflow: hidden;
}
#section-plot {
  width: 100%;
  height: 100%;
  display: block;
}

/* -------------------- 相模トラフ特集 -------------------- */
.sagami-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.sagami-copy article {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--coast);
}
.sagami-copy article:last-child {
  border-bottom: none;
}
.sagami-copy h2 {
  font-size: 17px;
}
.sagami-copy p {
  color: var(--fg);
  font-size: 14px;
}

/* -------------------- 統計 -------------------- */
.stats-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}
.chart-block h2 {
  font-size: 15px;
  margin-bottom: 6px;
}
.chart-block canvas {
  width: 100%;
  height: 220px;
  display: block;
  border: 1px solid var(--coast);
  border-radius: 6px;
}
.stats-notes {
  margin: 16px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}
.stats-tooltip {
  position: fixed;
  z-index: 50;
  display: none;
  background: rgba(11, 15, 23, 0.92);
  border: 1px solid var(--coast);
  color: var(--fg);
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 5px;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 720px) {
  .stats-charts {
    grid-template-columns: 1fr 1fr;
  }
  .chart-block:first-child {
    grid-column: 1 / -1;
  }
}

/* -------------------- フッター -------------------- */
.site-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
  border-top: 1px solid var(--coast);
}
.site-footer .credit {
  margin-top: 8px;
  color: var(--muted);
}

/* -------------------- モバイル -------------------- */
@media (max-width: 480px) {
  #app {
    padding: 8px;
  }
  .tabs a {
    padding: 6px 9px;
    font-size: 12px;
  }
  .playback-controls {
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
