:root {
  color-scheme: light dark; /* let native widgets (checkbox, date/number spinners, select, color) follow the OS/browser theme */
  --bg: #f7f7f9;
  --panel: #ffffff;
  --border: #d8d8de;
  --text: #23232a;
  --muted: #6b6b76;
}

* { box-sizing: border-box; }

/* Author display rules (e.g. .card-form { display: flex }) beat the browser's
   [hidden] style, so a "hidden" panel would still show. Make it stick. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* A wide-content page overflowing the body horizontally used to drag the
     fixed bottom-nav off to the side with it on some mobile browsers, since
     the layout viewport widens along with the overflow. Any element that
     needs to scroll sideways (e.g. the sport tabs) gets its own scroll
     container instead - the page itself never should. */
  overflow-x: hidden;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 1.25rem; margin: 0; }
.title-group { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 0.75rem; }

.month-nav { display: flex; align-items: center; gap: 0.5rem; }
.month-nav button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-size: 1rem;
}
#month-label { min-width: 9rem; text-align: center; font-weight: 600; }

/* --- bottom app nav (all three main pages) ------------------------------ */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0 0.4rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
}
.bottom-nav-item.is-active { color: var(--text); }

/* Wide screens (typically landscape/desktop): the bar becomes a left
   sidebar instead of a bottom bar - body padding reserves its width, main
   content no longer needs bottom padding to clear a bottom-fixed bar. */
@media (min-width: 700px) {
  body { padding-left: 4.5rem; }
  .bottom-nav {
    top: 0;
    bottom: 0;
    right: auto;
    width: 4.5rem;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    padding-bottom: 0;
    padding-top: 0.5rem;
  }
  main, .analytics-main { padding-bottom: 1rem; }
}

/* Tall enough desktop windows: don't stretch the sidebar icons across the
   full viewport height (looks too spread out) - pack them near the top
   with some breathing room between them instead. The bar itself (its grey
   background/border) still spans the full height, from the top: 0/bottom: 0
   already set above. */
@media (min-width: 700px) and (min-height: 500px) {
  .bottom-nav { gap: 1rem; }
  .bottom-nav-item { flex: 0 0 auto; }
}

main { max-width: 900px; margin: 0 auto; padding: 1rem 1rem 4.5rem; }

.save-status {
  min-height: 1.2rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
  margin-bottom: 0.25rem;
}
.save-status.error { color: #b83227; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
  font-size: 0.85rem;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.legend .swatch {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  display: inline-block;
}

.calendar-wrap { overflow-x: auto; }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(2.6rem, 1fr));
  gap: 4px;
}

.cal-weekday {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  padding-bottom: 0.25rem;
}

.cal-day {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  padding: 0.25rem;
  overflow: hidden;
}
.cal-day:hover { border-color: #9a9aa6; }
/* Today: a grey box, always on, in one consistent grey (--muted) rather
   than the near-black/near-white pair this used to swap between across
   light/dark mode - that pairing is what made it read as "white" in dark
   mode instead of a stable, recognizable grey. */
.cal-day.today { border: 2px solid var(--muted); }
/* The clicked/selected day: a white ring, kept in sync with whichever date
   is "current" right now (see app.js's syncCalendarHighlight()) - drawn
   with box-shadow rather than border so it can be combined with .today's
   own border (both can apply to the same cell) instead of one silently
   overriding the other. The added 1px --border ring gives it a visible
   edge against a light-mode cell, which is itself already close to white. */
.cal-day.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--border); }
.cal-day.outside { opacity: 0.35; }

/* Day number: top right, drawn above the pills, which never run under it
   (app.js's avoidDayNumber() narrows the rows that reach its height). */
