:root {
  --bg: #05070a;
  --panel: #0b0e12;
  --panel-head: #131820;
  --border: #1c232c;
  --led: #ffb02e;
  --text: #e9edf2;
  --muted: #8691a1;
  --soon: #ff5a4e;
  --dot: rgba(255, 255, 255, 0.035);
  --font: "BIZ UDPGothic", "BIZ UDGothic", "Yu Gothic UI", "Meiryo", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

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

html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ヘッダー ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #000;
  border-bottom: 2px solid #1a1f26;
}
.station { font-size: clamp(20px, 3vw, 36px); font-weight: 700; line-height: 1.15; min-width: 0; }
.station small { display: block; font-size: 0.42em; font-weight: 400; color: var(--muted); letter-spacing: 0.12em; }
.when { margin-left: auto; text-align: right; }
.clock {
  font-size: clamp(30px, 4.6vw, 60px);
  font-weight: 700;
  line-height: 1;
  color: var(--led);
  text-shadow: 0 0 10px rgba(255, 176, 46, 0.5);
}
.clock .sec { font-size: 0.55em; opacity: 0.85; }
.date { margin-top: 4px; color: var(--muted); font-size: clamp(12px, 1.2vw, 16px); }
.daytype { display: inline-block; padding: 1px 8px; margin-left: 4px; border: 1px solid currentColor; border-radius: 4px; }
.daytype[data-type="weekday"] { color: #9fd3ff; }
.daytype[data-type="saturday"] { color: #7fb2ff; }
.daytype[data-type="holiday"] { color: #ff8f8f; }
.tools { display: flex; flex-direction: column; gap: 6px; }
.tools button {
  width: 34px; height: 30px;
  border: 1px solid #2a323d; border-radius: 6px;
  background: #0e1217; color: var(--muted);
  font-size: 16px; cursor: pointer;
}
.tools button:hover { color: var(--text); border-color: #46505d; }
:fullscreen .tools { opacity: 0; }
:fullscreen .tools:hover { opacity: 1; }

/* ---------- 運行情報 ---------- */
:root { --op-normal: #3ddc84; --op-warn: #ffc23d; --op-alert: #ff5a4e; --op-unknown: #8691a1; }
.opstatus {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 6px 16px; background: #0a0d11; border-bottom: 1px solid #1a1f26;
  font-size: clamp(12px, 1vw, 15px);
}
.op-title { color: var(--muted); letter-spacing: 0.1em; font-size: 0.85em; }
.op-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; }
.op-item b { font-weight: 700; }
a.op-item:hover b { text-decoration: underline; }
.op-test {
  padding: 1px 8px; border-radius: 4px; background: #5b1d8f; color: #fff;
  font-size: 0.85em; font-weight: 700; animation: blink 2s steps(1) infinite;
}
.settings select {
  height: 34px; padding: 0 8px; max-width: 60%;
  border: 1px solid #2f3843; border-radius: 6px; background: #0b0e12; color: var(--text); font: inherit; font-size: 14px;
}
.op-time { margin-left: auto; color: var(--muted); font-size: 0.85em; }
.op-time-stale { color: var(--op-warn); }

.op-chip {
  display: inline-block; padding: 1px 7px; border-radius: 4px;
  border: 1px solid currentColor; font-size: 0.85em; font-weight: 700; white-space: nowrap; line-height: 1.4;
}
.op-normal { --op: var(--op-normal); }
.op-warn { --op: var(--op-warn); }
.op-alert { --op: var(--op-alert); }
.op-unknown { --op: var(--op-unknown); }
.op-item .op-chip, .panel-head .op-chip { color: var(--op); }
.op-alert .op-chip, .panel-head .op-chip.op-alert { background: rgba(255, 90, 78, 0.16); }
.op-warn .op-chip, .panel-head .op-chip.op-warn { background: rgba(255, 194, 61, 0.14); }
.op-stale .op-chip, .panel-head .op-chip.op-stale { opacity: 0.55; border-style: dashed; }

.panel-head .op-chip { margin-left: auto; align-self: center; font-size: clamp(11px, 2.7cqi, 14px); }
.panel-head .op-chip + .op-chip { margin-left: 0; }
.op-detail {
  padding: 5px 12px 6px 22px;
  font-size: clamp(12px, 2.9cqi, 15px); line-height: 1.45;
  color: var(--op); background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---------- エラー ---------- */
.errors { padding: 8px 16px; background: #3a0d0d; color: #ffd0d0; font-size: 14px; border-bottom: 1px solid #6b1a1a; }
.errors li { margin-left: 1.2em; }

/* ---------- 掲示板 ---------- */
.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 12px;
  padding: 12px 16px;
  align-content: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  container-type: inline-size;
}
.panel-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel-head);
  border-left: 10px solid var(--line-color, #888);
}
.line-name { font-weight: 700; font-size: clamp(16px, 4.2cqi, 24px); white-space: nowrap; }
.dir { flex: 1; font-size: clamp(14px, 3.5cqi, 20px); white-space: nowrap; overflow: hidden; min-width: 0; }
.rev { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
@container (max-width: 470px) { .rev { display: none; } }

.rows {
  padding: 2px 0 4px;
  background-image: radial-gradient(var(--dot) 1px, transparent 1.3px);
  background-size: 4px 4px;
}
.row {
  display: grid;
  grid-template-columns: 3.1em 3.3em minmax(0, 1fr) 2.2em 4.4em;
  align-items: center;
  gap: 8px;
  min-height: 2.1em;
  padding: 4px 12px;
  font-size: clamp(15px, 4.4cqi, 28px);
  font-weight: 700;
  color: var(--led);
  text-shadow: 0 0 6px rgba(255, 176, 46, 0.45);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.row:last-child { border-bottom: 0; }
.no-plat .row { grid-template-columns: 3.1em 3.3em minmax(0, 1fr) 4.4em; }
.row.label {
  min-height: 0;
  padding: 4px 12px 2px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  text-shadow: none;
  letter-spacing: 0.1em;
}
.row.label > span { white-space: nowrap; }
.row.first { background: rgba(255, 176, 46, 0.045); }
.type { white-space: nowrap; overflow: hidden; text-shadow: 0 0 6px currentColor; }
.time { text-align: right; }
.dest { display: flex; flex-direction: column; justify-content: center; min-width: 0; line-height: 1.15; }
.dest .dn, .dest .note { white-space: nowrap; overflow: hidden; }
.fit { display: inline-block; white-space: nowrap; transform-origin: left center; }
.note { font-size: 0.55em; font-weight: 400; color: #ffd690; }
.plat { text-align: center; }
.label .plat, .label .status, .label .time { text-align: center; }
.status { text-align: right; font-size: 0.72em; white-space: nowrap; }
.status.soon { color: var(--soon); text-shadow: 0 0 6px rgba(255, 90, 78, 0.5); }
.status.dep { color: var(--soon); animation: blink 1s steps(1) infinite; }
.status.tomorrow { color: var(--muted); text-shadow: none; }
.row.departed { opacity: 0.55; }
.row.message { grid-template-columns: 1fr; color: var(--muted); text-shadow: none; font-weight: 400; font-size: clamp(13px, 3.2cqi, 20px); min-height: 0; }

@keyframes blink { 50% { opacity: 0; } }

.fatal { grid-column: 1 / -1; padding: 24px; border: 1px dashed #4a2a2a; border-radius: 8px; color: #ffcfcf; line-height: 1.7; }
.fatal code { background: #1a1a1a; padding: 1px 6px; border-radius: 4px; }

/* ---------- フッター ---------- */
.footer { background: #000; border-top: 2px solid #1a1f26; padding-bottom: env(safe-area-inset-bottom); }
.ticker { overflow: hidden; white-space: nowrap; color: var(--led); font-size: clamp(15px, 1.5vw, 22px); padding: 6px 0; border-bottom: 1px solid #12161b; text-shadow: 0 0 6px rgba(255, 176, 46, 0.45); }
.ticker span { display: inline-block; padding-left: 100%; animation: marquee linear infinite; }
@keyframes marquee { to { transform: translateX(-100%); } }
.meta { display: flex; gap: 16px; justify-content: flex-end; padding: 4px 16px; color: var(--muted); font-size: 12px; }
.meta .offline { color: #ffb4a8; }

/* ---------- 表示設定 ---------- */
.settings {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 20px;
  border: 1px solid #2a323d;
  border-radius: 10px;
  background: #10141a;
  color: var(--text);
  font-family: var(--font);
}
.settings::backdrop { background: rgba(0, 0, 0, 0.6); }
.settings h2 { font-size: 18px; margin-bottom: 14px; }
.settings h3 { font-size: 14px; margin: 18px 0 4px; }
.settings .hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; line-height: 1.5; }
.settings .hint.warn { color: #ffcf7a; }
.settings button {
  min-width: 36px; height: 34px; padding: 0 10px;
  border: 1px solid #2f3843; border-radius: 6px;
  background: #171c23; color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer;
}
.settings button:hover:not(:disabled) { border-color: #4a5563; }
.settings button:disabled { opacity: 0.3; cursor: default; }
.settings button:focus-visible, .settings input:focus-visible { outline: 2px solid var(--led); outline-offset: 1px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.stepper { display: flex; gap: 4px; }
.stepper input {
  width: 56px; height: 34px; text-align: center;
  border: 1px solid #2f3843; border-radius: 6px;
  background: #0b0e12; color: var(--led); font: inherit; font-size: 18px; font-weight: 700;
}
.line-list { list-style: none; border: 1px solid #222a33; border-radius: 8px; overflow: hidden; }
.line-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid #1c232b; }
.line-list li:last-child { border-bottom: 0; }
.line-list li.empty { color: var(--muted); font-size: 13px; }
.line-list label { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.line-list input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--led); flex: none; }
.line-list .chip { width: 6px; height: 28px; border-radius: 2px; flex: none; }
.line-list .nm { min-width: 0; font-size: 14px; font-weight: 700; }
.line-list .nm small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line-list li:has(input:not(:checked)) .nm { opacity: 0.45; }
.line-list .mv { display: flex; gap: 4px; flex: none; }
.actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.actions .primary { background: var(--led); border-color: var(--led); color: #1a1200; font-weight: 700; }

/* ---------- スマートフォン ---------- */
@media (max-width: 520px) {
  .topbar { gap: 10px; }
  .clock { font-size: 30px; }
  .tools button { width: 30px; height: 26px; font-size: 14px; }
  .tools button#btn-fullscreen { display: none; }
  .meta { flex-wrap: wrap; gap: 4px 12px; }
  .board { padding: 10px 16px; gap: 10px; }
  .row { gap: 6px; padding: 4px 10px; }
  .rev { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ticker span { animation-duration: 0s !important; padding-left: 16px; }
  .status.dep { animation: none; }
}
