/* HRI Learn — CEO / iPhone 16 Pro Max shell
   Design viewport target: ~440×956 CSS px (Pro Max logical) */

:root,
html[data-theme="dark"] {
  color-scheme: dark;
  /* Dark (default when system prefers dark / night fallback) */
  --bg: #0a0a0b;
  --bg-elev: #111113;
  --bg-card: #151517;
  --bg-soft: #1c1c1f;
  --border: rgba(244, 241, 234, 0.08);
  --border-strong: rgba(244, 241, 234, 0.14);
  --text: #f4f1ea;
  --muted: #a8a49a;
  --faint: #6e6b63;
  --accent: #c9a962;
  --accent-2: #8ba3b8;
  --accent-glow: rgba(201, 169, 98, 0.28);
  --warn: #c4a35a;
  --danger: #c47a7a;
  --ok: #6b9b7a;
  --energy: #c9a962;
  --energy-empty: rgba(244, 241, 234, 0.18);
  --ring-track: #2a2a2e;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  --theme-toggle-bg: rgba(244, 241, 234, 0.08);
  --chrome-fade-strong: rgba(10, 10, 11, 0.96);
  --chrome-fade-mid: rgba(10, 10, 11, 0.85);
  --chrome-fade-soft: rgba(10, 10, 11, 0.7);
  --choice-bg: #222226;
  --choice-bg-soft: rgba(244, 241, 234, 0.05);
  --diagram-bg: #0a0a0a;
  --caption: #d8d4cb;
  --body-soft: #d0ccc3;
  --steel-text: #c9d4de;
  --radius: 16px;
  --radius-sm: 12px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "SF Pro Text", Segoe UI, Roboto,
    Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --dock-h: calc(72px + var(--safe-bottom));
  --tap: 48px; /* ≥44px Apple HIG */
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(900px 480px at 50% -8%, rgba(201, 169, 98, 0.07), transparent 55%),
    radial-gradient(700px 400px at 100% 10%, rgba(139, 163, 184, 0.05), transparent 50%),
    var(--bg);
  min-height: 100dvh;
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* Full-bleed phone column — Pro Max ~430–440 wide */
.app {
  width: 100%;
  max-width: min(440px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
  padding:
    calc(10px + var(--safe-top))
    calc(16px + var(--safe-right))
    calc(12px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  position: relative;
}

/* Compact top bar — not desktop chrome */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
  padding: 4px 0 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(
    to bottom,
    var(--chrome-fade-strong) 40%,
    var(--chrome-fade-soft),
    transparent
  );
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

.topbar-meta {
  min-width: 0;
}

.brand {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}

.progress-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.pill-k {
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill span:last-child {
  color: var(--accent);
}

/* Focus / energy meter (replaces hearts) */
.energy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.energy .seg {
  width: 8px;
  height: 16px;
  border-radius: 3px;
  background: var(--energy);
  box-shadow: 0 0 8px var(--accent-glow);
  transition: opacity 0.15s ease, background 0.15s ease;
}

.energy .seg.empty {
  background: var(--energy-empty);
  box-shadow: none;
}

/* Mastery ring */
.ring-wrap {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.ring-wrap svg {
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 4.5;
}

.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
  filter: drop-shadow(0 0 5px var(--accent-glow));
}

.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.main.with-dock {
  padding-bottom: calc(var(--dock-h) + 8px);
}

/* Screens */
.screen {
  display: none;
  animation: rise 0.3s ease;
  flex: 1;
}

.screen.active {
  display: block;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hero-card,
.lesson-card,
.end-card {
  background: linear-gradient(180deg, var(--choice-bg-soft), transparent 42%), var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 18px;
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 12px;
}

.kicker .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

h1 {
  font-size: clamp(1.4rem, 5.5vw, 1.75rem);
  line-height: 1.18;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
  font-weight: 700;
}

h2 {
  font-size: clamp(1.15rem, 4.5vw, 1.35rem);
  margin: 0 0 14px;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.lede {
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
  margin: 0 0 20px;
}

.objective-box {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.objective-box strong {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--faint);
  margin-bottom: 6px;
  font-weight: 600;
}

.objective-box p {
  margin: 0;
  color: var(--text);
  line-height: 1.5;
  font-size: 0.95rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  background: var(--choice-bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 8px;
  text-align: center;
  min-height: var(--tap);
}

.stat .v {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat .l {
  font-size: 10px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

/* Sticky bottom dock — primary CTA */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  transform: none;
  margin-inline: auto;
  bottom: 0;
  width: auto;
  max-width: min(440px, 100%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding:
    12px calc(16px + var(--safe-right))
    calc(12px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  background: linear-gradient(
    to top,
    var(--chrome-fade-strong) 55%,
    var(--chrome-fade-mid),
    transparent
  );
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.dock.hidden {
  display: none;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 0 20px;
  min-height: var(--tap);
  font-size: 15px;
  font-weight: 650;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
}

.btn-primary {
  background: linear-gradient(135deg, #d4b56e 0%, #c9a962 45%, #a88b4a 100%);
  color: #1a1508;
  box-shadow: 0 8px 24px rgba(201, 169, 98, 0.28);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 10px 28px rgba(201, 169, 98, 0.38);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-dock {
  width: 100%;
}

.btn-dock-secondary {
  width: 100%;
  min-height: 44px;
  font-weight: 500;
  font-size: 14px;
}

.btn-wide {
  width: 100%;
}

.btn kbd {
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.65;
  font-weight: 500;
}

/* Lesson */
.session-progress {
  height: 3px;
  background: var(--ring-track);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}

.session-progress > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.35s ease;
}

.teach-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(139, 163, 184, 0.12);
  color: var(--accent-2);
  border: 1px solid rgba(139, 163, 184, 0.28);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.badge.check {
  background: rgba(201, 169, 98, 0.12);
  color: var(--accent);
  border-color: rgba(201, 169, 98, 0.3);
}

.badge.retry {
  background: rgba(196, 163, 90, 0.12);
  color: var(--warn);
  border-color: rgba(196, 163, 90, 0.3);
}

.lesson-body p {
  margin: 0 0 12px;
  line-height: 1.55;
  color: var(--caption);
  font-size: 0.98rem;
}

.schema {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: rgba(201, 169, 98, 0.06);
  border-radius: 0 12px 12px 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
}

.schema strong {
  display: block;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
  font-weight: 600;
}

.diagram {
  margin: 16px 0 4px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--diagram-bg);
}

.diagram img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 280px;
  object-fit: contain;
  background: var(--diagram-bg);
}

.diagram-caption {
  font-size: 11px;
  color: var(--faint);
  margin-top: 8px;
  line-height: 1.4;
}

/* Checks */
.prompt {
  font-size: 1.05rem;
  line-height: 1.45;
  margin: 0 0 16px;
  font-weight: 600;
}

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

.choice {
  text-align: left;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 14px 14px 12px;
  min-height: var(--tap);
  color: var(--text);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.choice:hover:not(:disabled),
.choice:focus-visible:not(:disabled) {
  border-color: rgba(139, 163, 184, 0.5);
  background: var(--choice-bg);
  outline: none;
}

.choice .num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--choice-bg-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  margin-top: 1px;
}

.choice .txt {
  flex: 1;
  line-height: 1.4;
  font-size: 0.95rem;
  padding-top: 3px;
}

.choice.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(139, 163, 184, 0.35);
}

.choice.correct {
  border-color: var(--ok);
  background: rgba(107, 155, 122, 0.12);
}

.choice.wrong {
  border-color: var(--danger);
  background: rgba(196, 122, 122, 0.1);
}

.apply-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.apply-box input,
.apply-box textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 14px 16px;
  min-height: var(--tap);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* avoid iOS zoom */
  outline: none;
}

.apply-box input:focus,
.apply-box textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(139, 163, 184, 0.15);
}

.feedback {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  display: none;
  animation: rise 0.25s ease;
}

.feedback.show {
  display: block;
}

.feedback.ok {
  background: rgba(107, 155, 122, 0.12);
  border: 1px solid rgba(107, 155, 122, 0.35);
}

.feedback.bad {
  background: rgba(196, 122, 122, 0.1);
  border: 1px solid rgba(196, 122, 122, 0.35);
}

.feedback .title {
  font-weight: 700;
  margin-bottom: 4px;
}

.feedback.ok .title {
  color: var(--ok);
}

.feedback.bad .title {
  color: var(--danger);
}

.feedback .why {
  color: var(--body-soft);
  line-height: 1.5;
  font-size: 0.92rem;
}

.feedback .xp-gain {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--accent);
}

.footer-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  position: sticky;
  bottom: calc(8px + var(--safe-bottom));
  z-index: 5;
}

/* End / fail */
.end-burst {
  text-align: center;
  margin-bottom: 16px;
}

.end-burst .mark {
  font-size: 36px;
  line-height: 1;
  color: var(--accent);
  filter: drop-shadow(0 6px 18px var(--accent-glow));
  animation: pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

@keyframes pop {
  0% {
    transform: scale(0.45);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.end-card h1 {
  text-align: center;
}

.end-card .lede {
  text-align: center;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 18px 0 20px;
}

.metric {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.metric .l {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
}

.metric .v {
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 4px;
  color: var(--accent);
}

.spaced-box {
  background: rgba(139, 163, 184, 0.08);
  border: 1px solid rgba(139, 163, 184, 0.25);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 18px;
  line-height: 1.5;
  color: var(--steel-text);
  font-size: 0.92rem;
}

.spaced-box strong {
  display: block;
  color: var(--accent-2);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
  font-weight: 600;
}

.fail-card .metric .v {
  color: var(--warn);
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-row .btn {
  width: 100%;
}

/* Toast / fx */
.fx-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
}

.float-xp {
  position: absolute;
  color: var(--accent);
  font-weight: 700;
  font-size: 17px;
  animation: floatUp 0.9s ease forwards;
  text-shadow: 0 0 12px var(--accent-glow);
}

@keyframes floatUp {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-48px);
  }
}

.shake {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

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

.footer-note {
  display: none; /* dock owns bottom; keep for a11y fallback */
}

/* Tall phone: extra breathing room between hero and dock */
@media (min-height: 900px) {
  .hero-card {
    padding-top: 32px;
    padding-bottom: 28px;
  }

  .lesson-body p {
    font-size: 1.02rem;
  }
}

/* Slightly wider tablets still cap at phone column — no desktop chrome */
@media (min-width: 480px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}


/* Hint nudges — ideas without answers */
.apply-actions {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 10px;
}
.apply-actions .btn-primary {
  flex: 1;
}
.apply-box input {
  margin-bottom: 0;
}
.hint-row {
  margin-top: 12px;
}
.btn-hint-inline {
  margin-bottom: 8px;
}
.hint-panel {
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  border-radius: 10px;
  padding: 12px 14px;
}
.hint-panel[hidden] {
  display: none;
}


html[data-theme="light"] {
  color-scheme: light;
  --bg: #fffdf7;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-soft: #f3efe4;
  --border: rgba(23, 21, 15, 0.12);
  --border-strong: rgba(23, 21, 15, 0.22);
  --text: #17150f;
  --muted: #3f3a30; /* was too light on cream */
  --faint: #5c5648;
  --accent: #8a6416;
  --accent-2: #3d5a70;
  --accent-glow: rgba(138, 100, 22, 0.2);
  --warn: #8a6416;
  --danger: #8b3e3e;
  --ok: #2f5c3f;
  --energy: #8a6416;
  --energy-empty: rgba(23, 21, 15, 0.18);
  --ring-track: #d8d3c6;
  --shadow: 0 16px 40px rgba(15, 13, 9, 0.1);
  --theme-toggle-bg: #ffffff;
  --chrome-fade-strong: rgba(255, 253, 247, 0.97);
  --chrome-fade-mid: rgba(255, 253, 247, 0.9);
  --chrome-fade-soft: rgba(255, 253, 247, 0.65);
  --choice-bg: #f3efe4;
  --choice-bg-soft: rgba(23, 21, 15, 0.04);
  --diagram-bg: #f3efe4;
  --caption: #3f3a30;
  --body-soft: #3f3a30;
  --steel-text: #3d5a70;
}

html[data-theme="light"] body {
  background:
    radial-gradient(900px 480px at 50% -8%, rgba(166, 124, 27, 0.1), transparent 55%),
    radial-gradient(700px 400px at 100% 10%, rgba(92, 122, 146, 0.07), transparent 50%),
    var(--bg);
  color: var(--text);
}

html[data-theme="light"] .brand,
html[data-theme="light"] .progress-meta,
html[data-theme="light"] .lede,
html[data-theme="light"] .prompt,
html[data-theme="light"] .lesson-body,
html[data-theme="light"] .objective-box p,
html[data-theme="light"] .stat .l,
html[data-theme="light"] .footer-note,
html[data-theme="light"] .hint-panel,
html[data-theme="light"] .choice .txt,
html[data-theme="light"] .feedback .why {
  color: var(--text);
}

html[data-theme="light"] .muted,
html[data-theme="light"] .kicker {
  color: var(--muted);
}

.theme-toggle {
  width: auto;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 12px;
  gap: 6px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--theme-toggle-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 1;
  min-width: 0;
  box-shadow: 0 1px 0 var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  z-index: 30;
  position: relative;
}
.theme-toggle .theme-label {
  display: none;
}
@media (min-width: 480px) {
  .theme-toggle .theme-label { display: inline; }
}
.theme-toggle svg {
  width: 18px;
  height: 18px;
  display: none;
  stroke: currentColor;
  flex-shrink: 0;
}
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }
/* Fallback if data-theme missing: show sun */
html:not([data-theme]) .theme-toggle .icon-sun { display: block; }
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.theme-toggle:active {
  transform: scale(0.98);
}
