/* ============================================
   Gym Tracking — dark sport theme
   Palette: carbon / plate / chalk / steel / ember
   ============================================ */

:root {
  --bg: #0B0C0E;          /* carbon black */
  --surface: #15171B;     /* plate dark */
  --surface-2: #1D2025;   /* plate light */
  --line: #262A31;        /* seam */
  --text: #F4F4F2;        /* chalk white */
  --muted: #8B9099;       /* steel grey */
  --accent: #FF6B1A;      /* ember orange */
  --accent-deep: #B63E05; /* burnt ember */
  --shell: 480px;         /* phone-first max width */
  --tabbar-h: 64px;

  --font-display: 'Anton', 'Arial Narrow', sans-serif;
  --font-body: -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

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

/* Author display rules (flex etc.) must never defeat the hidden attribute */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100dvh;
}

button { font-family: inherit; }

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */

.topbar {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 18px 20px 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 1px;
  color: var(--text);
}

.wordmark span { color: var(--accent); }

.topbar-date {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Views ---------- */

main {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 8px 20px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.view { display: none; }
.view.is-active { display: block; }

/* ---------- Streak scoreboard ---------- */

.scoreboard {
  text-align: center;
  padding: 26px 0 18px;
}

.scoreboard-label {
  font-size: 13px;
  letter-spacing: 6px;
  text-indent: 6px; /* balance the letter-spacing on the last char */
  color: var(--muted);
  text-transform: uppercase;
}

.scoreboard-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.scoreboard-num {
  font-family: var(--font-display);
  font-size: 112px;
  line-height: 1.1;
  color: var(--accent);
  text-shadow: 0 0 34px rgba(255, 107, 26, 0.35);
  font-variant-numeric: tabular-nums;
}

.scoreboard-unit {
  font-size: 18px;
  color: var(--muted);
}

.scoreboard-substats {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  margin-top: 6px;
}

.substat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.substat-num {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--text);
}

.substat-label {
  font-size: 13px;
  color: var(--muted);
}

.substat-divider {
  width: 1px;
  height: 16px;
  background: var(--line);
}

/* ---------- Big check-in button ---------- */

.checkin-btn {
  width: 100%;
  height: 64px;
  margin: 10px 0 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--accent), #E14E00);
  color: #17181A;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 4px 26px rgba(255, 107, 26, 0.30);
  animation: breathe 3s ease-in-out infinite;
}

.checkin-btn:active { transform: scale(0.98); }

@keyframes breathe {
  0%, 100% { box-shadow: 0 4px 22px rgba(255, 107, 26, 0.22); }
  50%      { box-shadow: 0 4px 34px rgba(255, 107, 26, 0.42); }
}

@media (prefers-reduced-motion: reduce) {
  .checkin-btn { animation: none; }
}

/* Already checked in today: quiet outline style, no glow */
.checkin-btn.is-done {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: none;
  animation: none;
  font-size: 16px;
  font-weight: 500;
}

/* ---------- Plate calendar ---------- */
/* Signature element: every checked day becomes an orange
   weight plate (disc with a center hole) hung on the month. */

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

.calendar-title {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--text);
  margin-bottom: 12px;
  padding-left: 4px;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  justify-items: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  justify-items: center;
  row-gap: 8px;
}

.day {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.day.is-blank {
  background: none;
  border: none;
}

.day.is-future {
  opacity: 0.35;
}

.day.is-today {
  border: 2px solid var(--accent);
  color: var(--text);
  animation: today-pulse 2.4s ease-in-out infinite;
}

@keyframes today-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 26, 0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(255, 107, 26, 0.18); }
}

@media (prefers-reduced-motion: reduce) {
  .day.is-today { animation: none; }
}

/* Checked day = orange weight plate: filled disc + center hole.
   It is a <button>: tap to view that day's photo. */
.day.is-checked {
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #FF8B45, var(--accent) 55%, var(--accent-deep));
  border-color: var(--accent-deep);
  color: #17181A;
  font-weight: 700;
}

.day.is-checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(23, 24, 26, 0.55); /* the plate's center hole */
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
}

.day.is-checked:active { transform: scale(0.92); }

/* Today + checked: keep the bright today ring on the plate */
.day.is-today.is-checked { border: 2px solid var(--accent); }

/* ---------- Photo viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 20px;
}

.viewer[hidden] { display: none; }

.viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
}

.viewer-body {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 100%;
}

.viewer-body img {
  max-width: 88vw;
  max-height: 66dvh;
  border-radius: 12px;
  border: 1px solid var(--line);
  object-fit: contain;
}

.viewer-body figcaption {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--text);
}

.viewer-actions {
  position: relative;
  display: flex;
  gap: 12px;
}

.viewer-btn {
  padding: 10px 22px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.viewer-btn.is-danger {
  color: #FF5C5C;
  border-color: rgba(255, 92, 92, 0.35);
  background: none;
}

/* ---------- Workout log ---------- */

.log-title {
  font-size: 18px;
  font-weight: 700;
  padding: 14px 0 14px;
}

