/* Broseidon — one stylesheet, no build step.
   Design constraints that drove this:
     * Used mid-workout with sweaty hands → every tap target >= 48px.
     * Used in a bright gym and a dark one → high contrast, dark base.
     * iOS zooms any input under 16px on focus → no font-size below 16px
       on anything the user types into.                                    */

:root {
  --bg:        #071620;
  --bg-raise:  #0d2432;
  --bg-card:   #102c3d;
  --bg-input:  #0a1e2a;
  --line:      #1c4257;

  --ink:       #e8f4fa;
  --ink-dim:   #8fb0c2;
  --ink-faint: #5b7c8f;

  --sea:       #1a9cc4;   /* primary — Poseidon blue */
  --sea-deep:  #12718f;
  --gold:      #f2b544;   /* accent — the trident */
  --good:      #35c48b;
  --bad:       #ef5f5f;

  --r:   14px;
  --r-s: 10px;

  --tap: 48px;            /* minimum interactive height */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: calc(62px + var(--safe-b));
  --top-h:  calc(54px + var(--safe-t));
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 40;
  height: var(--top-h); padding: var(--safe-t) 8px 0;
  display: flex; align-items: center; gap: 4px;
  background: rgba(7, 22, 32, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar__title {
  flex: 1; margin: 0; font-size: 18px; font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar__back {
  width: 40px; height: 40px; flex: none;
  background: none; border: 0; color: var(--sea);
  font-size: 30px; line-height: 1; padding: 0 0 4px;
}
.topbar__right { display: flex; gap: 6px; align-items: center; flex: none; }

/* ---------- screens ---------- */
.app {
  padding: calc(var(--top-h) + 12px) 14px calc(var(--tabs-h) + 20px);
  max-width: 720px; margin: 0 auto;
}
.screen[hidden] { display: none; }
/* Opacity only — deliberately NO transform. A transformed ancestor becomes the
   containing block for position:fixed descendants, which silently re-anchors
   the chat composer (and anything else fixed inside a screen) to the section
   instead of the viewport. */
.screen { animation: fade .16s ease-out; }
@keyframes fade { from { opacity: 0; } }

/* ---------- bottom tabs ---------- */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 40;
  height: var(--tabs-h); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(7, 22, 32, .94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  background: none; border: 0; color: var(--ink-faint);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 0;
}
.tab__ico { font-size: 20px; line-height: 1; filter: grayscale(1) opacity(.65); }
.tab__lbl { font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.tab.is-active { color: var(--sea); }
.tab.is-active .tab__ico { filter: none; }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--r-s);
  background: var(--bg-card); color: var(--ink);
  font-size: 16px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .06s, filter .12s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn--primary { background: var(--sea); color: #04141c; }
.btn--gold    { background: var(--gold); color: #2a1c00; }
.btn--ghost   { background: transparent; border-color: var(--line); color: var(--ink-dim); }
.btn--danger  { background: var(--bad); color: #2a0808; }
.btn--lg      { min-height: 56px; font-size: 17px; }
.btn--block   { width: 100%; }
.btn--sm      { min-height: 44px; padding: 0 14px; font-size: 14px; }

/* ---------- inputs ---------- */
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  background: var(--bg-input); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-s);
  font-size: 16px;            /* < 16px makes iOS zoom on focus */
  appearance: none; -webkit-appearance: none;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--sea);
  box-shadow: 0 0 0 3px rgba(26, 156, 196, .2);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }
.input--lg { min-height: 56px; font-size: 17px; }
.input--num { text-align: center; font-variant-numeric: tabular-nums; font-weight: 650; }
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%),
                    linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: right 18px center, right 13px center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 34px;
}
.label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-dim); margin: 0 0 6px 2px; }
.field { margin-bottom: 14px; }

/* ---------- cards & layout ---------- */
.card {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; margin-bottom: 12px;
}
.card--flat { background: var(--bg-raise); }
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.card__title { margin: 0; font-size: 16px; font-weight: 650; }

