/* Whiskey Tasting Book — iPhone client (SPEC.md §5 tokens, §9.2 iOS rules).

   The desktop palette, retuned for a phone: 44 pt touch targets, safe-area insets on every edge,
   16 px inputs so Safari never zooms on focus, and 100dvh rather than 100vh because vh is wrong
   while the URL bar is visible. */

:root {
  --bg:            #12100E;
  --surface:       #1B1815;
  --surface-2:     #241F1A;
  --line:          #332C22;
  --text:          #F2EDE4;
  --muted:         #9A9086;
  --brass:         #C8952F;
  --brass-bright:  #E8B44A;
  --ok:            #6FBF73;
  --warn:          #E8896A;

  /* UI text is the system stack so it renders as SF and matches the rest of the phone.
     Playfair is kept for spirit names only — the one deliberate departure (§9.2). */
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI",
          "Microsoft YaHei", sans-serif;
  --serif: "Playfair Display", Georgia, "Microsoft YaHei", serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --bar-h: 52px;
  --tabs-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100dvh;                     /* never 100vh on iOS Safari (§9.2) */
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; color: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- top bar */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--bar-h) + var(--safe-t));
  padding: var(--safe-t) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
/* The Dynamic Island eats the top centre — the title sits left of it, not under it. */
.bar h1 {
  font-family: var(--serif); font-size: 1.15rem; font-weight: 500; margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.back {
  width: 44px; height: 44px; margin-left: -10px; flex-shrink: 0;
  background: none; border: none; color: var(--brass-bright); font-size: 30px; line-height: 1;
}
.net { margin-left: auto; font-size: 0.75rem; color: var(--muted); flex-shrink: 0; }
.net.off { color: var(--warn); }

/* ---------------------------------------------------------------- layout */
#main {
  padding: calc(var(--bar-h) + var(--safe-t) + 8px) calc(14px + var(--safe-r))
           calc(var(--tabs-h) + var(--safe-b) + 20px) calc(14px + var(--safe-l));
}
body.keyboard #main { padding-bottom: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px; margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: 0.82rem; }
.empty { color: var(--muted); padding: 28px 4px; text-align: center; }

/* ---------------------------------------------------------------- tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  height: calc(var(--tabs-h) + var(--safe-b));
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
/* The bottom inset is the home indicator: a tab bar without it sits under the swipe strip. */
body.keyboard .tabs { display: none; }
.tab {
  flex: 1; min-height: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: 0.68rem; position: relative;
}
.tab .glyph { font-size: 1.15rem; line-height: 1; }
.tab.active { color: var(--brass-bright); }
.badge {
  position: absolute; top: 4px; right: 22%;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--brass); color: var(--bg);
  font-size: 0.66rem; line-height: 18px; text-align: center; font-weight: 600;
}

/* ---------------------------------------------------------------- lists */
.search {
  width: 100%; font-size: 16px;              /* 16px or Safari zooms and never zooms back */
  padding: 11px 13px; margin-bottom: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text);
}
.search:focus { outline: 2px solid var(--brass-bright); border-color: transparent; }

