:root {
  --bg: #0E1712;
  --surface: #17211A;
  --surface-2: #1F2B22;
  --text: #EAEAE2;
  --muted: #8FA091;
  --muted-dim: #5C6B5E;
  --gold: #D4AE5C;
  --gold-dim: #6E5C33;
  --line: #2A362D;
  --callout: #C77B5C;
  --callout-dim: #4A3229;
  --rest: #5F7E8C;
  --rest-dim: #2C4049;
  --freeze: #7FA5C4;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 28px 16px 80px;
  -webkit-tap-highlight-color: transparent;
}
.wrap { width: 100%; max-width: 520px; }

header { text-align: center; margin-bottom: 20px; }
.eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted-dim); margin-bottom: 6px;
}
h1 {
  font-family: 'Fraunces', serif; font-weight: 300; font-style: italic;
  font-size: 22px; color: var(--muted); margin: 0;
}

/* Tabs */
.tabs {
  display: flex; gap: 4px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 24px;
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted-dim);
  font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500;
  padding: 9px 4px; border-radius: 7px; cursor: pointer; transition: all .15s;
}
.tab.active { background: var(--surface-2); color: var(--gold); }
.tab:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* Message card */
.message-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 22px; font-size: 14px; line-height: 1.55;
}
.message-card.callout { border-color: var(--callout); background: var(--callout-dim); color: #F0DED4; }
.message-card .tag {
  display: block; font-family: 'JetBrains Mono', monospace; font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted-dim); margin-bottom: 6px;
}
.message-card.callout .tag { color: var(--callout); }

/* Hero streak */
.hero { text-align: center; padding: 8px 0 16px; }
.streak-number {
  font-family: 'Fraunces', serif; font-weight: 600; font-size: 108px; line-height: 1;
  color: var(--gold); letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.streak-number.zero { color: var(--muted-dim); }
.streak-number.bump { animation: bump .5s cubic-bezier(.34,1.56,.64,1); }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); text-shadow: 0 0 28px rgba(212,174,92,.5); }
  100% { transform: scale(1); }
}
.streak-label {
  font-family: 'JetBrains Mono', monospace; font-size: 12px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin-top: 2px;
}
.chain-svg { width: 100%; height: 18px; margin: 14px 0 6px; opacity: .5; }
.chain-svg line { stroke-dashoffset: 0; }
.chain-svg.animate line { animation: dash 1.2s linear; }
@keyframes dash { from { stroke-dashoffset: 60; } to { stroke-dashoffset: 0; } }
.meta-row {
  display: flex; justify-content: center; gap: 18px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted-dim); margin-top: 14px;
}
.meta-row b { color: var(--muted); font-weight: 500; }

/* Weekly goal ring */
.goal-row {
  display: flex; align-items: center; gap: 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 22px;
}
.goal-ring { flex-shrink: 0; }
.goal-text { flex: 1; }
.goal-title { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.goal-sub { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted-dim); }

.section-label {
  font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted-dim); margin: 26px 0 12px;
}

/* Chips */
.types { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  flex: 1 1 auto; min-width: 92px; background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 14px; font-weight: 500; padding: 13px 10px;
  border-radius: 10px; cursor: pointer; text-align: center; transition: all .15s; user-select: none;
}
.chip:hover { border-color: var(--muted-dim); }
.chip.active { background: var(--surface-2); border-color: var(--gold); color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold-dim); }
.chip.rest.active { border-color: var(--rest); color: var(--rest); box-shadow: inset 0 0 0 1px var(--rest-dim); }
.chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.chip.add { border-style: dashed; color: var(--muted-dim); }

.today-status {
  text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 12px;
  color: var(--muted-dim); margin-top: 14px; min-height: 16px;
}
.today-status.done { color: var(--gold); }

/* Detail inputs */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted-dim);
}
.field input, .field select, .field textarea {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-family: 'Inter', sans-serif; font-size: 14px; padding: 10px 11px; border-radius: 8px;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--gold); }
.field.full { grid-column: 1 / -1; }

