@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500;700&family=Inter:wght@400;500;700&display=swap');

:root {
  --pf-purple: #A4278D;
  --pf-purple-dark: #7A1D68;
  --pf-yellow: #F9F72E;
  --pf-black: #17151A;
  --pf-white: #FFFFFF;
  --pf-gray: #F3F1F5;
  --pf-gray-line: #E3DEE8;
  --radius: 14px;
}

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

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

body {
  margin: 0;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--pf-black);
  color: var(--pf-black);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

/* ── Login screen ───────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  text-align: center;
}
.login-screen .wordmark {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: clamp(26px, 8vw, 34px);
  color: var(--pf-white);
  text-transform: lowercase;
  margin: 0 0 28px;
}
.login-screen .wordmark span { color: var(--pf-yellow); }

.login-card {
  background: var(--pf-white);
  border-radius: 20px;
  padding: 32px 26px;
  width: 100%;
  max-width: 320px;
}
.login-card label {
  display: block;
  font-family: 'Oswald', sans-serif;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #4a4552;
  margin-bottom: 14px;
}
.login-card input {
  width: 100%;
  font-family: 'Oswald', sans-serif;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 16px;
  text-align: center;
  padding: 16px 0;
  border: 2px solid var(--pf-gray-line);
  border-radius: 12px;
  margin-bottom: 18px;
  background: var(--pf-white);
  color: var(--pf-black);
  color-scheme: light;
  touch-action: manipulation;
}
.login-card input:focus {
  outline: none;
  border-color: var(--pf-purple);
}
.login-card .btn { width: 100%; min-height: 58px; font-size: 18px; }
.login-error {
  color: #d13c3c;
  font-size: 15px;
  min-height: 20px;
  margin: 12px 0 0;
}

/* ── Header ─────────────────────────────────────────── */
header.top {
  background: var(--pf-black);
  padding: max(22px, env(safe-area-inset-top)) 20px 26px;
  text-align: center;
  border-bottom: 6px solid var(--pf-yellow);
}

header.top .wordmark {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: clamp(28px, 8vw, 34px);
  letter-spacing: 0.5px;
  color: var(--pf-white);
  text-transform: lowercase;
  margin: 0;
}
header.top .wordmark span { color: var(--pf-yellow); }

header.top .tagline {
  font-family: 'Oswald', sans-serif;
  color: var(--pf-purple);
  background: var(--pf-yellow);
  display: inline-block;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 10px;
}

