:root {
  --primary: #1B3A5C;
  --accent: #D4EBF5;
  --highlight: #E8705A;
  --success: #27AE60;
  --text: #333333;
  --muted: #667085;
  --line: #D8E0E7;
  --card: #FFFFFF;
  --bg: #F4F8FB;
  --shadow: 0 12px 32px rgba(27, 58, 92, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(212, 235, 245, 0.88), rgba(244, 248, 251, 0.94) 42%),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  position: relative;
  overflow: hidden;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #FFFFFF;
  color: var(--text);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

input {
  min-height: 48px;
  padding: 0.75rem 0.85rem;
}

textarea {
  min-height: 150px;
  resize: vertical;
  padding: 0.85rem;
  line-height: 1.65;
}

input:focus,
textarea:focus {
  border-color: var(--highlight);
  box-shadow: 0 0 0 4px rgba(232, 112, 90, 0.16);
}

textarea:focus {
  transform: translateY(-1px);
}

p,
li {
  line-height: 1.72;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  overflow-wrap: anywhere;
}

th,
td {
  border: 1px solid var(--line);
  padding: 0.68rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--accent);
  color: var(--primary);
}

blockquote {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  border-left: 4px solid var(--highlight);
  background: rgba(232, 112, 90, 0.08);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.app-shell {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 1rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -1rem -1rem 1rem;
  padding: 0.9rem 1rem 1rem;
  color: #FFFFFF;
  background: rgba(27, 58, 92, 0.96);
  box-shadow: 0 10px 28px rgba(27, 58, 92, 0.16);
  backdrop-filter: blur(10px);
}

.app-header h1,
.screen h2,
.screen h3 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: 1.35rem;
}

.eyebrow {
  margin: 0 0 0.28rem;
  color: var(--highlight);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

.app-header .eyebrow {
  color: var(--accent);
}

.progress-wrap {
  margin-top: 0.85rem;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.82rem;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--highlight), #F3B35E);
  transition: width 520ms cubic-bezier(0.2, 0.9, 0.25, 1);
}

.screen {
  display: none;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 260ms ease, transform 260ms ease;
}

.screen.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
  animation: screenFade 280ms ease both;
}

