/* Rapport XL — phone-first phrasebook, theme-able.
 *
 * Its own palette set (not the house five): five schemes swap the core tokens
 * below; soft tints derive via color-mix. --accent is brand/interactive;
 * --down marks "don't say this" lines (the wrong thing to say); --nt/--nf/
 * --sj/--sp are categorical temperament tints and carry no good/bad meaning.
 */

:root {                    /* default: Noir — charcoal & coral */
  --bg: #101114; --panel: #18191e; --panel2: #212229; --line: #2d2f37;
  --text: #efeef0; --muted: #9b9ca6; --accent: #ee9a84;
  --up: #74cf9a; --down: #ef7f7b;
  --nt: #b79cf2; --nf: #7fd3a1; --sj: #7cc3f0; --sp: #f2c063;
}
html[data-theme="harbor"] { /* navy & sea mint */
  --bg: #0c131a; --panel: #121c25; --panel2: #19262f; --line: #24343f;
  --text: #e6eef3; --muted: #8da3b1; --accent: #7fd6c0;
  --up: #74cf9a; --down: #ef7f7b;
  --nt: #b79cf2; --nf: #8fdcae; --sj: #86c8f2; --sp: #f2c063;
}
html[data-theme="plum"] { /* aubergine & lilac */
  --bg: #15101c; --panel: #1d1626; --panel2: #271e32; --line: #372c44;
  --text: #f0eaf5; --muted: #a797b5; --accent: #d6a7f3;
  --up: #74cf9a; --down: #ef7f7b;
  --nt: #c3a8f7; --nf: #8ad8a8; --sj: #8ccaf4; --sp: #f3c66f;
}
html[data-theme="moss"] { /* forest & olive gold */
  --bg: #0f1411; --panel: #161c18; --panel2: #1e2621; --line: #2b372f;
  --text: #e9efe9; --muted: #96a899; --accent: #dcc57c;
  --up: #74cf9a; --down: #ef7f7b;
  --nt: #b9a3f0; --nf: #8fd7a9; --sj: #88c6ee; --sp: #f0c46a;
}
html[data-theme="linen"] { /* light: linen & terracotta */
  --bg: #f6f3ee; --panel: #fffefb; --panel2: #efe9df; --line: #ddd5c8;
  --text: #26221e; --muted: #726a60; --accent: #b8562f;
  --up: #1f8f4e; --down: #c2443f;
  --nt: #6b4fc7; --nf: #1f8a55; --sj: #2a74b8; --sp: #b8761a;
}
:root {
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --up-soft: color-mix(in srgb, var(--up) 14%, transparent);
  --down-soft: color-mix(in srgb, var(--down) 14%, transparent);
  --radius: 16px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Charter, Georgia, serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px)
           calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 28px)
           calc(env(safe-area-inset-left) + 16px);
  -webkit-tap-highlight-color: transparent;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.theme-row { margin-top: 26px; display: flex; align-items: center; gap: 12px; justify-content: center; }
.theme-label { color: var(--muted); font-size: 0.75rem; }
.theme-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.theme-dot.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.theme-auto { color: var(--muted); font-size: 0.75rem; padding: 4px 6px; border-radius: 8px; }
.theme-auto.sel { color: var(--accent); }
.foot-note { color: var(--muted); font-size: 0.72rem; text-align: center; margin-top: 8px; line-height: 1.5; }

/* temperament tint, set per element by a g-* class */
.g-nt { --g: var(--nt); }
.g-nf { --g: var(--nf); }
.g-sj { --g: var(--sj); }
.g-sp { --g: var(--sp); }