.cal-day .num {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  z-index: 1;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

/* Pill rows start at the bottom of the cell and stack upwards; rows that no
   longer fit are clipped at the top. */
.cal-day .bars {
  position: absolute;
  inset: 0.25rem;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  gap: 2px;
  overflow: hidden;
}
.cal-day .bar-row {
  display: flex;
  gap: 2px;
  overflow: hidden;
  flex: none;
}
/* Pills share the row's width equally; the minimum is a circle (6x6), and
   pills that no longer fit are clipped on the right by .bar-row. */
.cal-day .bar {
  flex: 1 0 6px;
  height: 6px;
  min-width: 6px;
  border-radius: 3px;
  box-sizing: border-box;
}
.cal-day .bar.plan {
  /* Proposed/planned entries: hollow outline instead of a solid fill - a
     diagonal-stripe pattern doesn't render legibly at this height (~5-6px),
     it just looks like a slightly darker solid bar. An outline reads clearly
     as "different" at any size. */
  background-color: transparent !important;
  border: 1.5px solid currentColor;
}

.day-panel, #entry-form {
  margin-top: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.day-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.day-panel-header button {
  border: none;
  background: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

#day-entries { list-style: none; margin: 0.75rem 0; padding: 0; }
#day-entries li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#day-entries li:last-child { border-bottom: none; }
#day-entries .dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  flex-shrink: 0;
}
#day-entries li:has(.do-it-btn) { padding-top: 0; padding-bottom: 0; }
#day-entries .do-it-btn {
  margin-left: auto;
  flex: 0 0 10%;
  min-width: 4rem;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.4rem 0;
  border: none;
  border-radius: 0;
  background: none;
  color: #000; /* pure black / white, brighter than the --text of the headline */
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#add-entry-btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-family: inherit;
}

/* The entry form floats over the page as a modal: the wrapper is the dimmed
   backdrop (it scrolls if the form is taller than the screen). */
.entry-form-wrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  overflow-y: auto;
  padding: 1rem 1rem 5rem;
}
#entry-form {
  display: flex; flex-direction: column; gap: 0.7rem;
  max-width: 34rem;
  margin: 0 auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
#entry-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
#entry-form input, #entry-form select, #entry-form textarea {
  font-size: 1rem;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}
#entry-form textarea {
  font-family: inherit;
  resize: vertical;
}
#entry-form [hidden] { display: none; }

#entry-fields { display: flex; flex-direction: column; gap: 0.7rem; }
.field-row { display: flex; flex-direction: column; }

.duration-row { display: flex; gap: 0.75rem; }
.duration-row label { flex: 1; }
.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}
.checkbox-row input { width: auto; }

.form-actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.form-actions button {
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}
#entry-save-btn { background: #23232a; color: #fff; border-color: #23232a; }
#entry-delete-btn { background: #fdeaea; border-color: #e74c3c; color: #b83227; margin-left: auto; }
#entry-save-btn, #entry-delete-btn { display: inline-flex; align-items: center; padding: 0.5rem 0.8rem; }
/* Centred between the equally wide save and delete buttons, with the
   application icon's orange-to-purple gradient. */
