:root {
  --bg-a: #f6f1e6; --bg-b: #cfe0ea;
  --card: rgba(255, 255, 255, 0.82); --card-solid: #ffffff;
  --line: rgba(18, 58, 90, 0.12);
  --ink: #13283b; --ink-2: #5d6f80; --ink-3: #8b9aa8;
  --accent: #1f86b8; --accent-ink: #ffffff; --accent-soft: rgba(31, 134, 184, 0.12);
  --shadow: 0 10px 30px rgba(19, 40, 59, 0.13), 0 1px 3px rgba(19, 40, 59, 0.08);
  --sable: #efe0b4; --presale: #93ab62; --marais: #5f8b6c; --navline: #c2398f;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --halo: #fff;
  --blur: blur(14px) saturate(1.35);
}
body.night {
  --bg-a: #11223a; --bg-b: #03070f;
  --card: rgba(12, 24, 40, 0.84); --card-solid: #0f1d2f;
  --line: rgba(160, 200, 230, 0.14);
  --ink: #e5eef6; --ink-2: #9db1c4; --ink-3: #6f8498;
  --accent: #5ec2e4; --accent-ink: #04202f; --accent-soft: rgba(94, 194, 228, 0.15);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { color: var(--ink); font: 13px/1.4 var(--sans); background: radial-gradient(130% 100% at 50% 20%, var(--bg-a), var(--bg-b)); transition: background .6s;
  -webkit-font-smoothing: antialiased; }
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; outline: none; touch-action: none; }
a { color: var(--accent); }
button, select { font: inherit; color: inherit; }
svg { stroke-linecap: round; stroke-linejoin: round; }
.glass { background: var(--card); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--line); box-shadow: var(--shadow); }

/* ================= étiquettes ================= */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; white-space: nowrap; will-change: transform, opacity; opacity: 0; transition: opacity .3s;
  --h: var(--halo); text-shadow: 0 0 2px var(--h), 0 0 2px var(--h), 0 0 3px var(--h), 0 0 6px var(--h); }
