:root {
  --bg: #f6f5f2; --card: #ffffff; --ink: #17181c; --muted: #6b6f78; --line: #e6e4df; --soft: #efede8;
  --accent: #f25f3a; --accent-ink: #ffffff; --accent-soft: #fde5dd; --good: #1f9d6b; --good-soft: #dcf3e9; --bad: #d64545;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 16px; --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131417; --card: #1c1d22; --ink: #f2f2f3; --muted: #9a9ea8; --line: #2b2d34; --soft: #24262c;
    --accent: #ff7a55; --accent-ink: #1a0d08; --accent-soft: #3a2119; --good: #3ccf91; --good-soft: #15342a; --bad: #ff6b6b;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131417; --card: #1c1d22; --ink: #f2f2f3; --muted: #9a9ea8; --line: #2b2d34; --soft: #24262c;
  --accent: #ff7a55; --accent-ink: #1a0d08; --accent-soft: #3a2119; --good: #3ccf91; --good-soft: #15342a; --bad: #ff6b6b;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
html { -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }

/* layout */
.shell { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); min-height: 100vh; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 12px; }
.top h1 { font-size: 28px; letter-spacing: -.02em; margin: 0; }
.top .sub { color: var(--muted); font-size: 14px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; font-size: 18px; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabs-inner { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 560px; }
.tab { border: 0; background: none; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }

/* cards and controls */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px; margin-bottom: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; font-weight: 700; }
.btn { border: 0; border-radius: 14px; min-height: 52px; padding: 0 18px; font-weight: 700; font-size: 17px; background: var(--soft); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; font-size: 15px; padding: 0 14px; border-radius: 12px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
/* Include typeless inputs (the code field was missing type=, so it skipped this rule
   and kept iOS's native min-width, black dark-mode fill, and blue focus ring). */
input[type=text], input[type=email], input[type=number], input[type=search], input[type=tel],
input[type=datetime-local], input:not([type]), .code-input, select, textarea {
  width: 100%; max-width: 100%; min-width: 0;
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink); padding: 10px 12px; font-size: 17px;
  outline: none; box-sizing: border-box;
  -webkit-appearance: none; appearance: none;
}
select, input[type=datetime-local] { -webkit-appearance: auto; appearance: auto; } /* keep the native chevron / date picker */
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
input::placeholder, textarea::placeholder { color: var(--muted); -webkit-text-fill-color: var(--muted); opacity: 1; }
textarea { min-height: 80px; resize: vertical; }
label.field { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 12px 2px 6px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; min-height: 40px; padding: 0 14px; font-size: 15px; font-weight: 600; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tag { display: inline-block; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--soft); border-radius: 6px; padding: 2px 7px; margin: 2px 4px 0 0; text-transform: capitalize; }

/* exercise list */
.ex-item { color: var(--ink); display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: var(--card); border-top: 1px solid var(--line); padding: 12px 14px; min-height: 64px; }
.ex-list { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); margin-bottom: 12px; }
.ex-list .ex-item:first-child { border-top: 0; }
.ex-item .name { font-weight: 650; font-size: 16px; }
.ex-item .meta { font-size: 13px; color: var(--muted); }
.best-pill { margin-left: auto; text-align: right; flex: none; }
.best-pill b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.best-pill span { font-size: 12px; color: var(--muted); }
.best-pill.none b { color: var(--muted); font-weight: 500; font-size: 14px; }

/* steppers */
.stepper { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; background: var(--soft); border-radius: 14px; height: 56px; }
.stepper button { height: 56px; border: 0; background: none; font-size: 26px; font-weight: 500; color: var(--ink); }
.stepper input { border: 0 !important; background: transparent !important; box-shadow: none !important; text-align: center; font-size: 24px; font-weight: 750; padding: 0; min-height: 0; height: 56px; font-variant-numeric: tabular-nums; width: 100%; }
.stepper-label { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; font-weight: 600; }
.log-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* workout */
.wo-head { display: flex; justify-content: space-between; align-items: baseline; }
.wo-head h2 { margin: 0; font-size: 22px; }
.wo-ex h3 { margin: 0 0 2px; font-size: 18px; }
.target { font-size: 14px; color: var(--muted); }
.target b { color: var(--ink); }
.sets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.set-chip { border: 1px solid var(--line); background: var(--soft); border-radius: 10px; padding: 6px 10px; font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
.set-chip.best { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.set-chip small { color: var(--muted); font-weight: 600; margin-right: 4px; }
.hero { text-align: center; padding: 28px 16px; }
.hero h2 { margin: 6px 0; font-size: 22px; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; animation: fade .15s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg); border-radius: 22px 22px 0 0; max-height: 92vh; overflow-y: auto; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .2s ease-out; max-width: 560px; margin: 0 auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin: 4px 0 2px; font-size: 22px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }
.note-text { white-space: pre-wrap; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--soft); border-radius: 10px; padding: 10px; color: var(--muted); }
.big-best { font-size: 36px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 650; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 90vw; animation: up .2s; }
.toast.best { background: var(--good); color: #fff; }

/* history */
.hist-item { color: var(--ink); display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.hist-item .when { font-size: 13px; color: var(--muted); font-weight: 600; }
.hist-item .title { font-weight: 700; font-size: 17px; margin: 2px 0; }
.stat-row { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.stat-row b { color: var(--ink); }

/* weight */
.kg-display { font-size: 48px; font-weight: 800; text-align: center; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kg-input { text-align: center; font-size: 44px !important; font-weight: 800; height: 72px; border: 0 !important; background: transparent !important; box-shadow: none !important; padding: 0 !important; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 4px; }
.stat { background: var(--soft); border-radius: 12px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.chart { width: 100%; height: 240px; display: block; touch-action: pan-y; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .pt { fill: var(--accent); }
.chart .raw { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: .55; }
.chart .gap { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .6; }
.chart .trend { fill: none; stroke: var(--ink); stroke-width: 2.25; opacity: .8; }
.chart .hover line { stroke: var(--muted); stroke-dasharray: 2 3; }
.chart .hover circle { fill: var(--card); stroke: var(--accent); stroke-width: 2.5; }
.chart-tip { font-size: 13px; color: var(--muted); text-align: center; min-height: 20px; }
.w-item { color: var(--ink); display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: var(--card); padding: 12px 14px; min-height: 56px; }
.w-item:first-child { border-top: 0; }
.w-item b { font-size: 17px; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--bad); } .delta-down { color: var(--good); }

/* sign-in */
.signin { max-width: 400px; margin: 12vh auto 0; padding: 0 20px; }
.signin .logo { width: 56px; height: 56px; }
.signin h1 { font-size: 30px; margin: 14px 0 6px; letter-spacing: -.02em; }
.code-input {
  display: block; width: 100%; max-width: 100%; min-width: 0;
  text-align: center; font-size: 24px !important; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: 0.35em;
  text-indent: 0.35em; /* offsets the trailing letter-spacing so the 6 digits stay centered */
  padding: 12px;
}
.code-input::placeholder { letter-spacing: 0.35em; text-indent: 0.35em; text-align: center; }
.msg { color: var(--bad); font-size: 15px; min-height: 20px; margin: 10px 2px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 0; }
