:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #38bdf8;
  --accent-2: #0369a1;
  --ok: #22c55e;
  --lv1: #38bdf8;
  --lv2: #facc15;
  --lv3: #f97316;
  --lv4: #c026d3;
  --lv5: #111827;
  --danger: #ef4444;
  --radius: 14px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.topbar { position: sticky; top: 0; z-index: 10; background: rgba(15,23,42,0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 720px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.logo { color: var(--accent); }
.topbar-meta { display: flex; align-items: center; gap: 8px; }
.obs-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }
.icon-btn { background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 50%; width: 34px; height: 34px;
  font-size: 1.1rem; cursor: pointer; line-height: 1; }
.icon-btn.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.container { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(30px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.notify-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notify-title { font-weight: 700; }
.notify-actions { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.hint { margin-top: 10px; background: var(--card-2); border-radius: 10px; padding: 10px 12px; font-size: 0.85rem; color: var(--muted); }

.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #475569; border-radius: 30px; transition: 0.2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }

.label { display: block; font-weight: 700; margin-bottom: 8px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 0.95rem; }
.add-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn { background: var(--accent-2); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; cursor: pointer; font-size: 0.95rem; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: transparent; border: 1px solid var(--line); color: #fca5a5; }
.btn.small { padding: 6px 10px; font-size: 0.8rem; }
.error { margin-top: 8px; color: #fca5a5; font-size: 0.85rem; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.stations { display: flex; flex-direction: column; gap: 12px; }
.station { padding: 0; overflow: hidden; border-left: 6px solid var(--line); }
.station-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 12px 14px 0; }
.station-name { font-size: 1.1rem; margin: 0; }
.station-sub { margin-top: 2px; }
.badge { flex: none; font-size: 0.75rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.station-body { padding: 10px 14px 6px; }
.reading { display: flex; justify-content: space-between; align-items: baseline; }
.reading-main { display: flex; align-items: baseline; gap: 4px; }
.stg { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.unit { color: var(--muted); }
.trend { margin-left: 6px; font-size: 1rem; color: var(--muted); }
.trend.up { color: var(--danger); }
.trend.down { color: var(--accent); }

.gauge { position: relative; height: 34px; margin: 10px 0 4px; }
.gauge-track { position: absolute; left: 0; right: 0; top: 14px; height: 8px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
.gauge-fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #0ea5e9, #38bdf8); border-radius: 4px; }
.gauge-ticks { position: absolute; inset: 0; }
.tick { position: absolute; top: 8px; width: 2px; height: 20px; background: var(--muted); transform: translateX(-1px); }
.tick.lv1 { background: var(--lv1); } .tick.lv2 { background: var(--lv2); } .tick.lv3 { background: var(--lv3); } .tick.lv4 { background: var(--lv4); } .tick.lv6 { background: #6b7280; }
.tick span { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-size: 0.6rem; color: var(--muted); white-space: nowrap; }
.gauge-now { position: absolute; top: 6px; width: 12px; height: 24px; border-radius: 6px; background: #fff; border: 2px solid var(--bg); transform: translateX(-6px); box-shadow: 0 0 0 2px var(--accent); }
.gauge-now.missing { display: none; }

.levels { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; font-size: 0.78rem; }
.levels li { display: flex; justify-content: space-between; color: var(--muted); }
.levels li b { color: var(--text); font-variant-numeric: tabular-nums; }
.levels li.crossed { color: var(--text); }
.levels li.crossed::before { content: "▲ "; color: var(--danger); }
.station-msg { margin-top: 8px; }

.station-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding: 8px 14px; background: rgba(0,0,0,0.12); }
.margin-label { color: var(--muted); display: flex; align-items: center; gap: 4px; }
.margin-input { width: 60px; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 6px; font-size: 0.85rem; }
.station-links { display: flex; align-items: center; gap: 10px; }
.link { font-size: 0.8rem; }

/* 状態カラー */
.station.s-normal { border-left-color: var(--ok); }
.station.s-normal .badge { background: rgba(34,197,94,0.15); color: #86efac; }
.station.s-lv1 { border-left-color: var(--lv1); }
.station.s-lv1 .badge { background: rgba(56,189,248,0.18); color: #7dd3fc; }
.station.s-lv2 { border-left-color: var(--lv2); }
.station.s-lv2 .badge { background: rgba(250,204,21,0.2); color: #fde047; }
.station.s-lv3, .station.s-approach { border-left-color: var(--lv3); }
.station.s-lv3 .badge, .station.s-approach .badge { background: rgba(249,115,22,0.22); color: #fdba74; }
.station.s-lv4 { border-left-color: var(--lv4); }
.station.s-lv4 .badge { background: rgba(192,38,211,0.25); color: #f0abfc; }
.station.s-lv6 { border-left-color: #000; }
.station.s-lv6 .badge { background: #000; color: #fff; }
.station.s-missing { border-left-color: var(--line); opacity: 0.85; }
.station.s-error { border-left-color: var(--danger); }
.station.highlight { outline: 2px solid var(--accent); }

.footer { margin-top: 10px; line-height: 1.5; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #0ea5e9; color: #052e3d;
  padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 0.9rem; box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 50; max-width: 90vw; }
.toast.err { background: #ef4444; color: #fff; }