.chapter-enter {
  animation: chapterSlideIn 460ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.hero-mark {
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  margin: 0 0 1rem;
  border-radius: 24px;
  background: var(--primary);
  box-shadow: var(--shadow);
  font-size: 2.2rem;
}

.form-card,
.intro-panel,
.chapter-card,
.content-card,
.question-card,
.reflect-card,
.survey-form,
.summary-card {
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.form-card {
  display: grid;
  gap: 0.7rem;
  margin-top: 1.25rem;
  padding: 1rem;
}

.form-card label,
.field-label {
  color: var(--primary);
  font-size: 0.92rem;
  font-weight: 800;
}

.required-mark {
  color: var(--accent, #E8705A);
  font-size: 0.8rem;
  font-weight: 600;
  margin-left: 0.3rem;
}

textarea.input-error,
input.input-error,
select.input-error {
  border-color: var(--accent, #E8705A) !important;
  box-shadow: 0 0 0 2px rgba(232, 112, 90, 0.25);
}

.section-head,
.chapter-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.intro-panel {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid rgba(27, 58, 92, 0.08);
}

.chapter-grid {
  display: grid;
  gap: 0.85rem;
}

.chapter-card {
  width: 100%;
  padding: 1rem;
  border: 1px solid transparent;
  text-align: left;
  transition: transform 200ms ease, border-color 200ms ease, box-shadow 200ms ease, filter 200ms ease;
}

.chapter-card:not(:disabled):hover {
  transform: translateY(-2px);
  border-color: rgba(232, 112, 90, 0.44);
}

.chapter-card.locked {
  filter: grayscale(0.9);
  opacity: 0.68;
}

.chapter-card.completed {
  border-color: rgba(39, 174, 96, 0.42);
  animation: unlockPulse 580ms ease both;
}

.chapter-card.current {
  border-color: rgba(232, 112, 90, 0.66);
}

.chapter-card-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chapter-icon {
  display: grid;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  font-size: 1.5rem;
}

.chapter-card h3 {
  font-size: 1.05rem;
}

.chapter-status {
  display: inline-flex;
  align-items: center;
  margin-top: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(27, 58, 92, 0.08);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
}

.content-card,
.question-card,
.reflect-card {
  margin: 1rem 0;
  padding: 1rem;
}

.question-card {
  border-top: 5px solid var(--primary);
}

.reflect-card {
  border-top: 5px solid var(--highlight);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  padding: 0.34rem 0.58rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 900;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 46px;
  border-radius: var(--radius);
  padding: 0.72rem 1rem;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.primary-btn {
  color: #FFFFFF;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(27, 58, 92, 0.22);
}

.secondary-btn {
  color: #FFFFFF;
  background: var(--highlight);
  box-shadow: 0 8px 18px rgba(232, 112, 90, 0.22);
}

.ghost-btn {
  border: 1px solid rgba(27, 58, 92, 0.2);
  color: var(--primary);
  background: #FFFFFF;
}

.primary-btn:not(:disabled):active,
.secondary-btn:not(:disabled):active,
.ghost-btn:not(:disabled):active,
.chapter-card:not(:disabled):active {
  transform: translateY(1px);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1rem;
}

.action-row > button {
  flex: 1 1 180px;
}

.muted {
  color: var(--muted);
}

.status-message {
  min-height: 1.4rem;
  margin-top: 1rem;
  color: var(--primary);
  font-weight: 800;
}

.status-message.error {
  color: #B42318;
}

.status-message.success {
  color: var(--success);
}

.audio-toggle {
  position: fixed;
  top: 0.78rem;
  right: 0.78rem;
  z-index: 40;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 999px;
  background: rgba(27, 58, 92, 0.9);
  color: #FFFFFF;
  box-shadow: 0 10px 24px rgba(27, 58, 92, 0.22);
}

.reveal-box {
  max-height: 0;
  overflow: hidden;
  border-left: 5px solid var(--highlight);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: #FFF7F4;
  transform: translateY(-8px);
  transition: max-height 560ms ease, transform 360ms ease, opacity 360ms ease;
  opacity: 0;
}

.reveal-box.open {
  max-height: 2400px;
  transform: translateY(0);
  opacity: 1;
}

.reveal-inner {
  padding: 1rem;
}

.answer-feedback {
  min-height: 1.5rem;
  margin: 0.8rem 0 0;
  color: var(--success);
  font-weight: 900;
}

.shake {
  animation: shake 360ms ease both;
}

.success-pop {
  animation: successPop 460ms ease both;
}

.summary-card {
  overflow: hidden;
  color: #FFFFFF;
  background: var(--primary);
}

.summary-card .summary-body {
  padding: 1rem;
}

.summary-card table th {
  color: var(--primary);
  background: var(--accent);
}

.summary-card table td {
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.28);
}

.summary-card blockquote {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.1);
}

/* Fix: content-card inside dark summary-card needs dark text */
.summary-card .content-card {
  color: var(--text, #333333);
  background: #FFFFFF;
}

/* Auth tab switcher */
.auth-tabs {
  display: flex;
  gap: 0;
  margin: 1rem 0 0;
  border-bottom: 2px solid var(--primary);
}

.auth-tab {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface, #EBF4FA);
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.auth-tab.active {
  background: var(--primary);
  color: #FFFFFF;
}

/* Worksheet meta table */
.ws-meta-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.ws-meta-table td {
  padding: 0.2rem 0.5rem 0.2rem 0;
  border: none;
}

.survey-form {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.survey-question {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.survey-question:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.choice-group,
.scale-group {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.choice-option,
.scale-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #FFFFFF;
}

.choice-option input,
.scale-option input {
  width: auto;
  min-height: auto;
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.48);
  transform: scale(0);
  animation: ripple 560ms ease-out;
}

.ghost-btn .ripple,
.chapter-card .ripple {
  background: rgba(27, 58, 92, 0.18);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  overflow: hidden;
}

.confetti-particle {
  position: absolute;
  top: -16px;
  width: 9px;
  height: 15px;
  border-radius: 3px;
  background: var(--highlight);
  opacity: 0;
  animation: confettiFall 2s ease-in forwards;
}

.confetti-particle.big {
  width: 12px;
  height: 20px;
  animation-duration: 2.8s;
}

#worksheet {
  display: none;
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 1.5rem;
  background: #FFFFFF;
  color: #111111;
}

.ws-header,
.ws-footer {
  text-align: center;
}

.ws-header {
  padding-bottom: 1rem;
  border-bottom: 2px solid #111111;
}

.ws-header h1,
.ws-header h2 {
  margin: 0.3rem 0;
}

.ws-chapter {
  break-inside: avoid;
  margin: 1.2rem 0;
}

.ws-qa-table th,
.ws-qa-table td {
  font-size: 0.86rem;
}

.ws-question-text {
  max-width: 16rem;
}

.ws-survey {
  margin-top: 1.2rem;
}

.ws-footer {
  margin-top: 1.5rem;
  padding-top: 0.8rem;
  border-top: 1px solid #999999;
  font-size: 0.82rem;
}

@keyframes screenFade {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes chapterSlideIn {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes unlockPulse {
  0% {
    transform: scale(0.985);
    box-shadow: 0 0 0 rgba(39, 174, 96, 0);
  }
  50% {
    transform: scale(1.012);
    box-shadow: 0 0 0 8px rgba(39, 174, 96, 0.12);
  }
  100% {
    transform: scale(1);
    box-shadow: var(--shadow);
  }
}

@keyframes confettiFall {
  0% {
    opacity: 1;
    transform: translate3d(0, -20px, 0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift), 105vh, 0) rotate(720deg);
  }
}

@keyframes ripple {
  to {
    opacity: 0;
    transform: scale(4);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  20%, 60% {
    transform: translateX(-6px);
  }
  40%, 80% {
    transform: translateX(6px);
  }
}

@keyframes successPop {
  0% {
    transform: scale(0.96);
    box-shadow: var(--shadow);
  }
  55% {
    transform: scale(1.012);
    box-shadow: 0 0 0 8px rgba(39, 174, 96, 0.13), var(--shadow);
  }
  100% {
    transform: scale(1);
    box-shadow: var(--shadow);
  }
}

@media (min-width: 560px) {
  .app-shell {
    padding: 1.25rem;
  }

  .app-header {
    margin: -1.25rem -1.25rem 1.25rem;
    padding: 1rem 1.25rem;
    border-radius: 0 0 14px 14px;
  }

  .chapter-grid {
    grid-template-columns: 1fr;
  }

  .screen h2 {
    font-size: 1.65rem;
  }
}

@media print {
  body {
    background: #FFFFFF;
  }

  body > *:not(#worksheet) {
    display: none !important;
  }

  #worksheet {
    display: block !important;
    width: 100%;
    padding: 0;
    box-shadow: none;
  }

  @page {
    margin: 12mm;
  }
}
