:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --surface-hover: #f8fafc;
  --ink: #0f172a;
  --ink-secondary: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --teal: #0d9488;
  --teal-soft: #f0fdfa;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --emerald: #059669;
  --emerald-soft: #ecfdf5;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --sidebar-bg: #0f172a;
  --sidebar-surface: #1e293b;
  --sidebar-border: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #94a3b8;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 28px -6px rgba(15, 23, 42, 0.1), 0 4px 10px -3px rgba(15, 23, 42, 0.05);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
}

button {
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.1s ease;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Brand Lockup & Logo */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-logo-svg {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 6px rgba(79, 70, 229, 0.28));
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.wordmark {
  font-family: var(--sans);
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #ffffff;
}

.brand-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #94a3b8;
  margin-top: 2px;
}

/* Typography & Eyebrows */
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 0 0 6px;
}

h1 {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 28px;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin: 0 0 6px;
  color: var(--ink);
}

.intro-copy {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
  line-height: 1.55;
}

/* Buttons */
.primary-button {
  border: 1px solid transparent;
  background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  color: #ffffff;
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 18px;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.primary-button:not(:disabled):hover {
  background: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.32);
}

.button-auto {
  width: auto;
}

.button-arrow {
  font-size: 16px;
  line-height: 1;
}

.secondary-button {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.secondary-button:not(:disabled):hover {
  background: var(--surface-subtle);
  border-color: #94a3b8;
  color: var(--ink);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
}

.btn-accent {
  background: var(--primary-soft);
  border-color: #c7d2fe;
  color: var(--primary);
}

.btn-accent:not(:disabled):hover {
  background: #e0e7ff;
  border-color: #a5b4fc;
  color: var(--primary-hover);
}

.text-button {
  padding: 4px 8px;
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  border-radius: 6px;
}

.text-button:hover {
  background: var(--primary-soft);
}

.icon-button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-button:not(:disabled):hover {
  background: var(--surface-subtle);
  color: var(--ink);
}

/* Form Elements */
label, legend {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

fieldset {
  padding: 0;
  border: 0;
  margin: 0 0 18px;
}

legend {
  padding: 0;
}

/* Studio / Whiteboard Layout */
.studio-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.card-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-heading h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
}

.number-pill {
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 4px 8px;
}

.question-card .card-heading {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.question-input {
  position: relative;
  margin-bottom: 18px;
}

.question-input textarea {
  width: 100%;
  height: 135px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  border-radius: var(--radius-sm);
  resize: vertical;
  padding: 12px 14px 28px;
  line-height: 1.6;
  font-size: 13.5px;
  min-height: 110px;
  color: var(--ink);
}

.question-input textarea:focus {
  background: var(--surface);
  border-color: var(--primary);
}

textarea::placeholder,
input::placeholder {
  color: #94a3b8;
}

.question-input > span {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 500;
}

.form-row {
  margin-bottom: 18px;
}

.form-row > div {
  width: 100%;
}

.style-choices {
  display: flex;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: var(--radius-sm);
  gap: 4px;
}

.style-choices label {
  margin: 0;
  flex: 1;
  cursor: pointer;
}

.style-choices input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.style-choices span {
  display: block;
  text-align: center;
  padding: 8px 6px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.style-choices input:checked + span {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.voice-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
}

.voice-icon {
  font-size: 18px;
  line-height: 1;
}

.voice-label strong {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}

.voice-label small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.generation-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 0;
}

/* Player & Whiteboard Frame */
.player-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}

.lesson-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid #99f6e4;
  border-radius: 6px;
  padding: 5px 10px;
}

.player {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.board-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #fffef9;
}

