/* =========================================================================
   Gym Log — Atheric house style. Dark, editorial, precise. Mobile-first.
   Pure design layer: no behavior here. Data/auth/fetch live in app.js.
   ========================================================================= */

/* ---- Design tokens ---- */
:root {
  /* color — off-black base, near-white ink, one restrained accent */
  --bg:          #0b0b0d;
  --bg-2:        #0e0e11;
  --surface:     #141418;
  --surface-2:   #1b1b21;
  --line:        #26262e;
  --line-2:      #34343f;
  --ink:         #f5f4f0;
  --ink-dim:     #a4a4a1;
  --ink-faint:   #6d6d72;
  --accent:      #d8ff35;   /* used ONLY for active / primary / success-key */
  --accent-ink:  #0b0b0d;
  --accent-dim:  #2c3310;
  --danger:      #ff6a5d;
  --ok:          #b8f24a;

  /* type */
  --font-ui:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;

  /* modular type scale */
  --t--1: 0.78rem;
  --t-0:  0.94rem;
  --t-1:  1.12rem;
  --t-2:  1.45rem;
  --t-3:  2rem;
  --t-4:  2.85rem;

  /* spacing rhythm */
  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem;
  --s-5: 1.5rem;  --s-6: 2rem;   --s-7: 3rem;    --s-8: 4.5rem;

  /* radii */
  --r-1: 7px; --r-2: 11px; --r-3: 18px; --r-pill: 999px;

  /* motion */
  --fast: 110ms; --med: 190ms; --slow: 300ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --tap: 48px;            /* min thumb target */
  --maxw: 640px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
*::selection { background: var(--accent); color: var(--accent-ink); }

html { -webkit-text-size-adjust: 100%; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-0);
  line-height: 1.5;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Flex/grid children default to min-width:auto, which lets wide content push
   the page wider than the viewport. Reset so everything stays within bounds. */
.topbar, .view-body, .actions, [data-set-row], [data-exercise-block], [data-sets] { min-width: 0; }

/* The hidden attribute must always win over layout display rules. */
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; }

/* All numeric readouts: tabular monospace so columns align at a glance. */
input[type="number"],
.num,
#sessions-list .readout,
#meals-list li,
#bw-list li,
#export-output,
#current-session-label {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* =======================================================================
   Buttons & inputs
   ======================================================================= */

button {
  font-family: var(--font-ui);
  font-size: var(--t-0);
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-1);
  min-height: var(--tap);
  padding: 0 var(--s-4);
  cursor: pointer;
  transition: transform var(--fast) var(--ease),
              background var(--fast) var(--ease),
              border-color var(--fast) var(--ease),
              color var(--fast) var(--ease);
}
button:hover { border-color: var(--line-2); background: #20202a; }
button:active { transform: scale(0.94); }            /* tactile press feedback */

/* Primary call-to-action (Start session, Add meal, Add entry, Sign in…) */
.btn,
button[type="submit"],
#start-session,
#add-exercise {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--r-2);
  font-weight: 650;
  letter-spacing: 0.005em;
  min-height: 52px;
}
.btn:hover,
button[type="submit"]:hover,
#start-session:hover,
#add-exercise:hover { background: #e6ff61; }

.btn-ghost,
#logout,
#finish-session,
#export-copy {
  width: auto;
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--ink-dim);
  border-radius: var(--r-pill);
  min-height: 40px;
  font-size: var(--t--1);
}
.btn-ghost:hover,
#logout:hover,
#finish-session:hover,
#export-copy:hover { color: var(--ink); border-color: var(--ink-faint); background: transparent; }

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: 0.55; cursor: default; }
button:disabled:active { transform: none; }

input,
textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;                 /* >=16px avoids iOS zoom-on-focus */
  min-height: var(--tap);
  padding: 0 var(--s-3);
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
textarea { padding: var(--s-3); line-height: 1.45; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: #101014; }

/* Quiet, clear invalid flag — only after the user has interacted. */
input:user-invalid { border-color: var(--danger); }
input:user-invalid + .err { color: var(--danger); }

/* Form field rhythm. Labels created as <label>text <input></label>. */
form p { margin: 0 0 var(--s-4); }
label {
  display: block;
  font-size: var(--t--1);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
label input { margin-top: var(--s-2); text-transform: none; letter-spacing: -0.01em; }

/* =======================================================================
   Auth view
   ======================================================================= */

#auth-view {
  max-width: 420px;
  margin: 0 auto;
  padding: var(--s-8) var(--s-5) var(--s-7);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
#auth-view h2 {
  font-size: var(--t--1);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: var(--s-6) 0 var(--s-4);
}
#auth-view h2:first-of-type { margin-top: var(--s-7); }
#auth-msg {
  margin: var(--s-4) 0 0;
  color: var(--danger);
  font-size: var(--t-0);
  min-height: 1.4em;
}

