:root {
  --bg: #2b2e32;
  --surface: #36393e;
  --surface-2: #42464c;
  --line: #4d5258;
  --text: #f1f1ef;
  --muted: #a9adb2;
  --home-light: #686a6c;
  --home-mid: #5e6062;
  --home-dark: #47494b;
  --sun: #f4b860;
  --sun-deep: #e8743b;
  --tide: #6cc3d5;
  --moon: #a9c8ff;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #1e2023;
  color: var(--text);
  font: 15px/1.4 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  position: relative;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}
@media (min-width: 520px) {
  #app { height: min(100dvh, 920px); margin-top: max(0px, calc((100dvh - 920px) / 2)); border-radius: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
}

.screen { position: absolute; inset: 0; }

/* ===== Accueil ===== */
.home { background: var(--home-light); }
.tri {
  position: absolute; inset: 0;
  border: 0; padding: 0; margin: 0;
  background: var(--home-dark);
  transition: filter .2s;
}
.tri:hover, .tri:focus-visible { filter: brightness(1.15); outline: none; }
.tri:active { filter: brightness(1.3); }
.tri-nd     { clip-path: polygon(0 0, 100% 27%, 0 51%); }
.tri-soleil { clip-path: polygon(100% 27%, 0 51%, 100% 74%); background: var(--home-mid); }
.tri-marees { clip-path: polygon(0 51%, 100% 74%, 0 100%); }
.tri-label {
  position: absolute;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-weight: 500; font-size: 17px;
}
.tri-label .ico { width: 62px; height: 62px; fill: #fff; }
.tri-soleil .ico { width: 78px; }
.home-corner {
  position: absolute; right: 18px; bottom: 18px;
  text-align: right; font-size: 12px; color: rgba(255,255,255,.65);
  pointer-events: none;
}
.home-brand {
  position: absolute; right: 18px; top: calc(env(safe-area-inset-top) + 18px);
  font-weight: 700; font-size: 15px; letter-spacing: .04em; color: rgba(255,255,255,.85);
  pointer-events: none;
}
.chip.install-btn {
  position: absolute; right: 16px; top: calc(env(safe-area-inset-top) + 48px);
  background: var(--sun); color: #222;
}
.home-corner b { display: block; font-size: 14px; color: #fff; font-weight: 500; }

/* ===== Écran principal ===== */
.main { display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); }

.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 10px) 10px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  display: inline-grid; place-items: center;
  min-width: 36px; height: 36px; padding: 0 6px;
  border: 0; border-radius: 10px; background: transparent;
  font-size: 22px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.big { min-width: 48px; height: 48px; font-size: 26px; background: var(--surface-2); }
.ico-s { width: 18px; height: 18px; fill: currentColor; flex: none; }
.spot-btn {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 10px;
  border: 0; border-radius: 10px; background: var(--surface-2);
  text-align: left;
}
.spot-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-ctl { display: flex; align-items: center; flex: none; }
.date-ctl .icon-btn { min-width: 28px; padding: 0; }
.date-ctl input {
  width: 112px; height: 36px; padding: 0 4px;
  border: 0; border-radius: 10px; background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 14px; text-align: center;
}

.content { overflow-y: auto; overscroll-behavior: contain; }
.panel { padding: 12px 14px 28px; }