.row { display: flex; gap: 10px; align-items: center; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.h2 { font-size: 15px; font-weight: 650; color: var(--ink-dim);
      text-transform: uppercase; letter-spacing: .06em; margin: 22px 0 10px 2px; }
.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); font-size: 14px; }
.num   { font-variant-numeric: tabular-nums; }

.empty {
  text-align: center; padding: 40px 20px; color: var(--ink-faint);
}
.empty__ico { font-size: 36px; display: block; margin-bottom: 10px; opacity: .5; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-raise); border: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--ink-dim);
}
.pill--live { background: rgba(53, 196, 139, .16); border-color: var(--good); color: var(--good); }
.pill--gold { background: rgba(242, 181, 68, .14); border-color: var(--gold); color: var(--gold); }

/* ---------- lock ---------- */
.lock {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(170deg, #0a2130, var(--bg) 62%);
  display: grid; place-items: center; padding: 24px;
}
.lock[hidden] { display: none; }
.lock__inner { width: 100%; max-width: 340px; text-align: center; }
.lock__mark { color: var(--gold); margin-bottom: 6px; }
.lock__title { margin: 0; font-size: 30px; font-weight: 750; letter-spacing: -.02em; }
.lock__tag { margin: 2px 0 26px; color: var(--ink-faint); font-size: 14px; font-style: italic; }
.lock__form > * + * { margin-top: 10px; }
.lock__hint { color: var(--ink-dim); font-size: 14px; margin: 0 0 4px; }
.lock__err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 0; }
.lock__link {
  background: none; border: 0; color: var(--ink-faint);
  font-size: 13px; text-decoration: underline; padding: 12px; min-height: 44px;
}

.diag { margin-top: 14px; text-align: left; }
.diag[hidden] { display: none; }
.diag__out {
  background: var(--bg-input); border: 1px solid var(--line); border-radius: var(--r-s);
  padding: 10px; margin: 0 0 10px;
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink-dim);
  max-height: 44vh; overflow: auto; -webkit-overflow-scrolling: touch;
  white-space: pre-wrap; word-break: break-word;
  user-select: text; -webkit-user-select: text;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed; left: 0; right: 0; top: calc(var(--top-h) + 8px);
  z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 14px;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--r-s); padding: 11px 16px; font-size: 15px; font-weight: 550;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateY(-10px); transition: opacity .2s, transform .2s;
  max-width: 100%;
}
.toast.is-in { opacity: 1; transform: none; }
.toast--error { border-color: var(--bad); color: #ffdcdc; }
.toast--good  { border-color: var(--good); color: #d3f7e8; }

/* ---------- active workout ---------- */

/* Rest timer. Counts up from the last set; sticks under the top bar so it's
   readable without scrolling back up. */
.rest {
  position: sticky; top: calc(var(--top-h) + 4px); z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-raise); border: 1px solid var(--sea-deep);
  border-radius: var(--r-s); padding: 8px 8px 8px 14px; margin-bottom: 12px;
}
.rest[hidden] { display: none; }
.rest__lbl { font-size: 13px; font-weight: 650; color: var(--ink-dim);
             text-transform: uppercase; letter-spacing: .07em; }
.rest__val { flex: 1; font-size: 22px; font-weight: 700; color: var(--sea); }
.rest__x {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-faint); font-size: 15px;
}

.exblock {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; margin-bottom: 12px;
  width: 100%; display: block; text-align: left;
}
.exblock--collapsed {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); background: var(--bg-raise); color: var(--ink);
}
.exblock--active { border-color: var(--sea-deep); }
.exblock__head { display: flex; align-items: center; justify-content: space-between;
                 gap: 10px; margin-bottom: 12px; }
.exblock__name { margin: 0; font-size: 17px; font-weight: 650; }

