/*
 * style.css
 * ---------
 * レスポンシブ・アクセシブルなUI。3つのテーマ（ライト/ダーク/赤色ナイトモード）に対応。
 * 現地では暗所でスマホを使うため、赤色ナイトモードは暗順応を妨げないよう
 * 背景をほぼ黒、文字を低輝度の赤系のみで構成する（設計仕様 8章）。
 */

:root {
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --text: #1a2030;
  --text-muted: #5a6472;
  --border: #d8dee6;
  --accent: #2f6fed;
  --accent-contrast: #ffffff;
  --danger: #d3423e;
  --success: #2f9e5c;

  --band-civil: #6fa8dc;
  --band-nautical: #3d6ea5;
  --band-astro: #23335c;
  --band-window: #0c1230;
  --band-window-border: #ffd54a;
  --moon-overlay: rgba(255, 214, 102, 0.35);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-card: #131c2e;
  --text: #e7ecf5;
  --text-muted: #9aa7bd;
  --border: #263352;
  --accent: #5b9dff;
  --accent-contrast: #04101f;
  --band-civil: #4f7fb3;
  --band-nautical: #2c4d78;
  --band-astro: #16203b;
  --band-window: #060912;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0b1220;
    --bg-card: #131c2e;
    --text: #e7ecf5;
    --text-muted: #9aa7bd;
    --border: #263352;
    --accent: #5b9dff;
    --accent-contrast: #04101f;
    --band-civil: #4f7fb3;
    --band-nautical: #2c4d78;
    --band-astro: #16203b;
    --band-window: #060912;
  }
}

[data-theme="night"] {
  --bg: #000000;
  --bg-card: #0c0000;
  --text: #ff3b30;
  --text-muted: #8a1410;
  --border: #3a0908;
  --accent: #ff3b30;
  --accent-contrast: #000000;
  --danger: #ff6b60;
  --success: #ff3b30;
  --band-civil: #4a0d0a;
  --band-nautical: #380806;
  --band-astro: #260403;
  --band-window: #140100;
  --band-window-border: #ff3b30;
  --moon-overlay: rgba(255, 59, 48, 0.25);
}

* { box-sizing: border-box; }

/*
 * hidden属性の安全網。
 * 本来ブラウザ既定で [hidden] { display: none; } が効くはずだが、
 * .modal-overlay / .install-banner / .coord-fields のように同じ詳細度で
 * display:flex 等を指定しているクラスと組み合わせると、後発の作者スタイルが
 * UA既定スタイルより優先されるため hidden属性のトグルが画面に反映されなくなる。
 * !important で確実にhidden属性側を勝たせ、このクラスのバグを一括で防ぐ。
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 8px 16px;
  z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.app-title { font-size: 1.15rem; margin: 0; color: var(--text); text-decoration: none; font-weight: 700; }
.page-h1 { font-size: 1.3rem; margin: 4px 0 14px; }
.header-controls { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge-online { color: var(--success); border-color: var(--success); }
.badge-offline { color: var(--danger); border-color: var(--danger); }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 36px; height: 36px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
}

main { max-width: 760px; margin: 0 auto; padding: 12px 12px 60px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }

/* ---- オフライン動作の訴求バナー ---- */
.offline-highlight {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin: 14px 0;
  padding: 18px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--band-astro) 100%);
  color: var(--accent-contrast);
}
[data-theme="night"] .offline-highlight { background: #1a0302; color: var(--text); }
.offline-highlight-icon { font-size: 1.8rem; line-height: 1; }
.offline-highlight-main { font-size: 1.15rem; font-weight: 800; margin: 0 0 6px; }
.offline-highlight-sub { font-size: 0.9rem; margin: 0; opacity: 0.95; line-height: 1.6; }

/* ---- ホーム画面追加バナー ---- */
.install-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--accent);
  background: var(--bg-card);
}
.install-banner-text strong { display: block; margin-bottom: 4px; font-size: 1rem; }
.install-banner-text p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.install-banner-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.install-ios-note {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: var(--bg-card);
}

.about-card p { font-size: 0.9rem; }

.breadcrumb { font-size: 0.78rem; color: var(--text-muted); margin: 10px 0; }
.breadcrumb a { color: var(--text-muted); }

.spot-intro p { font-size: 0.92rem; }
.spot-meta-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.85rem; }
.spot-meta-table th, .spot-meta-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); }
.spot-meta-table th { width: 30%; color: var(--text-muted); font-weight: 500; }
.spot-notes { font-size: 0.82rem; color: var(--text-muted); background: rgba(255, 213, 74, 0.1); padding: 8px 10px; border-radius: 8px; }

.spots-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 10px; }
.spot-list-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--bg); }
.spot-list-card h3 { margin: 0 0 4px; font-size: 1rem; }
.spot-list-card h3 a { color: var(--text); text-decoration: none; }
.spot-list-card h3 a:hover { color: var(--accent); }
.spot-list-card p { margin: 0; font-size: 0.82rem; color: var(--text-muted); }
.spot-list-pref { font-size: 0.75rem; color: var(--accent); margin-bottom: 6px; display: block; }

.footer-nav { display: flex; justify-content: center; gap: 16px; margin-bottom: 8px; }
.footer-nav a { color: var(--accent); text-decoration: none; }
.footer-nav a:hover { text-decoration: underline; }

.widget-card { border-color: var(--accent); }
.widget-subtitle { color: var(--text-muted); margin-top: -8px; }

.countdown-text {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  padding: 10px 0;
}
.countdown-before { color: var(--text-muted); }
.countdown-during { color: var(--success); }
.countdown-after { color: var(--text-muted); }

/* ---- タイムライン ---- */
.timeline {
  position: relative;
  margin: 10px 0 6px;
}
.tl-hover-area {
  position: relative;
  cursor: crosshair;
}
.tl-bands {
  display: flex;
  width: 100%;
  height: 34px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.tl-seg { height: 100%; }
.tl-seg-civil-dusk, .tl-seg-civil-dawn { background: var(--band-civil); }
.tl-seg-nautical-dusk, .tl-seg-nautical-dawn { background: var(--band-nautical); }
.tl-seg-astro-dusk, .tl-seg-astro-dawn { background: var(--band-astro); }
.tl-seg-astro-window {
  background: var(--band-window);
  box-shadow: inset 0 0 0 2px var(--band-window-border);
}

.tl-moon-layer {
  position: relative;
  height: 8px;
  margin-top: 3px;
}
.tl-moon-visible {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--moon-overlay);
  border-radius: 4px;
}

.tl-now-marker {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 40px;
  background: var(--accent);
}
.tl-now-marker::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -3px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.tl-hover-tooltip {
  position: absolute;
  bottom: 100%;
  margin-bottom: 8px;
  left: 0;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  z-index: 5;
}
.tl-hover-tooltip strong { display: block; font-size: 0.95rem; }
.tl-hover-sub { display: block; color: var(--text-muted); font-size: 0.72rem; margin-top: 1px; }

.tl-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 8px 0;
}
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-civil-dusk { background: var(--band-civil); }
.legend-nautical-dusk { background: var(--band-nautical); }
.legend-astro-dusk { background: var(--band-astro); }
.legend-astro-window { background: var(--band-window); box-shadow: inset 0 0 0 2px var(--band-window-border); }
.legend-moon { background: var(--moon-overlay); }

.astro-window-summary {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.moon-info {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  margin-top: 6px;
}
.moon-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 0.92rem; }
.moon-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 8px; }

.widget-actions { margin-top: 12px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ---- ？ヘルプボタン ---- */
.btn-help {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}
.btn-help:hover, .btn-help:focus-visible { color: var(--accent); border-color: var(--accent); }

/* ---- モーダル（.ics説明ポップアップ） ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}
.modal-box {
  position: relative;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 20px 20px;
  max-width: 440px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.modal-box h2 { margin: 0 0 12px; font-size: 1.05rem; }
.modal-box p { font-size: 0.88rem; margin: 0 0 10px; line-height: 1.6; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.modal-ok { display: block; margin: 14px auto 0; }

/* ---- タブ ---- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab-btn {
  flex: 1 1 auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.tab-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.tab-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-note { color: var(--text-muted); font-size: 0.85rem; margin-top: 0; }

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}
.field-row label { font-size: 0.85rem; color: var(--text-muted); }

input, select, button {
  font-family: inherit;
  font-size: 0.95rem;
}

input[type="text"], input[type="number"], input[type="date"], select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
}

.coord-fields { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0; }
.coord-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-muted); flex: 1 1 160px; }
.coord-fields fieldset { border: 1px solid var(--border); border-radius: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.coord-fields fieldset input { width: 70px; }

button {
  cursor: pointer;
  border-radius: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-secondary { background: var(--bg); border-color: var(--border); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }

.file-input-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.file-input-label input[type="file"] { display: none; }

.status-text { font-size: 0.82rem; color: var(--text-muted); }
.status-error { color: var(--danger); }

.current-location-box {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.timezone-row { margin-top: 8px; }

.map-container { height: 280px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }

.notice {
  background: rgba(211, 66, 62, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.results-table { width: 100%; border-collapse: collapse; }
.results-table th, .results-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 0.9rem; font-weight: normal; }
.results-table td { text-align: right; font-variant-numeric: tabular-nums; }
.row-highlight th, .row-highlight td { color: var(--accent); font-weight: 600; }
.row-total th, .row-total td { font-weight: 700; font-size: 1.05rem; border-bottom: none; padding-top: 12px; }

.compare-table-wrap { overflow-x: auto; }
.compare-table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
.compare-table th, .compare-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: center; white-space: nowrap; }
.compare-table thead th { background: var(--bg); }
.compare-dur { font-weight: 600; }
.compare-moon { color: var(--text-muted); font-size: 0.75rem; }
.compare-na { color: var(--text-muted); }
.compare-newmoon { background: rgba(255, 213, 74, 0.15); }

.preset-save-details, .preset-io-details { margin-top: 10px; font-size: 0.88rem; }
.preset-save-details summary, .preset-io-details summary { cursor: pointer; color: var(--accent); }

.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 30px;
  padding: 16px 8px;
}
.version-note { margin-top: 4px; }

@media (max-width: 480px) {
  .app-title { font-size: 1rem; }
  .field-row { flex-direction: column; align-items: stretch; }
  .coord-fields fieldset input { width: 60px; }
  .install-banner { flex-direction: column; align-items: stretch; }
  .install-banner-actions { justify-content: flex-end; }
  .offline-highlight { flex-direction: column; }
}