/* =======================================================================
   App shell: top bar / scrolling views / fixed bottom nav
   ======================================================================= */

#app-view {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + var(--s-5));
}

.topbar {
  view-transition-name: topbar;       /* stays put across section transitions */
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: rgba(11, 11, 13, 0.82);
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-size: var(--t-1);
  font-weight: 600;
  letter-spacing: -0.04em;
}
.wordmark b { color: var(--accent); font-weight: 600; }
.topbar .who-wrap {
  margin-left: auto;
  min-width: 0;
  font-size: var(--t--1);
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar #who { color: var(--ink-dim); }
.topbar #logout { flex: none; }

/* Section header — editorial eyebrow + title */
.view { padding: var(--s-6) var(--s-5) 0; }
.view-head { margin-bottom: var(--s-5); }
.eyebrow {
  display: block;
  font-family: var(--font-num);
  font-size: var(--t--1);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: var(--s-3);
}
.view-head h2 { font-size: var(--t-3); }
.view-body h3 {
  font-size: var(--t--1);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: var(--s-6) 0 var(--s-4);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--line);
}
.view-body h3:first-child { margin-top: 0; }

/* Only the active view is shown (switchable views). */
#app-view > .view { display: none; }
#app-view > .view.is-active { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: var(--s-5);
  margin-bottom: var(--s-5);
}

/* =======================================================================
   Bottom navigation (thumb zone)
   ======================================================================= */

.tabbar {
  view-transition-name: tabbar;       /* persistent across transitions */
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(11, 11, 13, 0.86);
  background: color-mix(in oklab, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  min-height: 0;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  color: var(--ink-faint);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.tabbar button:hover { background: none; color: var(--ink-dim); transform: none; }
.tabbar button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.tabbar button.is-active { color: var(--accent); }
.tabbar button.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--accent);
}

/* =======================================================================
   Training
   ======================================================================= */

#current-session-label { color: var(--accent); margin-left: var(--s-2); }

[data-exercise-block] {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: var(--s-4);
  margin: var(--s-4) 0 !important;
}
[data-exercise-block] > h4 {
  font-size: var(--t-1);
  margin-bottom: var(--s-3);
}
[data-exercise-block] > button {          /* the "+ set" control */
  width: 100%;
  margin-top: var(--s-3);
  background: transparent;
  border: 1px dashed var(--line-2);
  color: var(--ink-dim);
  border-radius: var(--r-1);
}
[data-exercise-block] > button:hover { color: var(--accent); border-color: var(--accent-dim); }

/* A single set row: weight stepper · reps stepper · save · remove */
[data-set-row] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--line);
  font-size: var(--t--1);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
[data-set-row]:first-child { border-top: none; }

[data-set-row] input {
  width: 3.5rem;
  min-height: 44px;
  text-align: center;
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0 var(--s-1);
}
/* Steppers are the first four buttons (− + − +); save is 5th, remove is 6th. */
[data-set-row] button:nth-of-type(-n+4) {
  min-height: 44px;
  width: 42px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  background: var(--surface-2);
  color: var(--ink);
}
[data-set-row] button:nth-of-type(5) {     /* Save set */
  min-height: 44px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-weight: 650;
}
[data-set-row] button:nth-of-type(6) {     /* Remove */
  min-height: 44px;
  background: transparent;
  border-color: var(--line);
  color: var(--ink-faint);
}
[data-set-row] button:nth-of-type(6):hover { color: var(--danger); border-color: var(--danger); }
[data-set-row] [data-status] {
  flex-basis: 100%;
  color: var(--ok);
  letter-spacing: 0.04em;
}

/* Past sessions readout */
#sessions-list > div {
  padding: var(--s-4) 0;
}
#sessions-list strong {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--t-0);
  margin-bottom: var(--s-2);
}
#sessions-list em {
  font-style: normal;
  font-family: var(--font-ui);
  color: var(--ink-dim);
  letter-spacing: 0.02em;
}
#sessions-list > div > div {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  padding: var(--s-1) 0;
}
#sessions-list hr { border: none; border-top: 1px solid var(--line); margin: 0; }

