:root {
  --bg: #d8e0db;
  --paper: #f4efe4;
  --paper-2: #ebe4d4;
  --ink: #1b2421;
  --ink-soft: #3e4b46;
  --muted: #66736e;
  --line: #d7cdb8;
  --accent: #2f6b60;
  --accent-2: #b0894d;
  --accent-soft: #e3eee8;
  --ocean: #6a9eab;
  --ocean-deep: #3d7180;
  --land: #d2c19a;
  --coast: #5a5348;
  --danger: #8a3030;
  --chip: #efe8d8;
  --header-h: 44px;
  --tabs-h: 52px;
  --dock-h: 108px;
  --font-ui: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-brand: "Iowan Old Style", Palatino, "Palatino Linotype",
    "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  --shadow: 0 10px 28px rgba(27, 36, 33, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
}

button, input {
  font-family: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.shell {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 100svh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding:
    calc(env(safe-area-inset-top) + 6px)
    8px
    calc(env(safe-area-inset-bottom) + 8px);
}

.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 8px;
  flex-shrink: 0;
}

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

.mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:active { background: var(--paper-2); }

.icon-btn svg { width: 18px; height: 18px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 2px;
  margin: 0;
  background: rgba(244, 239, 228, 0.72);
  border: 1px solid var(--line);
  border-radius: 14px;
  flex-shrink: 0;
  height: var(--tabs-h);
  min-width: 0;
  width: 100%;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 11px;
  padding: 4px 2px 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
}

.tab-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.tab-range {
  display: block;
  font-size: 9px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.tab.active {
  background: var(--ink);
  color: #f6f1e6;
}

.tab.active .tab-range { color: rgba(246, 241, 230, 0.72); }

.tab:focus-visible,
.icon-btn:focus-visible,
.btn:focus-visible,
.play:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.info-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
  margin: 6px 0 8px;
  padding: 2px 2px 0;
}

.age {
  font-family: var(--font-brand);
  font-size: 20px;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  flex-shrink: 0;
}

.color-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
  flex: 1 1 auto;
}

body[data-mode="earth"] #eventsBtn,
body[data-mode="earth"] #colorCluster,
#eventsBtn[hidden],
#colorCluster[hidden] { display: none !important; }

.btn.toggle {
  height: 32px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: 10px;
  flex-shrink: 0;
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 180px;
  border-radius: 18px;
  overflow: hidden;
  background: var(--ocean);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.map-view,
.earth-view {
  position: absolute;
  inset: 0;
}

.map-view {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: none;
  background: var(--ocean);
  width: 100%;
  height: 100%;
  min-width: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(27, 36, 33, 0.25) transparent;
}

.map-view::-webkit-scrollbar { height: 4px; width: 4px; }
.map-view::-webkit-scrollbar-thumb {
  background: rgba(27, 36, 33, 0.28);
  border-radius: 99px;
}

.map-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--ocean);
}

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