.repeat-btn {
  width: 100%;
  padding: 13px 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 107, 26, 0.45);
  border-radius: 12px;
  background: rgba(255, 107, 26, 0.10);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.repeat-btn:active { transform: scale(0.98); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.chip {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.chip:active { transform: scale(0.95); }

.chip.is-add {
  background: none;
  border-style: dashed;
  color: var(--muted);
}

/* Pick-style chips (coach setup): orange when selected */
.chip.is-on {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 107, 26, 0.10);
}

/* Entry form */

.log-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 18px;
}

.form-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.form-row label {
  font-size: 13px;
  color: var(--muted);
  min-width: 30px;
}

.form-row input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px; /* 16px+ stops iOS from zooming in on focus */
  padding: 9px 10px;
  min-width: 0;
}

.form-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row input[type='number'] { width: 74px; text-align: center; }
.form-row input[type='text'] { flex: 1; }

.form-row .unit {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.kind-toggle { gap: 8px; }

.kind-btn {
  flex: 1;
  padding: 9px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.kind-btn.is-on {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 107, 26, 0.08);
}

.form-add-set {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  padding: 4px 0 10px 38px;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.form-save {
  flex: 1;
  padding: 12px 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #17181A;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.form-cancel {
  padding: 12px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}

/* Today's list */

.log-section-title {
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--muted);
  margin: 4px 0 10px;
}

.log-list { list-style: none; }

.log-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.log-item-main {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  min-width: 0;
}

.log-item-name { font-size: 15px; font-weight: 700; }

.log-item-detail { font-size: 14px; color: var(--accent); }

.log-item-note {
  width: 100%;
  font-size: 13px;
  color: var(--muted);
}

.log-item-del {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  padding: 6px;
  cursor: pointer;
}

.log-empty {
  font-size: 14px;
  color: var(--muted);
  padding: 6px 0 14px;
}

.week-stats {
  font-size: 13px;
  color: var(--muted);
  padding: 10px 0;
  text-align: center;
}

.log-item-kcal {
  font-size: 13px;
  color: var(--muted);
}

.weight-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
}

.compare-weight {
  display: block;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

.weight-row input {
  width: 64px;
  padding: 7px 8px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
}

.weight-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.weight-hint { color: var(--line); }

/* ---------- AI coach ---------- */

.coach-setup select,
.form-row select {
  flex: 1;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}

.coach-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 60px 0;
}

.coach-idle .form-save { width: 100%; max-width: 260px; }

.coach-idle-hint { color: var(--muted); font-size: 14px; }

.coach-loading {
  text-align: center;
  padding: 80px 0;
  color: var(--muted);
  font-size: 15px;
  animation: coach-pulse 1.4s ease-in-out infinite;
}

@keyframes coach-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .coach-loading { animation: none; }
}

.coach-settings-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 6px;
}

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

.rx-theme {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 12px;
}

.rx-row {
  font-size: 14px;
  color: var(--text);
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.rx-label {
  display: inline-block;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 2px;
  margin-right: 8px;
}

.rx-exercise {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.rx-ex-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rx-ex-name { font-size: 16px; font-weight: 700; }

.rx-import {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 107, 26, 0.45);
  background: rgba(255, 107, 26, 0.10);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.rx-ex-dose {
  font-size: 14px;
  color: var(--accent);
  margin-top: 4px;
}

.rx-ex-load {
  font-size: 13px;
  color: var(--text);
  margin-top: 4px;
}

.rx-cues {
  list-style: none;
  margin-top: 6px;
}

.rx-cues li {
  font-size: 13px;
  color: var(--muted);
  padding: 2px 0 2px 14px;
  position: relative;
}

.rx-cues li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--accent);
}

.rx-cues li.rx-mistake { color: #C77; }
.rx-cues li.rx-mistake::before { content: ''; }

.rx-meta {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--text);
  padding: 12px 0 6px;
}

.rx-note {
  font-size: 13px;
  color: var(--muted);
  padding: 2px 0;
}

.rx-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
}

/* ---------- Photo compare ---------- */

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.compare-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compare-cell img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.compare-cell select {
  width: 100%;
  padding: 9px 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  text-align: center;
}

.compare-gap {
  text-align: center;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--accent);
  padding: 16px 0;
}

/* ---------- Empty states ---------- */

.empty-state {
  min-height: 55dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.empty-state svg { color: var(--line); }

.empty-state p { font-size: 16px; color: var(--text); }

.empty-state .empty-hint { font-size: 13px; color: var(--muted); max-width: 260px; }

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(21, 23, 27, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.tab.is-active { color: var(--accent); }

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

.login {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.login-box .wordmark { font-size: 26px; }

.login-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.login-box input {
  padding: 13px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
}

.login-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-box button {
  padding: 13px 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #17181A;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.login-box button:disabled { opacity: 0.6; }

.login-error {
  min-height: 18px;
  font-size: 13px;
  color: #FF5C5C;
}

.logout-btn {
  display: block;
  margin: 6px auto 14px;
  padding: 8px 18px;
  background: none;
  border: none;
  color: var(--line);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  max-width: 86vw;
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
