:root {
  color-scheme: light;
  --navy: #071f3d;
  --navy-soft: #123a67;
  --red: #d24a37;
  --cream: #f7f1e5;
  --paper: #fffdf8;
  --ink: #10223a;
  --muted: #5d6875;
  --line: #ddcfb8;
  --shadow: 0 24px 60px rgba(18, 38, 61, .14);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --cream: #0d1724;
  --paper: #142236;
  --ink: #f6f1e7;
  --muted: #bac4cf;
  --line: #30445c;
  --shadow: 0 24px 60px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

html { min-height: 100%; background: var(--cream); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 12% 4%, rgba(210, 74, 55, .10), transparent 34%),
    var(--cream);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.brand-bar, .session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand span:last-child { display: grid; }
.brand strong { font-size: 17px; }
.brand small { color: var(--muted); font-size: 11px; }

.brand-mark {
  display: grid;
  width: 44px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 14px;
  background: var(--navy);
  color: #fff;
  font-weight: 900;
  letter-spacing: -.04em;
}

.icon-button, .secondary-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 750;
}

.auth-view { padding-top: clamp(40px, 10vh, 90px); }
.hero-copy { margin-bottom: 24px; }
h1, h2, p { margin: 0; }
.hero-copy h1 { max-width: 12ch; margin: 7px 0 12px; font-size: clamp(36px, 10vw, 52px); line-height: .98; letter-spacing: -.055em; }
.hero-copy > p:last-child { max-width: 45ch; color: var(--muted); line-height: 1.55; }
.eyebrow, .step { color: var(--red); font-size: 12px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }

.card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.auth-card { display: grid; gap: 13px; padding: 22px; }
.auth-card h2 { margin-top: 4px; font-size: 25px; }
label { color: var(--muted); font-size: 13px; font-weight: 750; }

input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 15px;
  background: var(--cream);
  color: var(--ink);
  font-size: 17px;
  outline: none;
}

select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 42px 0 14px;
  background: var(--cream);
  color: var(--ink);
}

input:focus { border-color: var(--navy-soft); box-shadow: 0 0 0 3px rgba(18, 58, 103, .12); }
.field-group { display: grid; gap: 9px; }

.otp-delivery { color: var(--muted); font-size: 13px; line-height: 1.45; }
.otp-boxes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
.otp-box {
  min-width: 0;
  min-height: 54px;
  padding: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 900;
}

.primary-button {
  min-height: 54px;
  border: 0;
  border-radius: 14px;
  background: var(--navy);
  color: #fff;
  font-weight: 850;
}

