:root {
  --bg: #161616;
  --panel: #222;
  --panel-2: #2b2b2b;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --accent: #ff8a3d;
  --danger: #e0242c;
  --font: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}
button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { background: #363636; }
.hidden { display: none !important; }

/* ---------- ホーム画面 ---------- */
.home {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  grid-template-rows: auto 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 60px);
}
.clock-panel, .weather-panel, .quake-panel {
  background: var(--panel);
  border-radius: 16px;
  padding: 24px;
}
.clock-panel { grid-column: 1; grid-row: 1; }
.weather-panel { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-direction: column; gap: 16px; overflow: auto; }
.quake-panel { grid-column: 1; grid-row: 2; overflow: auto; }

.date { font-size: clamp(18px, 2.6vw, 32px); color: var(--muted); }
.time {
  font-size: clamp(64px, 13vw, 180px);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.time .sec { font-size: 0.3em; color: var(--muted); margin-left: 0.2em; }

.weather-now { display: flex; align-items: center; gap: 20px; }
.weather-icon { font-size: clamp(56px, 8vw, 96px); line-height: 1; }
.weather-temp { font-size: clamp(40px, 6vw, 72px); font-weight: 700; line-height: 1; }
.weather-temp small { font-size: 0.4em; color: var(--muted); }
.weather-desc { font-size: 20px; margin-top: 4px; }
.weather-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.weather-place { color: var(--muted); font-size: 14px; }
.weather-hourly { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.weather-hourly .h {
  flex: 0 0 auto; text-align: center; background: var(--panel-2);
  border-radius: 10px; padding: 8px 10px; min-width: 58px;
}
.weather-hourly .h .t { color: var(--muted); font-size: 12px; }
.weather-hourly .h .i { font-size: 24px; }
.weather-hourly .h .p { color: #6fb6ff; font-size: 11px; }
.weather-daily .d {
  display: grid; grid-template-columns: 4.5em 2em 1fr auto; align-items: center;
  gap: 8px; padding: 8px 0; border-bottom: 1px solid #333;
}
.weather-daily .d:last-child { border-bottom: 0; }
.weather-daily .d .hi { color: #ff9b7a; }
.weather-daily .d .lo { color: #7ab8ff; }
.weather-daily .d .p { color: #6fb6ff; font-size: 12px; text-align: right; }

.panel-label { color: var(--muted); font-size: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.conn { font-size: 10px; color: #666; }
.conn.ok { color: #3ecf6e; }
.conn.ng { color: var(--danger); }

.quake-latest { display: flex; gap: 20px; align-items: center; cursor: pointer; }
.quake-latest .scale-badge { width: 96px; height: 96px; font-size: 48px; border-radius: 14px; flex: 0 0 auto; }
.quake-latest .info div { margin: 2px 0; }
.quake-latest .info .hypo { font-size: 24px; font-weight: 700; }
.quake-latest .info .meta { color: var(--muted); }
.quake-history { margin-top: 16px; font-size: 14px; }
.quake-history .row {
  display: grid; grid-template-columns: 2.4em 7em 1fr 4em; gap: 8px; align-items: center;
  padding: 6px 0; border-top: 1px solid #333; cursor: pointer;
}
.quake-history .row .scale-badge { width: 2.2em; height: 2.2em; font-size: 14px; border-radius: 6px; }

.toolbar {
  height: 60px; display: flex; gap: 8px; align-items: center; justify-content: flex-end;
  padding: 0 16px;
}
.toolbar button { font-size: 13px; padding: 6px 12px; opacity: 0.75; }

/* ---------- 震度バッジ（気象庁配色に準拠） ---------- */
.scale-badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; border: 2px solid rgba(255,255,255,0.85);
  color: #111; line-height: 1;
}
.s10 { background: #7fb2d9; }
.s20 { background: #49b07d; }
.s30 { background: #f2e45c; }
.s40 { background: #f5a623; }
.s45, .s46 { background: #e8562a; color: #fff; }
.s50 { background: #c8221f; color: #fff; }
.s55 { background: #a3172d; color: #fff; }
.s60 { background: #7d0f3a; color: #fff; }
.s70 { background: #4b0a46; color: #fff; }
.s0  { background: #555; color: #ddd; }
.scale-badge small { font-size: 0.55em; font-weight: 700; }

/* ---------- 各地域の震度情報（全画面） ---------- */
.quake-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; grid-template-columns: 1fr minmax(300px, 22vw);
  background: #111;
}
.q-map-wrap { position: relative; }
.q-map { position: absolute; inset: 0; background: #141414; }
.q-header {
  position: absolute; top: 16px; left: 0; z-index: 500;
  background: rgba(30,30,30,0.92); padding: 14px 28px 12px;
}
.q-title { font-size: clamp(28px, 3.6vw, 56px); font-weight: 800; letter-spacing: 0.04em; line-height: 1.1; }
.q-title-en { font-size: clamp(14px, 1.5vw, 24px); }
.q-issued {
  position: absolute; top: calc(16px + clamp(28px,3.6vw,56px)*1.1 + clamp(14px,1.5vw,24px)*1.4 + 40px); left: 28px; z-index: 500;
  font-size: clamp(14px, 1.5vw, 24px); text-shadow: 0 0 6px #000;
}
.q-side {
  background: #111; padding: 32px 20px; display: flex; flex-direction: column; gap: 28px;
  overflow-y: auto;
}
.q-item {
  border-left: 6px solid var(--accent); padding-left: 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}
.q-label { font-size: 24px; font-weight: 700; line-height: 1.2; }
.q-label small { display: block; font-size: 14px; font-weight: 400; }
.q-value { font-size: 26px; font-weight: 700; text-align: right; margin-left: auto; line-height: 1.2; }
.q-value.big { font-size: 64px; }
.q-value.warn { color: #ff5a5a; }
.q-close { margin-top: auto; }

/* 緊急地震速報モード（現在地周辺） */
.quake-overlay.eew .q-header { background: var(--danger); animation: eew-flash 1s steps(2, start) infinite; }
.quake-overlay.eew .q-item { border-left-color: var(--danger); }
.q-here .q-value { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.q-countdown { font-size: 56px; font-weight: 900; color: #ff5a5a; font-variant-numeric: tabular-nums; line-height: 1; }
.q-countdown small { font-size: 0.4em; }
.q-countdown.done { font-size: 26px; }
.q-here-scale { font-size: 18px; font-weight: 700; }
.map-here {
  width: 18px; height: 18px; border-radius: 50%; background: #2f8cff; border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(47,140,255,0.7); animation: here-pulse 2s infinite;
}
.map-here-label { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 0 4px #000, 0 0 2px #000; }
@keyframes here-pulse { 70% { box-shadow: 0 0 0 16px rgba(47,140,255,0); } 100% { box-shadow: 0 0 0 0 rgba(47,140,255,0); } }
@media (prefers-reduced-motion: reduce) { .map-here, .eew-banner, .quake-overlay.eew .q-header { animation: none; } }

.map-scale {
  width: 34px; height: 34px; font-size: 24px; border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.map-scale.small { width: 26px; height: 26px; font-size: 17px; }
.map-epicenter { display: block; filter: drop-shadow(0 0 4px rgba(0,0,0,0.7)); }
.map-tiles-land { filter: url(#map-land); }
.map-tiles-lines { filter: url(#map-lines); mix-blend-mode: lighten; }
.leaflet-div-icon { background: transparent; border: 0; }
.leaflet-container { background: #141414; font-family: var(--font); }

/* ---------- 緊急地震速報 ---------- */
.eew-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
  background: var(--danger); color: #fff; padding: 16px 64px 16px 24px;
  animation: eew-flash 1s steps(2, start) infinite;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
}
.eew-banner.forecast { background: #c26a00; animation: none; }
.eew-title { font-size: clamp(28px, 4vw, 52px); font-weight: 900; }
.eew-body { font-size: clamp(18px, 2.2vw, 30px); font-weight: 700; margin-top: 4px; }
.eew-areas { font-size: clamp(14px, 1.6vw, 20px); margin-top: 6px; }
.eew-close { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,0.3); border: 0; font-size: 24px; }
@keyframes eew-flash { 50% { background: #a10f15; } }

/* ---------- 設定 ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid #444; border-radius: 16px;
  padding: 24px; width: min(440px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.settings-form h2 { margin: 0 0 4px; }
.settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.settings-form label.check { flex-direction: row; align-items: center; color: var(--text); }
.settings-form .row { display: flex; gap: 12px; }
.settings-form .row label { flex: 1; }
.settings-form input, .settings-form select {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid #444;
  border-radius: 8px; padding: 8px;
}
.settings-form menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 8px 0 0; }
.settings-form .primary { background: var(--accent); color: #111; border: 0; }

/* ---------- 縦長・スマホ ---------- */
@media (max-width: 820px), (orientation: portrait) {
  body { overflow: auto; }
  .home { grid-template-columns: 1fr; grid-template-rows: auto; height: auto; }
  .clock-panel, .weather-panel, .quake-panel { grid-column: 1; grid-row: auto; }
  .toolbar { flex-wrap: wrap; height: auto; padding: 8px 16px 16px; }
  .quake-overlay { grid-template-columns: 1fr; grid-template-rows: 60vh auto; overflow-y: auto; }
  .q-side { gap: 16px; padding: 16px; }
  .q-value.big { font-size: 44px; }
}
