*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #5a6a7e;
  --border: #d5dde8;
  --accent: #b33a2b;
  --accent-soft: #f8ebe9;
  --link: #1f4e79;
  --ok-bg: #e7f6ec;
  --ok-text: #1b6b3a;
  --ok-border: #9dceb0;
  --warn-bg: #fff4e5;
  --warn-text: #8a4b00;
  --warn-border: #efc48a;
  --alert-bg: #fdecea;
  --alert-text: #8f1f1b;
  --alert-border: #efb0ab;
  --shadow: 0 1px 3px rgba(26, 35, 50, 0.08);
  --radius: 12px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

html, body {
  height: 100%;
}

body.viewer-page {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.viewer-embed {
  height: 100%;
  overflow: hidden;
}

body.viewer-embed .viewer-layout {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 64px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.eq-ticker {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-width: 0;
}

.live-status {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 3.75rem;
  padding: 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
}

.live-status.live-on {
  background: var(--accent);
}

.live-status.live-off {
  background: #7a8798;
}

.eq-ticker-track {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  background: #f7f9fc;
  border-left: 1px solid var(--border);
}

.eq-ticker-content {
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  padding-left: 1rem;
}

.eq-ticker-content.scrolling {
  display: flex;
  width: max-content;
  animation: ticker-scroll 45s linear infinite;
  padding-left: 0;
}

.eq-ticker-content.scrolling span {
  padding-right: 3rem;
}

@keyframes ticker-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.85rem;
  border-left: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.refresh-btn {
  border: 1px solid var(--border);
  background: #1f4e79;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.refresh-btn:hover {
  background: #173a5c;
}

.refresh-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.refresh-btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
}

.clock-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
  min-width: 7.5rem;
}

.clock-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.current-clock {
  font-size: 1.85rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Tools banner - separate page CTA */
.tools-banner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(90deg, #1f4e79, #2a6aa3);
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
  border-bottom: 3px solid #16385a;
}

.tools-banner:hover {
  filter: brightness(1.05);
}

.tools-banner-badge {
  flex-shrink: 0;
  background: #f4c542;
  color: #1a2332;
  font-size: 0.75rem;
  font-weight: 900;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
}

.tools-banner-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}

.tools-banner-main strong {
  font-size: 1.05rem;
  font-weight: 900;
}

.tools-banner-sub {
  font-size: 0.8rem;
  opacity: 0.92;
}

.tools-banner-arrow {
  font-size: 1.5rem;
  font-weight: 900;
  flex-shrink: 0;
}

.info-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.info-card-header .info-card-title {
  margin-bottom: 0;
}

.refresh-btn-ghost {
  background: #fff;
  color: #1f4e79;
}

.refresh-btn-ghost:hover {
  background: #eef2f6;
}

dialog.guide-modal {
  inset: 0;
  margin: auto;
  width: min(480px, calc(100vw - 2rem));
  max-height: 80vh;
  overflow: auto;
  padding: 1rem 1.15rem 1.25rem;
  border: none;
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.28);
  color: #1f2937;
}

dialog.guide-modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.guide-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.guide-modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  margin: 0;
}

.guide-modal-close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
}

.guide-modal-close:hover {
  background: #f1f5f9;
  color: #c0392b;
}

.guide-modal .usage-guide-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  line-height: 1.7;
  color: #334155;
}

.guide-modal .usage-guide-list li {
  margin-bottom: 0.45rem;
}

.tools-card-link {
  display: block;
  margin-top: 0.75rem;
  padding: 0.85rem 0.9rem;
  background: #1f4e79;
  color: #fff;
  text-decoration: none;
  border-radius: 10px;
  flex-shrink: 0;
}

.tools-card-link:hover {
  background: #173a5c;
}

.tools-card-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 900;
}

.tools-card-desc {
  display: block;
  font-size: 0.75rem;
  opacity: 0.9;
  margin-top: 0.2rem;
}

.eq-flash-banner {
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  z-index: 2000;
  background: var(--accent);
  color: #fff;
  padding: 0.85rem 1rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  animation: flash-slide-in 0.3s ease-out;
}

.eq-flash-banner.eew {
  background: #7a2f8a;
}

.eq-flash-banner[hidden] {
  display: none;
}

.eq-flash-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.85rem;
  align-items: center;
  font-size: 1rem;
  max-width: 1100px;
  margin: 0 auto;
}

.eq-flash-badge {
  background: rgba(255, 255, 255, 0.22);
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 800;
}

