:root {
  color-scheme: light;
  --ink: #14213d;
  --ink-soft: #53617b;
  --ink-muted: #7b8495;
  --paper: #f7f3eb;
  --paper-deep: #eee7d9;
  --panel: #fffdf8;
  --panel-2: #fbf7ee;
  --line: #ded4c2;
  --line-strong: #c7bda9;
  --gold: #b88a2d;
  --gold-dark: #7b5a18;
  --blue: #1d3d6f;
  --blue-dark: #122949;
  --red: #9f2c2c;
  --green: #1e6f55;
  --shadow: 0 22px 50px rgba(29, 42, 63, 0.12);
  --shadow-soft: 0 12px 30px rgba(29, 42, 63, 0.09);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font-sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Libre Baskerville", Georgia, serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(184, 138, 45, 0.13), transparent 34rem),
    linear-gradient(135deg, #fbf8f0 0%, var(--paper) 46%, #ede3d2 100%);
  color: var(--ink);
  font-family: var(--font-sans);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.page-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 26px;
  background:
    linear-gradient(180deg, rgba(18, 41, 73, 0.97), rgba(20, 33, 61, 0.98)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cpath d='M0 60h120M60 0v120' stroke='%23ffffff' stroke-opacity='.04'/%3E%3C/svg%3E");
  color: white;
  box-shadow: 12px 0 35px rgba(20, 33, 61, 0.14);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  color: white;
  text-decoration: none;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(184, 138, 45, 0.92), rgba(123, 90, 24, 0.92));
  font: 700 1.35rem var(--font-serif);
  box-shadow: inset 0 1px rgba(255,255,255,.2), 0 12px 30px rgba(0,0,0,.18);
}

.brand strong {
  display: block;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.brand small {
  color: rgba(255,255,255,.66);
  font-size: .8rem;
}

.side-nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px;
  color: rgba(255,255,255,.78);
  background: rgba(255,255,255,.05);
  padding: 16px;
  transition: .2s ease;
}

.nav-item:hover, .nav-item.is-active {
  color: #fff;
  border-color: rgba(184, 138, 45, .55);
  background: rgba(184, 138, 45, .16);
  transform: translateY(-1px);
}

.nav-item span { display: block; font-weight: 700; }
.nav-item small { color: rgba(255,255,255,.55); }

.sidebar-note {
  position: absolute;
  left: 26px;
  right: 26px;
  bottom: 26px;
  padding: 18px;
  border-radius: 20px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
}
.sidebar-note p { margin: 7px 0 0; color: rgba(255,255,255,.63); line-height: 1.45; }

.main {
  padding: 34px clamp(20px, 4vw, 56px) 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--gold-dark);
  font-weight: 800;
  font-size: .72rem;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 0;
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 3.8rem);
  letter-spacing: -.04em;
}
h2 { letter-spacing: -.02em; }

.top-actions, .form-actions, .inline-actions, .card-actions, .study-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn, .text-button, .icon-btn {
  border: 0;
  border-radius: 999px;
  min-height: 42px;
  padding: 0 18px;
  font-weight: 800;
  transition: .18s ease;
}

.btn:hover, .text-button:hover, .icon-btn:hover { transform: translateY(-1px); }
.btn:active, .text-button:active, .icon-btn:active { transform: translateY(0); }

.btn.primary {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  box-shadow: 0 10px 25px rgba(29, 61, 111, .22);
}
.btn.secondary {
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
}
.btn.gold {
  color: #fff;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
}
.btn.danger {
  color: #fff;
  background: var(--red);
}
.btn.ghost {
  color: var(--red);
  background: transparent;
  border: 1px solid rgba(159,44,44,.25);
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.text-button {
  color: var(--blue);
  background: transparent;
  padding: 0;
  min-height: 36px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 1.35rem;
}

.hero-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 28px;
  align-items: center;
  margin-bottom: 30px;
  padding: clamp(22px, 4vw, 38px);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(255,255,255,.93), rgba(251,247,238,.93)),
    repeating-linear-gradient(45deg, transparent 0 16px, rgba(184,138,45,.07) 16px 17px);
  border: 1px solid rgba(199,189,169,.78);
  box-shadow: var(--shadow);
}
.hero-card h2 {
  max-width: 780px;
  margin: 12px 0 10px;
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 3vw, 2.65rem);
  line-height: 1.1;
}
.hero-card p { max-width: 720px; color: var(--ink-soft); line-height: 1.6; margin: 0; }