/* Entry pad */
.pad { margin-bottom: 12px; }
.pad__row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pad__lbl {
  width: 46px; flex: none; font-size: 13px; font-weight: 650;
  color: var(--ink-dim); text-transform: uppercase; letter-spacing: .05em;
}
.pad__row--rpe { margin-bottom: 0; }

.stepper { flex: 1; display: flex; align-items: stretch; gap: 8px; min-width: 0; }
.stepper__btn {
  width: 58px; flex: none; border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--bg-raise); color: var(--sea);
  font-size: 26px; font-weight: 600; line-height: 1; padding: 0;
}
.stepper__btn:active { background: var(--sea-deep); color: #fff; }
.stepper__val { flex: 1; min-width: 0; font-size: 22px; height: 56px; }
/* Kill the native number spinners — they're unusable at this size. */
.stepper__val::-webkit-outer-spin-button,
.stepper__val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper__val { -moz-appearance: textfield; }

.rpes { flex: 1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rpe {
  min-height: 44px; border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--bg-raise); color: var(--ink-dim);
  font-size: 15px; font-weight: 650; padding: 0;
}
.rpe.is-on { background: var(--gold); border-color: var(--gold); color: #2a1c00; }

/* Logged sets */
.setlist { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 6px; }
.setrow {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; border-bottom: 1px solid rgba(28, 66, 87, .5);
}
.setrow:last-child { border-bottom: 0; }
.setrow__n {
  width: 24px; flex: none; text-align: center;
  color: var(--ink-faint); font-size: 13px; font-weight: 650;
}
.setrow__main { flex: 1; font-size: 16px; font-weight: 600; }
.setrow__del {
  width: 44px; height: 44px; flex: none; border: 0; background: none;
  color: var(--ink-faint); font-size: 14px;
}

/* ---------- session summary ---------- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; align-items: start; }
.stat { text-align: center; min-width: 0; }
.stat__v { font-size: 20px; font-weight: 700; line-height: 1.15; }
/* Four columns on a 390px phone leaves ~88px each. Labels are sized to fit
   the longest one ("kg this month") on a single line — a wrapped label makes
   its tile taller than its neighbours and the row stops reading as a row. */
.stat__l {
  font-size: 10px; line-height: 1.3; color: var(--ink-faint); margin-top: 3px;
  text-transform: uppercase; letter-spacing: .02em;
}

.rateblock + .rateblock { margin-top: 14px; }
.rateblock__top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; margin-bottom: 6px;
}
.rateblock__lbl { font-size: 14px; font-weight: 650; }
.rateblock__top .faint { font-size: 12px; }

.rates { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rate {
  min-height: 46px; border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--bg-raise); color: var(--ink-dim);
  font-size: 16px; font-weight: 650; padding: 0;
}
.rate.is-on { background: var(--sea); border-color: var(--sea); color: #04141c; }

.card--coach {
  border-color: var(--gold);
  background: linear-gradient(160deg, rgba(242, 181, 68, .08), var(--bg-card) 60%);
}

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

.toggle {
  display: flex; gap: 4px; padding: 3px;
  background: var(--bg-input); border: 1px solid var(--line);
  border-radius: var(--r-s);
}
.toggle__b {
  flex: 1; min-height: 40px; padding: 0 10px; white-space: nowrap;
  border: 0; border-radius: 7px; background: transparent;
  color: var(--ink-dim); font-size: 14px; font-weight: 600;
}
.toggle__b.is-on { background: var(--sea); color: #04141c; }

.pbrow {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; font-size: 15px;
  border-bottom: 1px solid rgba(28, 66, 87, .5);
}
.pbrow:last-child { border-bottom: 0; }

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

.monthbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin: 22px 2px 8px;
}
.monthbar:first-child { margin-top: 4px; }
.monthbar .faint { font-size: 12px; }

.histrow {
  display: block; width: 100%; text-align: left;
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px;
  color: var(--ink);
}
.histrow:active { background: var(--bg-raise); }
.histrow__top {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.histrow__date { font-size: 16px; font-weight: 650; flex: 1; }
.histrow__ex {
  font-size: 14px; color: var(--ink-dim); margin-bottom: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.histrow__meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  background: var(--bg-raise); border: 1px solid var(--line); color: var(--ink-dim);
}
.chip--note { border-style: dashed; }

/* ---------- coach chat ---------- */

/* Room for the fixed composer. */
.screen[data-screen="chat"] { padding-bottom: 92px; }

.chatctx {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: var(--tap); margin-bottom: 14px; padding: 10px 14px;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--r-s); color: var(--ink);
}

.chat { display: flex; flex-direction: column; gap: 14px; }

.msg { max-width: 88%; display: flex; flex-direction: column; }
.msg--coach { align-self: flex-start; }
.msg--user  { align-self: flex-end; align-items: flex-end; }

.msg__who {
  font-size: 12px; font-weight: 700; color: var(--gold);
  letter-spacing: .02em; margin: 0 0 4px 4px;
}
.msg__body {
  padding: 11px 14px; border-radius: var(--r);
  background: var(--bg-card); border: 1px solid var(--line);
  font-size: 16px; line-height: 1.5;
}
.msg--coach .msg__body {
  border-color: rgba(242, 181, 68, .35);
  border-bottom-left-radius: 4px;
}
.msg--user .msg__body {
  background: var(--sea-deep); border-color: var(--sea-deep); color: #eaf7fc;
  border-bottom-right-radius: 4px;
}
.msg__p { margin: 0; }
.msg__p + .msg__p { margin-top: 10px; }
.msg__ts { font-size: 11px; margin: 4px 6px 0; }

/* thinking indicator */
.thinking { display: flex; gap: 5px; align-items: center; padding: 15px 16px; }
.thinking .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gold);
  animation: bob 1.2s infinite ease-in-out;
}
.thinking .dot:nth-child(2) { animation-delay: .16s; }
.thinking .dot:nth-child(3) { animation-delay: .32s; }
@keyframes bob {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-4px); }
}

