:root {
  --paper: #f6efe3;
  --paper-2: #efe4d2;
  --ink: #3a2e26;
  --ink-soft: #6b5a4d;
  --wine: #7b2f3a;
  --wine-dark: #5c202a;
  --gold: #b08a52;
  --line: #d8c8b0;
  --shadow: 0 18px 50px rgba(58, 46, 38, .16);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(circle at 10% 0%, #fbf6ec 0%, transparent 55%),
    radial-gradient(circle at 90% 100%, #efe2cd 0%, transparent 45%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  min-height: 100vh;
}

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

h1, h2, h3, .serif { font-family: var(--serif); font-weight: 600; letter-spacing: .01em; }

.container { width: min(1080px, 92vw); margin: 0 auto; }

/* Landing */
.landing { min-height: 100vh; display: grid; place-items: center; padding: 4rem 0; }
.landing-card {
  text-align: center; max-width: 720px; padding: 4rem 2.5rem;
  background: rgba(255, 252, 246, .72);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  position: relative;
}
.landing-card::before {
  content: ""; position: absolute; inset: 14px; border: 1px solid var(--gold);
  opacity: .35; pointer-events: none;
}
.eyebrow { letter-spacing: .35em; text-transform: uppercase; font-size: .72rem; color: var(--gold); }
.landing h1 { font-size: clamp(2.6rem, 6vw, 4.4rem); margin: 1rem 0 .4rem; line-height: 1.02; }
.landing .tagline { color: var(--ink-soft); font-size: 1.1rem; max-width: 42ch; margin: 0 auto 2rem; }
.selo { font-family: var(--serif); letter-spacing: .3em; font-size: .8rem; color: var(--wine); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  background: var(--wine); color: #fdf9f2; border: 1px solid var(--wine);
  padding: .85rem 1.7rem; border-radius: 2px; font-size: .95rem;
  letter-spacing: .04em; cursor: pointer; transition: .18s ease;
}
.btn:hover { background: var(--wine-dark); border-color: var(--wine-dark); transform: translateY(-1px); }
.btn.ghost { background: transparent; color: var(--wine); }
.btn.ghost:hover { background: rgba(123, 47, 58, .06); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 3rem 1rem; }
.auth-card {
  width: min(440px, 94vw); background: #fffdf8; border: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 2.5rem;
}
.auth-card h1 { margin: 0 0 .3rem; font-size: 2rem; }
.auth-card p.sub { margin: 0 0 1.6rem; color: var(--ink-soft); font-size: .95rem; }
.tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.tab { padding: .6rem 0; margin-right: 1.2rem; color: var(--ink-soft); cursor: pointer; border-bottom: 2px solid transparent; font-size: .95rem; }
.tab.active { color: var(--wine); border-color: var(--wine); }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: .4rem; }
.field input {
  width: 100%; padding: .8rem .9rem; background: #fff; border: 1px solid var(--line);
  border-radius: 2px; font: inherit; color: var(--ink);
}
.field input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(176, 138, 82, .15); }
.check { display: flex; gap: .55rem; align-items: flex-start; font-size: .82rem; color: var(--ink-soft); margin: .4rem 0 1.2rem; }
.check input { margin-top: .2rem; }
.alert { padding: .8rem 1rem; border-radius: 2px; font-size: .88rem; margin-bottom: 1rem; display: none; }
.alert.show { display: block; }
.alert.error { background: #fbe9e9; color: #8a2b2b; border: 1px solid #e6b9b9; }
.alert.ok { background: #eaf4ea; color: #2f5c32; border: 1px solid #bfdcbf; }
.hidden { display: none !important; }

/* App shell */
.topbar {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px);
  background: rgba(246, 239, 227, .88); border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: .9rem 0; }
.brand { font-family: var(--serif); font-size: 1.35rem; color: var(--wine); letter-spacing: .04em; }
.brand small { display: block; letter-spacing: .3em; font-size: .55rem; color: var(--gold); text-transform: uppercase; }
.nav { display: flex; gap: 1.2rem; align-items: center; font-size: .9rem; }
.nav a { color: var(--ink-soft); cursor: pointer; }
.nav a.active, .nav a:hover { color: var(--wine); }

.page { padding: 2.2rem 0 5rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0 0 1.2rem; }
.section-head h2 { font-size: 1.7rem; margin: 0; }
.section-head .muted { color: var(--ink-soft); font-size: .85rem; }
.muted { color: var(--ink-soft); }

.hero-continue {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 2rem; align-items: center;
  background: linear-gradient(120deg, #fffdf8, #f2e7d6);
  border: 1px solid var(--line); box-shadow: var(--shadow); padding: 2.2rem; margin-bottom: 2.6rem;
}
.hero-continue h2 { font-size: 2.2rem; margin: .3rem 0 .6rem; }
.progressbar { height: 6px; background: #e4d7c3; border-radius: 99px; overflow: hidden; margin: .8rem 0 .4rem; }
.progressbar span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--wine)); }

