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

:root {
  --primary: #0E7490;
  --primary-light: #22D3EE;
  --cta: #15803D;
  --cta-hover: #166534;
  --bg: #F0FDFA;
  --text: #134E4A;
  --text-muted: #475569;
  --card-bg: #FFFFFF;
  --border: #CBD5E1;
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --warning: #F59E0B;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.08);
}

html { font-size: 16px; }

body {
  font-family: 'Figtree', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

/* Header */
.header {
  text-align: center;
  padding: 24px 0 16px;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.header p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* Step indicator */
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFF;
  font-size: 0.6875rem;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: middle;
}

/* Brand buttons */
.brand-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-btn {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  border: 2px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 44px;
  width: 100%;
}

.brand-btn:hover { border-color: var(--primary); background: #F0FDFA; }
.brand-btn:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }
.brand-btn.active { border-color: var(--primary); background: var(--primary); }
.brand-btn.active .brand-name { color: #FFF; }
.brand-btn.active .brand-sub { color: rgba(255,255,255,0.8); }

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

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Dose buttons */
.dose-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dose-btn {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 2px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  min-height: 44px;
  min-width: 60px;
}

.dose-btn:hover { border-color: var(--primary); background: #F0FDFA; }
.dose-btn:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }
.dose-btn.active { border-color: var(--primary); background: var(--primary); color: #FFF; }

.dose-mg {
  font-size: 0.9375rem;
  font-weight: 700;
}

.dose-clicks {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.dose-btn.active .dose-clicks { color: rgba(255,255,255,0.8); }

/* Info bar */
.info-bar {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: #F8FAFC;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.info-bar strong {
  color: var(--text);
  font-weight: 600;
}

/* Counter display */
.counter-display {
  text-align: center;
  padding: 24px 0;
}

.counter-number {
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: transform 0.15s ease;
}

.counter-number.bump { transform: scale(1.08); }

.counter-label {
  font-size: 1rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.dose-display {
  margin-top: 16px;
  padding: 16px;
  background: linear-gradient(135deg, #F0FDFA, #ECFDF5);
  border-radius: var(--radius-sm);
  text-align: center;
}

.dose-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.dose-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.dose-progress {
  margin-top: 12px;
  height: 8px;
  background: #E2E8F0;
  border-radius: 4px;
  overflow: hidden;
}

.dose-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--cta));
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.dose-progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Waveform */
.waveform-container {
  height: 80px;
  background: #F8FAFC;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}

.waveform-container canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.waveform-label {
  position: absolute;
  top: 6px;
  left: 10px;
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Click flash overlay */
.click-flash {
  position: fixed;
  inset: 0;
  background: rgba(34, 197, 94, 0.12);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.08s ease;
  z-index: 100;
}

.click-flash.active { opacity: 1; }

/* Main action button */
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  min-height: 56px;
}

.action-btn:active { transform: scale(0.98); }
.action-btn:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }

.btn-start { background: var(--cta); color: #FFF; }
.btn-start:hover { background: var(--cta-hover); }
.btn-stop { background: var(--danger); color: #FFF; }
.btn-stop:hover { background: var(--danger-hover); }

.btn-icon { width: 24px; height: 24px; flex-shrink: 0; }

/* Secondary buttons */
.secondary-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-secondary {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  min-height: 44px;
}

.btn-secondary:hover { border-color: var(--primary); background: #F0FDFA; }
.btn-secondary:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }

.btn-icon-sm { width: 18px; height: 18px; flex-shrink: 0; }

/* Advanced settings */
.advanced-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 8px;
  min-height: 44px;
}

.advanced-toggle:hover { color: var(--primary); }
.advanced-toggle svg { width: 16px; height: 16px; transition: transform 0.2s; }
.advanced-toggle.open svg { transform: rotate(180deg); }

.advanced-panel { display: none; padding-top: 12px; }
.advanced-panel.open { display: block; }

.setting-row { margin-bottom: 16px; }

.setting-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.setting-name { font-size: 0.875rem; font-weight: 500; }

.setting-value {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #E2E8F0;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid #FFF;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

input[type="range"]:focus-visible {
  outline: 3px solid var(--primary-light);
  outline-offset: 4px;
  border-radius: 3px;
}

/* Status indicator */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.status-dot.listening {
  background: var(--cta);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.calibrating {
  background: var(--warning);
  animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}


/* Counter adjust +/- buttons */
.counter-adjust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.adjust-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  flex-shrink: 0;
}

.adjust-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #F0FDFA;
}

.adjust-btn:active {
  transform: scale(0.93);
}

/* Detection mode toggle */
.mode-btn {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  min-height: 44px;
}

.mode-btn:hover { border-color: var(--primary); }
.mode-btn.active { border-color: var(--primary); background: var(--primary); color: #FFF; }

/* Done banner */
.done-banner {
  display: none;
  text-align: center;
  padding: 16px;
  background: linear-gradient(135deg, #ECFDF5, #D1FAE5);
  border: 2px solid var(--cta);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.done-banner.visible { display: block; }

.done-banner-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--cta-hover);
}

.done-banner-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.done-banner-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

.btn-done {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.btn-done-continue {
  background: var(--card-bg);
  border: 2px solid var(--border);
  color: var(--text);
}

.btn-done-continue:hover {
  border-color: var(--primary);
}

/* Hidden sections */
.hidden { display: none; }

/* Disclaimer */
.disclaimer {
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: #92400E;
}

.disclaimer strong {
  color: #78350F;
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px 0 0;
  font-size: 0.6875rem;
  color: var(--text-muted);
  opacity: 0.85;
  line-height: 1.5;
}

/* Skip navigation */
.skip-nav {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--primary);
  color: #FFF;
  padding: 8px 16px;
  border-radius: 0 0 8px 8px;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 200;
  text-decoration: none;
  transition: top 0.2s;
}

.skip-nav:focus {
  top: 0;
}

/* Focus-visible for all interactive elements */
a:focus-visible,
button:focus-visible,
.article-card:focus-visible,
.site-nav-logo:focus-visible,
.site-nav-links > a:focus-visible,
.lang-dropdown-menu a:focus-visible,
.breadcrumb a:focus-visible,
.cta-banner a:focus-visible,
.mode-btn:focus-visible,
.adjust-btn:focus-visible,
.install-banner-btn:focus-visible {
  outline: 3px solid var(--primary-light);
  outline-offset: 2px;
}

/* Touch targets: minimum 44px */
.mode-btn { min-height: 44px; }
.lang-dropdown-toggle { min-height: 44px; padding: 8px 10px; }
.install-banner-btn { min-height: 44px; }
.lang-dropdown-menu a { min-height: 44px; display: flex; align-items: center; }

/* Breadcrumb separator hidden from screen readers */
.breadcrumb-sep { user-select: none; }

/* Animations: respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .counter-number.bump { transform: none; }
}

@media (min-width: 520px) {
  .app { padding: 24px 24px 100px; }
}

/* ── Shared Navigation ── */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 90;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}

.site-nav-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  gap: 12px;
}

.site-nav-logo {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.site-nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-nav-links > a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.site-nav-links > a:hover { color: var(--primary); }
.site-nav-links > a.active { color: var(--primary); font-weight: 600; }

/* Language dropdown */
.lang-dropdown {
  position: relative;
  margin-left: 4px;
}

.lang-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
  transition: border-color 0.2s;
}

.lang-dropdown-toggle:hover { border-color: var(--primary); }

.lang-flag {
  font-size: 0.875rem;
  line-height: 1;
}

.lang-dropdown-arrow {
  width: 10px;
  height: 10px;
  transition: transform 0.2s;
}

.lang-dropdown.open .lang-dropdown-arrow {
  transform: rotate(180deg);
}

.lang-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 150px;
  overflow: hidden;
  z-index: 100;
}

.lang-dropdown.open .lang-dropdown-menu {
  display: block;
}

.lang-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}

.lang-dropdown-menu a:hover {
  background: #F0FDFA;
}

.lang-dropdown-menu a.active {
  background: #F0FDFA;
  color: var(--primary);
  font-weight: 600;
}

.lang-dropdown-menu .lang-flag {
  font-size: 1rem;
}

.lang-dropdown-menu {
  min-width: 140px;
}

/* ── Article Styles ── */
.article-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.article-header {
  margin-bottom: 32px;
}

.article-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.article-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.article-body {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
}

.article-body h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text);
}