.retry {
  align-self: flex-start; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border: 1px dashed var(--line); border-radius: var(--r-s);
}

/* Composer sits above the tab bar. */
.composer {
  position: fixed; z-index: 35;
  left: 0; right: 0; bottom: var(--tabs-h);
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px;
  background: rgba(7, 22, 32, .96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.composer[hidden] { display: none; }
.composer__input {
  flex: 1; min-height: var(--tap); max-height: 120px; resize: none;
  padding: 12px 14px; font-size: 16px; line-height: 1.4;
  background: var(--bg-input); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-s);
}
.composer__input:focus {
  outline: none; border-color: var(--sea);
  box-shadow: 0 0 0 3px rgba(26, 156, 196, .2);
}
.composer__send {
  width: var(--tap); height: var(--tap); flex: none;
  border: 0; border-radius: var(--r-s);
  background: var(--sea); color: #04141c;
  font-size: 22px; font-weight: 700; line-height: 1;
}
.composer__send:disabled { opacity: .45; }

/* The composer is fixed, so centre it with the content column. */
@media (min-width: 748px) {
  .composer { left: 50%; transform: translateX(-50%); width: 720px; }
}

/* Exercise picker */
.picker { max-width: 400px; display: flex; flex-direction: column; max-height: 78vh; }
.picker__list { margin-top: 10px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.picker__row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: var(--tap); padding: 8px 4px;
  background: none; border: 0; border-bottom: 1px solid rgba(28, 66, 87, .5);
  color: var(--ink); font-size: 16px;
}
.picker__row:active { background: var(--bg-raise); }
.picker__new { display: flex; gap: 8px; padding: 4px 0 12px; align-items: stretch; }
.picker__new .select { width: 108px; flex: none; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(3, 11, 16, .72); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 24px;
}
.modal__panel {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 20px; width: 100%; max-width: 340px;
}
.modal__msg { margin: 0 0 18px; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }
