:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --bg-elevated: #15181d;
  --bg-card: #1a1e24;
  --border: #262b33;
  --text: #f2f3f5;
  --text-dim: #8b93a1;
  --text-faint: #5a616e;
  --accent: #5eead4;
  --accent-dim: #2dd4bf22;
  --accent-strong: #14b8a6;
  --danger: #f87171;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS Safari auto-zoom on focus */
}

input,
select,
textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-strong);
}

button {
  border: none;
  cursor: pointer;
  font-weight: 600;
  border-radius: var(--radius-sm);
  -webkit-user-select: none;
  user-select: none;
}

button:active {
  transform: scale(0.97);
}

.btn {
  padding: 13px 18px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  color: #062420;
  border: none;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid #7f1d1d;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 10px;
  background: transparent;
  color: var(--text-dim);
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  margin: 0 0 4px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
  color: var(--text-dim);
}

/* ---------- app shell ---------- */

#app {
  min-height: 100%;
  padding-top: var(--safe-top);
}

.screen {
  padding: 22px 20px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
  animation: fadein 0.18s ease;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 18px;
}

.topbar h1 {
  font-size: 22px;
}

/* ---------- bottom nav ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(21, 24, 29, 0.92);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border-top: 1px solid var(--border);
  z-index: 40;
}

.tabbar button {
  flex: 1;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 0 0;
}

.tabbar button svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-faint);
  fill: none;
  stroke-width: 1.8;
}

.tabbar button.active {
  color: var(--accent);
}

.tabbar button.active svg {
  stroke: var(--accent);
}

/* ---------- cards / lists ---------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 14px;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

.stat-tile .value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-faint);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .field {
  flex: 1;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 18px 0;
  border: none;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #062420;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(94, 234, 212, 0.35);
  z-index: 30;
}

/* ---------- login ---------- */

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 26px;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}

.login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ---------- active session ---------- */

.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.set-row .set-num {
  color: var(--text-faint);
  font-weight: 700;
  text-align: center;
}

.set-row.done {
  opacity: 0.55;
}

.check-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
}

.check-btn.checked {
  background: var(--accent);
  color: #062420;
  border-color: var(--accent);
}

/* ---------- charts ---------- */

.chart-wrap {
  width: 100%;
  overflow: hidden;
}

.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-empty {
  color: var(--text-faint);
  font-size: 13px;
  padding: 30px 0;
  text-align: center;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 100px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}

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

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: dark;
  }
}
