/* Metabofit — dark-first, thumb-first. Tuned for iPhone 15 Pro Max (430×932pt)
   but fluid enough for any phone or a desktop browser. */

:root {
  --bg:        #0B0E13;
  --surface:   #151A23;
  --surface-2: #1E2530;
  --line:      #2A3340;

  --text:      #E8ECF2;
  --muted:     #8A94A6;

  --accent:    #FF6B35;
  --accent-dim:#3A2318;
  --done:      #3DDC84;
  --partial:   #FFB020;
  --skipped:   #FF5A5A;
  --unlogged:  #4A5666;

  --radius:    16px;
  --radius-sm: 10px;

  /* Nothing interactive is smaller than this. Sweaty thumbs, bad lighting. */
  --tap: 56px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --tabbar-h: 64px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:        #F4F6FA;
    --surface:   #FFFFFF;
    --surface-2: #EDF1F7;
    --line:      #DCE3ED;
    --text:      #131922;
    --muted:     #61708A;
    --accent-dim:#FFEDE4;
    --unlogged:  #B4BECC;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  /* Kill iOS rubber-band so the app feels native, not like a web page. */
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body { -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }

h1 { font-size: 1.65rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1rem; font-weight: 600; margin: 0; }
p  { margin: 0; }

.muted  { color: var(--muted); }
.sm     { font-size: 0.82rem; }
.center { text-align: center; }
.mono   { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.error  { color: var(--skipped); font-size: 0.9rem; }

/* ---------------------------------------------------------------- layout */

.view {
  position: fixed;
  inset: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 18px) 12px calc(var(--safe-l) + 18px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px calc(var(--safe-r) + 16px) 32px calc(var(--safe-l) + 16px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-title { color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.72rem; margin-top: 6px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: var(--tap);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); filter: brightness(1.15); }
.btn-sm { min-height: 40px; font-size: .88rem; padding: 0 12px; }
.btn-lg { min-height: 60px; font-size: 1.05rem; }
.btn-xl { min-height: 76px; font-size: 1.2rem; flex-direction: column; gap: 2px; }
.btn-xl small { font-weight: 500; font-size: .78rem; opacity: .85; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #14100D; }
.btn-warn    { background: var(--partial); border-color: var(--partial); color: #19120A; color: #1A1205; }
.btn-ghost   { background: transparent; }
.btn-ghost.danger { color: var(--skipped); border-color: transparent; }

.btn-done    { background: var(--done);    border-color: var(--done);    color: #06210F; flex: 1.4; }
.btn-partial { background: var(--surface-2); border-color: var(--partial); color: var(--partial); flex: 1; }
.btn-skip    { background: var(--surface-2); border-color: var(--line);    color: var(--muted);   flex: 1; }

.icon-btn {
  background: none; border: 0; color: var(--muted);
  font-size: 1.3rem; width: 44px; height: 44px; cursor: pointer;
}

.chip {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; min-height: 32px; padding: 0 12px; font-size: .78rem;
  font-weight: 600; cursor: pointer;
}
.chip.ok      { color: var(--done);     border-color: color-mix(in srgb, var(--done) 40%, transparent); }
.chip.pending { color: var(--partial);  border-color: color-mix(in srgb, var(--partial) 40%, transparent); }
.chip.offline { color: var(--muted); }

/* ---------------------------------------------------------------- tabbar */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  background: none; border: 0; color: var(--muted);
  font-family: inherit; font-size: .76rem; font-weight: 600; cursor: pointer;
}
.tab.active { color: var(--accent); }

/* ---------------------------------------------------------------- gate */

.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.gate-inner { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px;
  background: var(--accent); color: #14100D;
  display: grid; place-items: center; font-weight: 800; font-size: 1.5rem;
}
.gate input {
  font-family: inherit;
  /* 16px minimum: anything smaller makes iOS Safari zoom on focus. */
  font-size: 16px;
  min-height: var(--tap);
  padding: 0 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  -webkit-user-select: text; user-select: text;
}

/* ---------------------------------------------------------------- today */

.streak { display: flex; align-items: center; gap: 16px; }
.streak-num { font-size: 2.6rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.streak.warn .streak-num { color: var(--partial); }
.streak.cold .streak-num { color: var(--skipped); }
.streak.hot  .streak-num { color: var(--done); }

#resume-banner { display: flex; flex-direction: column; gap: 8px; }

.routine-preview { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.routine-preview li {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 14px;
}
.routine-preview .idx {
  width: 24px; height: 24px; flex: none; border-radius: 7px;
  background: var(--surface-2); color: var(--muted);
  display: grid; place-items: center; font-size: .72rem; font-weight: 700;
}
.routine-preview .nm { flex: 1; font-weight: 600; font-size: .94rem; }
.routine-preview .tg { color: var(--muted); font-size: .8rem; font-family: var(--mono); }
.routine-preview li.is-rest { opacity: .6; }

/* ---------------------------------------------------------------- stats */

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 10px; text-align: center;
}
.stat b { display: block; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.stat span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------------------------------------------------------------- history */

.history-list { display: flex; flex-direction: column; gap: 8px; }
.session-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 13px 14px; cursor: pointer;
  text-align: left; width: 100%; font-family: inherit; color: inherit;
}
.session-row:active { filter: brightness(1.2); }
.session-row .d { font-weight: 700; font-size: .95rem; }
.session-row .meta { flex: 1; }
.session-row .loc { color: var(--muted); font-size: .78rem; }
.session-row.rest-day { opacity: .55; }

.bars { display: flex; gap: 2px; align-items: center; }
.bars i { width: 4px; height: 18px; border-radius: 2px; display: block; }
.b-done { background: var(--done); }
.b-partial { background: var(--partial); }
.b-skipped { background: var(--skipped); }
.b-unlogged { background: var(--unlogged); }

/* ---------------------------------------------------------------- runner */

.runner {
  position: fixed; inset: 0; z-index: 40;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.runner-top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) 10px calc(var(--safe-l) + 12px);
  border-bottom: 1px solid var(--line);
}
.runner-progress { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.progress-track { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .25s ease; }
.elapsed { font-size: .9rem; color: var(--muted); min-width: 48px; text-align: right; }

.runner-card {
  flex: 1; overflow-y: auto;
  padding: 20px calc(var(--safe-r) + 18px) 12px calc(var(--safe-l) + 18px);
  display: flex; flex-direction: column; gap: 16px;
}

.ex-head { display: flex; flex-direction: column; gap: 4px; }
.ex-name { font-size: 1.9rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.ex-sub  { color: var(--muted); font-size: .88rem; }

.lasttime {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; font-size: .88rem;
}
.lasttime b { font-family: var(--mono); }
.pr-flag { color: var(--accent); font-weight: 700; font-size: .8rem; }

/* Big value stepper: the primary interaction in the whole app. */
.stepper { display: flex; flex-direction: column; gap: 8px; }
.stepper-label { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; }
.stepper-row { display: flex; align-items: stretch; gap: 10px; }
.stepper-btn {
  width: 76px; flex: none;
  font-size: 2rem; font-weight: 300; line-height: 1;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text); cursor: pointer;
}
.stepper-btn:active { background: var(--accent); color: #14100D; }
.stepper-val {
  flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); min-height: 72px;
}
.stepper-val b { font-size: 2.3rem; font-weight: 800; font-family: var(--mono); letter-spacing: -.02em; }
.stepper-val span { color: var(--muted); font-size: .9rem; }

.setpills { display: flex; gap: 8px; flex-wrap: wrap; }
.setpill {
  flex: 1; min-width: 84px; min-height: 58px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--muted);
  font-family: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.setpill b { font-size: 1.05rem; color: var(--text); }
.setpill.on { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.setpill.on b { color: var(--accent); }

/* Countdown / interval timer */
.timer-face { text-align: center; padding: 8px 0; }
.timer-time { font-size: 4.4rem; font-weight: 800; font-family: var(--mono); letter-spacing: -.04em; line-height: 1; }
.timer-time.done { color: var(--done); }
.timer-ring { width: 100%; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 12px; }
.timer-ring i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.timer-controls { display: flex; gap: 10px; margin-top: 14px; }
.timer-controls .btn { flex: 1; }

.runner-actions {
  display: flex; gap: 10px;
  padding: 10px calc(var(--safe-r) + 16px) 0 calc(var(--safe-l) + 16px);
}
.runner-actions .btn { min-height: 62px; font-size: 1.05rem; }
.runner-nav {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px calc(var(--safe-r) + 12px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 12px);
}

/* ---------------------------------------------------------------- progress */

.pr-list { display: flex; flex-direction: column; gap: 0; padding: 4px 0; }
.pr-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px; border-bottom: 1px solid var(--line);
}
.pr-row:last-child { border-bottom: 0; }
.pr-row .nm { font-weight: 600; font-size: .92rem; }
.pr-row .when { color: var(--muted); font-size: .74rem; }
.pr-row .val { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; }
.pr-row .delta { font-size: .72rem; color: var(--done); }

.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart-head .nm { font-weight: 600; font-size: .92rem; }
.chart-head .rng { color: var(--muted); font-size: .76rem; font-family: var(--mono); }
.chart-card svg { width: 100%; height: 92px; display: block; overflow: visible; }

.cal-grid { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.cal-week { display: flex; flex-direction: column; gap: 3px; }
.cal-day { width: 13px; height: 13px; border-radius: 3px; background: var(--surface-2); flex: none; }
.cal-day.has { background: var(--done); }
.cal-day.rest { background: var(--unlogged); }
.cal-months { display: flex; gap: 3px; margin-bottom: 5px; font-size: .62rem; color: var(--muted); }
.cal-legend { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: .72rem; color: var(--muted); }

/* ---------------------------------------------------------------- sheet */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.sheet-body {
  position: relative; width: 100%; max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--line);
  padding: 8px calc(var(--safe-r) + 18px) calc(var(--safe-b) + 22px) calc(var(--safe-l) + 18px);
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(22px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }

.detail-entry {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .9rem;
}
.detail-entry:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.detail-entry .nm { flex: 1; }
.detail-entry .vv { font-family: var(--mono); color: var(--muted); font-size: .84rem; }

/* ---------------------------------------------------------------- misc */

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

.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; transition: .2s; cursor: pointer;
}
.switch span::after {
  content: ''; position: absolute; width: 24px; height: 24px; left: 2px; top: 2px;
  background: var(--muted); border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); background: #14100D; }

.card > .btn { width: 100%; margin-bottom: 8px; }
.card > .btn:last-child { margin-bottom: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 11px 20px; font-size: .88rem; font-weight: 600;
  box-shadow: 0 8px 28px rgba(0,0,0,.45); animation: slideup .2s ease;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.pr { background: var(--accent); border-color: var(--accent); color: #14100D; }

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