.lbl.on { opacity: 1; }
body.dark-labels .lbl { --h: rgba(5, 14, 26, .9); }
.lbl.commune { font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: #13283b; }
.lbl.commune::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fff; border: 2.5px solid #13283b; margin-right: 6px; }
.lbl.water { font: italic 500 13.5px/1 var(--serif); letter-spacing: .04em; color: #1b5f8c; }
.lbl.water.small { font-size: 11.5px; font-weight: 400; letter-spacing: .02em; color: #2c78a6; }
.lbl.crassat { font: italic 400 11.5px/1 var(--serif); color: #7a5626; }
.lbl.crassat.big { font-size: 13px; font-weight: 500; }
.lbl.marais { font: italic 400 11.5px/1 var(--serif); color: #42662d; }
.lbl.place { font: 500 10.5px/1 var(--sans); color: #4b5966; }
.lbl.place.major { font-size: 11.5px; font-weight: 600; color: #2b3947; }
.lbl.landmark { font: italic 600 13px/1 var(--serif); color: #6b4a1c; letter-spacing: .02em; }
.lbl.port { font: 600 11px/1 var(--sans); color: #8d5600; pointer-events: auto; cursor: pointer; }
.lbl.port::before { content: "⚓"; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-right: 4px; border-radius: 50%;
  background: #f0a524; color: #fff; font-size: 10px; text-shadow: none; box-shadow: 0 0 0 1.5px #fff; vertical-align: -3px; }
.lbl.port.slip::before { content: "▲"; font-size: 7px; background: #9a8a72; }
.lbl.seamark { font: 600 10px/1 var(--sans); color: #a8287a; }
body.dark-labels .lbl.commune { color: #fff; } body.dark-labels .lbl.commune::before { border-color: #fff; background: #13283b; }
body.dark-labels .lbl.water { color: #9fe0ff; } body.dark-labels .lbl.water.small { color: #8fd0f0; }
body.dark-labels .lbl.crassat { color: #f1d9a8; } body.dark-labels .lbl.marais { color: #c4e3a7; } body.dark-labels .lbl.landmark { color: #ffe2a8; }
body.dark-labels .lbl.place { color: #dbe5ee; } body.dark-labels .lbl.port { color: #ffd27a; } body.dark-labels .lbl.seamark { color: #ffb3e4; }

/* ================= en-tête ================= */
#topbar { position: fixed; top: 14px; left: 14px; width: 300px; z-index: 4; display: flex; flex-direction: column; gap: 8px; }
#topbar h1 { margin: 0 0 0 4px; font: 600 22px/1.1 var(--serif); letter-spacing: -.005em; --h: var(--halo);
  text-shadow: 0 0 2px var(--h), 0 0 8px var(--h), 0 0 14px var(--h); }
body.night #topbar h1 { --h: rgba(5,14,26,.9); }
.search { position: relative; }
.search-ico { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--ink-3); stroke-width: 2; z-index: 1; }
#search { width: 100%; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  color: var(--ink); padding: 0 12px 0 36px; font: inherit; outline: none; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
#search::placeholder { color: var(--ink-3); }
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
#results { position: absolute; left: 0; right: 0; top: 46px; margin: 0; padding: 5px; list-style: none; background: var(--card-solid);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 6; max-height: min(380px, 60vh); overflow: auto; }
#results .group { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); font-weight: 600; padding: 8px 9px 4px; }
#results li.opt { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 8px 9px; border-radius: 8px; cursor: pointer; }
#results li.opt[aria-selected="true"], #results li.opt:hover { background: var(--accent-soft); }
#results li.opt span:last-child { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; text-transform: uppercase; letter-spacing: .05em; }
#results li.empty { color: var(--ink-3); padding: 8px 9px; }

/* ================= commandes ================= */
#nav-ctrls { position: fixed; right: 14px; top: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 4; }
.ctrl { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; transition: transform .12s, background .3s, color .3s; }
.ctrl:hover { transform: translateY(-1px); }
.ctrl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.ctrl.txt { font-weight: 700; font-size: 13px; }
.ctrl-group { display: flex; flex-direction: column; border-radius: 12px; box-shadow: var(--shadow); }
.ctrl-group .ctrl { box-shadow: none; border-radius: 0; }
.ctrl-group .ctrl:first-child { border-radius: 12px 12px 0 0; border-bottom: 0; }
.ctrl-group .ctrl:last-child { border-radius: 0 0 12px 12px; }
.ctrl-group .ctrl:hover { transform: none; background: var(--card-solid); }
#compass { width: 44px; height: 44px; border-radius: 50%; }
#compass svg { width: 34px; height: 34px; stroke: none; }
#night.on, #layers-btn.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ================= panneau calques ================= */
#layers { position: fixed; right: 64px; top: 14px; width: 300px; max-height: calc(100% - 120px); overflow: auto; z-index: 5; padding: 12px 14px 14px;
  border-radius: 16px; background: var(--card); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--line); box-shadow: var(--shadow);
  transform-origin: top right; animation: pop .18s ease-out; scrollbar-width: thin; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(-4px); } }
.layers-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.layers-head h2 { margin: 0; font: 600 17px var(--serif); }
.x { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--ink-3); cursor: pointer; }
#layers h3 { margin: 14px 0 7px; font: 600 10.5px/1 var(--sans); text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 5px 4px 7px; cursor: pointer; font-size: 11.5px;
  font-weight: 500; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 5px; transition: all .15s; }
.seg button.on { border-color: var(--accent); color: var(--ink); box-shadow: 0 0 0 2px var(--accent-soft); font-weight: 600; }
.thumb { width: 100%; height: 36px; border-radius: 7px; display: block; }
.t-nat { background: linear-gradient(135deg, #e9dcb7 0 22%, #8fd6cc 22% 38%, #2f8fb0 38% 62%, #0f3f6e 62%); }
.t-chart { background: linear-gradient(135deg, #f6e8b8 0 22%, #b5c993 22% 38%, #8fc2e8 38% 55%, #d4e8f7 55% 75%, #f8fbfe 75%); }
.t-photo { background: linear-gradient(135deg, #4f5d3d 0 25%, #c9b98c 25% 38%, #4a8c9a 38% 60%, #1d4d6e 60%); }
#depth-legend { margin-top: 10px; }
#depth-legend .grad, #depth-legend .bands { height: 8px; border-radius: 5px; }
#depth-legend .bands { display: flex; overflow: hidden; } #depth-legend .bands i { flex: 1; }
#depth-legend .ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-2); margin-top: 3px; font-variant-numeric: tabular-nums; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tile { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 9px; border: 1px solid var(--line); background: transparent;
  cursor: pointer; text-align: left; font-size: 12px; color: var(--ink-3); transition: all .15s; }
.tile.on { background: var(--card-solid); color: var(--ink); border-color: rgba(31,134,184,.35); box-shadow: 0 1px 3px rgba(19,40,59,.08); }
.tile:not(.on) .sw { filter: grayscale(1); opacity: .45; }
.sw { flex: none; display: inline-grid; place-items: center; width: 18px; height: 14px; border-radius: 4px; font-style: normal; font-size: 9px; font-weight: 700; }
.sw-tree { background: linear-gradient(#3f7a3a, #2c5a2c); clip-path: polygon(50% 0, 100% 75%, 60% 75%, 60% 100%, 40% 100%, 40% 75%, 0 75%); border-radius: 0; height: 16px; }
.sw-cabane { background: #8a5a35; clip-path: polygon(50% 0, 100% 40%, 85% 40%, 85% 70%, 90% 70%, 90% 100%, 80% 100%, 80% 70%, 20% 70%, 20% 100%, 10% 100%, 10% 70%, 15% 70%, 15% 40%, 0 40%); border-radius: 0; height: 16px; }
.sw-crassat { background: rgba(185,154,104,.25); border: 1.5px dashed #8a6a3a; }
.sw-sable { background: var(--sable); border: 1px solid #b79a5c; }
.sw-presale { background: var(--presale); }
.sw-marais { background: repeating-linear-gradient(90deg, var(--marais) 0 2px, #3f6a50 2px 3px); }
.sw-names { font-family: var(--serif); font-style: italic; color: #1b5f8c; font-size: 11px; }
.sw-iso { background: linear-gradient(#5ab0d8, #134a73); box-shadow: inset 0 -4px 0 -3px #fff, inset 0 4px 0 -3px #fff; }
.sw-nav { background: linear-gradient(90deg, #d7263d 0 33%, #1e9e4a 33% 66%, #f2c80f 66%); border-radius: 3px; }
.sw-navline { border-top: 2px dashed var(--navline); height: 0; border-radius: 0; }
.sw-port { background: #f0a524; color: #fff; border-radius: 50%; width: 16px; height: 16px; font-size: 9px; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--ink-2); font-size: 12px; }
.row input { flex: 1; accent-color: var(--accent); }
.sources { margin-top: 12px; font-size: 11px; color: var(--ink-3); }
.sources summary { cursor: pointer; color: var(--ink-2); }
.sources p { margin: 6px 0 0; line-height: 1.45; }

/* ================= barre de marée ================= */
#tidebar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 14px;
  padding: 8px 16px 8px 9px; border-radius: 20px; width: min(620px, calc(100% - 28px));
  background: var(--card); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border: 1px solid var(--line); box-shadow: var(--shadow); }
.play { width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 3px 10px rgba(31,134,184,.35); transition: transform .12s; }
.play:hover { transform: scale(1.06); }
.play svg { width: 18px; height: 18px; fill: currentColor; }
.tide-read { flex: none; min-width: 112px; }
.tide-value { font: 600 26px/1 var(--serif); font-variant-numeric: tabular-nums; }
.tide-value small { font: 500 13px var(--sans); color: var(--ink-2); }
#tide-phase { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; white-space: nowrap; }
#tide-curve { flex: 1; min-width: 0; height: 58px; cursor: ew-resize; touch-action: none; overflow: visible; }
.tc-ticks text { fill: var(--ink-3); }
body.night #tc-dot { fill: #0e1c2e; stroke: #5ec2e4; } body.night #tc-now { stroke: #9db1c4; }
.coef { flex: none; display: flex; flex-direction: column; gap: 2px; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }
.coef select { border: 1px solid var(--line); background: var(--card-solid); border-radius: 8px; padding: 4px 6px; font-size: 12px; text-transform: none; letter-spacing: 0;
  font-weight: 500; color: var(--ink); cursor: pointer; max-width: 150px; }

#readout { position: fixed; left: 50%; bottom: 102px; transform: translateX(-50%); display: flex; gap: 12px; padding: 5px 13px; border-radius: 999px; font-size: 11.5px;
  font-variant-numeric: tabular-nums; white-space: nowrap; z-index: 3; background: var(--card); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--line); transition: opacity .3s; }
#readout.idle { opacity: 0; }
#ro-pos { color: var(--ink-2); } #ro-depth { font-weight: 600; color: var(--accent); } #ro-depth:empty { display: none; }
#scale { position: fixed; left: 18px; bottom: 22px; display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--ink-2); z-index: 3;
  --h: var(--halo); text-shadow: 0 0 3px var(--h), 0 0 6px var(--h); }
body.night #scale { --h: #000; }
#scale .bar { height: 6px; border: 1.5px solid var(--ink); border-top: 0; transition: width .15s; }

#tooltip { position: fixed; pointer-events: none; z-index: 6; background: rgba(19,40,59,.92); color: #fff; padding: 5px 9px; border-radius: 7px;
  font-size: 11.5px; transform: translate(14px, 14px); white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
#tooltip small { color: #a9c3d8; margin-left: 6px; }
#tooltip .lc { font-family: ui-monospace, Consolas, monospace; color: #ffe27a; margin-left: 6px; }
#popup { position: fixed; z-index: 5; width: 270px; background: var(--card-solid); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 14px 40px rgba(19,40,59,.25); transform: translate(-50%, calc(-100% - 16px)); animation: pop .16s ease-out; }
#popup::after { content: ""; position: absolute; left: 50%; bottom: -7px; width: 12px; height: 12px; background: inherit; border: inherit; border-top: 0; border-left: 0; transform: translateX(-50%) rotate(45deg); }
#popup .close { position: absolute; right: 8px; top: 6px; background: none; border: 0; color: var(--ink-3); font-size: 20px; cursor: pointer; line-height: 1; }
#popup .kind { color: var(--accent); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; font-weight: 600; display: flex; align-items: center; gap: 6px; }
#popup .kind i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
#popup h3 { margin: 3px 22px 6px 0; font: 600 17px/1.2 var(--serif); }
#popup p.desc { margin: 0 0 8px; font-size: 12px; color: var(--ink-2); line-height: 1.45; }
#popup table { border-collapse: collapse; width: 100%; font-size: 12px; }
#popup td { padding: 4px 0; vertical-align: top; border-top: 1px solid var(--line); }
#popup td:first-child { color: var(--ink-3); padding-right: 10px; white-space: nowrap; width: 1%; }
#popup .lightchar { font-family: ui-monospace, Consolas, monospace; background: #13283b; color: #ffe27a; padding: 1px 5px; border-radius: 4px; }
#popup .more { display: inline-block; margin-top: 8px; font-size: 11px; }
#popup .depth-big { font: 600 22px/1 var(--serif); color: var(--accent); }

/* ================= tutoriel ================= */
#tuto { position: fixed; inset: 0; z-index: 20; }
#tuto-spot { position: fixed; border-radius: 16px; box-shadow: 0 0 0 9999px rgba(8, 22, 38, .52); transition: all .45s cubic-bezier(.4,.1,.2,1); pointer-events: none; }
#tuto-spot.center { left: 50% !important; top: 50% !important; width: 0 !important; height: 0 !important; }
#tuto-spot.ring::after { content: ""; position: absolute; inset: -4px; border-radius: 19px; border: 2px solid rgba(255,255,255,.85); animation: ring 1.6s ease-out infinite; }
@keyframes ring { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.08); } }
#tuto-card { position: fixed; width: min(340px, calc(100% - 28px)); background: var(--card-solid); color: var(--ink); border-radius: 16px; padding: 18px 18px 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); transition: left .45s cubic-bezier(.4,.1,.2,1), top .45s cubic-bezier(.4,.1,.2,1); }
.tuto-step { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); font-weight: 700; }
#tuto-card h2 { margin: 4px 0 6px; font: 600 20px/1.2 var(--serif); }
#tuto-card p { margin: 0; color: var(--ink-2); line-height: 1.5; font-size: 13px; }
#tuto-card p b { color: var(--ink); font-weight: 600; }
.tuto-foot { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.dots { display: flex; gap: 5px; flex: 1; }
.dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--line); transition: all .3s; }
.dots i.on { width: 18px; background: var(--accent); }
.ghost, .primary { border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 12.5px; border: 0; }
.ghost { background: transparent; color: var(--ink-2); }
.ghost:hover { color: var(--ink); }
.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 10px rgba(31,134,184,.3); }

#loading { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; z-index: 30;
  background: radial-gradient(130% 100% at 50% 20%, #f6f1e6, #cfe0ea); color: var(--ink-2); font: italic 16px var(--serif); transition: opacity .7s; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(31,134,184,.2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= mobile ================= */
@media (max-width: 760px) {
  #topbar { right: 66px; width: auto; }
  #topbar h1 { font-size: 18px; }
  #tidebar { bottom: max(10px, env(safe-area-inset-bottom)); gap: 10px; padding: 7px 10px 7px 7px; flex-wrap: wrap; }
  .tide-read { min-width: 0; }
  .tide-value { font-size: 22px; }
  #tide-curve { order: 3; flex-basis: 100%; height: 46px; }
  .coef { margin-left: auto; }
  .coef span { display: none; }
  #layers { right: 10px; left: 10px; width: auto; top: 112px; max-height: calc(100% - 300px); }
  #readout, #scale { display: none; }
  #pitch { display: none; }
}
