:root {
  --bg: #E8EFF1; --card: #FFFFFF; --ink: #0D2533; --muted: #4F6672; --border: #C4D2D8;
  --primary: #0F5C7A; --on-primary: #FFFFFF; --water-top: #8FC4D6; --water-deep: #0E3F56;
  --sky: #F6FAFB; --buoy: #F0A800; --warn: #A33A12; --ok: #1E7A45;
  --tabbar-h: 64px;
  --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a; --viz-other: #898781;
  --viz-grid: #E3EAED; --viz-axis: #B9C6CC;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071820; --card: #0F2732; --ink: #EAF3F6; --muted: #9DB4BE; --border: #23414E;
    --primary: #5CC1E0; --on-primary: #06202B; --water-top: #1F6F8B; --water-deep: #04141C;
    --sky: #12303D; --buoy: #FFC02E; --warn: #FF9A6B; --ok: #6FD39A;
    --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-other: #898781;
    --viz-grid: #1C3A47; --viz-axis: #2E4E5C;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px; line-height: 1.4;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px calc(env(safe-area-inset-bottom, 0px) + var(--tabbar-h) + 24px);
}
main { max-width: 460px; margin: 0 auto; }
[hidden] { display: none !important; }
h1 { font-size: 1.15rem; font-weight: 700; margin: 0 0 12px; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 22px 0 10px; }

/* ---------- app shell ---------- */
.apphead { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.apphead img { width: 44px; height: 44px; }
.apphead h1 { margin: 0; font-size: 1.25rem; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--border);
  padding: 4px 8px calc(env(safe-area-inset-bottom, 0px) + 4px);
}
.tabbar button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 0.85rem; font-weight: 600; min-height: 56px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button[aria-selected="true"] { color: var(--primary); }
.banner {
  background: var(--card); border: 1px solid var(--buoy); border-radius: 14px;
  padding: 10px 14px; margin: 0 0 12px; font-size: 0.92rem;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner p { margin: 0; flex: 1; }
.banner button { appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 2px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 3000;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tabbar-h) + 16px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 0.95rem; max-width: 90vw; text-align: center;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- depth tool ---------- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; }
.result { padding: 14px 18px 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.result .lead { margin: 0; color: var(--muted); font-size: 0.95rem; }
.result .value {
  margin: 0; font-size: 2.7rem; line-height: 1.05; font-weight: 800;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.result .value small { font-size: 1.1rem; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.result .cap { margin: 0; color: var(--muted); font-size: 0.8rem; }
.result .extra { margin: 8px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.3em; }
.result .bad { margin: 0; font-size: 1.2rem; font-weight: 700; color: var(--warn); }
svg#dia { display: block; width: 100%; height: auto; }

/* ---------- form controls ---------- */
.field { margin-bottom: 14px; }
.field > label, .field > .lab { display: block; font-weight: 600; margin-bottom: 6px; }
.stepper { display: grid; grid-template-columns: 60px 1fr 60px; gap: 8px; align-items: stretch; }
.stepper button {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--ink);
  font: inherit; font-size: 1.7rem; font-weight: 600; line-height: 1;
  border-radius: 14px; min-height: 56px; cursor: pointer; touch-action: manipulation;
}
.stepper button:active { background: var(--primary); color: var(--on-primary); }
.inwrap { position: relative; }
.inwrap input {
  width: 100%; height: 100%; min-height: 56px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--card); color: var(--ink); font: inherit; font-size: 1.5rem; font-weight: 700;
  text-align: center; font-variant-numeric: tabular-nums; padding: 4px 48px; -moz-appearance: textfield;
}
.inwrap input::-webkit-outer-spin-button, .inwrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inwrap span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }

select, input.text, textarea {
  width: 100%; min-height: 56px;
  border: 1px solid var(--border); border-radius: 14px; background-color: var(--card); color: var(--ink);
  font: inherit; font-size: 1.1rem; font-weight: 600; padding: 8px 14px;
}
textarea { min-height: 96px; font-weight: 500; resize: vertical; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%237A8F9A' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.row2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .inwrap input { font-size: 1.25rem; padding: 4px 40px 4px 12px; text-align: left; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 4px;
}
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; min-height: 52px; border-radius: 10px; padding: 6px 2px; cursor: pointer;
}
.seg button small { display: block; font-size: 0.72rem; font-weight: 500; opacity: 0.8; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid var(--buoy); outline-offset: 2px; }

details { border-top: 1px solid var(--border); margin-top: 22px; padding-top: 4px; }
summary { font-weight: 600; padding: 12px 0; cursor: pointer; }
.note { color: var(--muted); font-size: 0.9rem; margin: 14px 0 0; }

.btn {
  appearance: none; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 56px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 700; font-size: 1.05rem;
  cursor: pointer; touch-action: manipulation; padding: 8px 14px; text-decoration: none;
}
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.big { min-height: 68px; font-size: 1.25rem; }
.btn.danger { color: var(--warn); border-color: var(--warn); }
.btn:disabled { opacity: 0.55; }
.btns { display: grid; gap: 10px; margin: 12px 0; }
.check { display: flex; align-items: center; gap: 12px; font-weight: 600; min-height: 48px; cursor: pointer; }
.check input { width: 26px; height: 26px; accent-color: var(--primary); }

/* ---------- journal ---------- */
#map {
  height: 42vh; min-height: 240px; border-radius: 18px; border: 1px solid var(--border);
  background: var(--sky); z-index: 0;
}
.maphint { color: var(--muted); font-size: 0.85rem; margin: 6px 2px 12px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list li button {
  appearance: none; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); color: var(--ink); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; font: inherit; display: grid; gap: 2px;
}
.list .t1 { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.list .t1 span:last-child { color: var(--muted); font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.list .t2, .list .t3 { color: var(--muted); font-size: 0.92rem; }
.chip { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); }
.chip.pending { border-color: var(--buoy); }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* catch sheet */
.sheet {
  position: fixed; inset: 0; z-index: 2000; background: var(--bg); overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) max(14px, calc((100% - 460px) / 2)) calc(env(safe-area-inset-bottom, 0px) + 40px);
}
.sheethead {
  position: sticky; top: calc(-1 * (env(safe-area-inset-top, 0px) + 8px)); z-index: 2;
  background: var(--bg); display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 0 10px; margin-top: calc(-1 * (env(safe-area-inset-top, 0px) + 8px));
  border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.sheethead h2 { margin: 0; }
.sheethead .btn { width: auto; min-height: 46px; padding: 6px 20px; }
.savestate { font-size: 0.85rem; color: var(--ok); font-weight: 600; }
.meta { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px; margin-bottom: 14px; font-size: 0.92rem; }
.meta p { margin: 2px 0; }
.meta .muted { color: var(--muted); }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); vertical-align: -2px; margin-right: 2px; }
.colorbar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; border: 1px solid var(--border); margin-top: 6px; }
.colorbar i { flex: 1; }

/* settings */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { margin-top: 0; }
.card p { margin: 6px 0; }
.status { font-size: 0.92rem; color: var(--muted); }

/* lock screen */
.lock {
  position: fixed; inset: 0; z-index: 5000; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px;
}
.lock img { width: 120px; height: 120px; }
.lock input { max-width: 240px; text-align: center; font-size: 1.6rem; letter-spacing: 0.3em; }
.lock .btn { max-width: 240px; }
.lock .bad { color: var(--warn); font-weight: 600; min-height: 1.4em; margin: 0; }

