/* Palette comes from /theme.css (linked before this file). No local tokens
   needed — BPM uses only shared ones. */

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

html, body {
  margin: 0;
  overscroll-behavior: none;
}

/* Mobile-portrait-first: don't let the OS inflate text on rotation/zoom. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* iOS standalone (Add to Home Screen) apps run in a WKWebView that, unlike
   a normal Safari tab, often doesn't scroll the document itself even when
   content overflows the viewport. Pinning body with position:fixed + its
   own overflow-y makes it a real, independently-scrollable region that iOS
   recognizes reliably — the standard fix for this. */
body {
  position: fixed;
  inset: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
}

/* Phone-portrait column: fills the screen on a phone, and on wider screens
   stays a centred column instead of stretching edge-to-edge (Matkompis-style). */
.app {
  min-height: 100%; /* fills body's box (viewport height) in portrait, but
                        can grow taller (landscape) so body scrolls to
                        reach everything instead of clipping */
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: env(safe-area-inset-top, 16px) 16px 8px;
  text-align: center;
}

.topbar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tap-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--bg-panel);
  margin: 0 16px;
  border-radius: 28px;
  cursor: pointer;
  transition: background-color 0.08s ease;
  padding: 24px;
  text-align: center;
  touch-action: pan-y; /* the tap zone covers nearly the whole screen, so it
                           must explicitly hand vertical drags to page scroll
                           — this is the whole scrollable surface, not just
                           a small control like Wavelets' scrub bar */
  -webkit-touch-callout: none; /* no iOS long-press callout on the tap area */
}

.tap-zone.tapped {
  background-color: var(--surface-active);
}

.bpm-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.bpm-value {
  font-size: 6rem; /* fixed: never rescale on rotation (was clamp(...,22vw,...)) */
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  transition: transform 0.06s ease;
}

.bpm-value.pulse {
  transform: scale(1.06);
}

.bpm-label {
  margin-top: 8px;
  font-size: 1rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.hint {
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: 22em;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px 28px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#interval {
  display: inline-block;
  width: 11ch;
  text-align: center;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.controls {
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--surface-active);
  color: var(--text);
  border-color: var(--accent-dim);
}

.reset-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  padding: 12px 32px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}

.reset-btn:active {
  background: var(--danger);
  color: var(--text);
  border-color: var(--danger);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

.overlay[hidden] {
  display: none;
}

.about-panel {
  position: relative;
  background: var(--bg-panel);
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.about-panel h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  color: var(--text);
}

.about-panel h3 {
  margin: 20px 0 6px;
  font-size: 0.95rem;
  color: var(--accent);
}

.about-panel h3:first-of-type {
  margin-top: 0;
}

.about-panel p {
  margin: 0 0 8px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-dim);
}

.about-panel code {
  display: inline-block;
  margin: 2px 0 10px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
}

.about-panel a {
  color: var(--accent);
}

.about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 6px 10px;
}

.about-close:active {
  color: var(--text);
}

/* Short landscape (phone rotated): reclaim the padding/gaps that only
   exist for portrait's taller aspect ratio. Text sizes are untouched —
   if content still doesn't fit after compacting, the page scrolls
   (see min-height on html/body/.app above) rather than shrinking text
   or clipping the ? / Reset controls. */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar {
    padding: 6px 16px 4px;
  }

  .tap-zone {
    gap: 10px;
    margin: 0 12px;
    padding: 12px;
  }

  .bpm-label {
    margin-top: 2px;
  }

  .stats {
    gap: 6px 24px;
  }

  .controls {
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .reset-btn {
    padding: 8px 24px;
  }
}