.board-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.loading {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e0e7ff;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading strong {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  margin-bottom: 6px;
}

.loading p {
  font-size: 14px;
  color: var(--ink-secondary);
  margin: 4px 0 8px;
}

.loading-note {
  font-size: 12px;
  color: var(--muted);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  border-top: 1px solid var(--line);
  padding: 0 18px;
  background: #f8fafc;
}

.play-button {
  background: var(--primary);
  color: white;
  border: 0;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 12px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(79, 70, 229, 0.25);
}

.play-button:not(:disabled):hover {
  background: var(--primary-hover);
}

.time {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

#timeline {
  flex: 1;
  min-width: 60px;
  accent-color: var(--primary);
  height: 5px;
  cursor: pointer;
}

.control-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.control-button.selected {
  border-color: #c7d2fe;
  background: var(--primary-soft);
  color: var(--primary);
}

/* Lesson Meta & Steps */
.lesson-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.lesson-meta h2 {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 20px;
  margin: 0;
  color: var(--ink);
}

.lesson-meta p:last-child {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.6;
  margin: 6px 0 0;
}

.lesson-meta-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.export-note {
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 16px;
}

.lesson-tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  margin: 12px 0 16px;
}

.lesson-tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 4px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
}

.lesson-tabs button[aria-selected="true"] {
  border-bottom-color: var(--primary);
  color: var(--primary);
}

.lesson-tabs span {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 6px;
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.step-card {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: left;
  min-height: 96px;
  box-shadow: var(--shadow-sm);
}

.step-card:not(:disabled):hover {
  border-color: #a5b4fc;
  background: #fafaff;
}

.step-card.current {
  background: var(--primary-soft);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.step-card span {
  display: inline-block;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.step-card strong {
  font-size: 13.5px;
  font-weight: 600;
  display: block;
  line-height: 1.45;
  color: var(--ink);
}

.step-card small {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.quiet-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--muted);
}

.quiet-note > span {
  font-size: 15px;
  color: var(--primary);
}

.transcript {
  max-height: 340px;
  overflow: auto;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.transcript section {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.transcript section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.transcript h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 6px;
}

.transcript p {
  font-size: 13.5px;
  color: var(--ink-secondary);
  line-height: 1.7;
  margin: 0;
}

/* Lesson History Grid */
.history {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.history-card {
  display: flex;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  padding: 16px 18px;
  background: var(--surface);
  border-radius: var(--radius-md);
  text-align: left;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.history-card:not(:disabled):hover {
  border-color: #a5b4fc;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.history-card > span {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.history-card.is-completed > span {
  background: var(--emerald-soft);
  color: var(--emerald);
}

.history-card strong {
  font-size: 14px;
  font-weight: 600;
  display: block;
  color: var(--ink);
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.history-card small {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-top: 4px;
  line-height: 1.4;
}

/* Footer, Toast, Dialogs */
footer {
  padding: 24px 40px;
  margin-top: 40px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  color: var(--muted);
  gap: 12px;
}

.muted {
  color: var(--muted);
  font-weight: 400;
  margin-left: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 90;
  max-width: 580px;
  width: calc(100% - 32px);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #f8fafc;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.5;
  border: 1px solid #334155;
}

.toast.error {
  background: #991b1b;
  border-color: #dc2626;
  color: #fef2f2;
}

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  max-width: 520px;
  width: calc(100% - 32px);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

dialog h2 {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 22px;
  margin: 0 0 16px;
  color: var(--ink);
}

dialog ol {
  padding-left: 20px;
  margin: 12px 0 20px;
}

dialog li {
  padding: 0 0 12px 6px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink-secondary);
}

dialog strong {
  color: var(--ink);
}

.help-note {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
  padding: 12px 14px;
  background: var(--surface-subtle);
  border-radius: var(--radius-sm);
  margin: 0;
}

.player:fullscreen {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #fffef9;
}

.player:fullscreen .board-wrap {
  width: min(100vw, calc((100vh - 56px) * 16 / 9));
  align-self: center;
}

.player:fullscreen .player-controls {
  flex-shrink: 0;
}

@media (max-width: 960px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }
  .lesson-meta {
    flex-direction: column;
  }
}