#entry-done-btn {
  margin: 0 auto;
  background: linear-gradient(160deg, #ff9f1c, #a21395);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
#entry-done-btn:not([hidden]) ~ #entry-delete-btn { margin-left: 0; }

.form-error { color: #b83227; font-size: 0.85rem; }
.empty-state { color: var(--muted); font-size: 0.9rem; }

/* --- config page --------------------------------------------------------- */
.color-pick { display: inline-flex; align-items: center; gap: 0.3rem; }
.color-pick input[type="color"] {
  width: 2.2rem; height: 2.2rem; padding: 0; border: 1px solid var(--border);
  border-radius: 6px; background: none; cursor: pointer;
}

.sport-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.sport-card-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.sport-card-header .sport-name {
  flex: 1; min-width: 8rem; font-size: 1rem; padding: 0.4rem;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel);
  color: var(--text); font-family: inherit;
}
.icon-toggle {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  line-height: 0;
}
.trash-btn:hover, .trash-btn:focus-visible { color: #b83227; border-color: #e74c3c; background: #fdeaea; }
.active-toggle[aria-pressed="true"] { color: var(--text); }
.lock-toggle[aria-pressed="true"] { color: #b9770e; border-color: #f39c12; }
.share-add { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.share-add input { flex: 1; min-width: 0; }
.badge-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.user-badge {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 1.9rem;
  padding: 0 0.8rem 0 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.85rem;
  overflow: hidden;
}
/* The x sits in a circle as tall as the pill's inside, flush with its left
   edge. Selector is .user-badge .badge-remove so it beats the generic
   ".card-form button" rule (radius, padding, border). */
.user-badge .badge-remove {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(1.9rem - 2px);
  height: calc(1.9rem - 2px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  cursor: pointer;
  line-height: 0;
}
.user-badge .badge-remove svg { display: block; flex: none; }
.user-badge .badge-remove:hover, .user-badge .badge-remove:focus-visible { background: #c0392b; color: #fff; }
.sport-card-header .sport-order { width: 2.35rem; } /* 2/3 of the 3.5rem used in field rows */
.sport-order {
  width: 3.5rem; text-align: center; padding: 0.35rem;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text);
}
.sport-card-header > button {
  margin-left: auto; border: 1px solid var(--border); background: var(--bg);
  color: #b83227; border-radius: 6px; padding: 0.3rem 0.6rem; cursor: pointer; font-family: inherit;
}

.sport-fields-details { margin-top: 0.6rem; }
.sport-fields-details > summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.fields-table, .derived-fields-table { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.4rem; }
.field-admin-row, .derived-field-admin-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.5rem;
}
.field-admin-row input[type="text"], .field-admin-row select,
.derived-field-admin-row input[type="text"], .derived-field-admin-row input[type="number"], .derived-field-admin-row select {
  padding: 0.3rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--text); font-family: inherit; font-size: 0.85rem;
}
.field-admin-row input[type="text"] { flex: 1; min-width: 6rem; }
.derived-field-admin-row input[type="text"] { flex: 1 1 8rem; min-width: 6rem; }
.field-admin-row button, .derived-field-admin-row button {
  margin-left: auto; border: 1px solid var(--border); background: var(--panel);
  color: #b83227; border-radius: 6px; padding: 0.25rem 0.5rem; cursor: pointer; font-size: 0.8rem; font-family: inherit;
}
.scale-input { width: 4rem; }

/* Groups a scale-factor input with the field <select> it multiplies (see
   config.js's makeDerivedTerm()) so the pair wraps to the next line as one
   unit on narrow screens, instead of the factor splitting off onto its own
   line above the field it belongs to. */
.derived-term {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}
.derived-term-times {
  color: var(--muted);
  font-size: 0.8rem;
}

.admin-add-row { margin-top: 1rem; }
.admin-add-row summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.admin-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  align-items: center;
}
.admin-add-form input, .admin-add-form select {
  font-size: 0.9rem;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.admin-add-form input[type="text"] { flex: 1; min-width: 8rem; }
.admin-add-form button {
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #23232a;
  color: #fff;
  font-family: inherit;
}
.admin-api-link { margin-top: 1.5rem; font-size: 0.8rem; }
.admin-api-link a { color: var(--muted); }

/* --- analytics page ------------------------------------------------------ */
.analytics-main { max-width: 720px; }

.sport-tabs {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
}
.sport-tab {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-bottom: 3px solid transparent;
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px 999px 0 0;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}
.sport-tab.is-active { color: var(--text); border-bottom-color: var(--tab-color, var(--text)); font-weight: 600; }

.range-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.range-control .range-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 6px; padding: 0.3rem 0.7rem; cursor: pointer; font-size: 0.85rem; font-family: inherit;
}
.range-presets { display: flex; align-items: center; gap: 0.5rem; }
.range-presets .range-label { margin-right: -0.2rem; } /* same 0.3rem label-to-control gap as From / To */
.range-control label, .range-control .range-label { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.3rem; }
.range-control input[type="date"] {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 6px; padding: 0.25rem 0.4rem;
}

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.chart-card h3 { margin: 0 0 0.5rem; font-size: 0.9rem; display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; }
.chart-readout { font-weight: normal; color: var(--muted); margin-left: auto; text-align: right; }
.chart-body { width: 100%; }
/* No width/height here: the SVG's own width/height attributes (set in
   charts.js from the container's real measured pixel width) are what keep
   font-size/stroke-width in real CSS pixels on every device - a CSS
   stretch here would make the viewBox differ from the rendered box again
   and reintroduce the same scaling this was fixed to avoid. */
.mini-chart { display: block; }

.bubble-track { position: relative; width: 100%; }
.bubble-axis-line { position: absolute; left: 0; right: 0; height: 1px; background: var(--border); }
.bubble {
  position: absolute;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  /* top/left are set in px/% by charts.js, marking this bubble's own
     center - translate(-50%,-50%) is what actually centers the glyph on
     that point in both axes (a raw top/left is the box's corner, not its
     center). Do not also set top/left as fixed values here - that would
     silently override the per-bubble position charts.js computes. */
  transform: translate(-50%, -50%);
}
.bubble-date {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
}

/* --- shared docs-page styling (api-docs.html) -------------------------- */
.docs { max-width: 720px; margin: 0 auto; padding: 1rem 1rem 3rem; }
.docs h2 { margin-top: 2rem; }
.docs h2:first-child { margin-top: 0; }
.docs code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.9em;
}
.docs pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
}
.docs pre code { border: none; background: none; padding: 0; }
.docs table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 1rem 0;
}
.docs th, .docs td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.docs th { color: var(--muted); font-weight: 600; }
.docs .back-link { display: inline-block; margin-bottom: 1rem; }
.docs .muted { color: var(--muted); }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --panel: #232328;
    --border: #35353c;
    --text: #eaeaef;
    --muted: #9a9aa6;
  }
  .admin-add-form button { background: #eaeaef; color: #17171a; }
  #day-entries .do-it-btn { color: #fff; }
}