/* Calendar */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-nav button {
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1;
}
.cal-nav button:hover { border-color: var(--muted-dim); }
.cal-month { font-family: 'Fraunces', serif; font-size: 17px; color: var(--text); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow {
  text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 9px;
  color: var(--muted-dim); padding-bottom: 4px;
}
.cal-day {
  aspect-ratio: 1; border-radius: 7px; background: var(--surface); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted-dim);
  cursor: pointer; transition: all .12s;
}
.cal-day:hover { border-color: var(--muted-dim); }
.cal-day.empty { background: none; border: none; cursor: default; }
.cal-day.active { background: var(--gold-dim); border-color: var(--gold); color: var(--gold); }
.cal-day.rest { background: var(--rest-dim); border-color: var(--rest); color: var(--rest); }
.cal-day.frozen { background: var(--surface-2); border-color: var(--freeze); color: var(--freeze); }
.cal-day.today { box-shadow: 0 0 0 2px var(--muted-dim); }
.cal-day.future { opacity: .3; cursor: default; }
.cal-legend {
  display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px;
  font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted-dim);
}
.cal-legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot.g { background: var(--gold-dim); border: 1px solid var(--gold); }
.dot.r { background: var(--rest-dim); border: 1px solid var(--rest); }
.dot.f { background: var(--surface-2); border: 1px solid var(--freeze); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 15px;
}
.stat-val {
  font-family: 'Fraunces', serif; font-size: 30px; font-weight: 600; color: var(--gold);
  line-height: 1; font-variant-numeric: tabular-nums;
}
.stat-key {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted-dim); margin-top: 7px;
}
.bars { display: flex; align-items: flex-end; gap: 5px; height: 110px; margin-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; background: var(--gold-dim); border: 1px solid var(--gold);
  border-radius: 4px 4px 0 0; min-height: 3px; transition: height .3s;
}
.bar.empty { background: var(--surface); border-color: var(--line); }
.bar-lbl { font-family: 'JetBrains Mono', monospace; font-size: 9px; color: var(--muted-dim); }
.type-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.type-name { font-size: 13px; width: 100px; flex-shrink: 0; color: var(--muted); }
.type-bar-bg { flex: 1; height: 7px; background: var(--surface); border-radius: 4px; overflow: hidden; }
.type-bar-fill { height: 100%; background: var(--gold); border-radius: 4px; }
.type-count { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted-dim); width: 26px; text-align: right; }

/* Settings */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 14px; }
.setting-hint { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted-dim); margin-top: 3px; line-height: 1.5; }
.btn {
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: .06em;
  padding: 9px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted-dim); }
.btn.gold { border-color: var(--gold); color: var(--gold); }
.btn.danger:hover { border-color: var(--callout); color: var(--callout); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
input.num {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: 14px; width: 56px;
  padding: 8px; border-radius: 8px; text-align: center;
}
input.url {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: 11px; width: 100%;
  padding: 10px; border-radius: 8px; margin-top: 8px;
}

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: flex-end; justify-content: center; z-index: 50;
}
/* The [hidden] attribute sets display:none, but the rule above overrides it.
   This puts it back — without it, an invisible overlay eats every click. */
.sheet-backdrop[hidden] { display: none; }
.toast[hidden] { display: none; }
.sheet {
  background: var(--bg); border: 1px solid var(--line); border-bottom: none;
  border-radius: 16px 16px 0 0; padding: 22px 20px 30px; width: 100%; max-width: 520px;
  animation: slideUp .22s ease; max-height: 88vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { font-family: 'Fraunces', serif; font-weight: 500; font-size: 18px; margin: 0 0 4px; }
.sheet .sub { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted-dim); margin-bottom: 18px; }
.sheet-actions { display: flex; gap: 9px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; text-align: center; padding: 12px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--gold); color: var(--gold);
  font-family: 'JetBrains Mono', monospace; font-size: 12px; padding: 11px 18px;
  border-radius: 9px; z-index: 60; animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

