/* Provenance — data-dense, phone-first, theme-able.
 *
 * Themes swap the nine core colors below; the soft tints derive via color-mix.
 * Semantic meaning never moves between themes: green = boosts size, red = cuts
 * size (shades may tune per theme, meaning is sacred).
 */

:root {                    /* default: Royal — royal blue & gold */
  --bg: #0d1322;
  --panel: #15203a;
  --panel2: #1d2b4e;
  --line: #2b3c66;
  --text: #e9ecf5;
  --muted: #96a2c4;
  --accent: #d9b45b;
  --up: #66c98a;
  --down: #e0716f;
}

html[data-theme="ember"] { /* the original warm-dark launch scheme */
  --bg: #111318;
  --panel: #191c24;
  --panel2: #222633;
  --line: #2a2f3c;
  --text: #eae7e0;
  --muted: #9298a8;
  --accent: #e5a558;
  --up: #69c98a;
  --down: #e0716f;
}

html[data-theme="ice"] {
  --bg: #0d1418;
  --panel: #141d23;
  --panel2: #1c2830;
  --line: #263540;
  --text: #e4ebee;
  --muted: #8fa3ad;
  --accent: #56c3dc;
  --up: #69c98a;
  --down: #e0716f;
}

html[data-theme="nocturne"] {
  --bg: #141020;
  --panel: #1c1730;
  --panel2: #262040;
  --line: #322a52;
  --text: #eae6f2;
  --muted: #9d94b8;
  --accent: #a78bda;
  --up: #69c98a;
  --down: #e0716f;
}

html[data-theme="paper"] { /* light */
  --bg: #f5f2ec;
  --panel: #fdfbf7;
  --panel2: #ece6d8;
  --line: #d8d1c0;
  --text: #29261f;
  --muted: #7a7468;
  --accent: #8a6d1d;
  --up: #1a8f4a;
  --down: #c04543;
}

: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: 14px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { 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; }

/* ---------------------------------------------------------------- home */
.home-head { margin: 6px 2px 16px; }
.home-head h1 { font-size: 1.45rem; letter-spacing: 0.01em; }
.tagline { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

.btn-new {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
}
.btn-new:active { transform: scale(0.99); }

.cards { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  color: inherit;
}
.card:active { background: var(--panel2); }
.card-left { flex: 1; min-width: 0; }
.card-name { font-weight: 600; font-size: 0.98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--muted); font-size: 0.75rem; margin-top: 4px; }
.card-right { text-align: right; }
.card-lots { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.35rem; font-weight: 700; }
.card-lots-label { color: var(--muted); font-size: 0.7rem; }

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

.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); }

.home-foot { margin-top: 18px; display: flex; align-items: center; gap: 10px; justify-content: center; }
.link-btn { color: var(--accent); font-size: 0.85rem; padding: 6px 2px; }
.dot { color: var(--muted); }
.foot-note { color: var(--muted); font-size: 0.72rem; text-align: center; margin-top: 8px; line-height: 1.5; }

/* --------------------------------------------------------------- trade */
.trade-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.back {
  font-size: 1.7rem;
  line-height: 1;
  color: var(--accent);
  text-decoration: none;
  padding: 4px 10px 8px 2px;
}
.name-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;             /* ≥16px stops iOS focus zoom */
  font-weight: 600;
  padding: 8px 2px;
  border-radius: 0;
}
.name-input:focus { outline: none; border-bottom-color: var(--accent); }
.name-input::placeholder { color: var(--muted); font-weight: 400; }

.result {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(env(safe-area-inset-top) + 6px) 0 10px;
  background: var(--bg);
}
.result::after {           /* soft edge below the solid sticky block */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 14px;
  background: linear-gradient(180deg, var(--bg), transparent);
  pointer-events: none;
}
.result-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.result-left { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.r-row { display: flex; align-items: baseline; gap: 8px; }
.r-label { color: var(--muted); font-size: 0.72rem; min-width: 86px; }
.r-val { font-size: 0.95rem; }
.result-right { text-align: right; }
.r-lots { font-size: 2rem; font-weight: 700; line-height: 1.05; }
.r-lots-label { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }
.r-floor { color: var(--accent); font-size: 0.75rem; margin-top: 3px; font-family: var(--mono); }
.result-hint { color: var(--muted); font-size: 0.75rem; text-align: center; padding-top: 8px; }
.result-hint:empty { display: none; }

.commit-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.commit-info { color: var(--muted); font-size: 0.72rem; flex: 1; }
.commit-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 7px 16px;
}
.commit-btn:disabled {
  background: var(--panel);
  color: var(--muted);
  border-color: var(--line);
  opacity: 0.7;
}

/* -------------------------------------------------------------- factors */
.factors { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.factor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px 12px;
  transition: opacity 0.15s ease;
}
.factor.skipped { opacity: 0.5; }

.factor-head { display: flex; align-items: center; gap: 8px; }
.flabel { font-weight: 600; font-size: 0.92rem; }
.fbounds { color: var(--muted); font-size: 0.7rem; }
.skip-btn {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
}
.factor.skipped .skip-btn { color: var(--accent); border-color: var(--accent); }
.fchip {
  font-size: 0.82rem;
  padding: 3px 9px;
  border-radius: 999px;
  min-width: 62px;
  text-align: center;
}
.chip-neutral { background: var(--panel2); color: var(--muted); }
.chip-boost { background: var(--up-soft); color: var(--up); }
.chip-cut { background: var(--down-soft); color: var(--down); }

.factor-ctl { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

.nudge {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
}
.nudge:active { color: var(--accent); border-color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--panel2) var(--fill, 50%));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
}
.factor.skipped input[type="range"] { filter: grayscale(1); }

.factor-number .num-input {
  width: 100%;
  margin-top: 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;              /* ≥16px stops iOS focus zoom */
  padding: 11px 12px;
  text-align: right;
}
.num-input:focus { outline: none; border-color: var(--accent); }
.num-input.invalid { border-color: var(--down); }
.num-input::placeholder { color: var(--muted); }

.divide-rule { display: flex; align-items: center; gap: 10px; margin: 6px 2px 0; }
.divide-line { flex: 1; height: 1px; background: var(--line); }
.divide-label { color: var(--accent); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; }

/* ---------------------------------------------------------------- misc */
.notes {
  width: 100%;
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 11px 12px;
  resize: vertical;
}
.notes:focus { outline: none; border-color: var(--accent); }
.notes::placeholder { color: var(--muted); }

.history { margin-top: 18px; }
.history-head {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin: 0 2px 8px;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }
.hist-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.hist-main { display: flex; align-items: baseline; gap: 10px; cursor: pointer; }
.hist-ts { font-size: 0.82rem; flex: 1; }
.hist-meta { color: var(--muted); font-size: 0.75rem; }
.hist-lots { font-size: 0.9rem; font-weight: 700; }
.hist-detail { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.hist-f {
  color: var(--muted);
  font-size: 0.7rem;
  background: var(--panel2);
  border-radius: 6px;
  padding: 3px 7px;
}

.trade-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn-ghost, .btn-danger {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.9rem;
}
.btn-ghost:active { border-color: var(--accent); color: var(--accent); }
.btn-danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 35%, transparent); }
.btn-danger:active { background: var(--down-soft); }