.primary-button:disabled { opacity: .6; cursor: wait; }
.message { min-height: 22px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.message.error { color: #b02f24; }
.message.success { color: #177245; }

.subscription-card { display: grid; gap: 13px; margin-top: 18px; padding: 22px; }
.subscription-card h2 { margin: 4px 0 8px; font-size: 23px; }
.subscription-card > div:first-child > p:last-child { color: var(--muted); line-height: 1.5; }
.paypal-box { min-height: 48px; }

.content-view { padding-top: 44px; }
.session-row { align-items: end; margin-bottom: 18px; }
.session-row h1 { margin-top: 5px; font-size: 32px; letter-spacing: -.04em; }
.library-intro { margin-bottom: 16px; color: var(--muted); line-height: 1.5; }

.catalog-tools {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 12px;
  padding: 15px;
  box-shadow: none;
}

.catalog-tools label { display: grid; gap: 7px; }
.catalog-tools .search-field { grid-column: 1 / -1; }
.catalog-tools input { min-height: 50px; font-size: 15px; }

.catalog-summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.text-button, .back-button {
  border: 0;
  padding: 8px 0;
  background: transparent;
  color: var(--red);
  font-weight: 800;
}

.catalog-grid { display: grid; gap: 18px; }
.catalog-card { overflow: hidden; }

.catalog-cover {
  display: block;
  width: 100%;
  height: clamp(210px, 58vw, 300px);
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0;
  background: #f8f4eb;
}

.catalog-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform .25s ease;
}

.catalog-cover:hover img { transform: scale(1.025); }
.catalog-cover:focus-visible { outline: 3px solid var(--red); outline-offset: -3px; }
.catalog-card-copy { padding: 18px; }
.catalog-card-copy h2 { margin: 5px 0 9px; font-size: 22px; line-height: 1.12; }
.catalog-card-copy > p:last-child { color: var(--muted); font-size: 14px; }

.empty-state { padding: 30px 22px; text-align: center; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--muted); }

.study-view { display: grid; gap: 12px; }
.study-card { overflow: hidden; }
.study-copy { padding: 22px; }
.study-copy h2 { margin: 6px 0 10px; font-size: 27px; line-height: 1.08; }
.study-copy > p:not(.step) { color: var(--muted); line-height: 1.5; }
.study-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.study-stats span { border-radius: 999px; padding: 7px 10px; background: var(--cream); color: var(--muted); font-size: 12px; font-weight: 800; }

.study-viewport {
  position: relative;
  width: 100%;
  height: min(68vh, 720px);
  min-height: 430px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f8f4eb;
  touch-action: manipulation;
  outline: none;
}

.study-viewport:focus-visible { box-shadow: inset 0 0 0 3px var(--red); }
.study-canvas { position: absolute; top: 0; left: 0; transform-origin: top left; will-change: transform; transition: transform 700ms cubic-bezier(.2, .78, .22, 1); }
.study-canvas > img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.study-hotspots { position: absolute; inset: 0; }

.study-hotspot {
  position: absolute;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 0;
  background: transparent;
  color: transparent;
}

.study-hotspot:hover, .study-hotspot:focus-visible { border-color: var(--red); background: rgba(210, 74, 55, .08); outline: none; }
.study-hotspot[aria-current="step"] { border-color: var(--red); box-shadow: 0 0 0 3px rgba(210, 74, 55, .15); }

.study-focus-label {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(7, 31, 61, .92);
  color: #fff;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.study-navigation { display: grid; gap: 7px; padding: 12px 16px 16px; }
.study-progress-track { height: 5px; overflow: hidden; border-radius: 999px; background: var(--line); }
.study-progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--red); transition: width .3s ease; }
.study-controls { display: flex; align-items: center; justify-content: center; gap: 5px; }
.study-icon {
  display: grid;
  width: 42px;
  min-height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-size: 25px;
  line-height: 1;
  opacity: .72;
}
.study-icon:hover, .study-icon:focus-visible { background: rgba(127, 127, 127, .14); opacity: 1; outline: none; }
.study-icon:disabled { opacity: .22; cursor: default; }
.primary-button.compact { min-height: 42px; }

