:root {
  --bg: #efeae1;
  --bg-deep: #e5deD2;
  --surface: #fbf8f3;
  --ink: #1a2420;
  --muted: #5d675f;
  --line: #ddd4c6;
  --forest: #1c5c40;
  --forest-2: #143f2d;
  --moss: #e7f2eb;
  --brass: #9a7340;
  --brass-soft: #f3ead7;
  --danger: #8d2e2e;
  --shadow: 0 18px 50px rgba(26, 36, 32, 0.08);
  --radius: 22px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  font-size: 1.02rem;
  line-height: 1.5;
  background:
    radial-gradient(1100px 480px at 8% -10%, rgba(154, 115, 64, 0.16), transparent 55%),
    radial-gradient(900px 420px at 100% 0%, rgba(28, 92, 64, 0.12), transparent 50%),
    var(--bg);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3, .serif {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
p { margin: 0; }
:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

.noscript {
  max-width: 36rem;
  margin: 15vh auto;
  text-align: center;
  padding: 0 20px;
}

.loading, .gate {
  min-height: 100dvh;
}
.loading {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  color: var(--muted);
}

.gate {
  display: grid;
}
.gate-story {
  background:
    radial-gradient(500px 240px at 20% 10%, rgba(196, 164, 106, 0.22), transparent 60%),
    var(--forest-2);
  color: #f6f1e7;
  padding: 36px 28px 42px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 36px;
}
.gate-story h1 {
  font-size: clamp(2.5rem, 5vw, 4.6rem);
  margin: 12px 0 16px;
  max-width: 11ch;
}
.gate-story .lede {
  max-width: 36ch;
  color: rgba(246, 241, 231, 0.82);
  font-size: 1.08rem;
}
.steps { list-style: none; margin: 28px 0 0; padding: 0; display: grid; gap: 14px; }
.steps li { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.steps b {
  font-family: "Fraunces", Georgia, serif;
  color: #e7d3a4;
  font-size: 1.15rem;
}
.quiet { color: rgba(246, 241, 231, 0.62); font-size: 0.92rem; }
.gate-panel {
  display: grid;
  align-content: center;
  padding: 36px 22px 48px;
}
.panel-card { width: min(440px, 100%); margin: 0 auto; }
.panel-card h2 { font-size: 2.2rem; margin: 0 0 8px; }
.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--brass);
}
.gate-story .eyebrow { color: #e7d3a4; }
.sub { color: var(--muted); margin-bottom: 22px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(16px);
  background: rgba(239, 234, 225, 0.88);
  border-bottom: 1px solid rgba(26, 36, 32, 0.06);
}
.topbar-inner, .wrap {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}
.topbar-inner {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.28rem;
  letter-spacing: -0.03em;
}
.logo { display: inline-flex; }
.logo svg { display: block; }
.topbar-actions, .inline-actions, .player-actions, .row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.who {
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wrap { padding: 28px 0 72px; }
.page-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-end; margin-bottom: 22px; }
.page-head h1 { font-size: clamp(2.1rem, 4vw, 3.5rem); margin: 0; max-width: 16ch; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.course-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 240px;
  padding: 18px;
  text-decoration: none;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.course-card:hover { transform: translateY(-2px); }
.course-card-top, .card-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.index, .percent-label {
  font-family: "Fraunces", Georgia, serif;
  letter-spacing: -0.03em;
}
.index { color: var(--brass); font-size: 1.05rem; }
.percent-label { font-size: 1.8rem; color: var(--forest-2); }
.course-card h2 { font-size: 1.55rem; margin: 0; }
.course-card p, .muted, .meta { color: var(--muted); }
.course-card p {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { margin-top: auto; font-size: 0.92rem; }

.progress-panel, .block, .lesson-row, .person, .stage {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.75);
}
.progress-panel { padding: 22px 22px 18px; margin-bottom: 18px; }
.progress-panel.is-done .percent-xl { color: var(--brass); }
.progress-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 14px; }
.percent-xl {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(3.2rem, 7vw, 4.6rem);
  line-height: 0.8;
  letter-spacing: -0.045em;
  color: var(--forest-2);
}
.meter {
  height: 8px;
  background: rgba(20, 63, 45, 0.1);
  border-radius: 99px;
  overflow: hidden;
}
.meter.lg { height: 12px; }
.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--forest-2), #2f8a5e);
  border-radius: inherit;
  transition: width 0.45s ease;
}
.meter.is-done > span { background: linear-gradient(90deg, var(--forest), var(--brass)); }