.seal {
  display: inline-flex;
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--gold-dark);
  background: rgba(184,138,45,.12);
  border: 1px solid rgba(184,138,45,.25);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .04em;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 12px;
}
.hero-stats div {
  padding: 16px;
  border-radius: 20px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
}
.hero-stats strong { display: block; font-size: 1.75rem; }
.hero-stats span { color: var(--ink-muted); font-weight: 700; font-size: .78rem; }

.view { display: none; }
.view.is-visible { display: block; }

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin: 26px 0 18px;
}
.section-heading h2 { margin-bottom: 6px; font-size: 1.6rem; }
.section-heading p { margin: 0; color: var(--ink-soft); }

.search-wrap input,
.modal input,
.modal textarea,
.inline-form input,
.inline-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.88);
  border-radius: 14px;
  color: var(--ink);
  padding: 12px 14px;
  outline: none;
  transition: .2s ease;
}
.search-wrap input { width: min(360px, 100%); }
input:focus, textarea:focus {
  border-color: rgba(29,61,111,.45);
  box-shadow: 0 0 0 4px rgba(29,61,111,.09);
}
textarea { resize: vertical; }

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.deck-card, .panel, .card-row, .study-panel, .progress-deck, .empty-state {
  border: 1px solid var(--line);
  background: rgba(255,253,248,.94);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.deck-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 18px;
  padding: 22px;
}
.deck-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--blue), var(--gold));
}
.deck-card h3 { margin-bottom: 8px; font-size: 1.25rem; }
.deck-card p { color: var(--ink-soft); line-height: 1.55; margin-bottom: 0; }
.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--ink-muted);
  font-size: .82rem;
  font-weight: 700;
}
.meta-pill, .tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: .76rem;
  font-weight: 800;
}

.empty-state {
  text-align: center;
  padding: 46px 24px;
}
.empty-icon { color: var(--gold); font-size: 3rem; margin-bottom: 8px; }
.empty-state p { color: var(--ink-soft); }

.deck-detail-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  padding: 26px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: rgba(255,253,248,.94);
  box-shadow: var(--shadow);
  margin: 12px 0 20px;
}
.deck-detail-head h2 {
  margin-bottom: 8px;
  font-family: var(--font-serif);
  font-size: clamp(1.7rem, 3vw, 2.4rem);
}
.deck-detail-head p { color: var(--ink-soft); line-height: 1.6; }
.deck-detail-head .inline-actions { justify-content: flex-end; }

.cards-list { display: grid; gap: 12px; }
.card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px;
}
.card-row h4 { margin: 0 0 7px; }
.card-row p { margin-bottom: 8px; color: var(--ink-soft); line-height: 1.5; white-space: pre-wrap; }
.card-row .answer-preview { color: var(--green); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.backup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.panel { padding: 24px; }
.panel.wide { grid-column: 1 / -1; }
.panel p { color: var(--ink-soft); line-height: 1.6; }
pre {
  overflow: auto;
  padding: 16px;
  border-radius: 16px;
  background: #17233a;
  color: #f4ebd7;
  line-height: 1.5;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 122px;
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  background: rgba(255,255,255,.55);
  cursor: pointer;
  font-weight: 800;
  color: var(--blue);
}
.file-drop input { display: none; }

.study-panel {
  padding: clamp(20px, 4vw, 34px);
}
.study-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}
.study-title h2 {
  margin: 0 0 5px;
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 3vw, 2.4rem);
}
.study-title p { margin: 0; color: var(--ink-soft); }
.session-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.session-strip div {
  padding: 12px;
  border-radius: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  text-align: center;
}
.session-strip strong { display: block; font-size: 1.35rem; }
.session-strip span { font-size: .75rem; font-weight: 800; color: var(--ink-muted); }