@keyframes flash-slide-in {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Layout: 左=いまの地震 / 中央=地図 / 右=最近の地震 */
.viewer-layout {
  flex: 1 1 auto;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.viewer-sidebar {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.viewer-sidebar-left {
  flex: 0 0 300px;
  width: 300px;
  max-width: 300px;
  border-right: 1px solid var(--border);
  order: 1;
}

.viewer-sidebar-right {
  flex: 0 0 320px;
  width: 320px;
  max-width: 320px;
  border-left: 1px solid var(--border);
  background: #f8fafc;
  order: 3;
}

.viewer-map-pane {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  order: 2;
  position: relative;
  background: #d9e2ec;
}

.info-card,
.history-card {
  padding: 1rem 1.1rem;
}

.info-card {
  border-bottom: none;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.today-summary {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.today-summary-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.today-summary-count {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.2rem;
  color: var(--link);
  line-height: 1;
}

#today-quake-count {
  font-size: 2.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.today-summary-unit {
  font-size: 1.1rem;
  font-weight: 800;
}

.today-summary-note {
  margin-top: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
}

.history-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
  height: 100%;
  box-sizing: border-box;
}

.info-card-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.intensity-block {
  text-align: center;
  margin-bottom: 1rem;
}

.intensity-caption {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.latest-intensity {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 5.5rem;
  min-height: 5.5rem;
  padding: 0.5rem 1rem;
  border-radius: 16px;
  font-size: 3rem;
  font-weight: 900;
  line-height: 1;
  border: 2px solid var(--border);
  background: #f4f7fb;
  color: var(--text);
}

.latest-intensity.intensity-1,
.latest-intensity.intensity-2 {
  background: #e8f7ef;
  border-color: #8fcea8;
  color: #1d6b3f;
}

.latest-intensity.intensity-3 {
  background: #fff8d9;
  border-color: #e2c84a;
  color: #6b5a00;
}

.latest-intensity.intensity-4 {
  background: #ffedd5;
  border-color: #e29a45;
  color: #8a4a00;
}

.latest-intensity.intensity-5m,
.latest-intensity.intensity-5p {
  background: #ffe0d4;
  border-color: #e07040;
  color: #8a2a00;
}

.latest-intensity.intensity-6m,
.latest-intensity.intensity-6p,
.latest-intensity.intensity-7 {
  background: #f8d4d0;
  border-color: #c0392b;
  color: #7a1210;
}

.latest-meta {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
}

.meta-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.45rem 0.6rem;
  background: #f7f9fc;
  border-radius: 8px;
  border: 1px solid #e8eef5;
}

.meta-row dt {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.meta-row dd {
  font-size: 0.95rem;
  font-weight: 700;
  word-break: break-word;
}

.tsunami-badge {
  margin-top: 0.85rem;
  flex-shrink: 0;
  text-align: center;
  padding: 0.7rem 0.75rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 800;
  border: 1px solid;
}

.tsunami-badge.tsunami-none {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: var(--ok-border);
}

.tsunami-badge.tsunami-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: var(--warn-border);
}

.tsunami-badge.tsunami-alert {
  background: var(--alert-bg);
  color: var(--alert-text);
  border-color: var(--alert-border);
}

.history-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: -0.35rem 0 0.65rem;
}

.history-list {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding-bottom: 0.75rem;
}

.history-item {
  display: grid;
  grid-template-columns: 2.75rem 1fr;
  gap: 0.7rem;
  padding: 0.7rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  width: 100%;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.history-item:hover {
  border-color: #9db4d0;
}

.history-item.selected {
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(31, 78, 121, 0.18);
}

.history-item:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.history-scale {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.05rem;
  color: #1a2332;
  background: #d5dde8;
}

.history-scale.s1 { background: #b8e6cb; }
.history-scale.s2 { background: #8fd4ad; }
.history-scale.s3 { background: #f5d76e; }
.history-scale.s4 { background: #f0b27a; }
.history-scale.s5 { background: #e67e22; color: #fff; }
.history-scale.s6 { background: #c0392b; color: #fff; }
.history-scale.s7 { background: #7b1a14; color: #fff; }

.history-body {
  min-width: 0;
}

.history-name {
  display: block;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.4;
}

.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1.25rem 0.5rem;
  text-align: center;
}

/* Map */
.viewer-map-pane {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  order: 2;
  background: #d9e2ec;
}

.earthquake-map {
  width: 100%;
  height: 100%;
}

.map-chrome {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none;
}

.map-updated {
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.map-reset-btn {
  pointer-events: auto;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--link);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.map-reset-btn:hover {
  background: #fff;
}

.map-legend-bar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.9rem;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  box-shadow: var(--shadow);
  max-width: calc(100% - 24px);
}

.map-legend-bar span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-ring {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  box-sizing: border-box;
}

.legend-ring.legend-p {
  border: 2px solid #2f80c4;
  background: rgba(47, 128, 196, 0.18);
}

.legend-ring.legend-s {
  border: 2px solid #c0392b;
  background: rgba(192, 57, 43, 0.18);
}

.legend-ring.legend-expected {
  border: 2px dashed #c47a12;
  background: rgba(196, 122, 18, 0.12);
}

.wave-hud {
  position: absolute;
  left: 12px;
  bottom: 72px;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  pointer-events: none;
  max-width: calc(100% - 24px);
}

.wave-hud[hidden] {
  display: none;
}

.map-count-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: min(320px, calc(100% - 24px));
  padding: 0.45rem 0.65rem;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.map-count-sample {
  flex-shrink: 0;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f1c40f;
  color: #1a2332;
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0, 0, 0, 0.25);
}

.map-count-text {
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--muted);
}

.map-count-text strong {
  color: var(--text);
  font-weight: 800;
}

.today-quake-total {
  display: block;
  margin-top: 0.15rem;
  color: var(--link);
  font-weight: 800;
}

.wave-hud-item {
  background: rgba(26, 35, 50, 0.82);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
}

.wave-hud-item.wave-p { border-left: 3px solid #5dade2; }
.wave-hud-item.wave-s { border-left: 3px solid #e74c3c; }
.wave-hud-item.wave-expected { border-left: 3px solid #f0b27a; }

.eq-marker,
.eq-highlight-marker {
  background: transparent;
  border: none;
}

.eq-pin {
  position: relative;
  width: 36px;
  height: 48px;
}

.eq-pin-pulse {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  border-radius: 50%;
  background: rgba(192, 57, 43, 0.3);
  animation: eq-pulse 1.5s ease-out infinite;
}

.eq-pin-head {
  position: absolute;
  left: 50%;
  top: 0;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.eq-pin-arrow {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 0;
  height: 0;
  margin-left: -6px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid var(--accent);
}

@keyframes eq-pulse {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(2.2); opacity: 0; }
}

.leaflet-container {
  background: #d9e2ec;
  font: inherit;
}

@media (max-width: 768px) {
  body.viewer-page {
    overflow: auto;
  }

  .topbar {
    flex-wrap: wrap;
    min-height: 0;
  }

  .eq-ticker {
    width: 100%;
    min-height: 40px;
    border-bottom: 1px solid var(--border);
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
    border-left: none;
  }

  .current-clock {
    font-size: 1.6rem;
  }

  .viewer-layout {
    flex-direction: column;
    overflow: auto;
  }

  .viewer-sidebar-left,
  .viewer-sidebar-right,
  .viewer-map-pane {
    width: 100%;
    max-width: none;
    flex: none;
    order: unset;
  }

  .viewer-sidebar-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .viewer-map-pane {
    min-height: 45vh;
    height: 45vh;
  }

  .viewer-sidebar-right {
    border-left: none;
    border-top: 1px solid var(--border);
    min-height: 320px;
    height: 40vh;
  }

  .history-card {
    min-height: 0;
    height: 100%;
  }

  .history-list {
    max-height: none;
    min-height: 0;
  }

  .latest-intensity {
    min-width: 4.75rem;
    min-height: 4.75rem;
    font-size: 2.5rem;
  }

  .meta-row {
    grid-template-columns: 6.5rem 1fr;
  }

  .map-legend-bar {
    left: auto;
    right: 12px;
    bottom: 12px;
    max-width: min(220px, calc(50% - 18px));
  }

  .map-count-hint {
    max-width: min(240px, calc(50% - 18px));
  }

  .wave-hud {
    bottom: 5.5rem;
  }
}

@media (max-height: 800px) {
  .latest-intensity {
    min-width: 4.25rem;
    min-height: 4.25rem;
    font-size: 2.35rem;
  }

  .meta-row {
    padding: 0.3rem 0.55rem;
  }

  .info-card,
  .history-card {
    padding: 0.75rem 0.9rem;
  }

  .history-card {
    min-height: 0;
  }

  .history-list {
    min-height: 120px;
  }
}
  .tools-banner {
    padding: 0.65rem 0.75rem;
    gap: 0.55rem;
  }

  .tools-banner-main strong {
    font-size: 0.95rem;
  }

  .tools-banner-sub {
    font-size: 0.72rem;
  }

  .current-clock {
    font-size: 1.4rem;
  }

  .eq-ticker-content {
    font-size: 0.8rem;
  }

  .info-card,
  .history-card {
    padding: 0.85rem;
  }
}