.grid { display: grid; gap: 1.4rem; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.themes { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.card {
  background: #fffdf8; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(58,46,38,.06);
  overflow: hidden; cursor: pointer; transition: .18s ease; display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cover {
  aspect-ratio: 3 / 4; display: grid; place-items: center; padding: 1.4rem; text-align: center;
  background: linear-gradient(160deg, #6d3f33, #3f2620); color: #f4e8d2;
}
.cover .cover-title { font-family: var(--serif); font-size: 1.35rem; line-height: 1.15; }
.cover .cover-author { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; opacity: .8; margin-top: .6rem; }
.card-body { padding: 1rem 1.1rem 1.2rem; }
.card-body h3 { margin: 0 0 .3rem; font-size: 1.15rem; }
.tag { display: inline-block; font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }

.theme-card {
  background: #fffdf8; border: 1px solid var(--line); padding: 1.4rem; text-align: center;
  font-family: var(--serif); font-size: 1.1rem; cursor: pointer; transition: .18s ease;
}
.theme-card:hover { border-color: var(--gold); color: var(--wine); }

/* Study detail */
.study-head { display: grid; grid-template-columns: 220px 1fr; gap: 2rem; margin-bottom: 2.4rem; }
.study-head .cover { aspect-ratio: 3/4; }
.study-head h1 { font-size: 2.6rem; margin: .4rem 0; }
.chapter {
  display: flex; align-items: center; gap: 1rem; padding: 1rem 1.1rem;
  background: #fffdf8; border: 1px solid var(--line); margin-bottom: .7rem; cursor: pointer;
}
.chapter:hover { border-color: var(--gold); }
.chapter .idx { font-family: var(--serif); color: var(--gold); font-size: 1.2rem; width: 2rem; }
.chapter .meta { margin-left: auto; font-size: .8rem; color: var(--ink-soft); }
.chapter.playing { border-color: var(--wine); background: #fdf6ee; }
.badge { font-size: .65rem; letter-spacing: .1em; text-transform: uppercase; padding: .15rem .5rem; border: 1px solid var(--line); color: var(--ink-soft); border-radius: 99px; }

.summary-box { background: #f2e7d6; border-left: 3px solid var(--gold); padding: 1.4rem 1.6rem; margin-top: 2rem; }
.summary-box h3 { margin: 0 0 .5rem; }

/* Player */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(58, 46, 38, .97); color: #f6efe3; padding: .9rem 0;
  box-shadow: 0 -10px 30px rgba(0,0,0,.2); transform: translateY(110%); transition: .25s ease;
}
.player.show { transform: translateY(0); }
.player-inner { display: flex; align-items: center; gap: 1.2rem; }
.player-info { min-width: 0; flex: 1; }
.player-info strong { display: block; font-family: var(--serif); font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-info span { font-size: .78rem; color: #cbb9a4; }
.player button { background: none; border: 1px solid rgba(246,239,227,.4); color: #f6efe3; width: 2.4rem; height: 2.4rem; border-radius: 50%; cursor: pointer; }
.player .rate { width: auto; border-radius: 2px; padding: 0 .6rem; font-size: .8rem; }
.player .timeline { flex: 2; }
.player .timeline input { width: 100%; accent-color: var(--gold); }

.empty { text-align: center; padding: 4rem 1rem; color: var(--ink-soft); }
.empty h3 { font-size: 1.8rem; margin-bottom: .3rem; }

.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.2rem; }
.plan { background: #fffdf8; border: 1px solid var(--line); padding: 1.6rem; }
.plan h3 { margin: 0 0 .2rem; }
.plan .price { font-family: var(--serif); font-size: 2.2rem; color: var(--wine); }
.plan ul { padding-left: 1rem; color: var(--ink-soft); font-size: .88rem; }

.profile-row { display: flex; justify-content: space-between; padding: .9rem 0; border-bottom: 1px solid var(--line); gap: 1rem; }
.profile-row span:first-child { color: var(--ink-soft); }

.toast {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%) translateY(-150%);
  background: var(--ink); color: #f6efe3; padding: .8rem 1.4rem; z-index: 100;
  transition: .3s ease; border-radius: 2px; font-size: .9rem;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  .hero-continue { grid-template-columns: 1fr; padding: 1.5rem; }
  .study-head { grid-template-columns: 120px 1fr; gap: 1rem; }
  .study-head h1 { font-size: 1.9rem; }
  .nav a span.label { display: none; }
  .player .timeline { display: none; }
}

/* Admin */
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 0; }
.admin-tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--line); margin: 1.4rem 0 1.8rem; flex-wrap: wrap; }
.admin-tab { padding: .7rem 1.1rem; cursor: pointer; color: var(--ink-soft); border-bottom: 2px solid transparent; font-size: .92rem; }
.admin-tab.active { color: var(--wine); border-color: var(--wine); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.8rem; }
.stat { background: #fffdf8; border: 1px solid var(--line); padding: 1.1rem 1.2rem; }
.stat .num { font-family: var(--serif); font-size: 2rem; color: var(--wine); line-height: 1; }
.stat .lbl { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.table { width: 100%; border-collapse: collapse; background: #fffdf8; border: 1px solid var(--line); }
.table th, .table td { text-align: left; padding: .75rem .9rem; border-bottom: 1px solid var(--line); font-size: .88rem; vertical-align: middle; }
.table th { background: #f2e7d6; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.mini { font-size: .78rem; padding: .4rem .65rem; }
.danger { color: #8a2b2b; border-color: #d8a9a9; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-card { background: #fffdf8; border: 1px solid var(--line); padding: 1.5rem; margin-bottom: 1.5rem; }
.form-card h3 { margin-top: 0; }
textarea { width: 100%; padding: .8rem .9rem; border: 1px solid var(--line); font: inherit; min-height: 90px; border-radius: 2px; background: #fff; }
select { width: 100%; padding: .8rem .9rem; border: 1px solid var(--line); font: inherit; background: #fff; border-radius: 2px; }
.pill { font-size: .68rem; padding: .15rem .55rem; border-radius: 99px; letter-spacing: .06em; text-transform: uppercase; }
.pill.on { background: #e4f0e4; color: #2f5c32; }
.pill.off { background: #f4e4e4; color: #8a2b2b; }
.chapter-admin { display: flex; gap: .8rem; align-items: center; padding: .7rem .9rem; border: 1px solid var(--line); margin-bottom: .5rem; background: #fffdf8; }
.chapter-admin .grow { flex: 1; min-width: 0; }
.hint { font-size: .78rem; color: var(--ink-soft); margin-top: .25rem; }
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}

/* Theme toggle */
.theme-toggle {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  width: 2rem; height: 2rem; border-radius: 50%; cursor: pointer; font-size: .9rem;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
  transition: .18s ease; padding: 0;
}
.theme-toggle:hover { color: var(--wine); border-color: var(--gold); }
.theme-fab {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  background: var(--paper); box-shadow: var(--shadow); width: 2.4rem; height: 2.4rem;
}

/* Dark theme */
[data-theme="dark"] {
  --paper: #17130f;
  --paper-2: #201a15;
  --ink: #ece1d1;
  --ink-soft: #b5a591;
  --wine: #cc8590;
  --wine-dark: #b56c77;
  --gold: #c6a267;
  --line: #3b322a;
  --shadow: 0 18px 50px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
[data-theme="dark"] body {
  background:
    radial-gradient(circle at 10% 0%, #241d17 0%, transparent 55%),
    radial-gradient(circle at 90% 100%, #1d1712 0%, transparent 45%),
    var(--paper);
}
[data-theme="dark"] .landing-card { background: rgba(32, 26, 21, .82); }
[data-theme="dark"] .topbar { background: rgba(23, 19, 15, .9); }
[data-theme="dark"] .auth-card,
[data-theme="dark"] .card,
[data-theme="dark"] .theme-card,
[data-theme="dark"] .chapter,
[data-theme="dark"] .plan,
[data-theme="dark"] .stat,
[data-theme="dark"] .table,
[data-theme="dark"] .form-card,
[data-theme="dark"] .chapter-admin { background: #211b16; }
[data-theme="dark"] .hero-continue { background: linear-gradient(120deg, #211b16, #2a221a); }
[data-theme="dark"] .progressbar { background: #3b322a; }
[data-theme="dark"] .chapter.playing { background: #2b2219; }
[data-theme="dark"] .summary-box { background: #2a221a; }
[data-theme="dark"] .table th { background: #2a221a; }
[data-theme="dark"] .field input,
[data-theme="dark"] textarea,
[data-theme="dark"] select { background: #161210; color: var(--ink); }
[data-theme="dark"] .field input::placeholder,
[data-theme="dark"] textarea::placeholder { color: #8a7a68; }
[data-theme="dark"] .alert.error { background: #3a1f1f; color: #f0b4b4; border-color: #6b3a3a; }
[data-theme="dark"] .alert.ok { background: #1f3224; color: #b4e0bd; border-color: #3a5f42; }
[data-theme="dark"] .pill.on { background: #1f3224; color: #b4e0bd; }
[data-theme="dark"] .pill.off { background: #3a1f1f; color: #f0b4b4; }
[data-theme="dark"] .danger { color: #e09696; border-color: #7a4a4a; }
[data-theme="dark"] .btn.ghost:hover { background: rgba(204, 133, 144, .14); }
[data-theme="dark"] .cover { background: linear-gradient(160deg, #4a2f27, #1d1410); }
[data-theme="dark"] .toast { background: #ece1d1; color: #1b1714; }
[data-theme="dark"] .landing-card::before { opacity: .3; }
[data-theme="dark"] .btn:not(.ghost) { background: #8f3f4a; border-color: #8f3f4a; color: #fdf9f2; }
[data-theme="dark"] .btn:not(.ghost):hover { background: #a44a56; border-color: #a44a56; }
