:root {
  --bg: #f2f6f5;
  --card: #ffffff;
  --ink: #17272e;
  --muted: #5b7078;
  --line: #d7e2e0;
  --accent: #12333f;
  --accent-ink: #eaf6f2;
  --brand: #1b7f79;
  --brand-soft: #e2f1ee;
  --danger: #b3402e;
  --chip: #e8efed;
  --chip-on: #1b7f79;
  --shadow: 0 1px 3px rgba(23, 39, 46, 0.10);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1a1f;
    --card: #16262d;
    --ink: #e4eeec;
    --muted: #92a8a4;
    --line: #27404a;
    --accent: #0b2530;
    --accent-ink: #eaf6f2;
    --brand: #3db3a5;
    --brand-soft: #133c3c;
    --danger: #e06a52;
    --chip: #1e343c;
    --chip-on: #2c8d81;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(160deg, var(--accent) 0%, #175243 100%);
  color: var(--accent-ink);
  padding: max(10px, env(safe-area-inset-top)) 16px 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 0 4px; }
.brand-icon { width: 38px; height: 38px; border-radius: 9px; }
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.02em; }
.tagline { margin: 0; font-size: 0.72rem; opacity: 0.75; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tab {
  flex: 1;
  appearance: none; border: none; background: transparent;
  color: var(--accent-ink); opacity: 0.72;
  font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 9px 6px; cursor: pointer; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tab.active { opacity: 1; border-bottom-color: #7fd6c2; }

/* ---------- Layout ---------- */
main { max-width: 760px; margin: 0 auto; padding: 14px 12px 80px; }
.view-head { display: flex; align-items: center; gap: 10px; margin: 4px 2px 12px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 1.2rem; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 1rem; }
.card h4 { margin: 14px 0 6px; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 4px 0 8px; }
.coords { font-variant-numeric: tabular-nums; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
textarea { width: 100%; resize: vertical; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0; }

.btn {
  appearance: none; font: inherit; font-weight: 600; font-size: 0.88rem;
  background: var(--chip); color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 14px;
  cursor: pointer;
  transition: filter 0.1s;
}
.btn:hover { filter: brightness(0.96); }
.btn:active { filter: brightness(0.9); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.big { padding: 13px 22px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.file-btn { display: inline-flex; align-items: center; flex-direction: row; color: var(--ink); font-size: 0.88rem; }
.form-actions { display: flex; gap: 10px; margin: 18px 0; flex-wrap: wrap; }

/* ---------- Map ---------- */
.pin-mode.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.end-pin { font-size: 24px; line-height: 1; text-shadow: 0 1px 2px rgba(0,0,0,0.45); }

.map { height: 280px; border-radius: 10px; border: 1px solid var(--line); margin: 8px 0; z-index: 1; }
.map-tools { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.map-tools input { flex: 1; min-width: 160px; }

/* ---------- Photos ---------- */
.photo-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photo-thumbs .thumb { position: relative; }
.photo-thumbs img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb-x {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: var(--danger); color: #fff;
  font-size: 0.8rem; line-height: 1; cursor: pointer;
}

/* ---------- Gauges ---------- */
.gauge-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.gauge-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; font-size: 0.83rem;
  flex-wrap: wrap;
}
.gauge-row .g-name { flex: 1; min-width: 180px; font-weight: 600; }
.gauge-row .g-meta { color: var(--muted); font-size: 0.76rem; }
.gauge-row select { padding: 5px 8px; font-size: 0.8rem; }
.g-cfs { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); }

/* ---------- Weather ---------- */
.weather-display { margin-top: 8px; }
.wx-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.wx-cell { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.wx-cell .k { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.wx-cell .v { font-size: 1.02rem; font-weight: 700; margin-top: 2px; }

/* ---------- Catches ---------- */
.catch-row {
  border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: 10px; padding: 10px; margin-bottom: 10px;
  background: var(--bg);
}
.catch-row .field-row { margin: 6px 0; }
.catch-head { display: flex; justify-content: space-between; align-items: center; }
.catch-head .title { font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.fly-rows { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 8px; }
.fly-row { display: flex; gap: 6px; }
.fly-row .c-fly { flex: 2; min-width: 0; }
.fly-row .c-size { flex: 1; max-width: 90px; }
.fly-row .rm-fly { padding: 6px 10px; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  appearance: none; font: inherit; font-size: 0.76rem; font-weight: 600;
  background: var(--chip); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px; cursor: pointer;
}
.chip.on { background: var(--chip-on); border-color: var(--chip-on); color: #fff; }

/* ---------- Trip list ---------- */
.log-stats { font-size: 0.78rem; color: var(--muted); }
.trip-list { display: flex; flex-direction: column; gap: 10px; }
.trip-card {
  display: flex; gap: 12px; align-items: stretch;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  cursor: pointer; box-shadow: var(--shadow);
}
.trip-card:hover { border-color: var(--brand); }
.card-edit { align-self: center; padding: 8px 10px; font-size: 0.9rem; flex-shrink: 0; }
.trip-card img.tc-photo { width: 74px; height: 74px; object-fit: cover; border-radius: 9px; }
.tc-body { flex: 1; min-width: 0; }
.tc-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.tc-water { font-weight: 700; }
.tc-date { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.tc-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.tc-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge {
  font-size: 0.72rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: 3px 9px;
}
.badge.gray { background: var(--chip); color: var(--muted); }

.empty-state { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Detail ---------- */
.detail-hero { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-hero img { height: 120px; border-radius: 10px; border: 1px solid var(--line); }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 8px 0; }
.detail-catch { border-top: 1px solid var(--line); padding: 8px 0; font-size: 0.9rem; }
.detail-catch:first-of-type { border-top: none; }
.detail-catch .dc-main { font-weight: 700; }
.detail-catch .dc-sub { color: var(--muted); font-size: 0.8rem; }

/* ---------- Game plan results ---------- */
.plan-headline { font-size: 1.02rem; font-weight: 700; margin: 4px 0 10px; }
.rec-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.rec-row:first-of-type { border-top: none; }
.rec-rank { font-weight: 800; color: var(--brand); min-width: 24px; }
.rec-name { flex: 1; font-weight: 600; }
.rec-meta { color: var(--muted); font-size: 0.78rem; text-align: right; }
.rec-bar { height: 5px; border-radius: 4px; background: var(--brand); min-width: 4px; }
.match-row { padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.85rem; cursor: pointer; }
.match-row:hover .m-water { color: var(--brand); }
.m-water { font-weight: 700; }
.m-sub { color: var(--muted); font-size: 0.78rem; }
.m-score { float: right; font-weight: 800; color: var(--brand); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; padding: 11px 18px;
  font-size: 0.88rem; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 2000; max-width: 90vw;
}
.toast.error { background: var(--danger); color: #fff; }

.about a { color: var(--brand); }

.sync-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--bg);
  border: 1px dashed var(--brand);
  border-radius: 9px;
  padding: 10px 14px;
  text-align: center;
  user-select: all;
  -webkit-user-select: all;
}

@media (max-width: 480px) {
  .brand h1 { font-size: 1.15rem; }
  .map { height: 230px; }
  .trip-card img.tc-photo { width: 60px; height: 60px; }
}