.back {
  display: inline-flex;
  margin-bottom: 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}
.player-layout { display: grid; gap: 18px; }
.stage { padding: 18px; }
.stage-kicker {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--brass);
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}
.stage h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); margin: 8px 0 14px; }
.frame {
  position: relative;
  background: #0e1612;
  border-radius: 16px;
  overflow: hidden;
}
.frame::before { content: ""; display: block; padding-top: 56.25%; }
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.lede { margin-top: 14px; color: var(--muted); white-space: pre-wrap; }
.player-actions { margin-top: 16px; }
.help-line { margin-top: 10px; color: var(--muted); font-size: 0.9rem; }

.syllabus { padding: 8px 8px 16px; }
.syllabus h2 { font-size: 1.35rem; margin: 12px 12px 8px; }
.lesson-link {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 14px;
}
.lesson-link button[data-action="select"] {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 0;
  text-align: left;
  min-height: 44px;
}
.lesson-link.is-current { background: #fff; box-shadow: 0 8px 24px rgba(26, 36, 32, 0.06); }
.lesson-link small, .check { color: var(--muted); }
.lesson-link strong { display: block; font-weight: 560; }
.tick {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--moss);
  color: var(--forest);
  font-size: 0.85rem;
}
.tick.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); color: transparent; }
.check {
  border: 0;
  background: transparent;
  min-width: 44px;
  min-height: 44px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span, .switch span { font-size: 0.86rem; color: var(--muted); }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
}
textarea { min-height: 96px; resize: vertical; }
.switch { display: flex; gap: 10px; align-items: center; margin: 4px 0 16px; }
.switch input { width: auto; }
.btn, .text-btn {
  border: 0;
  border-radius: 999px;
  min-height: 44px;
  padding: 0.7rem 1.1rem;
  background: var(--forest);
  color: #f6f1e7;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.secondary, .text-btn {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn.ghost { background: transparent; color: var(--forest-2); box-shadow: none; padding-inline: 0.4rem; }
.btn.danger, .text-btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px #e4c9c5; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.stack { display: grid; gap: 16px; }
.block { padding: 18px; }
.block h2, .block h3 { margin: 0 0 6px; }
.block h2 { font-size: 1.7rem; }
.block h3 { font-size: 1.25rem; }
.split-form { display: grid; gap: 12px; }
.note {
  background: var(--brass-soft);
  color: #4e3c22;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.92rem;
  margin-bottom: 14px;
}
.lesson-row, .person { padding: 12px; display: grid; gap: 12px; }
.lesson-row { grid-template-columns: 120px 1fr; }
.thumb {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 10px;
  background: #e7e1d6;
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  background: var(--brass-soft);
  color: #6b5228;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.badge.ok { background: var(--moss); color: var(--forest-2); }
.person { grid-template-columns: 1fr auto; align-items: center; }
.preview {
  margin-bottom: 14px;
  border-radius: 16px;
  overflow: hidden;
  background: #0e1612;
}
.admin-list { display: grid; gap: 12px; }
.course-admin {
  display: grid;
  gap: 8px;
  padding: 18px;
  text-decoration: none;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.course-admin h2 { margin: 0; font-size: 1.6rem; }
.empty {
  padding: 28px 8px;
  color: var(--muted);
}
.empty h2 { color: var(--ink); font-size: 2rem; margin-bottom: 8px; }
.danger-zone { margin-top: 8px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #f6f1e7;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  z-index: 30;
  max-width: min(520px, calc(100% - 24px));
  text-align: center;
}
.toast.bad { background: var(--danger); }
.done-flag {
  display: inline-flex;
  margin-top: 8px;
  color: var(--forest);
  font-weight: 600;
}

@media (min-width: 900px) {
  .gate { grid-template-columns: 1.15fr 0.85fr; }
  .gate-story { padding: 56px 64px; min-height: 100dvh; }
  .player-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .syllabus { position: sticky; top: 92px; }
  .editor { grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr); align-items: start; }
  .editor .side { position: sticky; top: 92px; }
  .split-form { grid-template-columns: 1.4fr 0.6fr; }
}
@media (max-width: 640px) {
  .who { display: none; }
  .lesson-row { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .meter > span, .course-card { transition: none; }
}