.sync-bar {
  text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: var(--muted-dim); margin-top: 30px; min-height: 14px;
}
.loading { text-align: center; color: var(--muted-dim); font-family: 'JetBrains Mono', monospace; font-size: 13px; padding: 60px 0; }
.empty-note { text-align: center; color: var(--muted-dim); font-size: 13px; padding: 30px 0; line-height: 1.6; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============ v3 additions ============ */

/* Greeting */
.greeting-row { margin-bottom: 14px; }
.greeting {
  font-family: 'Fraunces', serif; font-size: 17px; font-weight: 400;
  color: var(--muted); font-style: italic;
}

/* Daily motivation line */
.daily-line {
  font-family: 'Fraunces', serif; font-style: italic; font-size: 14px;
  color: var(--muted-dim); line-height: 1.5; max-width: 340px;
  margin: 14px auto 0; text-align: center;
}

/* Entrance animations */
.fade-in { animation: fadeUp .35s ease both; }
.fade-in-slow { animation: fadeUp .6s ease .15s both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
main > * { animation: fadeUp .3s ease both; }

/* Chip press feedback */
.chip { transform: scale(1); }
.chip:active { transform: scale(.96); }
.chip.active { animation: chipPop .28s cubic-bezier(.34,1.56,.64,1); }
@keyframes chipPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* Goal ring fill */
.goal-ring circle:last-child {
  transition: stroke-dashoffset .7s cubic-bezier(.4,0,.2,1);
  animation: ringDraw .9s cubic-bezier(.4,0,.2,1) both;
}
@keyframes ringDraw { from { stroke-dashoffset: 126; } }

/* Exercise log */
.vol-badge {
  float: right; color: var(--gold); text-transform: none; letter-spacing: 0;
  font-size: 10px;
}
.ex-list { display: flex; flex-direction: column; gap: 8px; }
.ex-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; cursor: pointer;
  transition: border-color .15s, transform .12s;
  animation: fadeUp .25s ease both;
}
.ex-item:hover { border-color: var(--muted-dim); }
.ex-item:active { transform: scale(.99); }
.ex-main { flex: 1; min-width: 0; }
.ex-name { font-size: 14px; font-weight: 500; color: var(--text); }
.ex-detail {
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
  color: var(--muted-dim); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ex-del {
  background: none; border: none; color: var(--muted-dim);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 6px;
  border-radius: 6px; flex-shrink: 0;
}
.ex-del:hover { color: var(--callout); background: var(--callout-dim); }

.btn-add-ex {
  width: 100%; margin-top: 10px; background: none;
  border: 1px dashed var(--line); color: var(--muted-dim);
  font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500;
  padding: 13px; border-radius: 10px; cursor: pointer; transition: all .15s;
}
.btn-add-ex:hover { border-color: var(--gold); color: var(--gold); }
.btn-add-ex:active { transform: scale(.99); }

/* Strength / cardio toggle */
.kind-toggle {
  display: flex; gap: 4px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px; padding: 4px;
}
.kind {
  flex: 1; background: none; border: none; color: var(--muted-dim);
  font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 500;
  padding: 9px; border-radius: 6px; cursor: pointer; transition: all .15s;
}
.kind.on { background: var(--surface-2); color: var(--gold); }

/* Personal records */
.pr-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.pr-row:last-child { border-bottom: none; }
.pr-name { font-size: 13px; color: var(--text); }
.pr-count {
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: var(--muted-dim); margin-left: 8px;
}
.pr-best {
  font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600;
  color: var(--gold); font-variant-numeric: tabular-nums;
}
.pr-unit {
  font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: var(--muted-dim); margin-left: 3px; font-weight: 400;
}

/* Welcome */
.welcome { text-align: center; }
.welcome-mark { margin-bottom: 14px; animation: linkIn .7s cubic-bezier(.34,1.56,.64,1) both; }
@keyframes linkIn {
  from { opacity: 0; transform: scale(.7) rotate(-8deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}
.welcome h3 {
  font-family: 'Fraunces', serif; font-style: italic; font-weight: 300;
  font-size: 26px; color: var(--gold); margin: 0 0 16px;
}
.welcome p {
  font-size: 14px; line-height: 1.6; color: var(--muted);
  margin: 0 0 12px; max-width: 380px; margin-inline: auto;
}
.welcome-list {
  list-style: none; padding: 0; margin: 22px auto 4px; max-width: 380px; text-align: left;
}
.welcome-list li {
  font-size: 13px; line-height: 1.5; color: var(--muted-dim);
  padding: 11px 0 11px 18px; border-bottom: 1px solid var(--line); position: relative;
}
.welcome-list li:last-child { border-bottom: none; }
.welcome-list li::before {
  content: ''; position: absolute; left: 0; top: 17px;
  width: 6px; height: 6px; border-radius: 2px; background: var(--gold-dim); border: 1px solid var(--gold);
}
.welcome-list b { color: var(--muted); font-weight: 600; }

/* Confetti (PR celebration) */
.confetti-box {
  position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden;
}
.confetti-box i {
  position: absolute; top: -12px; width: 7px; height: 11px;
  background: var(--gold); border-radius: 2px; opacity: .9;
  animation: fall linear forwards;
}
.confetti-box i:nth-child(3n) { background: var(--freeze); }
.confetti-box i:nth-child(4n) { background: var(--muted); width: 5px; height: 5px; border-radius: 50%; }
@keyframes fall {
  to { transform: translateY(102vh) translateX(var(--drift)) rotate(540deg); opacity: 0; }
}

.footer-note {
  text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 10px;
  color: var(--muted-dim); line-height: 1.7; margin-top: 40px; padding-top: 24px;
  border-top: 1px solid var(--line);
}

/* Sheet inputs get a bit more room on mobile */
@media (max-width: 480px) {
  .sheet { padding: 20px 16px 28px; }
}
