/* Page Turners. Mobile-first, light + dark, each reader's color as the accent.
   Deliberately conservative CSS (no :has, no container queries, no nesting)
   so a Kindle Fire's Silk browser renders it. */

:root {
  --bg: #fbf7f0;
  --card: #ffffff;
  --card-2: #f3eee4;
  --line: #e4dccd;
  --text: #22201c;
  --muted: #6f685c;
  --accent: #4f7cff;
  --accent-ink: #ffffff;
  --good: #2b9a66;
  --warn: #c77700;
  --bad: #d64545;
  --heat-0: #efe9de;
  --heat-1: color-mix(in srgb, var(--accent) 25%, var(--heat-0));
  --heat-2: color-mix(in srgb, var(--accent) 50%, var(--heat-0));
  --heat-3: color-mix(in srgb, var(--accent) 75%, var(--heat-0));
  --heat-4: var(--accent);
  --radius: 18px;
  --tap: 52px;
  --shadow: 0 2px 10px rgba(60, 40, 10, 0.08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --card: #1f2229;
    --card-2: #282c35;
    --line: #353a45;
    --text: #f1eee8;
    --muted: #a7a196;
    --heat-0: #2a2e37;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  }
}

/* Fallback for browsers without color-mix: fixed opacity overlays. */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .heat-1 { background: var(--accent) !important; opacity: 0.35; }
  .heat-2 { background: var(--accent) !important; opacity: 0.55; }
  .heat-3 { background: var(--accent) !important; opacity: 0.78; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
body { padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }

a { color: var(--accent); }
.wrap { max-width: 760px; margin: 0 auto; padding: 12px 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.tiny { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { height: 12px; }
.err { color: var(--bad); font-weight: 600; min-height: 1.2em; }

h1 { font-size: 28px; margin: 10px 0 6px; line-height: 1.2; }
h2 { font-size: 21px; margin: 18px 0 8px; }
h3 { font-size: 18px; margin: 0 0 6px; }

/* ---- header ---- */
header.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
header.bar .brand { font-weight: 800; font-size: 20px; letter-spacing: 0.2px; }
header.bar .brand .dot { color: var(--accent); }
header.bar .me-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 4px 14px 4px 6px; border-radius: 999px;
  border: 2px solid var(--accent); background: var(--card); color: var(--text);
  font: inherit; font-weight: 700; cursor: pointer;
}
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); font-size: 21px; line-height: 1; flex: 0 0 auto;
}
.avatar.big { width: 84px; height: 84px; font-size: 48px; }

/* ---- cards and buttons ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow);
}
.card.accent { border: 2px solid var(--accent); }

button, .btn {
  font: inherit; font-weight: 700; cursor: pointer;
  min-height: var(--tap); padding: 10px 18px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--card-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; -webkit-tap-highlight-color: transparent;
}
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.small, .btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; border-radius: 12px; }
button:disabled { opacity: 0.5; cursor: default; }
button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 2px solid var(--line); border-radius: 12px;
  min-height: 48px; padding: 8px 12px; width: 100%;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: 15px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }

/* ---- quick log ---- */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick-grid button { min-height: 68px; font-size: 24px; }
.quick-grid button.plus { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 1 auto; min-height: 46px; }

.big-number { font-size: 44px; font-weight: 800; line-height: 1; }
.timer-face { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; letter-spacing: 1px; }

.progress { height: 16px; border-radius: 999px; background: var(--heat-0); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s ease; }
.progress.thin { height: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card-2); border-radius: 14px; padding: 12px; }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.book { display: flex; gap: 12px; align-items: flex-start; }
.cover {
  width: 64px; height: 96px; border-radius: 8px; object-fit: cover; flex: 0 0 auto;
  background: var(--card-2); display: flex; align-items: center; justify-content: center; font-size: 30px;
}
.book .t { font-weight: 800; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); }

.tabs { display: flex; gap: 6px; margin: 0 0 12px; }
.tabs button { flex: 1 1 0; min-height: 46px; font-size: 16px; }