/* --- multi-user: login, account, admin, user switcher ------------------- */
.muted-text { color: var(--muted); font-size: 0.85rem; }

.login-main { max-width: 22rem; padding-top: 12vh; }
.card-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.card-form h1, .card-form h2 { margin: 0; font-size: 1.1rem; }
.card-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.card-form label.checkbox-row { flex-direction: row; align-items: center; gap: 0.5rem; }
.card-form input[type="text"], .card-form input[type="password"] {
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.card-form button, .inline-form button, .token-list button, .row-actions button {
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}
.card-form .form-actions button[type="submit"], #login-btn, #save-profile { background: #23232a; color: #fff; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.inline-form input { flex: 1; min-width: 10rem; font-size: 0.9rem; padding: 0.4rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-family: inherit; }
.token-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.token-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; }
.new-token { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.75rem; border: 1px solid var(--border); border-left: 4px solid #2ecc71; border-radius: 6px; background: var(--panel); margin-bottom: 1rem; }
.new-token code, .card-form code { word-break: break-all; }
.table-scroll { overflow-x: auto; }
.user-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.user-table th, .user-table td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.user-table th { color: var(--muted); font-weight: 600; }
.row-actions { display: flex; gap: 0.4rem; }
.row-actions button.danger, .card-form .form-actions button.danger { background: #b83227; border-color: #b83227; color: #fff; }

.user-switch {
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}
/* Viewing someone else's shared training: no editing controls. */
.readonly #add-entry-btn { display: none; }
.readonly .topbar { border-bottom: 3px solid #f39c12; }

/* --- AI chat ----------------------------------------------------------------- */
.chat-top-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.chat-top-actions button, .memory-list button, .proposal-actions button, .chat-form button {
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}
/* The chat page does not scroll as a whole: it is exactly one screen tall.
   Title bar, memory panel, notices and the input stay in place and only the
   message log (.chat-log) scrolls inside its own box. Body padding reserves
   the room for the navigation (bottom bar on phones, the left sidebar via the
   existing rule on wide screens). */
body.chat-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0));
}
@media (min-width: 700px) {
  body.chat-page { padding-bottom: 0; }
}
.chat-page .topbar { flex: none; }
.chat-page .chat-main {
  flex: 1;
  min-height: 0;            /* let the flex child shrink so the log can scroll */
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem 0.5rem;
}
.chat-page .chat-main > * { flex: none; }
.chat-page .chat-main > .chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.25rem 0.25rem 0.5rem 0;
}
.chat-log { display: flex; flex-direction: column; gap: 0.6rem; }
.chat-msg {
  flex: none;               /* don't squash bubbles when the log is short of room */
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.chat-user { align-self: flex-end; background: #23232a; color: #fff; border-color: #23232a; }
.chat-assistant { align-self: flex-start; }
.chat-waiting { color: var(--muted); font-style: italic; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-form {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.chat-form[hidden] { display: none; }
.chat-form textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}
.chat-form button { background: #23232a; color: #fff; padding: 0 1rem; }
.chat-form button:disabled { opacity: 0.5; }
.proposal { margin-top: 0.5rem; padding: 0.5rem; border: 1px dashed var(--border); border-left: 4px solid #f39c12; border-radius: 6px; font-size: 0.9rem; }
.proposal-applied { border-left-color: #2ecc71; }
.proposal-dismissed { border-left-color: var(--muted); opacity: 0.7; }
.proposal-invalid, .proposal-failed { border-left-color: #b83227; }
.proposal-note { color: var(--muted); font-size: 0.8rem; margin-top: 0.2rem; }
.proposal-actions { display: flex; gap: 0.5rem; margin-top: 0.3rem; }
.proposal-memory { border-left-color: #3498db; }
.proposal-memory.proposal-applied { border-left-color: #2ecc71; }
.memory-panel { margin-bottom: 0.75rem; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.75rem; }
.memory-panel summary { cursor: pointer; font-weight: 600; }
.memory-list { list-style: none; margin: 0.4rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; max-height: min(28vh, 14rem); overflow-y: auto; }
@media (max-width: 699px) { .memory-list { max-height: 18vh; } }
.memory-list li { display: flex; gap: 0.4rem; align-items: baseline; }
.memory-note { flex: 1; overflow-wrap: anywhere; }
.ai-fields { display: flex; flex-direction: column; gap: 0.75rem; }
.card-form textarea {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
.chat-notice { margin: 0 0 0.6rem; padding: 0.4rem 0.6rem; font-size: 0.85rem; color: var(--muted); border-left: 3px solid #2ecc71; background: var(--panel); border-radius: 4px; }

/* The Chat tab only exists for users who picked an AI provider (auth.js sets
   body.ai-enabled). On the chat page itself it stays, so the page isn't
   left without a highlighted item. */
.bottom-nav .bottom-nav-item[href="chat.html"]:not(.is-active) { display: none; }
body.ai-enabled .bottom-nav .bottom-nav-item[href="chat.html"] { display: flex; }

/* Small "Experimental" tag next to a section heading. */
.badge-experimental {
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.4rem;
  padding: 0.1rem 0.45rem;
  border: 1px solid #f39c12;
  border-radius: 999px;
  color: #b9770e;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#day-entries li > span:not(.dot) { white-space: pre-line; }

.workout-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  padding: 1rem;
}
.workout-foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 1.1rem; }
.workout-close { border: none; background: none; color: inherit; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.workout-step {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(1.8rem, 6vw, 3.5rem);
  line-height: 1.25;
  overflow-wrap: anywhere;
  overflow-y: auto;
}
.workout-stage { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.workout-stage > .workout-step { cursor: text; }
.workout-edit-btn {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 4.5rem; height: 4.5rem; padding: 0.9rem;
  border: 2px solid currentColor; border-radius: 50%;
  background: var(--bg); color: inherit; cursor: pointer;
}
.workout-edit-btn[hidden], .workout-editor[hidden], .workout-editor-bar[hidden], .workout-step[hidden] { display: none; }
.workout-edit-btn svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.workout-editor {
  flex: 1; min-height: 0; width: 100%; box-sizing: border-box;
  resize: none; border: 1px dashed var(--muted); border-radius: 10px; background: none; color: inherit;
  font: inherit; font-size: clamp(1.8rem, 6vw, 3.5rem); line-height: 1.25;
  text-align: center; padding: 0.5rem; overflow-wrap: anywhere;
}
.workout-editor:focus { outline: none; border-color: currentColor; }
.workout-editor-bar { display: flex; justify-content: center; gap: 1rem; padding-top: 0.8rem; }
.workout-editor-btn {
  border: 2px solid currentColor; border-radius: 10px; background: none; color: inherit;
  font: inherit; font-size: 1.3rem; font-weight: 600; padding: 0.6rem 1.4rem; cursor: pointer;
}
.workout-editor-btn.primary { border-color: transparent; color: #fff; background: linear-gradient(160deg, #ff9f1c, #a21395); }
.workout-overlay.editing .workout-foot { visibility: hidden; }
.workout-next {
  border: 2px solid currentColor;
  border-radius: 10px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 1.5rem;
  font-weight: 600;
  padding: 0.8rem 1.6rem;
  cursor: pointer;
}
.workout-next.last { border-color: transparent; color: #fff; background: linear-gradient(160deg, #ff9f1c, #a21395); }

/* Countdown timer: the picker and the play/stop button share one slot. */
.workout-timer { position: relative; flex: none; width: min(92vw, 24rem); height: 5.5rem; align-self: center; margin-top: max(0.5rem, env(safe-area-inset-top)); }
.workout-picker-box { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }
.workout-picker {
  --item-w: 4.5rem;
  display: flex;
  flex: none;
  width: 100%;
  height: 4rem;
  overflow-x: scroll;
  overflow-y: hidden;
  touch-action: pan-x;
  scroll-snap-type: x mandatory;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 25%, #000 75%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 25%, #000 75%, transparent);
}
.workout-picker:focus-visible { outline: none; }
.workout-picker::-webkit-scrollbar { display: none; }
.workout-picker::before, .workout-picker::after { content: ''; flex: none; width: calc(50% - var(--item-w) / 2); }
.workout-picker div {
  flex: none;
  width: var(--item-w);
  line-height: 4rem;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  scroll-snap-align: center;
  cursor: pointer;
}
.workout-picker-unit { position: absolute; right: 0; top: 3.5rem; font-size: 0.9rem; opacity: 0.7; }
/* Frame: a line above and below the numbers, fading out towards their ends.
   They also stand in for a focus ring (brighter while the picker has keyboard focus). */
.workout-picker-box::before, .workout-picker-box::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, currentColor, transparent);
  opacity: 0.6;
  pointer-events: none;
}
.workout-picker-box::before { top: 0.8rem; }
.workout-picker-box::after { top: 3.2rem; }
.workout-picker-box:has(.workout-picker:focus-visible)::before,
.workout-picker-box:has(.workout-picker:focus-visible)::after { opacity: 1; height: 2px; }
.workout-timer-btn {
  position: absolute;
  left: 50%;
  top: 2rem; /* centre of the picker numbers */
  transform: translate(-50%, -50%);
  width: 4rem;
  height: 4rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  visibility: hidden;
}
.workout-timer-btn svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; }
.workout-timer.button .workout-timer-btn { visibility: visible; }
.workout-timer.button .workout-picker-box { visibility: hidden; }

/* White + difference inverts whatever is underneath; clicks pass through. */
.workout-tiles {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  mix-blend-mode: difference;
  pointer-events: none;
}

/* Counter: same look as the picker's numbers; tap the number to get + / -.
   The + takes the number's place, the smaller - sits to its right. */
.workout-counter { position: relative; flex: none; align-self: flex-start; width: 4.5rem; height: 4.5rem; }
.workout-counter-box { display: flex; align-items: center; height: 3rem; position: relative; }
/* Frame: a line above and below the number, fading out towards their ends. */
.workout-counter-box::before, .workout-counter-box::after {
  content: '';
  position: absolute;
  left: 0;
  width: 4.5rem;
  height: 1px;
  background: linear-gradient(to right, transparent, currentColor, transparent);
  opacity: 0.6;
  pointer-events: none;
}
.workout-counter-box::before { top: 0.3rem; }
.workout-counter-box::after { bottom: 0.3rem; }
.workout-count-num, .workout-count-step {
  flex: none;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  line-height: 3rem;
  height: 3rem;
  padding: 0;
  cursor: pointer;
}
.workout-count-num { width: 4.5rem; text-align: center; }
.workout-count-step { display: none; width: 4.5rem; border: 1px solid currentColor; border-radius: 8px; line-height: 1; }
.workout-count-step + .workout-count-step { width: 3rem; height: 2.4rem; font-size: 1.5rem; margin-left: 0.5rem; }
.workout-counter.editing .workout-count-num { display: none; }
.workout-counter.editing .workout-count-step { display: block; }
.workout-counter-unit { position: absolute; left: 0; right: 0; top: 3rem; text-align: center; font-size: 0.9rem; opacity: 0.7; }
