:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2a2f3a;
  --text: #e8ebf1;
  --text-dim: #9098a8;
  --accent: #4ade80;
  --accent-dim: #2f7f4f;
  --gold: #ffb020;
  --gold-dim: #8a5e0e;
  --danger: #f87171;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  height: 100%;
  /* Lock body scroll bounce so the app feels app-like on iOS. */
  overscroll-behavior-y: none;
}
body {
  background: radial-gradient(1200px 600px at 50% -200px, #1b2030 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  min-height: 100%;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  /* Disable text selection on UI chrome — feels native. The recent feed
     is fine because users won't usually drag-select rep counts. */
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input { font: inherit; color: inherit; }
input { -webkit-user-select: text; user-select: text; }

.app {
  max-width: 480px;
  margin: 0 auto;
  /* Respect iOS notch and home-indicator safe areas. */
  padding:
    calc(20px + env(safe-area-inset-top))
    calc(18px + env(safe-area-inset-right))
    calc(40px + env(safe-area-inset-bottom))
    calc(18px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ── Topbar ───────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin: 0;
  color: var(--text);
}
.streak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.streak-flame { font-size: 16px; }

/* ── Exercise pills ───────────────────────────────── */
.exercises {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-weight: 500;
  font-size: 14px;
  min-height: 40px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.pill:hover { background: var(--surface-2); }
.pill:active { transform: scale(0.97); }
.pill.is-active {
  background: rgba(74, 222, 128, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}
.pill.add { color: var(--text-dim); }

/* ── Hero (ring + big number) ─────────────────────── */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
  text-align: center;
}
.ring-wrap {
  position: relative;
  width: 240px;
  height: 240px;
}
.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 14;
}
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.55s cubic-bezier(.2,.7,.2,1), stroke 0.3s ease;
}
.ring-fill.is-goal {
  stroke: var(--gold);
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}
.big-number {
  font-size: 72px;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1.5px;
  color: var(--text);
}
.big-number.is-goal { color: var(--gold); }
.goal {
  background: transparent;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 500;
  pointer-events: auto;
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.goal:hover { background: var(--surface); color: var(--text); }
.pencil { font-size: 12px; opacity: 0.6; }

.pop {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  pointer-events: none;
  animation: pop-rise 0.9s ease-out forwards;
  text-shadow: 0 2px 12px rgba(74, 222, 128, 0.35);
}
@keyframes pop-rise {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.8); }
  20%  { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}

.last-set {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.motivation {
  color: var(--text-dim);
  font-size: 15px;
  font-style: italic;
  min-height: 1.4em;
}

/* ── Logger ───────────────────────────────────────── */
.logger {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.log-form {
  display: flex;
  gap: 10px;
}
.log-input {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
  -moz-appearance: textfield;
}
.log-input::-webkit-outer-spin-button,
.log-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.log-input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
}
.log-input::placeholder { color: var(--text-dim); font-weight: 500; }
.log-submit {
  height: var(--tap);
  padding: 0 22px;
  background: var(--accent);
  color: #07120c;
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(74, 222, 128, 0.25);
}
.log-submit:hover { background: #5ee895; }
.log-submit:active { transform: scale(0.97); }

.quick-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.quick {
  height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.quick:hover { background: var(--surface-2); border-color: var(--accent-dim); }
.quick:active { transform: scale(0.96); }

/* ── Charts ───────────────────────────────────────── */
.charts {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 18px;
  box-shadow: var(--shadow);
}
.tabs {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  margin-bottom: 10px;
}
.tab {
  padding: 6px 14px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab.is-active {
  background: var(--surface);
  color: var(--text);
}
.chart-wrap {
  position: relative;
  height: 200px;
}

/* ── Recent list ──────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 4px 10px;
}
.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}
.recent-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 16px 0;
  font-style: italic;
}
.recent-reps {
  font-weight: 700;
  color: var(--text);
}
.recent-meta {
  color: var(--text-dim);
  font-size: 13px;
  margin-left: 8px;
}
.undo {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.undo:hover {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
}

/* ── Footer ───────────────────────────────────────── */
.footer {
  text-align: center;
  margin-top: 4px;
}
.reset-link {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: rgba(144, 152, 168, 0.4);
  text-underline-offset: 3px;
  padding: 8px 12px;
}
.reset-link:hover { color: var(--danger); }

/* ── Toast ────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--gold);
  color: #1a1100;
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(255, 176, 32, 0.35);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Dialogs ──────────────────────────────────────── */
.dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  width: min(92vw, 360px);
  box-shadow: var(--shadow);
}
.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}
.dialog-form h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
.dialog-form input {
  height: 44px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.dialog-form input:focus { border-color: var(--accent); }
.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.btn-primary, .btn-secondary {
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--accent);
  color: #07120c;
}
.btn-primary:hover { background: #5ee895; }
.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }

/* ── Small screens ────────────────────────────────── */
@media (max-width: 380px) {
  .app { padding-left: calc(14px + env(safe-area-inset-left));
         padding-right: calc(14px + env(safe-area-inset-right)); gap: 18px; }
  .big-number { font-size: 60px; }
  .ring-wrap { width: 220px; height: 220px; }
  .quick { font-size: 14px; }
  .pill { padding: 9px 12px; font-size: 13px; }
  .brand { font-size: 16px; }
}

/* ── iOS standalone (Add to Home Screen) ──────────── */
@media all and (display-mode: standalone) {
  body { background-color: var(--bg); }
}

/* ── Reduced motion ───────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