.grid {
  fill: none;
  stroke: rgba(255, 255, 255, 0.28);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.grid.equator { stroke: rgba(255, 255, 255, 0.45); stroke-width: 0.9; }

.land {
  fill: var(--land);
  stroke: var(--coast);
  stroke-width: 1;
  fill-rule: evenodd;
  vector-effect: non-scaling-stroke;
  transition: opacity 0.25s ease;
}

.land.simple {
  fill: #efe6cf;
  stroke: #7a7266;
  stroke-width: 0.85;
}

body[data-mode="civil"] {
  --ocean: #9eb9c4;
}

body[data-mode="civil"] .map-view,
body[data-mode="civil"] .map-canvas {
  background: #9eb9c4;
}

.fill {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 0.45;
  fill-opacity: 0.78;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}

.trace {
  stroke: #fff;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.region {
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 0.6;
  fill-opacity: 0.62;
  vector-effect: non-scaling-stroke;
}

.marker { cursor: pointer; }

.dot {
  fill: #141414;
  stroke: #fff;
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.dot-ring {
  fill: none;
  stroke: #1b2421;
  stroke-width: 1.4;
  opacity: 0.35;
  vector-effect: non-scaling-stroke;
}

.label {
  fill: #1b2421;
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 4;
  paint-order: stroke;
  stroke-linejoin: round;
  font-size: 14px;
  font-weight: 800;
  font-family: var(--font-ui);
}

.nav-cluster {
  position: absolute;
  z-index: 6;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-cluster button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: rgba(244, 239, 228, 0.94);
  border-radius: 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(27, 36, 33, 0.1);
}

.nav-cluster button:active { background: var(--paper-2); }
.nav-cluster[hidden] { display: none !important; }

.legend {
  display: none;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 10px;
  line-height: 1.3;
}

.legend::-webkit-scrollbar { display: none; }

.legend.show { display: flex; }

.legend .key {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.sw {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.loading,
.toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, calc(100% - 24px));
  border-radius: 14px;
  padding: 12px 14px;
  text-align: center;
}

.loading {
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(27, 36, 33, 0.86);
  color: #f6f1e6;
  box-shadow: var(--shadow);
  max-width: calc(100% - 24px);
}

.loading[hidden],
.toast[hidden] { display: none !important; }

.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto 8px;
  border: 2px solid rgba(246, 241, 230, 0.25);
  border-top-color: #f6f1e6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading p { margin: 0; font-size: 13px; font-weight: 700; }
.loading .muted { margin-top: 4px; font-size: 11px; font-weight: 500; color: rgba(246, 241, 230, 0.7); }

.toast {
  bottom: 12px;
  background: #7f2626;
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow);
}

.toast button {
  margin-top: 8px;
  border: 0;
  background: #fff;
  color: #7f2626;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
}

.banner {
  position: absolute;
  z-index: 7;
  left: 10px;
  right: 58px;
  bottom: 10px;
  background: rgba(244, 239, 228, 0.95);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 11px;
  line-height: 1.45;
}

.banner[hidden] { display: none !important; }

.earth-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 14px;
  overflow: auto;
  background:
    radial-gradient(circle at 50% 38%, #24343f 0 18%, #10171c 58%, #090d10 100%);
}

.space {
  flex: 0 0 auto;
  width: 100%;
  display: grid;
  place-items: center;
}

.atmosphere {
  width: min(58vw, 42dvh, 280px);
  height: min(58vw, 42dvh, 280px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 14px rgba(160, 206, 214, 0.08), 0 0 48px rgba(125, 211, 252, 0.16);
}

.globe {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
}

.globe-surface,
.globe-light,
.globe-shade {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.globe-light {
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.42), transparent 36%);
}

.globe-shade {
  box-shadow: inset -18px -12px 28px rgba(0, 0, 0, 0.45);
}

.globe[data-visual="hadean"] .globe-surface {
  background:
    radial-gradient(circle at 30% 28%, #ffd9a8 0 6%, transparent 24%),
    radial-gradient(circle at 62% 58%, #d2551c 0 22%, #7a1f0d 48%, #140806 74%);
}

.globe[data-visual="hadean-cool"] .globe-surface {
  background:
    radial-gradient(circle at 34% 30%, #f0c48a 0 5%, transparent 22%),
    radial-gradient(circle at 58% 60%, #8a3a24 0 18%, #2a4454 46%, #0d1822 72%);
}

.globe[data-visual="archean"] .globe-surface {
  background:
    radial-gradient(circle at 32% 28%, #d7ecec 0 4%, transparent 20%),
    radial-gradient(circle at 50% 50%, #2f6d7c 0 38%, #163445 62%, #08141c 100%);
}

.globe[data-visual="archean-late"] .globe-surface {
  background:
    radial-gradient(circle at 40% 58%, #4e7c55 0 8%, transparent 22%),
    radial-gradient(circle at 50% 50%, #2c6b7a 0 40%, #1a3d4c 66%, #0a171f 100%);
}

.globe[data-visual="goe"] .globe-surface {
  background:
    radial-gradient(circle at 30% 26%, #f2f7ff 0 6%, transparent 22%),
    radial-gradient(circle at 60% 55%, #3f8f7a 0 14%, #2a6d86 42%, #16384a 70%);
}

.globe[data-visual="paleoproterozoic"] .globe-surface {
  background:
    radial-gradient(circle at 28% 26%, #e7f3ff 0 6%, transparent 20%),
    radial-gradient(circle at 55% 48%, #6aa07a 0 10%, #2e7390 40%, #173b4d 72%);
}

.globe[data-visual="mesoproterozoic"] .globe-surface {
  background:
    radial-gradient(circle at 64% 42%, #cbb889 0 7%, transparent 18%),
    radial-gradient(circle at 38% 58%, #b7a078 0 6%, transparent 16%),
    radial-gradient(circle at 50% 50%, #3c7f93 0 42%, #1d4556 70%);
}

.globe[data-visual="tonian"] .globe-surface {
  background:
    radial-gradient(circle at 58% 40%, #d2c09a 0 8%, transparent 18%),
    radial-gradient(circle at 34% 60%, #c2b089 0 6%, transparent 16%),
    radial-gradient(circle at 50% 50%, #4689a0 0 40%, #215064 72%);
}

.globe[data-visual="hadean"] ~ .atmosphere,
.atmosphere[data-visual="hadean"] {
  box-shadow: 0 0 0 16px rgba(239, 130, 70, 0.1), 0 0 60px rgba(239, 108, 61, 0.28);
}

.atmosphere[data-visual="goe"],
.atmosphere[data-visual="paleoproterozoic"] {
  box-shadow: 0 0 0 16px rgba(186, 230, 253, 0.1), 0 0 54px rgba(125, 211, 252, 0.22);
}

.earth-caption {
  margin: 0 auto;
  max-width: 34em;
  padding: 0 12px;
  color: rgba(246, 241, 230, 0.72);
  font-size: 11px;
  text-align: center;
  line-height: 1.5;
  position: relative;
  z-index: 1;
}

.earth-facts {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  list-style: none;
  background: rgba(15, 20, 24, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  backdrop-filter: blur(10px);
}

.earth-facts li {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 8px;
  align-items: baseline;
  color: #f6f1e6;
  font-size: 13px;
  line-height: 1.45;
  padding: 5px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.earth-facts li:first-child { border-top: 0; padding-top: 0; }
.earth-facts li:last-child { padding-bottom: 0; }

.earth-facts .k { color: rgba(246, 241, 230, 0.55); font-size: 11px; font-weight: 700; }
.earth-facts .e {
  font-size: 10px;
  color: rgba(246, 241, 230, 0.62);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hidden { display: none !important; }

.dock {
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
  margin-top: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px 11px;
  box-shadow: var(--shadow);
}

.tl-row {
  display: grid;
  grid-template-columns: 36px 1fr 44px;
  gap: 8px;
  align-items: center;
}

.tl-end {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tl-end.right { text-align: right; }

.tl-wrap { position: relative; padding: 8px 0 16px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:focus { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  background: linear-gradient(90deg, var(--accent) var(--p, 0%), #d2c7b0 var(--p, 0%));
  border-radius: 99px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(27, 36, 33, 0.22);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  background: #d2c7b0;
  border-radius: 99px;
}

input[type="range"]::-moz-range-progress {
  height: 5px;
  background: var(--accent);
  border-radius: 99px;
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(27, 36, 33, 0.22);
}

.ticks {
  position: absolute;
  left: 2px;
  right: 2px;
  top: 34px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 56px 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 2px;
  min-width: 0;
}

.btn {
  height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 8px;
  white-space: nowrap;
}

.btn:active { background: var(--paper-2); }

.btn[aria-pressed="true"] {
  background: var(--ink);
  color: #f6f1e6;
  border-color: var(--ink);
}

.play {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #f7f3ea;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(47, 107, 96, 0.32);
  justify-self: center;
}

.play:active { transform: translateY(1px); }
.play.is-playing { background: var(--ink); box-shadow: none; }

.sheet {
  position: absolute;
  z-index: 20;
  left: 10px;
  right: 10px;
  bottom: 10px;
  max-height: min(48%, 380px);
  overflow: auto;
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(27, 36, 33, 0.28);
  transform: translateY(120%);
  transition: transform 0.28s ease;
  padding: 8px 16px 14px;
}

.sheet.is-open { transform: translateY(0); }

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: #d2c7b0;
  margin: 4px auto 10px;
}

.sheet-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.sheet h2 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.25;
  font-family: var(--font-brand);
  font-weight: 600;
}

.sheet .meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  white-space: pre-line;
}

.sheet p {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.7;
}

.sheet a { color: var(--accent); }

.sheet .note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.sheet-close {
  border: 0;
  background: var(--paper-2);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
}

dialog.about {
  width: min(440px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 18px 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog.about::backdrop { background: rgba(16, 22, 20, 0.45); }

dialog.about h2 {
  margin: 0 0 8px;
  font-family: var(--font-brand);
  font-size: 22px;
}

dialog.about p,
dialog.about li {
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink-soft);
}

dialog.about ul { padding-left: 1.1em; margin: 8px 0; }

body[data-mode="earth"] {
  --bg: #10161a;
  --paper: #182126;
  --paper-2: #223036;
  --ink: #f3eee3;
  --ink-soft: #d9d1c3;
  --muted: #a8b0ab;
  --line: #314047;
  --chip: #243035;
  --accent-soft: #1e3a36;
}

body[data-mode="earth"] .tabs {
  background: rgba(24, 33, 38, 0.8);
}

body[data-mode="earth"] .tab.active {
  background: #f3eee3;
  color: #182126;
}

body[data-mode="earth"] .icon-btn,
body[data-mode="earth"] .btn {
  background: #182126;
  color: #f3eee3;
}

body[data-mode="earth"] .btn[aria-pressed="true"] {
  background: #f3eee3;
  color: #182126;
}

body[data-mode="earth"] .dock { box-shadow: none; }

body[data-mode="earth"] input[type="range"]::-webkit-slider-thumb {
  background: #182126;
  border-color: #d7b16a;
}

@media (min-width: 760px) {
  .shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 16px 16px;
  }

  .brand h1 { font-size: 24px; }
  .tabs { height: 56px; }
  .tab-label { font-size: 14px; }
  .age { font-size: 24px; }

  .atmosphere {
    width: min(260px, 32dvh);
    height: min(260px, 32dvh);
  }

  .earth-view {
    padding: 24px 24px 20px;
  }

  .earth-facts { max-width: 420px; }

  .sheet {
    left: auto;
    right: 16px;
    width: min(380px, 36vw);
    max-height: calc(100% - 20px);
    top: 16px;
    bottom: 16px;
    transform: translateX(110%);
    padding: 16px 16px 18px;
  }

  .sheet.is-open { transform: translateX(0); }
  .sheet-handle { display: none; }
}

@media (min-width: 1100px) {
  .shell { max-width: 1280px; }
  .stage { min-height: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  .sheet { transition: none; }
  .play:active { transform: none; }
}

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