.article-body h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--text);
}

.article-body p {
  margin-bottom: 16px;
}

.article-body ul, .article-body ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.article-body li {
  margin-bottom: 6px;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.875rem;
}

.article-body th, .article-body td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.article-body th {
  font-weight: 600;
  background: #F8FAFC;
  color: var(--text);
}

.callout {
  background: #F0FDFA;
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 16px;
  margin: 20px 0;
  font-size: 0.9375rem;
}

.callout-warning {
  background: #FEF3C7;
  border-left-color: var(--warning);
}

.callout strong {
  display: block;
  margin-bottom: 4px;
}

/* Related articles */
.related-articles {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.related-articles h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

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

@media (min-width: 520px) {
  .article-cards { grid-template-columns: 1fr 1fr; }
}

.article-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, transform 0.1s;
  display: block;
}

.article-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.article-card h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.article-card p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Article overview page */
.overview-header {
  text-align: center;
  padding: 32px 0 24px;
}

.overview-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.overview-header p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* CTA banner in articles */
.cta-banner {
  background: linear-gradient(135deg, var(--primary), #0E7490);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin: 32px 0;
  color: #FFF;
}

.cta-banner h3 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.cta-banner p {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-bottom: 16px;
}

.cta-banner a {
  display: inline-block;
  background: #FFF;
  color: var(--primary);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
  transition: transform 0.1s;
}

.cta-banner a:hover { transform: scale(1.03); }

/* Adjust app container when nav is present */
.has-nav .app {
  padding-top: 8px;
}

.has-nav .header {
  padding-top: 16px;
}

/* ── PWA Install Banner ── */
.install-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  z-index: 80;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.install-banner.visible {
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-banner-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

.install-banner-text {
  flex: 1;
  min-width: 0;
}

.install-banner-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.install-banner-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.install-banner-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #FFF;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
}

.install-banner-close {
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

/* Breadcrumbs */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb a:hover { color: var(--primary); }

.breadcrumb-sep {
  color: var(--border);
}