/* ---- bottom tab bar ---- */
nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
nav.tabbar button {
  flex: 1 1 0; border: 0; border-radius: 0; background: transparent; min-height: 66px;
  flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); padding: 6px 0;
}
nav.tabbar button .ic { font-size: 24px; line-height: 1; }
nav.tabbar button.active { color: var(--accent); }
nav.tabbar button.active .ic { transform: scale(1.12); }

/* ---- picker ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  overflow-y: auto; padding: 24px 16px;
}
.picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; max-width: 560px; margin: 0 auto; }
.picker button {
  flex-direction: column; min-height: 170px; border-radius: 22px; font-size: 22px;
  background: var(--card); border: 3px solid var(--line);
}
.picker button:hover, .picker button:focus-visible { border-color: var(--pc, var(--accent)); }

/* ---- modal ---- */
.modal-bg {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 700px) {
  .modal-bg { align-items: center; }
  .modal { border-radius: 22px; }
}

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 70;
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 14px; font-weight: 700; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px);
}
.toast button { min-height: 36px; padding: 4px 10px; background: transparent; color: inherit; border-color: currentColor; }

/* ---- calendar ---- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .hd { text-align: center; font-size: 13px; color: var(--muted); font-weight: 700; }
.cal .cell {
  aspect-ratio: 1 / 1; min-height: 42px; border-radius: 10px; background: var(--heat-0);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 13px; border: 2px solid transparent; padding: 0; cursor: pointer; color: var(--text);
}
.cal .cell .d { font-size: 12px; opacity: 0.75; font-weight: 600; }
.cal .cell .m { font-weight: 800; font-size: 15px; }
.cal .cell.today { border-color: var(--text); }
.cal .cell.sel { outline: 3px solid var(--accent); }
.heat-1 { background: var(--heat-1) !important; }
.heat-2 { background: var(--heat-2) !important; }
.heat-3 { background: var(--heat-3) !important; color: var(--accent-ink) !important; }
.heat-4 { background: var(--heat-4) !important; color: var(--accent-ink) !important; }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart .bar { fill: var(--accent); }
svg.chart .bar.zero { fill: var(--heat-0); }
svg.chart text { fill: var(--muted); font-size: 12px; font-family: inherit; }
svg.chart text.v { fill: var(--text); font-weight: 700; }
svg.chart line.goal { stroke: var(--warn); stroke-width: 2; stroke-dasharray: 5 4; }

/* ---- badges ---- */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 14px; background: var(--card-2); }
.badge .e { font-size: 34px; line-height: 1.1; }
.badge .n { font-weight: 800; font-size: 14px; }
.badge .h { font-size: 12px; color: var(--muted); }
.badge.locked .e { filter: grayscale(1); opacity: 0.35; }
.badge.locked .n { color: var(--muted); }

.stars { display: flex; gap: 6px; justify-content: center; }
.stars button { font-size: 34px; min-height: 60px; min-width: 56px; padding: 0; background: transparent; border: 0; }

@media (min-width: 560px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .badges { grid-template-columns: repeat(4, 1fr); }
  .picker { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- v2: coach, Libby, inbox ---- */
header.bar .bell {
  position: relative; min-height: 44px; min-width: 44px; padding: 4px 10px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--card); font-size: 20px; margin-left: auto;
}
header.bar .bell + .me-chip { margin-left: 0; }
header.bar .bell .count {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 12px; font-weight: 800; line-height: 20px; text-align: center; padding: 0 5px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--card-2); color: var(--text); }
.chip.good { background: var(--good); color: #fff; }
.chip.warn { background: var(--warn); color: #fff; }
.chip.muted { color: var(--muted); }
.chip.label-sure_bet { background: var(--good); color: #fff; }
.chip.label-stretch { background: var(--warn); color: #fff; }
.chip.label-wildcard { background: #8e6cff; color: #fff; }
.due-soon { color: var(--bad); font-weight: 800; }
.why { margin: 6px 0 0; font-size: 15px; }
.connection { margin: 4px 0 0; font-size: 14px; color: var(--muted); font-style: italic; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 88%; padding: 10px 12px; border-radius: 16px; font-size: 16px; white-space: pre-wrap; }
.bubble.coach { background: var(--card-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 4px; }
.thinking { color: var(--muted); font-style: italic; }
.notice { border-left: 4px solid var(--accent); padding-left: 10px; }