/* location card, map tools, locate button, update banner */
.loccard { border-color: var(--buoy); }
.loccard .btns { grid-template-columns: 2fr 1fr; }
.steps { margin: 8px 0 4px; padding-left: 22px; font-size: 0.95rem; }
.steps li { margin-bottom: 8px; }
.maptools { margin-top: 4px; }
.maptools .lab { display: block; font-weight: 600; margin-bottom: 4px; }
.maptools .check small { display: block; color: var(--muted); font-weight: 500; font-size: 0.82rem; }
.maptools .note { margin-top: 6px; }
.leaflet-control.tt-locbar a.tt-locate {
  width: 44px; height: 44px; line-height: 44px; border-radius: 10px;
  display: flex !important; align-items: center; justify-content: center; color: #0F5C7A !important;
}
.leaflet-control.tt-locbar { border-radius: 12px; margin-bottom: 26px !important; }
.tt-locate svg { width: 24px; height: 24px; }
.tt-locate.on svg path { fill: currentColor; }
.update {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 4000;
  top: calc(env(safe-area-inset-top, 0px) + 10px); width: min(440px, calc(100% - 28px));
  background: var(--primary); color: var(--on-primary); border-radius: 14px; padding: 10px 12px 10px 16px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.update p { margin: 0; flex: 1; font-weight: 600; }
.update button { appearance: none; border: 0; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; min-height: 44px; padding: 0 14px; background: var(--on-primary); color: var(--primary); }
.update button.x { background: transparent; color: var(--on-primary); font-size: 1.4rem; padding: 0 6px; }
.tt-blend { mix-blend-mode: multiply; }

/* views */
.viewstop { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.viewstop h2 { margin: 0; }
.viewstop .btn { width: auto; min-height: 48px; padding: 6px 16px; }
.viewcard { padding-bottom: 8px; }
.viewhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.viewhead h2 { margin: 0 0 2px; font-size: 1rem; }
.viewhead p { margin: 0; }
.btn.small { width: auto; min-height: 40px; padding: 4px 14px; font-size: 0.95rem; }
.headbtns { display: flex; gap: 8px; }
.headbtns .btn { width: auto; min-height: 46px; padding: 6px 16px; }
.viz { min-height: 60px; }
.viz svg { display: block; overflow: visible; }
.viz-bar { fill: var(--viz-1); }
.viz-bar:hover { opacity: 0.85; }
.viz-label { fill: var(--ink); font-size: 12px; font-family: inherit; }
.viz-value { fill: var(--muted); font-size: 12px; font-weight: 600; font-family: inherit; font-variant-numeric: tabular-nums; }
.viz-tick { fill: var(--muted); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.viz-axis-title { fill: var(--muted); font-size: 11px; font-weight: 600; font-family: inherit; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { stroke: var(--viz-axis); stroke-width: 1; }
.viz-dot { stroke: var(--card); stroke-width: 2; }
.viz-dot.viz-1 { fill: var(--viz-1); } .viz-dot.viz-2 { fill: var(--viz-2); }
.viz-dot.viz-3 { fill: var(--viz-3); } .viz-dot.viz-other { fill: var(--viz-other); }
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 2px; font-size: 0.85rem; color: var(--ink); }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }
.viz-legend .sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sw.viz-1 { background: var(--viz-1); } .sw.viz-2 { background: var(--viz-2); }
.sw.viz-3 { background: var(--viz-3); } .sw.viz-other { background: var(--viz-other); }
.viz-tip {
  position: fixed; z-index: 4500; pointer-events: none; max-width: 240px;
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 0.85rem; line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.viz-table { margin-top: 6px; border-top: 0; padding-top: 0; }
.viz-table summary { font-size: 0.9rem; padding: 8px 0; color: var(--muted); }
.tablewrap { overflow-x: auto; }
.viz-table table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.viz-table th, .viz-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.viz-table td:last-child, .viz-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#vPreview { padding: 12px; }
.loctable { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 4px; }
.loctable th { text-align: left; vertical-align: top; padding: 6px 8px 6px 0; color: var(--muted); font-weight: 600; white-space: nowrap; }
.loctable td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.loctable tr:last-child td { border-bottom: 0; }
