/* ==========================================================================
   Barbell Plate Calculator — Mobile-First Apple Fitness / Whoop Dark Theme
   - Zero mobile tap-to-zoom (touch-action: manipulation, font-size >= 16px)
   - Compact single-screen layout for phones (320px+)
   - Frosted dark glass with luminous accents
   ========================================================================== */

:root {
  /* Dark space glass palette */
  --bg-core: #08090c;
  --bg-card: rgba(18, 22, 30, 0.78);
  --bg-subtle: rgba(255, 255, 255, 0.04);
  --bg-active: rgba(56, 189, 248, 0.12);

  --border-glass: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(255, 255, 255, 0.14);
  --border-accent: rgba(56, 189, 248, 0.45);

  /* Luminous accents */
  --accent-cyan: #38bdf8;
  --accent-cyan-glow: rgba(56, 189, 248, 0.25);
  --accent-rose: #fb7185;

  /* Typography */
  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Plate Colors (Olympic Competition) */
  --plate-blue: #2563eb;
  --plate-yellow: #eab308;
  --plate-yellow-text: #0f172a;
  --plate-green: #16a34a;
  --plate-white: #f1f5f9;
  --plate-white-text: #0f172a;

  /* Barbell Metals */
  --bar-shaft: #94a3b8;
  --bar-collar: #e2e8f0;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", -apple-system, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;

  --radius-pill: 9999px;
  --radius-xl: 18px;
  --radius-lg: 12px;
  --radius-md: 8px;
  --radius-sm: 6px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Zero zoom & smooth touch behavior */
html, body {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-core);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.4;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

/* Prevent double-tap zoom across all buttons, chips, and controls */
button, input, select, a,
.stepper-btn, .segmented-pill, .quick-chip, .clear-chip, .closest-btn {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* Ambient glow */
.ambient-glow {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  width: 500px;
  height: 300px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.07) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app-container {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 1;
}

main {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ==========================================================================
   Header (Minimalist & Compact)
   ========================================================================== */
.app-header {
  text-align: center;
  padding: 2px 0;
}

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.4));
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ==========================================================================
   Glass Card
   ========================================================================== */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: 16px;
  box-shadow: 0 12px 28px -6px rgba(0, 0, 0, 0.65), inset 0 1px 0 var(--border-highlight);
}

/* ==========================================================================
   Segmented Bar Control (Single row, touch-friendly)
   ========================================================================== */