/* ---------------------------------------------------------------- shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin: 2px 0 10px;
}
.brand { font-size: 1.45rem; letter-spacing: 0.01em; }
.brand small { color: var(--accent); font-size: 0.72em; font-weight: 600; margin-left: 4px; letter-spacing: 0.04em; }
.back { color: var(--muted); font-size: 0.9rem; padding: 8px 0; }
.back:active { color: var(--text); }
.nav { display: flex; gap: 6px; }
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.82rem;
}
.nav-btn svg { width: 15px; height: 15px; }
.nav-btn svg path { fill: none; stroke: currentColor; stroke-width: 2; }
.nav-btn.has svg path { fill: currentColor; }
.nav-btn.sel { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.nav-count { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tagline { color: var(--muted); font-size: 0.85rem; margin: 0 2px 14px; }
.view-title { font-size: 1.3rem; margin: 6px 2px 12px; }
.muted { color: var(--muted); font-size: 0.8rem; }

/* ---------------------------------------------------------------- home */
.search {
  width: 100%;
  font-size: 16px;                 /* ≥16px stops iOS focus zoom */
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  text-transform: uppercase;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.search::placeholder { color: var(--muted); text-transform: none; font-family: inherit; letter-spacing: 0; }
.search:focus { border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  aspect-ratio: 1 / 1.05;
  padding: 8px 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--g, var(--line));
  border-radius: var(--radius);
}
.tile:active { background: var(--panel2); }
.tile-code { font-family: var(--mono); font-weight: 700; font-size: 1.02rem; letter-spacing: 0.02em; }
.tile-wants { color: var(--muted); font-size: 0.6rem; text-align: center; line-height: 1.2; }
@media (min-width: 420px) {
  .tile-code { font-size: 1.12rem; }
  .tile-wants { font-size: 0.68rem; }
}
.legend { display: flex; justify-content: center; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 0.7rem; }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--g); margin-right: 5px; vertical-align: 0; }

.empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px 16px;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ---------------------------------------------------------------- type card */
.type-head { margin: 4px 2px 14px; }
.type-code-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.type-code { font-family: var(--mono); font-size: 1.9rem; font-weight: 700; letter-spacing: 0.03em; color: var(--g, var(--text)); }
.type-wants { color: var(--accent); font-size: 0.86rem; }
.type-read { color: var(--muted); font-size: 0.88rem; margin-top: 4px; line-height: 1.45; }

/* two-row strip, scrolls sideways; bleeds to the screen edge so it reads as scrollable */
.tabs {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: auto auto;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -16px 12px;
  padding: 0 16px 4px;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  text-align: left;
}
.tab.sel { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.tab.avoid.sel { color: var(--down); border-color: var(--down); background: var(--down-soft); }

.lines { display: flex; flex-direction: column; gap: 8px; }
.line {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px 6px 2px 14px;
  transition: background 0.25s, border-color 0.25s;
}
.line.copied { background: var(--accent-soft); border-color: var(--accent); }
.line.avoid { border-left: 3px solid var(--down); padding-left: 12px; }
.line-top { display: flex; align-items: flex-start; gap: 4px; }
.line-main { flex: 1; min-width: 0; text-align: left; padding: 11px 0 4px; }
.say { font-family: var(--serif); font-size: 1.08rem; line-height: 1.42; }
.say::before { content: "\201C"; color: var(--accent); }
.say::after { content: "\201D"; color: var(--accent); }
.line.avoid .say::before, .line.avoid .say::after { color: var(--down); }
.line-meta { color: var(--muted); font-size: 0.74rem; margin-top: 5px; }

.heart {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  margin-top: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--muted);
}
.heart svg { width: 20px; height: 20px; }
.heart svg path { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.heart.on { color: var(--accent); }
.heart.on svg path { fill: currentColor; }
.heart:active { transform: scale(0.88); }

.why-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0 9px;
  color: var(--muted);
  font-size: 0.74rem;
}
.why-btn::after { content: "\25BE"; font-size: 0.7rem; transition: transform 0.15s; }
.why-btn.open::after { transform: rotate(180deg); }
.why { color: var(--muted); font-size: 0.84rem; line-height: 1.45; padding: 0 8px 11px 0; }
.why[hidden] { display: none; }

.list-foot { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.hint { color: var(--muted); font-size: 0.74rem; text-align: center; }
.shuffle { color: var(--accent); font-size: 0.78rem; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.shuffle:active { background: var(--panel2); }

/* ---------------------------------------------------------------- favorites */
.fav-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.fav-group-head { display: flex; align-items: baseline; gap: 10px; text-align: left; padding: 6px 2px 0; }
.fav-group-head .mono { font-weight: 700; font-size: 1.05rem; color: var(--g, var(--text)); }

/* ---------------------------------------------------------------- surprise */
.surprise-card {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.surprise-head { display: flex; align-items: baseline; gap: 10px; text-align: left; padding: 2px 2px 10px; }
.surprise-code { font-weight: 700; font-size: 1.3rem; color: var(--g, var(--text)); }
.surprise-card .line { background: var(--panel); }
.surprise-card .say { font-size: 1.22rem; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.btn {
  flex: 1;
  padding: 13px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.btn.ghost { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 600; }
.btn:active { transform: scale(0.99); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
