/* ---------- Design tokens ---------- */
:root,
[data-theme="dark"] {
  --bg: #16140f;
  --surface: #201d17;
  --surface-2: #2a261c;
  --border: #3a3529;
  --text: #f2ede1;
  --text-dim: #a89d89;
  --accent: #e8a33d;
  --accent-ink: #1a1408;
  --danger: #c1443a;
  --success: #7a9f6a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

[data-theme="light"] {
  --bg: #f6f1e7;
  --surface: #ffffff;
  --surface-2: #efe8d8;
  --border: #ddd3bd;
  --text: #211d15;
  --text-dim: #6f6552;
  --accent: #b5762a;
  --accent-ink: #fff8ec;
  --danger: #a83226;
  --success: #4c7a44;
  --shadow: 0 8px 24px rgba(60,50,20,0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

h1, h2, h3 {
  font-family: inherit;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { color: var(--text-dim); margin: 0 0 8px; line-height: 1.45; }
a { color: var(--accent); }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
}

/* ---------- App shell ---------- */
#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px 16px 96px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 18px;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
}
.plate-mark {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  position: relative;
}
.plate-mark::after {
  content: "";
  position: absolute; inset: 7px;
  border-radius: 50%;
  background: var(--bg);
}

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 6px 2px 4px;
  border-radius: var(--radius-sm);
}
.bottom-nav a .icon { display: block; font-size: 1.15rem; margin-bottom: 2px; }
.bottom-nav a.active { color: var(--accent); background: var(--surface-2); }

/* ---------- Building blocks ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card.tappable { cursor: pointer; }
.card.tappable:active { transform: scale(0.99); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-dim); margin: 10px 0 4px; }
label:first-child { margin-top: 0; }

.field-row { display: flex; gap: 8px; }
.field-row > div { flex: 1; }

.tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  margin: 0 4px 4px 0;
}
.tag.accent { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

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

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 0 10px;
}
.section-head:first-child { margin-top: 0; }

/* ---------- Drag handles / reorder ---------- */
.block-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 10px;
  margin-bottom: 8px;
}
.block-item.dragging { opacity: 0.4; }
.drag-handle { cursor: grab; color: var(--text-dim); padding: 0 6px; user-select: none; }
.superset-wrap { border-left: 3px solid var(--accent); padding-left: 8px; margin: 6px 0; }

/* ---------- Session runner ---------- */
.timer-ring-wrap { display: flex; justify-content: center; margin: 18px 0; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat-grid .num { font-size: 1.3rem; font-weight: 800; }
.stat-grid .label { font-size: 0.65rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

.rep-counter {
  display: flex; align-items: center; justify-content: center; gap: 18px; margin: 14px 0;
}
.rep-counter .count { font-size: 2.4rem; font-weight: 800; min-width: 70px; text-align: center; }
.round-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  border: none; font-size: 1.5rem; font-weight: 800; cursor: pointer;
}

.pr-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--danger); color: #fff;
  font-size: 0.68rem; font-weight: 800;
  padding: 2px 8px; border-radius: 999px;
}

/* ---------- Charts ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar-chart .bar { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bar-chart .bar .bar-label { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 0.6rem; color: var(--text-dim); }

.streak-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.streak-cell { aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.streak-cell.done { background: var(--accent); border-color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow);
  font-size: 0.85rem; font-weight: 600; z-index: 40;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

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