:root {
  --bg: #eef3f7;
  --card: #ffffff;
  --text: #13202e;
  --muted: #5d6b7a;
  --line: #d5dee7;
  --accent: #1673c9;
  --tide: #1d7fd6;
  --tide-fill: rgba(29, 127, 214, 0.16);
  --night: rgba(20, 40, 80, 0.08);
  --best: rgba(250, 170, 40, 0.22);
  --now: #e0423a;
  --hi: #1d7fd6;
  --lo: #2b9a6a;
  --wind1: #3a9d5d;
  --wind2: #c79a12;
  --wind3: #e06b1f;
  --wind4: #d0302a;
  --on: #e8875a;
  --off: #5b8fd6;
  --neutral: #a7b3bf;
  --eq-short: #8a52c9;
  --eq-long: #d0302a;
  --eq-off: #2d63b8;
  --wave: #138a8a;
  --swell: #6b7c8f;
  --sel: rgba(22, 115, 201, 0.08);
  --fish: #8fa3b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1623;
    --card: #13212f;
    --text: #e4ecf3;
    --muted: #8fa1b3;
    --line: #26394c;
    --accent: #5cb0ff;
    --tide: #4fa8ff;
    --tide-fill: rgba(79, 168, 255, 0.18);
    --night: rgba(0, 0, 0, 0.28);
    --best: rgba(250, 170, 40, 0.2);
    --now: #ff6a5f;
    --hi: #4fa8ff;
    --lo: #4cc68e;
    --wind1: #5cc480;
    --wind2: #e3bd3a;
    --wind3: #ff8a3d;
    --wind4: #ff5a50;
    --on: #ff9b6b;
    --off: #6fa4ef;
    --neutral: #50647a;
    --eq-short: #b98cf0;
    --eq-long: #ff6a5f;
    --eq-off: #77b3ff;
    --wave: #3cc9c9;
    --swell: #93a4b8;
    --sel: rgba(92, 176, 255, 0.1);
    --fish: #c9d6e3;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
h2 { font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.station-btn { flex: 1; text-align: left; font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; }
.station-btn span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--muted); font-size: 14px; }
.icon-btn { min-width: 40px; height: 40px; border-radius: 10px; font-size: 22px; display: grid; place-items: center; }
.icon-btn:active, .pill:active { background: var(--sel); }
#favBtn.on { color: #f0b400; }
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; background: var(--card); }
.pill.wide { width: 100%; margin: 8px 0; padding: 10px; }

.datebar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; }
.date-main { flex: 1; position: relative; text-align: center; padding: 4px; border-radius: 10px; cursor: pointer; }
.date-main span { display: block; font-size: 17px; font-weight: 700; }
.date-main small { color: var(--muted); font-size: 12px; }
.date-main input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.tabs { display: flex; margin: 0 12px; background: var(--card); border-radius: 12px; padding: 4px; border: 1px solid var(--line); }
.tabs button { flex: 1; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--accent); color: #fff; }

main { padding: 10px 12px 24px; max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border-radius: 14px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--line); }

/* サマリー */
.summary { display: flex; gap: 12px; align-items: center; }
.score-badge {
  width: 64px; height: 64px; flex: none; border-radius: 16px; display: grid; place-items: center;
  font-size: 26px; font-weight: 800; color: #fff; background: var(--neutral); text-shadow: 0 1px 2px rgba(0,0,0,.35);
  position: relative;
}
.score-badge::after { content: '期待度'; position: absolute; bottom: 3px; font-size: 9px; font-weight: 600; }
.summary-body { min-width: 0; }
.summary-row { font-size: 13.5px; }
.summary-row b { font-size: 15px; }

/* チャート */
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; user-select: none; }
.chart text { font-size: 9px; fill: var(--muted); }
.chart .ylab { text-anchor: end; }
.chart .xlab { text-anchor: middle; }
.chart .exlab { font-size: 9.5px; fill: var(--text); font-weight: 600; }
.chart .wslab, .chart .wvlab, .chart .wxicon { text-anchor: middle; font-size: 10px; font-weight: 700; }
.chart .wvlab { fill: var(--wave); }
.chart .wxicon { font-size: 11px; fill: var(--muted); }
.chart .daylab { font-size: 9px; }
.grid { stroke: var(--line); stroke-width: 0.6; }
.night { fill: var(--night); }
.best { fill: var(--best); }
.tide-area { fill: var(--tide-fill); }
.tide-line { fill: none; stroke: var(--tide); stroke-width: 2; }
.fish { fill: var(--fish); }
.fish.hot { fill: #f5b700; }
.fish-eye { fill: var(--card); }
.fish-ic { color: #f5b700; letter-spacing: -2px; white-space: nowrap; }
.hi-dot { fill: var(--hi); }
.lo-dot { fill: var(--lo); }
.now { stroke: var(--now); stroke-width: 1.2; stroke-dasharray: 3 2; }
.cur-line { stroke: var(--text); stroke-width: 1; opacity: .7; }
.cur-dot { fill: var(--card); stroke: var(--text); stroke-width: 1.5; }
.sel-day { fill: var(--sel); }
.bar-on { fill: var(--on); }
.bar-off { fill: var(--off); }
.bar-n { fill: var(--neutral); }
.eq-short, .eq-long, .eq-off, .wave-line, .swell-line { fill: none; stroke-width: 1.8; }
.eq-short { stroke: var(--eq-short); }
.eq-long { stroke: var(--eq-long); }
.eq-off { stroke: var(--eq-off); stroke-dasharray: 4 2; }
.wave-line { stroke: var(--wave); }
.per-line { fill: none; stroke: var(--text); stroke-width: 1.8; }
.pow-line { fill: none; stroke: var(--eq-short); stroke-width: 1.8; }
.lg.ln.pow-line { border-color: var(--eq-short); }
.per-good { fill: rgba(58, 157, 93, 0.16); }
.per-bad { fill: rgba(208, 48, 42, 0.16); }
.swell-line { stroke: var(--swell); stroke-dasharray: 3 2; }

.cursor-info { font-size: 13px; min-height: 2.9em; padding: 2px 2px 6px; color: var(--muted); }
.cursor-info b { color: var(--text); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.lg { display: inline-block; width: 12px; height: 10px; border-radius: 2px; }
.lg.best { background: var(--best); outline: 1px solid rgba(250,170,40,.6); }
.lg.night { background: var(--night); outline: 1px solid var(--line); }
.lg.grad { width: 40px; background: linear-gradient(90deg, rgb(70,90,120), rgb(60,140,190), rgb(60,180,120), rgb(235,200,60), rgb(250,130,50)); }
.lg.bar-on { background: var(--on); } .lg.bar-off { background: var(--off); } .lg.bar-n { background: var(--neutral); }
.lg.ln { height: 0; border-top: 2.5px solid; border-radius: 0; width: 16px; }
.lg.ln.eq-short { border-color: var(--eq-short); } .lg.ln.eq-long { border-color: var(--eq-long); }
.lg.ln.eq-off { border-color: var(--eq-off); border-top-style: dashed; }
.lg.ln.per-line { border-color: var(--text); }
.lg.per-good { background: rgba(58, 157, 93, 0.35); } .lg.per-bad { background: rgba(208, 48, 42, 0.35); }
.period-cfg { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 14px; margin-top: 8px; }
.period-cfg input { width: 4.5em; font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; }
.lg.ln.wave-line { border-color: var(--wave); } .lg.ln.swell-line { border-color: var(--swell); border-top-style: dashed; }

/* 狙い目 */
.windows { list-style: none; margin: 0; padding: 0; }
.windows li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.windows li:first-child { border-top: 0; }
.windows .time { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; }
.windows .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.tag { font-size: 11.5px; border-radius: 6px; padding: 1px 6px; background: var(--sel); color: var(--accent); margin-right: 4px; white-space: nowrap; }
.link { color: var(--accent); font-size: 13px; margin-left: auto; font-weight: 600; }

/* 海況 */
.sea-setup { display: flex; gap: 12px; align-items: center; }
.compass { width: 110px; height: 110px; flex: none; cursor: pointer; touch-action: none; }
.compass-ring { fill: none; stroke: var(--line); stroke-width: 1.5; }
.compass-lab { font-size: 9px; fill: var(--muted); text-anchor: middle; }
.compass-lab.sea { fill: var(--accent); font-weight: 700; font-size: 10px; }
.compass-sea { fill: rgba(29, 127, 214, 0.18); }
.compass-wind { fill: var(--eq-long); opacity: .85; }
/* iPhone は16px未満の入力欄をタップすると画面が拡大されるため16pxに */
select { font: inherit; font-size: 16px; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.gauges { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.gauge { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.gauge .g-title { font-size: 12px; color: var(--muted); }
.gauge .g-val { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.gauge .g-val small { font-size: 12px; font-weight: 600; color: var(--muted); }
.gauge .g-lv { font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 6px; display: inline-block; }
.lv1 { background: rgba(58,157,93,.18); color: var(--wind1); }
.lv2 { background: rgba(60,140,190,.18); color: var(--accent); }
.lv3 { background: rgba(199,154,18,.2); color: var(--wind2); }
.lv4 { background: rgba(224,107,31,.2); color: var(--wind3); }
.lv5 { background: rgba(208,48,42,.2); color: var(--wind4); }
.meter { height: 6px; border-radius: 3px; background: var(--line); margin-top: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; }
.notes { margin: 10px 0 0; padding-left: 18px; font-size: 13.5px; }
.notes li { margin: 3px 0; }
.sea-mini-row { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13.5px; align-items: center; }

/* カレンダー */
.month-head { display: flex; align-items: center; justify-content: space-between; }
.month-head h2 { margin: 0; font-size: 17px; }
.cal-week, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-week { font-size: 11px; text-align: center; color: var(--muted); margin: 8px 0 3px; }
.sun { color: #d0453c; } .sat { color: #2f6fc0; }
.cal-day {
  border-radius: 8px; padding: 3px 2px 4px; min-height: 64px; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 1px; border: 1.5px solid transparent; position: relative; overflow: hidden;
}
.cal-day .bar { position: absolute; left: 0; right: 0; top: 0; height: 100%; opacity: .2; }
.cal-day > *:not(.bar) { position: relative; }
.cal-day .d { font-weight: 700; font-size: 14px; }
.cal-day .s { font-size: 10.5px; font-weight: 700; border-radius: 4px; padding: 0 3px; color: #fff; }
.cal-day .t { font-size: 10px; color: var(--text); font-variant-numeric: tabular-nums; }
.cal-day .w { font-size: 10px; font-weight: 700; }
.cal-day .star { color: #f0b400; font-size: 11px; margin-left: 1px; }
.cal-day.sel { border-color: var(--accent); }
.cal-day.today .d { text-decoration: underline; }
.cal-day.empty { visibility: hidden; }
.shio-大潮 { background: #d0453c; } .shio-中潮 { background: #e08a2e; } .shio-小潮 { background: #5d8fbf; }
.shio-長潮 { background: #7d8a99; } .shio-若潮 { background: #4ea37a; }

/* 地点シート */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-panel {
  background: var(--card); width: 100%; max-width: 720px; height: 86vh; border-radius: 16px 16px 0 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column;
}
.sheet-head { display: flex; gap: 8px; }
.sheet-head input { flex: 1; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
.station-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.station-list li { display: flex; align-items: center; padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer; gap: 8px; }
.station-list li:active { background: var(--sel); }
.station-list .sec { font-size: 12px; color: var(--muted); padding: 10px 6px 4px; cursor: default; font-weight: 700; }
.station-list .dist { margin-left: auto; font-size: 12px; color: var(--muted); }
.station-list .code { font-size: 11px; color: var(--muted); }

.sheet-actions { display: flex; gap: 8px; margin: 8px 0; }
.sheet-actions .pill { flex: 1; padding: 10px 6px; }
.station-list .edit { margin-left: auto; font-size: 12px; color: var(--accent); padding: 4px 8px; }
.station-list .spot-sub { font-size: 11px; color: var(--muted); }
.spot-form { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.spot-form[hidden] { display: none; }
.spot-form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 2px; }
.spot-form input:not([type=range]), .spot-form select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0;
}
.spot-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.spot-form b { color: var(--text); }
.form-btns { display: flex; gap: 8px; margin-top: 6px; }
.form-btns .pill { flex: 1; padding: 10px; }
.pill.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.pill.danger { color: var(--wind4); }

.help ul, .help ol { margin: 4px 0; padding-left: 20px; font-size: 14px; }
.help li { margin: 5px 0; }
.help p { margin: 6px 0; }
.tips { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.tips summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.tips ul { margin: 6px 0; padding-left: 18px; }
.tips li { margin: 3px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #233446; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 90vw; }
.toast[hidden] { display: none; }