body.study-immersive { overflow: hidden; background: #050505; }
body.study-immersive .app-shell { width: 100%; min-height: 100dvh; padding: 0; }
body.study-immersive .brand-bar,
body.study-immersive .session-row,
body.study-immersive .study-copy { display: none; }
body.study-immersive .content-view,
body.study-immersive .study-view { min-height: 100dvh; padding: 0; }
body.study-immersive .study-card {
  position: fixed;
  inset: 0;
  z-index: 20;
  border: 0;
  border-radius: 0;
  background: #050505;
  box-shadow: none;
}
body.study-immersive .study-viewport { height: 100dvh; min-height: 0; border: 0; background: #050505; }
body.study-immersive .study-focus-label { display: none !important; }
body.study-immersive .study-hotspot:hover,
body.study-immersive .study-hotspot:focus-visible,
body.study-immersive .study-hotspot[aria-current="step"] { border-color: transparent; background: transparent; box-shadow: none; }
body.study-immersive .study-navigation {
  position: absolute;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 4;
  width: min(334px, calc(100vw - 24px));
  transform: translateX(-50%);
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 999px;
  padding: 6px 10px 7px;
  background: rgba(7, 18, 31, .34);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
body.study-immersive .study-progress-track { height: 2px; background: rgba(255, 255, 255, .15); }
body.study-immersive .study-progress-track span { background: rgba(255, 255, 255, .68); }
body.study-immersive .study-controls { justify-content: space-between; }
body.study-immersive .study-icon { width: 40px; min-height: 36px; color: #fff; opacity: .56; }
body.study-immersive .study-icon:hover,
body.study-immersive .study-icon:focus-visible,
body.study-immersive .study-icon.is-playing { background: rgba(255, 255, 255, .10); opacity: .95; }

.quiz-card { padding: 22px; }
.quiz-setup > h2 { margin: 6px 0 10px; }
.quiz-setup > p:not(.step) { color: var(--muted); line-height: 1.5; }
.quiz-length-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.quiz-length-options label { position: relative; color: var(--ink); cursor: pointer; }
.quiz-length-options input { position: absolute; width: 1px; min-height: 1px; opacity: 0; pointer-events: none; }
.quiz-length-options span {
  display: grid;
  gap: 3px;
  min-height: 86px;
  place-content: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--cream);
  text-align: center;
}
.quiz-length-options strong { font-size: 27px; }
.quiz-length-options small { color: var(--muted); font-size: 12px; }
.quiz-length-options input:checked + span { border-color: var(--red); box-shadow: 0 0 0 3px rgba(210, 74, 55, .12); }
.quiz-length-options input:focus-visible + span { outline: 3px solid rgba(18, 58, 103, .28); outline-offset: 2px; }
.quiz-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.quiz-header strong { color: var(--muted); font-size: 13px; }
.quiz-card h2 { margin-bottom: 20px; font-size: 25px; line-height: 1.18; }
.quiz-answer { display: grid; gap: 10px; }

.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: var(--cream);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
  cursor: pointer;
}

.quiz-option input { width: 20px; min-height: 20px; margin: 0; padding: 0; flex: 0 0 auto; }
.quiz-fill { font-size: 18px; }
.matching-list { display: grid; gap: 12px; }
.matching-row { display: grid; gap: 7px; }
.matching-row strong { font-size: 14px; }
.matching-row select { font-size: 14px; }
.quiz-feedback { min-height: 24px; margin-top: 16px; font-size: 14px; font-weight: 750; line-height: 1.45; }
.quiz-feedback.correct { color: #177245; }
.quiz-feedback.incorrect { color: #b02f24; }
.quiz-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.quiz-actions .secondary-button { margin-right: auto; }
.quiz-result { padding: 14px 0 4px; text-align: center; }
.quiz-result h2 { margin: 7px 0 10px; font-size: 34px; }
.quiz-result > p:not(.step) { color: var(--muted); line-height: 1.55; }
.result-actions { justify-content: center; margin-top: 24px; }
.result-actions .secondary-button { margin-right: 0; }

.landscape-lock { display: none; }

@media (orientation: landscape) and (max-height: 600px) {
  .app-shell { display: none; }
  .landscape-lock {
    display: grid;
    min-height: 100vh;
    place-content: center;
    gap: 10px;
    padding: 24px;
    text-align: center;
  }
  .rotate-icon { color: var(--red); font-size: 58px; font-weight: 900; line-height: 1; }
  .landscape-lock p { color: var(--muted); }
}

@media (max-width: 390px) {
  .brand small { display: none; }
  .session-row { align-items: stretch; flex-direction: column; }
  .catalog-tools { grid-template-columns: 1fr; }
  .study-viewport { height: 62vh; min-height: 390px; }
  body.study-immersive .study-viewport { height: 100dvh; min-height: 0; }
  .otp-boxes { gap: 5px; }
  .otp-box { min-height: 48px; font-size: 20px; }
  .quiz-actions { display: grid; grid-template-columns: 1fr; }
  .quiz-actions .secondary-button { margin-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .study-canvas, .catalog-cover img, .study-progress-track span { transition: none; }
}
