/* ============================================================
   IPPT Counter – Stylesheet
   Dark theme · Singapore red accents
   ============================================================ */

:root {
  --red:        #DC2626;
  --red-light:  #EF4444;
  --red-dark:   #B91C1C;
  --bg:         #0D0D0D;
  --surface:    #1A1A1A;
  --surface2:   #252525;
  --surface3:   #333333;
  --border:     rgba(255,255,255,0.08);
  --text:       #F5F5F5;
  --text-muted: #9CA3AF;
  --green:      #22C55E;
  --yellow:     #F59E0B;
  --orange:     #F97316;
  --blue:       #3B82F6;
  --radius:     14px;
  --radius-sm:  8px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ======================== SCREEN SYSTEM ======================== */

.screen {
  display: none;
  min-height: 100dvh;
  min-height: 100vh;
}
.screen.active { display: block; }

/* ======================== HOME SCREEN ======================== */

.home-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 32px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.logo-section {
  text-align: center;
  padding-top: 16px;
}

.logo-badge {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 4px rgba(220,38,38,0.3);
}
.logo-badge svg { width: 100%; height: 100%; }

h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 0%, #ccc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 6px;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* Profile card */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.toggle-group {
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.toggle-btn {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.active {
  background: var(--red);
  color: #fff;
  box-shadow: 0 2px 6px rgba(220,38,38,0.4);
}

.select-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  padding-right: 28px;
}
.select-input:focus { outline: 2px solid var(--red); outline-offset: 1px; }

/* Exercise cards */
.exercise-section {}

.exercise-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  user-select: none;
}
.exercise-card:hover, .exercise-card:focus-visible {
  border-color: var(--red);
  background: var(--surface2);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(220,38,38,0.15);
  outline: none;
}
.exercise-card:active { transform: translateY(0); }

.exercise-icon { font-size: 2rem; margin-bottom: 8px; }

.exercise-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.exercise-card p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.exercise-arrow {
  position: absolute;
  top: 10px; right: 12px;
  color: var(--red);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.2s;
}
.exercise-card:hover .exercise-arrow { opacity: 1; }

.disclaimer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--surface3);
}

/* ======================== SETUP SCREEN ======================== */

.setup-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
}
.setup-header h2 { font-size: 1.2rem; font-weight: 700; }

.icon-btn {
  width: 40px; height: 40px;
  border: none;
  background: var(--surface);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--surface2); }
.icon-btn svg { width: 18px; height: 18px; }

.setup-diagram-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.setup-diagram-wrapper svg { max-width: 100%; height: 140px; }

.setup-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setup-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px;
  border: 1px solid var(--border);
}

.step-num {
  width: 28px; height: 28px;
  background: var(--red);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.step-body strong { font-size: 0.9rem; }
.step-body span { font-size: 0.82rem; color: var(--text-muted); }

/* ======================== EXERCISE SCREEN ======================== */

.exercise-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  max-width: 600px;
  margin: 0 auto;
}

.ex-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
}

.ex-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.timer-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 1.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  min-width: 66px;
  text-align: center;
}
.timer-pill.running { color: var(--green); border-color: var(--green); }
.timer-pill.low { color: var(--orange); border-color: var(--orange); }

/* Camera wrapper */
.camera-wrapper {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
  min-height: 0;
}

#video, #canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}

#canvas { pointer-events: none; }

.cam-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
  z-index: 10;
}
.cam-loading.hidden { display: none; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--surface3);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.angle-svg {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 5;
}

.cam-flip-btn {
  position: absolute;
  bottom: 12px; right: 12px;
  width: 40px; height: 40px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: #fff;
  z-index: 20;
  transition: background 0.15s;
}
.cam-flip-btn:hover { background: rgba(0,0,0,0.8); }
.cam-flip-btn svg { width: 18px; height: 18px; }

/* Stats bar */
.stats-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.stat-box {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
}

.stat-val {
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.stat-val.warn { color: var(--orange); }
.stat-val.good { color: var(--green); }

.stat-lbl {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 4px;
}

.stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
}

/* Feedback strip */
.feedback-strip {
  padding: 10px 16px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  min-height: 44px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#feedback-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.2s;
}
#feedback-text.good  { color: var(--green); font-weight: 600; }
#feedback-text.warn  { color: var(--orange); font-weight: 600; }
#feedback-text.error { color: var(--red-light); font-weight: 600; }
#feedback-text.info  { color: var(--blue); font-weight: 600; }

/* Action row */
.action-row {
  padding: 12px 16px 20px;
  background: var(--bg);
  flex-shrink: 0;
}

/* ======================== BUTTONS ======================== */

.btn-primary, .btn-start {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 24px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 4px 16px rgba(220,38,38,0.3);
}
.btn-primary:hover, .btn-start:hover { background: var(--red-light); transform: translateY(-1px); }
.btn-primary:active, .btn-start:active { transform: translateY(0); }
.btn-primary svg { width: 18px; height: 18px; }
.btn-primary.full-width { width: 100%; }

.btn-start.counting {
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: none;
  cursor: default;
}

.btn-start.paused {
  background: var(--yellow);
  color: #000;
  box-shadow: 0 4px 16px rgba(245,158,11,0.3);
}

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-outline:hover { background: var(--surface); }

/* ======================== RESULTS SCREEN ======================== */

.results-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.results-header {
  text-align: center;
}
.results-badge { font-size: 3rem; }
.results-header h2 { font-size: 1.6rem; font-weight: 800; margin-top: 8px; }
.results-profile { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.big-count {
  text-align: center;
  background: linear-gradient(135deg, var(--red-dark), var(--red));
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 8px 32px rgba(220,38,38,0.25);
}
.big-num {
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.big-lbl {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.8;
  margin-top: 8px;
}

.results-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.results-detail-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
}
.rd-val {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.rd-lbl {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.ippt-score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ippt-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ippt-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}
.ippt-pts {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--yellow);
}
.ippt-progress-bar {
  height: 8px;
  background: var(--surface3);
  border-radius: 4px;
  overflow: hidden;
}
.ippt-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--yellow), var(--orange));
  border-radius: 4px;
  transition: width 0.6s ease;
}
.ippt-award {
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}
.ippt-award.gold   { color: #F59E0B; }
.ippt-award.silver { color: #9CA3AF; }
.ippt-award.pass   { color: var(--green); }

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ======================== REP FLASH ANIMATION ======================== */
@keyframes repFlash {
  0%   { background: rgba(34,197,94,0.3); }
  100% { background: transparent; }
}
.rep-flash { animation: repFlash 0.5s ease; }

/* ======================== RESPONSIVE ======================== */

@media (min-width: 640px) {
  .exercise-layout {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (max-width: 400px) {
  .profile-grid { grid-template-columns: 1fr; }
  .exercise-cards { grid-template-columns: 1fr 1fr; }
  .big-num { font-size: 4rem; }
}

/* Prevent iOS rubber-band scroll on exercise screen */
#screen-exercise { overflow: hidden; }