.row.gone .row-name, .row.gone .row-sub { opacity: 0.62; }
.tag {
  margin-left: 8px; padding: 1px 7px; border-radius: 999px; vertical-align: 1px;
  border: 1px solid var(--line); color: var(--muted); font-size: 0.66rem;
  font-family: var(--sans); letter-spacing: 0.02em;
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  min-height: 34px; padding: 6px 14px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; font-size: 0.82rem;
}
.chip.active { background: var(--brass); border-color: var(--brass); color: var(--bg); font-weight: 600; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--muted); border-radius: 12px;
}
.row-main { flex: 1; min-width: 0; }
.row-name { font-family: var(--serif); font-size: 1rem; line-height: 1.2;
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 0.74rem; margin-top: 2px;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-score { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.row-score b { font-family: var(--serif); font-size: 1.1rem; color: var(--brass-bright);
               font-weight: 500; }

.medal {
  display: inline-block; font-size: 0.64rem; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--m, var(--muted)); color: var(--m, var(--muted));
  background: color-mix(in srgb, var(--m, var(--muted)) 15%, transparent);
}

/* ---------------------------------------------------------------- scorecard */
.spirit-name { font-family: var(--serif); font-size: 1.35rem; line-height: 1.15; }
.spirit-meta { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

.cat { padding: 12px 0; border-top: 1px solid var(--line); }
.cat:first-child { border-top: none; }
.cat-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.cat-name { font-weight: 500; font-size: 0.95rem; }
.cat-max { color: var(--muted); font-size: 0.74rem; }
.cat-val { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 1.05rem;
           color: var(--brass-bright); min-width: 2ch; text-align: right; }
.cat-val.unset { color: var(--muted); }

/* 44 px tall, not the 26 px used on desktop. Ten segments across a 390 pt screen is ~33 pt
   each — under the guideline horizontally — so tap is backed by drag (§9.2). */
.strip {
  display: grid; gap: 3px; height: 44px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.seg { border-radius: 5px; background: transparent; position: relative; }
.seg.filled { background: var(--brass); }
.seg.sel { box-shadow: inset 0 0 0 2px var(--brass-bright); }
.seg.tick::after {
  content: attr(data-label); position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.seg.filled.tick::after, .seg.sel.tick::after { color: var(--bg); font-weight: 600; }

textarea, input[type="text"], input[type="number"], input[type="date"] {
  width: 100%; font-family: inherit; font-size: 16px; line-height: 1.5;
  padding: 10px 12px; margin-top: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text);
}
textarea { resize: none; overflow: hidden; min-height: 44px; }
textarea:focus, input:focus { outline: 2px solid var(--brass-bright); border-color: transparent; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { color: var(--muted); font-size: 0.78rem; }

.total-bar {
  position: sticky; bottom: 0; margin: 16px -16px -14px;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.total-num { font-family: var(--serif); font-size: 1.9rem; color: var(--brass-bright);
             font-variant-numeric: tabular-nums; line-height: 1; }
.total-num.incomplete { color: var(--muted); }
.total-of { color: var(--muted); font-size: 0.8rem; }

.btn {
  min-height: 44px; padding: 12px 20px; border-radius: 12px; border: none;
  background: var(--brass); color: var(--bg); font-size: 1rem; font-weight: 600;
}
.btn:disabled { background: var(--surface-2); color: var(--muted); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted);
             font-weight: 400; }
.btn.wide { width: 100%; }
.actions { display: flex; gap: 10px; margin-top: 14px; }

/* ---------------------------------------------------------------- sync */
.state { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--warn); }
.qrow {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--surface-2); border-radius: 10px; font-size: 0.85rem;
}
.qrow .kind { color: var(--muted); font-size: 0.7rem; text-transform: uppercase;
              letter-spacing: .04em; flex-shrink: 0; }
.qrow .when { margin-left: auto; color: var(--muted); font-size: 0.72rem; flex-shrink: 0; }

.notice {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 0.86rem;
  border: 1px solid var(--line); background: var(--surface);
}
.notice.warn { color: var(--warn); border-color: #6a3a2a; }
.notice.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }

/* ---------------------------------------------------------------- charts (analysis) */
.chart-card { margin-top: 12px; }
.chart-title { font-family: var(--serif); font-size: 1.02rem; margin-bottom: 8px; }
.chart-note { color: var(--muted); font-size: 0.78rem; margin-bottom: 8px; line-height: 1.4; }
.chart { width: 100%; height: auto; display: block; margin-top: 4px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 9px; font-family: var(--sans); }
.chart .spark { fill: none; stroke: var(--brass); stroke-width: 2; stroke-linejoin: round; }
.chart-basis { color: var(--muted); font-size: 0.72rem; margin-top: 6px; }
.chart-empty { padding: 10px 2px; font-size: 0.85rem; }

.bars { margin-top: 6px; }
.bar-row {
  display: grid; grid-template-columns: 5.6rem 1fr 2.2rem 2.2rem;
  align-items: center; gap: 8px; padding: 4px 0;
}
.bar-label { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-value { font-size: 0.8rem; text-align: right; font-variant-numeric: tabular-nums; }
.bar-n { color: var(--muted); font-size: 0.7rem; text-align: right; }

.sum-row { display: flex; gap: 18px; }
.sum-cell { display: flex; flex-direction: column; }
.sum-cell b { font-family: var(--serif); font-size: 1.5rem; line-height: 1.1; }
.sum-cell span { color: var(--muted); font-size: 0.72rem; }
.sum-best { margin-top: 6px; font-size: 0.8rem; }

/* ---------------------------------------------------------------- compare */
.cmp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.btn.small { min-height: 34px; padding: 6px 14px; font-size: 0.85rem; }
.cmp-totals { display: flex; gap: 10px; overflow-x: auto; }
/* A fixed basis rather than an equal share: past three or four, equal shares are too
   narrow to read a name in, so the row scrolls instead of squeezing. */
.cmp-col { flex: 1 0 5.4rem; min-width: 0; text-align: center; }
.cmp-name {
  font-family: var(--serif); font-size: 0.9rem; line-height: 1.2; min-height: 3.4em;
  border-bottom: 2px solid var(--line); padding-bottom: 6px; margin-bottom: 8px;
  overflow: hidden;
}
.cmp-sub {
  display: block; color: var(--muted); font-size: 0.68rem; font-weight: 400;
  margin-top: 2px; font-family: var(--sans);
}
.cmp-score { font-family: var(--serif); font-size: 1.5rem; }
.cmp-drop {
  margin-top: 8px; background: none; border: 0; color: var(--muted);
  font-size: 0.7rem; text-decoration: underline; min-height: 34px;
}
.cmp-axes { display: flex; flex-direction: column; gap: 14px; }
.cmp-axis-head {
  display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 5px;
}
.cmp-bar-row { display: grid; grid-template-columns: 1fr 2.4rem; align-items: center; gap: 8px; margin: 3px 0; }
.cmp-bar-track { background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; }
.cmp-bar-fill { height: 100%; border-radius: 999px; opacity: 0.75; }
.cmp-bar-fill.lead { opacity: 1; }
.cmp-bar-val { font-size: 0.78rem; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- table */
/* Six tabs on a 375-point screen: the labels have to give a little. */
.tab { font-size: 0.62rem; }
.tab .glyph { font-size: 1.05rem; }

.ptable-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 4px; }
.ptable { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
.ptable th, .ptable td {
  padding: 8px 9px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.ptable th {
  color: var(--muted); font-weight: 500; font-size: 0.72rem; position: sticky; top: 0;
  background: var(--bg); min-height: 44px;
}
.ptable th.sorted { color: var(--brass-bright); }
.ptable .t-num { text-align: right; font-variant-numeric: tabular-nums; }
.ptable .t-code { color: var(--muted); font-variant-numeric: tabular-nums; }
.ptable .t-name { font-family: var(--serif); max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.ptable tbody tr.gone td { opacity: 0.6; }
.t-caret { font-size: 0.7rem; }

/* Per-sitting actions on the detail screen. 44 px targets, like everything else you tap. */
.qrow.sitting { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px; }
.linkish {
  background: none; border: 0; color: var(--brass-bright); font-size: 0.78rem;
  min-height: 44px; padding: 0 4px; text-decoration: underline;
}
.linkish.danger { color: #C97A6A; }

/* The sort row: every field the desktop sorts on, without hunting for a header off-screen. */
.sortbar { align-items: center; padding-bottom: 8px; }
.sortlabel {
  color: var(--muted); font-size: 0.72rem; padding-right: 2px; flex-shrink: 0;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.sortbar .chip { font-size: 0.78rem; padding: 5px 11px; }

/* The ranking lens: which categories the score is taken over. */
.lensbar { align-items: center; padding-bottom: 6px; }
.lenspicker {
  display: flex; flex-wrap: wrap; gap: 10px 16px;
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface-2); border-radius: 10px;
}
.lenschoice {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); font-size: 0.8rem; min-height: 44px;
}
.lenschoice input { accent-color: var(--brass); width: 20px; height: 20px; }

/* One sitting in full: what each category was given, and what was written against it. */
.qrow.sitting {
  width: 100%; text-align: left; background: none; border: 0;
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px;
  min-height: 44px; padding: 8px 2px; color: var(--text); font-size: 0.9rem;
  border-bottom: 1px solid var(--line);
}
.qrow.sitting:last-child { border-bottom: 0; }
.qrow.sitting .chev { color: var(--muted); font-size: 1.1rem; }

.brk { padding: 9px 0; border-bottom: 1px solid var(--line); }
.brk:last-child { border-bottom: 0; }
.brk-head { display: flex; justify-content: space-between; font-size: 0.86rem; margin-bottom: 6px; }
.brk-val { color: var(--muted); font-variant-numeric: tabular-nums; }
.brk-track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.brk-fill { height: 100%; border-radius: 999px; }
.brk-note { color: var(--muted); font-size: 0.82rem; margin-top: 6px; line-height: 1.45; }
.brk-overall { font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; }
.btn.danger {
  background: none; color: #C97A6A;
  border: 1px solid color-mix(in srgb, #C97A6A 45%, transparent);
}
