:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-elevated: #121821;
  --bg-card: #171e29;
  --border: #253041;
  --text: #f2f5f8;
  --muted: #8b97a8;
  --primary: #3dd68c;
  --primary-press: #2fb875;
  --primary-text: #062416;
  --danger: #ff6b6b;
  --danger-bg: #2a1518;
  --accent: #5b9dff;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 48px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100dvh;
  padding:
    calc(12px + var(--safe-top))
    16px
    calc(20px + var(--safe-bottom));
}

.app-screen {
  max-width: 480px;
  margin: 0 auto;
}

.overlay-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  overflow-y: auto;
  max-width: 480px;
  margin: 0 auto;
  left: 0;
  right: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.spacer {
  width: var(--tap);
}

.muted {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 0.9rem;
}

.sync-status {
  margin-top: 2px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.sync-status.ok {
  color: var(--primary);
}

.sync-status.warn {
  color: #f0c674;
}

.sync-status.err {
  color: var(--danger);
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 1.15rem;
  display: grid;
  place-items: center;
}

.icon-btn:active {
  transform: scale(0.96);
  background: #1d2633;
}

.log-panel {
  background: linear-gradient(180deg, #151c27 0%, var(--bg-card) 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.exercise-btn {
  min-height: 64px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

.exercise-btn .name {
  font-weight: 700;
  font-size: 1rem;
}

.exercise-btn .unit {
  color: var(--muted);
  font-size: 0.8rem;
}

.exercise-btn.selected {
  border-color: var(--primary);
  background: rgba(61, 214, 140, 0.12);
  box-shadow: inset 0 0 0 1px rgba(61, 214, 140, 0.35);
}

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

.stopwatch-panel {
  margin-top: 18px;
  padding: 14px 12px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.08);
  text-align: center;
}

.stopwatch-display {
  font-size: 3.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin: 4px 0 12px;
  color: var(--primary);
}

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

.stopwatch-actions .btn {
  min-height: 48px;
}

.value-panel {
  margin-top: 18px;
}

.value-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.value-row {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  gap: 10px;
  align-items: center;
}

.step-btn {
  height: 64px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 1.8rem;
  font-weight: 500;
  line-height: 1;
}

.step-btn:active {
  background: #1d2633;
}

#value-input {
  width: 100%;
  height: 64px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #0e131a;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  outline: none;
}

#value-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(61, 214, 140, 0.18);
}

/* Hide number spinners */
#value-input::-webkit-outer-spin-button,
#value-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#value-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.quick-adds {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
}

.chip:active {
  background: #1d2633;
}

.btn {
  min-height: var(--tap);
  border-radius: 14px;
  padding: 0 16px;
  font-weight: 700;
  font-size: 1rem;
  border: 1px solid transparent;
}

.btn.full {
  width: 100%;
  margin-top: 10px;
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn.primary:active {
  background: var(--primary-press);
}

.btn.secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn.secondary:active {
  background: #1d2633;
}

.btn.danger {
  background: var(--danger-bg);
  border-color: #4a2228;
  color: var(--danger);
}

.log-btn {
  width: 100%;
  margin-top: 16px;
  min-height: 60px;
  font-size: 1.15rem;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(61, 214, 140, 0.22);
}

.today-section {
  margin-top: 22px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.totals {
  margin: 0;
  text-align: right;
  font-size: 0.82rem;
  line-height: 1.35;
  max-width: 60%;
}

.set-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.set-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px 12px 14px;
  min-height: 56px;
}

.set-item .meta {
  min-width: 0;
}

.set-item .name {
  font-weight: 700;
  font-size: 1rem;
}

.set-item .time {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.set-item .value {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  white-space: nowrap;
}

.set-item .delete {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 1.1rem;
  background: transparent;
}

.set-item .delete:active {
  color: var(--danger);
  background: var(--danger-bg);
}

.empty {
  text-align: center;
  padding: 18px 8px 8px;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.day-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.day-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.day-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.pill {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 600;
}

.day-sets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day-sets li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 4px 0;
  border-top: 1px solid rgba(37, 48, 65, 0.7);
}

.day-sets li:first-child {
  border-top: none;
}

.day-sets .strong {
  color: var(--text);
  font-weight: 700;
}

/* Settings */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.settings-card h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.settings-card input[type="password"],
.pin-card input,
.auth-card input,
.settings-card input[type="password"],
.settings-card input[type="email"] {
  width: 100%;
  min-height: 52px;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0e131a;
  padding: 0 14px;
  font-size: 1.1rem;
  outline: none;
  color: var(--text);
}

.settings-card input:focus,
.pin-card input:focus,
.auth-card input:focus {
  border-color: var(--accent);
}

.auth-card {
  text-align: left;
}

.auth-card h1,
.auth-card > .muted {
  text-align: center;
}

.auth-card .btn.full:first-of-type {
  margin-top: 14px;
}

.file-label {
  display: grid;
  place-items: center;
  margin-top: 10px;
}

.msg {
  min-height: 1.2em;
  margin-top: 10px;
}

.ok {
  color: var(--primary);
  font-weight: 600;
}

.error {
  color: var(--danger);
  margin: 8px 0 0;
  font-size: 0.9rem;
}

/* PIN */
.pin-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #162033 0%, var(--bg) 55%);
  padding: 24px;
}

.pin-card {
  width: min(100%, 360px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
  text-align: center;
}

.pin-card h1 {
  margin: 0;
  font-size: 1.4rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  background: #203049;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (min-width: 481px) {
  body {
    background: #070a0e;
  }

  .app-screen,
  .overlay-screen {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
