:root {
  --bg: #070b12;
  --bg-panel: #0f1622;
  --bg-panel-2: #141c2b;
  --line: #243247;
  --text: #eef3fb;
  --muted: #8b9bb0;
  --accent: #3dd6c6;
  --danger: #e53935;
  --warn: #ffd54f;
  --eew-purple: #9c27b0;
  --font: "IBM Plex Sans JP", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(900px 500px at 80% 10%, rgba(229, 57, 53, 0.08), transparent 55%),
    radial-gradient(800px 480px at 10% 90%, rgba(156, 39, 176, 0.07), transparent 50%),
    var(--bg);
}

#app {
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  grid-template-rows: auto 1fr;
  height: 100%;
  min-height: 100dvh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 18, 0.92);
  backdrop-filter: blur(10px);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.2), 0 0 16px rgba(229, 57, 53, 0.55);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.88); opacity: 0.7; }
}

.brand h1 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}

.brand-sub {
  margin: 0.12rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toggles {
  display: flex;
  gap: 0.35rem;
}

.toggle-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.32rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}

.toggle-btn[aria-pressed="true"] {
  color: #0b0f14;
  background: var(--accent);
  border-color: var(--accent);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.76rem;
  color: var(--muted);
  padding: 0.32rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-panel);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status[data-state="connected"] .status-dot {
  background: #3cd47a;
  box-shadow: 0 0 10px rgba(60, 212, 122, 0.7);
}

.status[data-state="connected"] { color: #b8f0cb; }

.status[data-state="error"] .status-dot {
  background: var(--danger);
}

.clock {
  font-family: var(--mono);
  font-size: 0.86rem;
  letter-spacing: 0.03em;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.75rem;
  border-right: 1px solid var(--line);
  background: rgba(10, 14, 22, 0.96);
  overflow: auto;
  z-index: 20;
}

.eew-card {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #5a1820;
  background: linear-gradient(180deg, #1a0c12 0%, #120d14 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.eew-card[data-active="true"] {
  border-color: #c62828;
  box-shadow: 0 0 0 1px rgba(229, 57, 53, 0.35), 0 14px 36px rgba(198, 40, 40, 0.28);
}

.eew-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background:
    repeating-linear-gradient(
      -45deg,
      #b71c1c 0 8px,
      #1a1a1a 8px 16px
    );
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.eew-card-title {
  font-size: 0.92rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.eew-serial {
  font-size: 0.72rem;
  background: #111;
  color: #ff8a80;
  border: 1px solid #5a1820;
  border-radius: 4px;
  padding: 0.18rem 0.45rem;
  font-family: var(--mono);
}

.eew-place-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.85rem 0.85rem 0.2rem;
}

.eew-place {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
}

.eew-place-suffix {
  font-size: 0.95rem;
  color: var(--muted);
}

.eew-origin {
  padding: 0 0.85rem 0.7rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
}

.eew-metrics {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 0.55rem;
  padding: 0 0.75rem 0.75rem;
}

.eew-maxbox {
  border-radius: 8px;
  padding: 0.55rem 0.6rem 0.65rem;
  background: #6a1b9a;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 5.4rem;
}

.eew-maxlab {
  font-size: 0.72rem;
  opacity: 0.92;
}

.eew-maxval {
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
}

.eew-side-metrics {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.eew-metric {
  flex: 1;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-left: 4px solid #ab47bc;
}

.eew-metric:last-child {
  border-left-color: #c0ca33;
}

.eew-metric .k {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.eew-metric .v {
  font-size: 1.25rem;
  font-weight: 700;
}

.eew-tsunami {
  margin: 0 0.75rem 0.75rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(255, 213, 79, 0.12);
  border: 1px solid rgba(255, 213, 79, 0.35);
  color: var(--warn);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.45;
}

.detect-card {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-panel-2);
  overflow: hidden;
}

.detect-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  background: #1565c0;
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
}

.detect-max {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.25);
  min-width: 2.4rem;
  text-align: center;
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
}

.detect-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem;
  max-height: 180px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.detect-empty {
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0.55rem 0.45rem;
}

.detect-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0.4rem;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.03);
  animation: detectIn 0.25s ease-out;
}

@keyframes detectIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: none; }
}

.detect-scale {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #111;
}

.detect-name {
  font-size: 0.84rem;
  font-weight: 600;
}

.panel {
  background: var(--bg-panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
}

.panel-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}

.ghost-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ghost-btn:not(:disabled):hover {
  color: var(--text);
  border-color: #3a4b63;
}

.playback-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.18rem 0.48rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.playback-badge[data-state="playing"] {
  color: #0b0f14;
  background: var(--accent);
  border-color: var(--accent);
}

.playback-badge[data-state="paused"] {
  color: #111;
  background: var(--warn);
  border-color: var(--warn);
}

.playback-badge[data-state="live"] {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.playback-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}

.play-btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #0b0f14;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  cursor: pointer;
}

.play-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.speed-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--muted);
}

.speed-label select {
  appearance: none;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.7rem;
  padding: 0.25rem 0.4rem;
}

.playback-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.playback-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #7cf0e4);
  transition: width 0.2s ease;
}

.playback-meta {
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.4;
  min-height: 2em;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: min(28vh, 260px);
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: center;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  color: inherit;
  font: inherit;
  border-radius: 9px;
  padding: 0.45rem 0.5rem;
  cursor: pointer;
}

.history-item:hover,
.history-item.active {
  background: rgba(229, 57, 53, 0.1);
  border-color: rgba(229, 57, 53, 0.35);
}

.hist-scale {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #111;
}

.hist-place {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.1rem;
}

.hist-meta {
  font-size: 0.68rem;
  color: var(--muted);
  font-family: var(--mono);
}

.map-wrap {
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #05080e;
}

.map-clock {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 550;
  font-family: var(--mono);
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid #333;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  pointer-events: none;
}

.intensity-legend {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 550;
  background: rgba(8, 12, 18, 0.88);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-size: 0.68rem;
  color: var(--muted);
  display: grid;
  gap: 0.28rem;
  pointer-events: none;
}

.intensity-legend .leg-title {
  color: var(--text);
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.intensity-legend .leg-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.intensity-legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.map-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(11, 15, 20, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.32rem 0.5rem;
  pointer-events: none;
}

.epicenter-x {
  width: 28px;
  height: 28px;
  position: relative;
}

.epicenter-x::before,
.epicenter-x::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 5px;
  background: #e53935;
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(229, 57, 53, 0.8);
}

.epicenter-x::before { transform: translate(-50%, -50%) rotate(45deg); }
.epicenter-x::after { transform: translate(-50%, -50%) rotate(-45deg); }

.region-label {
  min-width: 26px;
  height: 26px;
  padding: 0 4px;
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  font-family: var(--font);
  line-height: 1;
  animation: popIn 0.22s ease-out;
}

.intensity-dot {
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 10px;
  font-family: var(--font);
  line-height: 1;
  animation: popIn 0.22s ease-out;
}

@keyframes popIn {
  from { transform: scale(0.2); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.quake-marker {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 11px;
  color: #111;
  font-family: var(--font);
  opacity: 0.55;
}

.leaflet-container {
  font-family: var(--font);
  background: #05080e;
}

.map-tiles-dark {
  filter: invert(1) hue-rotate(180deg) brightness(0.88) contrast(0.95) saturate(0.3);
}

.leaflet-control-attribution {
  background: rgba(11, 15, 20, 0.75) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a { color: var(--accent) !important; }

.live-interrupt {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  align-items: center;
  padding: 0.55rem 0.9rem;
  border-radius: 12px;
  background: rgba(198, 40, 40, 0.94);
  color: #fff;
  box-shadow: 0 12px 30px rgba(198, 40, 40, 0.4);
  font-size: 0.8rem;
  pointer-events: none;
  animation: slideDown 0.28s ease-out;
}

@keyframes slideDown {
  from { transform: translate(-50%, -120%); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.mono { font-family: var(--mono); }

@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(48vh, 1fr);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 46vh;
  }

  .history-list { max-height: 140px; }
  .detect-list { max-height: 120px; }
  .brand h1 { font-size: 0.92rem; }
}