.flashcard-wrap { perspective: 1100px; }
.flashcard {
  min-height: min(52vh, 520px);
  transform-style: preserve-3d;
  transition: transform .45s ease;
  position: relative;
}
.flashcard.is-flipped { transform: rotateY(180deg); }
.face {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  gap: 14px;
  padding: clamp(24px, 6vw, 60px);
  border-radius: 28px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(255,255,255,.94), rgba(249,244,234,.96)),
    linear-gradient(90deg, rgba(184,138,45,.08), transparent);
  backface-visibility: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.55), var(--shadow-soft);
}
.face.back { transform: rotateY(180deg); }
.face small {
  color: var(--gold-dark);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 900;
}
.face .card-text {
  white-space: pre-wrap;
  font-size: clamp(1.25rem, 3vw, 2.3rem);
  line-height: 1.35;
  font-family: var(--font-serif);
}
.face .notes { color: var(--ink-soft); white-space: pre-wrap; line-height: 1.6; }

.study-actions {
  justify-content: center;
  margin-top: 18px;
}
.rating-actions {
  display: none;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.rating-actions.is-visible { display: grid; }
.rating-btn {
  min-height: 58px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font-weight: 900;
  transition: .18s ease;
}
.rating-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.rating-btn.correct { border-color: rgba(30,111,85,.3); color: var(--green); }
.rating-btn.half { border-color: rgba(184,138,45,.35); color: var(--gold-dark); }
.rating-btn.wrong, .rating-btn.unknown { border-color: rgba(159,44,44,.28); color: var(--red); }

.progress-grid { display: grid; gap: 16px; }
.progress-deck { padding: 20px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}
.progress-head h3 { margin: 0 0 4px; }
.progress-head p { margin: 0; color: var(--ink-soft); }
.progress-bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.progress-tile {
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.progress-tile strong { display: block; font-size: 1.4rem; }
.progress-tile span { color: var(--ink-muted); font-weight: 800; font-size: .78rem; }
.weak-list { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.weak-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.62);
  color: var(--ink-soft);
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(720px, calc(100vw - 28px));
  width: 100%;
}
.modal::backdrop { background: rgba(20,33,61,.42); backdrop-filter: blur(6px); }
.modal-card {
  padding: 24px;
  border-radius: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(20,33,61,.28);
  display: grid;
  gap: 16px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}
.modal-head h2 { margin: 0; font-family: var(--font-serif); }
.modal label { display: grid; gap: 7px; font-weight: 800; color: var(--ink-soft); }
.form-actions { justify-content: flex-end; margin-top: 6px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 14px 16px;
  border-radius: 16px;
  color: white;
  background: rgba(18,41,73,.96);
  box-shadow: var(--shadow);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: .24s ease;
  z-index: 20;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .page-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 18px;
  }
  .side-nav { grid-template-columns: repeat(3, 1fr); }
  .sidebar-note { position: static; margin-top: 14px; }
  .hero-card { grid-template-columns: 1fr; }
  .deck-detail-head { grid-template-columns: 1fr; }
  .deck-detail-head .inline-actions { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .topbar, .section-heading, .study-top, .progress-head { align-items: stretch; flex-direction: column; }
  .top-actions, .inline-actions, .card-actions { width: 100%; }
  .btn { flex: 1; }
  .side-nav { grid-template-columns: 1fr; }
  .hero-stats, .session-strip, .progress-bars, .rating-actions, .backup-grid { grid-template-columns: 1fr; }
  .card-row { grid-template-columns: 1fr; }
  .main { padding-top: 24px; }
  .search-wrap input { width: 100%; }
}