/* =======================================================================
   Eating & Bodyweight lists
   ======================================================================= */

#meals-list h4 {
  font-family: var(--font-num);
  font-size: var(--t--1);
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  margin: var(--s-5) 0 var(--s-3);
}
#meals-list ul, #bw-list ul { list-style: none; margin: 0; padding: 0; }
#meals-list li, #bw-list li {
  padding: var(--s-3) 0;
  border-top: 1px solid var(--line);
  color: var(--ink);
}
#bw-list li:first-child, #meals-list li:first-child { border-top: none; }

/* =======================================================================
   Export
   ======================================================================= */

[data-section="export"] .actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-bottom: var(--s-4); }
[data-section="export"] .actions button { width: auto; flex: 1 1 auto; min-width: 8rem; }
#export-status { color: var(--ink-faint); font-size: var(--t--1); align-self: center; }
#export-output {
  width: 100%;
  min-height: 50vh;
  font-size: var(--t--1);
  line-height: 1.5;
  color: var(--ink-dim);
  background: var(--bg-2);
}

/* empty-state text nodes that app.js drops directly into list hosts */
#sessions-list, #meals-list, #bw-list { color: var(--ink-faint); }

/* =======================================================================
   Motion — section entrances, micro-interactions, view transitions.
   All non-essential motion disabled under prefers-reduced-motion.
   ======================================================================= */

@media (prefers-reduced-motion: no-preference) {

  /* Distinct, coherent entrance per section so each feels identifiable. */

  /* Training — rises and stacks (staggered). */
  @keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  [data-section="training"].is-active .view-head,
  [data-section="training"].is-active .view-body > * {
    animation: rise var(--slow) var(--ease) both;
  }
  [data-section="training"].is-active .view-body > *:nth-child(1) { animation-delay: 30ms; }
  [data-section="training"].is-active .view-body > *:nth-child(2) { animation-delay: 70ms; }
  [data-section="training"].is-active .view-body > *:nth-child(3) { animation-delay: 110ms; }
  [data-section="training"].is-active .view-body > *:nth-child(n+4) { animation-delay: 150ms; }

  /* Eating — fades and settles into place. */
  @keyframes settle { from { opacity: 0; transform: scale(0.985) translateY(6px); } to { opacity: 1; transform: none; } }
  [data-section="eating"].is-active .view-head,
  [data-section="eating"].is-active .view-body { animation: settle var(--slow) var(--ease) both; }
  [data-section="eating"].is-active .view-body { animation-delay: 50ms; }

  /* Bodyweight — draws in top-to-bottom, like plotting a line. */
  @keyframes draw { from { opacity: 0.3; clip-path: inset(0 0 100% 0); } to { opacity: 1; clip-path: inset(0 0 0 0); } }
  [data-section="bodyweight"].is-active .view-head,
  [data-section="bodyweight"].is-active .view-body { animation: draw var(--slow) var(--ease) both; }

  /* Export — quiet fade. */
  @keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
  [data-section="export"].is-active .view-head,
  [data-section="export"].is-active .view-body { animation: fadein var(--med) var(--ease) both; }

  /* A newly added set row animates in. */
  @keyframes row-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
  [data-set-row] { animation: row-in var(--med) var(--ease) both; }

  /* Save success: brief pop when the Save button locks in. */
  @keyframes saved-pop { 0% { transform: scale(1); } 45% { transform: scale(1.07); } 100% { transform: scale(1); } }
  [data-set-row] button:nth-of-type(5):disabled {
    animation: saved-pop 360ms var(--ease);
    background: var(--ok);
    color: var(--accent-ink);
    opacity: 1;
  }

  /* Newly rendered list items settle in. */
  @keyframes item-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
  #meals-list li, #bw-list li, #sessions-list > div { animation: item-in var(--med) var(--ease) both; }

  /* View Transitions API: seamless cross-fade between sections.
     The persistent chrome (topbar, tabbar) keeps its own names and is excluded. */
  @keyframes vt-out { to { opacity: 0; } }
  @keyframes vt-in  { from { opacity: 0; } }
  ::view-transition-old(root) { animation: vt-out 130ms var(--ease) both; }
  ::view-transition-new(root) { animation: vt-in 170ms var(--ease) both; }
}

/* Reduced motion: keep state legible, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