.tabbar {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--home-dark);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  height: 60px; border: 0; background: transparent;
  display: grid; place-items: center;
  transition: background .2s;
}
.tabbar button.active { background: var(--home-light); }
.ico-tab { width: 36px; height: 36px; fill: #fff; }

/* ===== Éléments communs ===== */
.h { font-size: 13px; font-weight: 500; text-transform: none; color: var(--muted); margin: 22px 2px 8px; letter-spacing: .02em; }
.hint, .note { color: var(--muted); font-size: 12.5px; margin: 8px 2px; }
.note a { color: var(--tide); }
.chip {
  border: 0; border-radius: 999px; padding: 7px 14px;
  background: var(--surface-2); font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { filter: brightness(1.15); }
.chip.accent { background: var(--sun); color: #222; }
.lbl { margin: 0 0 6px; color: var(--muted); font-size: 12.5px; }

.timebar {
  background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px 6px; margin-top: 12px;
}
.timebar-top { display: flex; justify-content: space-between; align-items: center; }
.time-out { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.time-range { width: 100%; accent-color: var(--sun); margin: 8px 0 4px; }

.readout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px;
}
.ro { background: var(--surface); border-radius: var(--radius); padding: 9px 12px; }
.ro-k { display: block; font-size: 12px; color: var(--muted); }
.ro-v { font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; }
.ro-sun .ro-v { color: var(--sun); }
.ro-tide .ro-v { color: var(--tide); }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list .row {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border: 0; background: transparent; text-align: left;
}
.list button.row:hover { background: var(--surface-2); }
.row .t { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 92px; }
.row .l { flex: 1; }
.row .x { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.row .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.list .empty { padding: 12px 14px; color: var(--muted); font-size: 13.5px; }
.moon-line { color: var(--muted); font-size: 13px; margin: 8px 2px 0; }

/* ===== Soleil ===== */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; }
#map { height: 44dvh; min-height: 260px; background: #222; }
.map-tools { position: absolute; top: 10px; right: 10px; z-index: 500; display: flex; gap: 6px; }
.map-tools .chip { background: rgba(30,32,35,.85); backdrop-filter: blur(4px); }
.map-legend {
  position: absolute; left: 8px; bottom: 8px; z-index: 500;
  display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 78%;
  background: rgba(30,32,35,.82); border-radius: 8px; padding: 5px 8px; font-size: 11px;
}
.lg { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.lg-rise { background: var(--sun); }
.lg-set { background: var(--sun-deep); }
.lg-now { background: #ffe066; height: 6px; }
.lg-moon { background: repeating-linear-gradient(90deg, var(--moon) 0 4px, transparent 4px 7px); }
.lg-night { background: #171c26; height: 10px; }
.lg-blue { background: #3a5f93; height: 10px; }
.lg-golden { background: #b9852f; height: 10px; }
.pin-icon { background: #fff; border: 4px solid var(--sun-deep); border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.leaflet-container { font: inherit; }

/* ===== Marées ===== */
.chart-card { background: var(--surface); border-radius: var(--radius); padding: 10px 6px 6px; margin-top: 10px; }
.chart-legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); padding: 0 8px 6px; }
.chart svg { display: block; width: 100%; touch-action: none; user-select: none; }
.chart-status { margin: 6px 8px 2px; font-size: 12.5px; color: var(--muted); }
.chart-status.err { color: #ff9b8a; }
.setting { display: flex; align-items: center; gap: 8px; margin: 10px 2px; font-size: 13.5px; color: var(--muted); }
.setting input { width: 64px; height: 32px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; text-align: center; }

/* ===== ND ===== */
.nd-card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.stepper output { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.nd-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.nd-grid button {
  height: 44px; border: 0; border-radius: 10px; background: var(--surface-2);
  font-weight: 500; font-size: 13px; line-height: 1.1;
}
.nd-grid button small { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; }
.nd-grid button.on { background: #fff; color: #222; }
.nd-grid button.on small { color: #555; }
.nd-result { text-align: center; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.nd-result output { font-size: 44px; font-weight: 700; color: var(--sun); display: block; line-height: 1.1; }
.nd-sub { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.nd-advice { margin: 0; font-size: 15px; text-align: center; }
.nd-advice b { color: var(--sun); }
.effects { display: flex; flex-wrap: wrap; gap: 6px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--surface); }
.nd-table { border-collapse: collapse; font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nd-table th, .nd-table td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--line); }
.nd-table thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 500; }
.nd-table tbody th { position: sticky; left: 0; background: var(--surface-2); font-weight: 700; }
.nd-table td { cursor: pointer; }
.nd-table .hl-row, .nd-table .hl-col { background: rgba(244,184,96,.12); }
.nd-table .hl { background: var(--sun); color: #222; font-weight: 700; }

/* ===== Dialogues ===== */
dialog {
  width: min(92vw, 420px); border: 0; border-radius: 18px; padding: 18px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 12px; font-weight: 500; }
.spot-opt {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 11px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left;
}
.spot-opt:hover, .spot-opt.on { background: var(--surface-2); }
.spot-opt.gps { color: var(--sun); font-weight: 500; }
#timer-dialog { text-align: center; }
#timer-out { display: block; font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0 14px; }
.timer-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-bottom: 18px; }
.timer-bar i { display: block; height: 100%; width: 0; background: var(--sun); }
