/* Labthrift Runs — pocket player tokens (may diverge from Plan cream/copper) */
:root {
  color-scheme: light;
  --bg: #f0ece4;
  --bg-elev: #e8e2d8;
  --ink: #1a1714;
  --muted: #5e564c;
  --ember: #c96b2c;
  --ember-ink: #fffaf5;
  --card: #faf7f2;
  --line: #ddd4c6;
  --danger: #9b2c2c;
  --shadow: 0 8px 28px rgba(26, 23, 20, 0.07), 0 1px 3px rgba(26, 23, 20, 0.04);
  --beat-duration: 280ms;
  --beat-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --sans: "Segoe UI", "Avenir Next", "Helvetica Neue", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  /* Compat aliases used by older markup */
  --copper: var(--ember);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0e0c;
  --bg-elev: #181512;
  --ink: #f0e6d8;
  --muted: #a89a88;
  --ember: #e08a4a;
  --ember-ink: #1a120c;
  --card: #1a1714;
  --line: #322c26;
  --danger: #f0a0a0;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.2);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

a { color: var(--ember); }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

header.app {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding:
    max(0.75rem, var(--safe-top))
    max(1rem, var(--safe-right))
    0.75rem
    max(1rem, var(--safe-left));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--ink);
  font-size: 1.02rem;
}
.brand span { color: var(--ember); }

main {
  max-width: 36rem;
  margin: 0 auto;
  padding: 1.35rem max(1.15rem, var(--safe-left)) 2rem max(1.15rem, var(--safe-right));
  width: 100%;
  flex: 1;
}

.foot {
  text-align: center;
  padding: 1rem max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.2rem 1.3rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); font-size: 0.95rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

h1 {
  font-family: var(--serif);
  font-size: 1.55rem;
  line-height: 1.25;
  margin: 0 0 0.5rem;
  font-weight: 650;
}
h2 {
  font-family: var(--serif);
  font-size: 1.15rem;
  margin: 0 0 0.35rem;
  font-weight: 650;
}

.beat-body {
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.55;
  margin: 0.65rem 0 1.2rem;
  white-space: pre-wrap;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

button, .btn {
  font: inherit;
  font-family: var(--sans);
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--ember);
  color: var(--ember-ink);
  padding: 0.72rem 0.95rem;
  cursor: pointer;
  min-height: 44px;
  text-align: left;
  width: 100%;
  transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease, border-color 140ms ease;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button:active:not(:disabled), .btn:active {
  transform: scale(0.985);
  filter: brightness(0.96);
}
button.secondary, .btn.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
button.chrome-btn {
  width: auto;
  min-width: 0;
  padding: 0.4rem 0.65rem;
  min-height: 36px;
  font-size: 0.88rem;
  text-align: center;
  font-weight: 500;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

.run-list { display: grid; gap: 0.7rem; list-style: none; padding: 0; margin: 1rem 0 0; }
.run-list a { display: block; text-decoration: none; color: inherit; }
.run-list .card:hover { border-color: var(--ember); }
.crumb { font-size: 0.9rem; margin-bottom: 0.75rem; }
.progress-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--ember);
  margin-right: 0.35rem;
  vertical-align: middle;
}
.hidden { display: none !important; }
.err { color: var(--danger); }

.for-you { margin: 1.25rem 0 1.75rem; }
.stack-actions button { width: auto; flex: 1; min-width: 5.5rem; text-align: center; }
.stack-list .card { margin-bottom: 0; }
section h2 { margin-top: 1.5rem; }

.ios-tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0;
  padding: 0.5rem max(1rem, var(--safe-right)) 0.5rem max(1rem, var(--safe-left));
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}

/* —— Immersive run player —— */
body.immersive {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-y;
}
body.immersive #site-header,
body.immersive #site-footer,
body.immersive #ios-tip {
  display: none !important;
}
body.immersive main#app {
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.player {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(0.75rem, var(--safe-top))
    max(1.1rem, var(--safe-right))
    max(1.25rem, var(--safe-bottom))
    max(1.1rem, var(--safe-left));
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, var(--bg-elev), transparent 60%),
    var(--bg);
  touch-action: pan-y;
}

.player-exit {
  position: absolute;
  top: max(0.5rem, var(--safe-top));
  right: max(0.6rem, var(--safe-right));
  z-index: 5;
  width: 2.65rem;
  height: 2.65rem;
  min-height: 2.65rem;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  line-height: 1;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: var(--shadow);
}
.player-exit:hover { border-color: var(--ember); }

.player-stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 34rem;
  width: 100%;
  margin: 0 auto;
  padding-top: 2.4rem;
  overflow: hidden;
  /* Isolate paint so transforms don't thrash siblings */
  contain: layout paint;
}

.player .card { margin-bottom: 0; }
.player-meta { margin-top: 1rem; font-size: 0.9rem; }
.player-title {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.player-hint {
  position: absolute;
  left: 50%;
  bottom: max(0.35rem, var(--safe-bottom));
  transform: translateX(-50%);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.55;
  pointer-events: none;
  white-space: nowrap;
}

.beat-pane {
  width: 100%;
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition:
    opacity var(--beat-duration) var(--beat-ease),
    transform var(--beat-duration) var(--beat-ease);
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.beat-pane.is-enter-forward {
  opacity: 0;
  transform: translate3d(0, 1.15rem, 0);
}
.beat-pane.is-exit-forward {
  opacity: 0;
  transform: translate3d(0, -0.75rem, 0);
  pointer-events: none;
}
.beat-pane.is-enter-back {
  opacity: 0;
  transform: translate3d(0, -1.15rem, 0);
}
.beat-pane.is-exit-back {
  opacity: 0;
  transform: translate3d(0, 0.75rem, 0);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  :root { --beat-duration: 1ms; }
  button, .btn, .beat-pane {
    transition: none !important;
  }
  button:active:not(:disabled), .btn:active {
    transform: none;
  }
  .beat-pane {
    will-change: auto;
  }
}

/* —— Auth gate + learning plan —— */
.auth-gate { max-width: 24rem; margin: 0 auto; }
.auth-gate h1 { margin-bottom: 0.35rem; }
.auth-card { margin-top: 1.25rem; }
.auth-label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}
.auth-card input {
  font: inherit;
  font-family: var(--sans);
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  margin-bottom: 0.85rem;
  min-height: 44px;
}
.auth-actions { margin-top: 0.25rem; }
.auth-status { min-height: 1.4em; margin: 0.75rem 0 0; }
.auth-foot { margin-top: 1.25rem; font-size: 0.9rem; }

.continue-wrap { margin: 1.1rem 0 1.5rem; }
a.continue-btn, .continue-btn {
  display: block;
  text-decoration: none;
  text-align: center;
  font-size: 1.06rem;
  font-weight: 650;
  padding: 0.95rem 1rem;
}
.pill {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  white-space: nowrap;
  font-weight: 600;
}
.plan-item.is-continue .card { border-color: var(--ember); }
.plan-item.is-done .card, .plan-item.is-skipped .card { opacity: 0.72; }
.plan-links { margin-top: 1.75rem; font-size: 0.95rem; }
.plan-links a { text-decoration: none; }
body.signed-out #stack-nav { display: none !important; }

/* Standalone PWA: slightly denser chrome, status-bar friendly */
body.standalone header.app {
  padding-top: max(0.55rem, var(--safe-top));
}
body.standalone.immersive .player {
  /* Full-bleed under notch when installed */
  padding-top: max(0.65rem, var(--safe-top));
}