.segmented-bar-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.segmented-pill {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  padding: 8px 4px;
  min-height: 44px; /* Apple minimum touch target */
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.segmented-pill .pill-name {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.15;
}

.segmented-pill .pill-weight {
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.segmented-pill:hover {
  color: var(--text-primary);
  background: var(--bg-subtle);
}

.segmented-pill.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-accent);
  color: #ffffff;
  box-shadow: 0 0 12px var(--accent-cyan-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.segmented-pill.active .pill-weight {
  color: var(--accent-cyan);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==========================================================================
   Weight Input & Steppers (Large thumb targets)
   ========================================================================== */
.weight-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 4px 8px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.weight-input-container:focus-within {
  border-color: var(--border-accent);
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

.weight-display-wrapper {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
}

.input-weight {
  width: 100%;
  max-width: 180px;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 2.5rem; /* well above 16px, prevents iOS zoom */
  font-weight: 800;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  text-align: center;
  padding: 2px 0;
  outline: none;
}

.input-weight::-webkit-outer-spin-button,
.input-weight::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.input-weight[type=number] {
  -moz-appearance: textfield;
}

.input-weight::placeholder {
  color: rgba(255, 255, 255, 0.15);
}

.weight-unit-badge {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent-cyan);
  margin-left: -8px;
  pointer-events: none;
}

/* Stepper buttons (48px touch targets) */
.stepper-btn {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}

.stepper-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.stepper-btn:active {
  transform: scale(0.92);
  background: var(--bg-active);
  border-color: var(--border-accent);
}

/* ==========================================================================
   Milestones Presets Row
   ========================================================================== */
.presets-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.presets-row::-webkit-scrollbar {
  display: none;
}

.presets-list {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
}

.quick-chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.quick-chip:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.quick-chip:active {
  transform: scale(0.94);
}

.clear-chip {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  margin-left: auto;
  transition: all 0.12s ease;
}

.clear-chip:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Empty & Error State Cards
   ========================================================================== */
.state-card {
  text-align: center;
  padding: 24px 16px;
}

.state-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
}

.error-state {
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.06);
}

.error-message {
  color: var(--accent-rose);
  font-size: 0.92rem;
  font-weight: 600;
}

.error-closest {
  margin-top: 8px;
}

.closest-heading {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.closest-buttons {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.closest-btn {
  background: rgba(251, 113, 133, 0.15);
  border: 1px solid rgba(251, 113, 133, 0.4);
  color: #ffffff;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.closest-btn:hover {
  background: var(--accent-rose);
  color: #000000;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Results View
   ========================================================================== */
.results-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 16px;
}

.result-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.result-headline {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
}

.res-target-weight {
  font-size: 2.3rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #ffffff;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.res-target-unit {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.res-dot {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.res-bar-name {
  font-size: 0.84rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.res-badge-wrap {
  margin-top: 5px;
}

.res-side-badge {
  display: inline-block;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent-cyan);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
}

/* ==========================================================================
   Barbell Visualization Stage
   ========================================================================== */
.barbell-stage {
  width: 100%;
  padding: 16px 0;
  margin: 4px 0;
  border-radius: var(--radius-lg);
  background: radial-gradient(ellipse at center, rgba(56, 189, 248, 0.06) 0%, rgba(0, 0, 0, 0.28) 70%);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

.barbell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  height: 124px;
  position: relative;
  user-select: none;
}

/* Center shaft */
.bar-shaft {
  flex: 1;
  min-width: 25px;
  max-width: 180px;
  height: 8px;
  background: linear-gradient(180deg, #e2e8f0 0%, #94a3b8 50%, #475569 100%);
  position: relative;
  border-radius: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.knurl {
  width: 20px;
  height: 100%;
  background: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2) 1px, transparent 1px, transparent 3px);
  opacity: 0.6;
}

/* Collar flanges */
.bar-collar {
  width: 6px;
  height: 32px;
  background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 45%, #64748b 100%);
  border-radius: 2px;
  flex-shrink: 0;
  z-index: 3;
}

/* Sleeves */
.sleeve {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 220px;
  height: 120px;
}

.sleeve::before {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 12px;
  background: linear-gradient(180deg, #94a3b8 0%, #64748b 50%, #1e293b 100%);
  border-radius: 2px;
  z-index: 1;
}

.sleeve-left {
  justify-content: flex-end;
}

.sleeve-right {
  justify-content: flex-start;
}

.plates {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 2;
  gap: 2px;
}

.plates-left {
  justify-content: flex-end;
}

.plates-right {
  justify-content: flex-start;
}

/* Empty bar */
.barbell.barbell-empty .sleeve {
  min-width: 45px;
}

/* ==========================================================================
   Plates Rendering (Clean Minimal Bumpers)
   ========================================================================== */
.plate {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: width 0.12s ease, height 0.12s ease;
  overflow: hidden;
}

.plate-large {
  height: 114px;
}

.plate-small {
  height: 70px;
}

.plate-thick {
  width: 18px;
}

.plate-medium {
  width: 13px;
}

.plate-thin {
  width: 8px;
}

.plate-blue {
  background: linear-gradient(90deg, #1e40af 0%, #2563eb 50%, #1d4ed8 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.plate-yellow {
  background: linear-gradient(90deg, #a16207 0%, #eab308 50%, #ca8a04 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--plate-yellow-text);
}

.plate-green {
  background: linear-gradient(90deg, #14532d 0%, #16a34a 50%, #15803d 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.plate-white {
  background: linear-gradient(90deg, #cbd5e1 0%, #f8fafc 50%, #e2e8f0 100%);
  border: 1px solid #94a3b8;
  color: var(--plate-white-text);
}

.plate-label {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 9.5px;
  line-height: 1;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  pointer-events: none;
  letter-spacing: -0.5px;
}

.plate-thin .plate-label {
  display: none;
}

/* Compact scale for many plates */
.barbell.barbell-compact .plate-thick {
  width: 14px;
}
.barbell.barbell-compact .plate-medium {
  width: 10px;
}
.barbell.barbell-compact .plate-thin {
  width: 6px;
}
.barbell.barbell-compact .plate-large {
  height: 104px;
}
.barbell.barbell-compact .plate-small {
  height: 64px;
}
.barbell.barbell-compact .bar-shaft {
  min-width: 18px;
}

/* ==========================================================================
   Compact Summary & Badges
   ========================================================================== */
.breakdown-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-chips-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.summary-chip {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.chip-label {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.chip-val {
  font-size: 0.88rem;
  font-weight: 800;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.chip-val.highlight {
  color: var(--accent-cyan);
}

.total-chip {
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.22);
}

.total-val {
  color: var(--accent-cyan);
}

/* Each Side Plate Badges */
.breakdown-side-section {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 7px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.breakdown-side-section::-webkit-scrollbar {
  display: none;
}

.breakdown-side-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

.breakdown-badges-list {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.breakdown-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.breakdown-badge strong {
  color: #ffffff;
}

.plate-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.plate-dot-blue {
  background-color: var(--plate-blue);
  box-shadow: 0 0 5px rgba(37, 99, 235, 0.7);
}

.plate-dot-yellow {
  background-color: var(--plate-yellow);
  box-shadow: 0 0 5px rgba(234, 179, 8, 0.7);
}

.plate-dot-green {
  background-color: var(--plate-green);
  box-shadow: 0 0 5px rgba(22, 163, 74, 0.7);
}

.plate-dot-white {
  background-color: var(--plate-white);
  border: 1px solid #94a3b8;
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
}

.breakdown-empty-text {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
  text-align: center;
  padding: 6px 0 2px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.app-footer a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.15s ease;
}

.app-footer a:hover {
  color: #ffffff;
}