/* ── Main app surface ───────────────────────────────── */
main {
  background: var(--pf-gray);
  border-radius: 22px 22px 0 0;
  min-height: calc(100vh - 100px);
  min-height: calc(100dvh - 100px);
  padding: 18px 16px calc(60px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

/* ── Profile switcher ───────────────────────────────── */
.profile-switch {
  display: flex;
  gap: 8px;
  background: var(--pf-white);
  padding: 6px;
  border-radius: 999px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.profile-switch button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 14px 0;
  min-height: 54px;
  font-family: 'Oswald', sans-serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--pf-black);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
  user-select: none;
}
.profile-switch button.active {
  background: var(--pf-purple);
  color: var(--pf-white);
}

/* ── Progress bar ───────────────────────────────────── */
/* ── New Session button ─────────────────────────────── */
.new-session-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  min-height: 76px;
  margin-bottom: 20px;
  background: var(--pf-yellow);
  color: var(--pf-black);
  border: none;
  border-radius: 16px;
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}
.new-session-btn .cal-icon { font-size: 32px; }
.new-session-btn:active { background: #e8e62a; }

.date-field {
  width: 100%;
  padding: 14px;
  min-height: 56px;
  border: 2px solid var(--pf-gray-line);
  border-radius: 12px;
  font-size: 20px;
  font-family: 'Oswald', sans-serif;
  font-weight: 600;
  text-align: center;
  background: var(--pf-white);
  color: var(--pf-black);
  color-scheme: light;
  touch-action: manipulation;
  margin-bottom: 18px;
}
.date-field:focus { outline: none; border-color: var(--pf-purple); }

.progress-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 0 4px;
}
.progress-wrap .date-label {
  font-size: 16px;
  color: #4a4552;
  font-weight: 600;
}
.progress-wrap .count-label {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--pf-purple);
}
.progress-track {
  height: 12px;
  background: var(--pf-gray-line);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 22px;
}
.progress-fill {
  height: 100%;
  background: var(--pf-yellow);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* ── Machine grid ───────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

.card {
  background: var(--pf-white);
  border-radius: var(--radius);
  padding: 18px 16px;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}
.card.done { border-color: var(--pf-yellow); }

.card .badge {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: var(--pf-white);
  background: var(--pf-purple);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.card .weight-line {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 36px;
  color: var(--pf-black);
  cursor: pointer;
  line-height: 1.15;
  touch-action: manipulation;
  padding: 4px 0;
}
.card .weight-line .unit { font-size: 16px; font-weight: 500; color: #4a4552; }
.card .rep-line {
  font-size: 16px;
  color: #4a4552;
  margin-top: 4px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 22px;
}
.card .empty-state {
  font-size: 17px;
  font-weight: 600;
  color: var(--pf-purple);
  cursor: pointer;
  padding: 12px 0;
  touch-action: manipulation;
}

.card .check-circle {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--pf-gray-line);
  background: var(--pf-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  touch-action: manipulation;
  user-select: none;
}
.card .check-circle::before {
  /* expands the tappable area a little further beyond the visible circle */
  content: '';
  position: absolute;
  inset: -6px;
}
.card .check-circle svg {
  width: 24px;
  height: 24px;
  opacity: 0;
  transition: opacity 0.1s ease;
}
.card.done .check-circle {
  background: var(--pf-yellow);
  border-color: var(--pf-yellow);
}
.card.done .check-circle svg { opacity: 1; }

.card .history-link {
  display: block;
  margin-top: 14px;
  padding: 6px 0;
  font-size: 15px;
  color: var(--pf-purple);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23,21,26,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  overscroll-behavior: contain;
  padding: 0;
}
@media (min-width: 480px) {
  .modal-overlay { align-items: center; padding: 20px; }
}
.modal {
  background: var(--pf-white);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 420px;
  max-height: min(85vh, 85dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
  position: relative;
}
@media (min-width: 480px) {
  .modal { border-radius: 20px; }
}
.modal h2 {
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  margin: 0 0 6px;
  font-size: 26px;
}
.modal .sub {
  font-size: 16px;
  color: #4a4552;
  margin-bottom: 20px;
}

/* stacked stepper fields — tap +/- instead of typing on a tiny keyboard */
.stepper-field { margin-bottom: 18px; }
.stepper-field label {
  display: block;
  font-family: 'Oswald', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: #4a4552;
  margin-bottom: 8px;
}
.stepper {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.step-btn {
  width: 56px;
  min-height: 56px;
  flex-shrink: 0;
  border: 2px solid var(--pf-gray-line);
  background: var(--pf-gray);
  color: var(--pf-purple);
  border-radius: 12px;
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-btn:active { background: var(--pf-purple); color: var(--pf-white); border-color: var(--pf-purple); }
.step-btn.minor { font-size: 17px; }
.stepper input {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 8px;
  border: 2px solid var(--pf-gray-line);
  border-radius: 12px;
  font-size: 30px;
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  text-align: center;
  background: var(--pf-white);
  color: var(--pf-black);
  color-scheme: light;
  touch-action: manipulation;
}
.stepper input:focus { outline: none; border-color: var(--pf-purple); }

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}
.btn {
  flex: 1;
  border: none;
  padding: 16px;
  min-height: 58px;
  border-radius: 12px;
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
  cursor: pointer;
  text-transform: uppercase;
  touch-action: manipulation;
  user-select: none;
}
.btn-primary { background: var(--pf-purple); color: var(--pf-white); }
.btn-secondary { background: var(--pf-gray); color: var(--pf-black); }

.modal .close-x {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  font-size: 26px;
  color: #6b6472;
  cursor: pointer;
  padding: 12px;
  touch-action: manipulation;
}

/* ── History view ───────────────────────────────────── */
.history-empty {
  text-align: center;
  color: #4a4552;
  font-size: 16px;
  padding: 30px 0;
}
canvas#historyChart {
  width: 100%;
  height: 170px;
  display: block;
  margin-bottom: 16px;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
}
.history-table th {
  text-align: left;
  color: #6b6472;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--pf-gray-line);
}
.history-table td {
  padding: 11px 0;
  border-bottom: 1px solid var(--pf-gray-line);
}
.history-table td.delta-up { color: #1a9e5c; font-weight: 700; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--pf-black);
  color: var(--pf-white);
  padding: 14px 24px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

.logout-link {
  display: block;
  margin: 28px auto 0;
  background: none;
  border: none;
  color: #6b6472;
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 10px;
  touch-action: manipulation;
}

.loading, .error-state {
  text-align: center;
  color: var(--pf-white);
  padding: 40px 20px;
}

/* ── Mobile refinements ─────────────────────────────── */

/* short/landscape phones: reclaim vertical space */
@media (orientation: landscape) and (max-height: 500px) {
  header.top { padding: max(10px, env(safe-area-inset-top)) 20px 12px; }
  header.top .tagline { display: none; }
  main { padding-top: 12px; }
  .modal { max-height: min(92vh, 92dvh); }
}

/* cleaner numeric inputs on mobile (hide spinner arrows) */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
