@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap");

:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --surface: #fffdfa;
  --surface-strong: #ffffff;
  --surface-muted: #eeebe4;
  --ink: #20221f;
  --muted: #73756e;
  --line: #ddd9d0;
  --accent: #c8f25d;
  --accent-strong: #a9dc2f;
  --blue: #9adcf5;
  --orange: #f5b766;
  --rose: #f09b91;
  --green: #5d9f66;
  --danger: #b54a43;
  --shadow: 0 18px 55px rgba(48, 45, 37, 0.09);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --max-width: 1180px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171916;
  --surface: #20231f;
  --surface-strong: #272a25;
  --surface-muted: #30332e;
  --ink: #f4f2eb;
  --muted: #aaada4;
  --line: #3c4039;
  --accent: #bce653;
  --accent-strong: #9bc82d;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% -10%, color-mix(in srgb, var(--accent) 17%, transparent), transparent 30rem),
    var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  transition: background 180ms ease, color 180ms ease;
}

button,
input,
select {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  width: min(calc(100% - 32px), var(--max-width));
  height: 84px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.brand {
  border: 0;
  padding: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  justify-self: start;
  font-family: "Manrope", sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px 10px 10px 3px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #1b1d18;
  transform: rotate(-3deg);
}

.main-nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-muted);
  border-radius: 999px;
}

.nav-item {
  border: 0;
  border-radius: 999px;
  padding: 9px 17px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.nav-item.active {
  background: var(--surface-strong);
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(34, 34, 30, 0.08);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-dark {
  background: var(--ink);
  color: var(--bg);
}

.button-primary {
  background: var(--accent);
  color: #20221f;
}

.button-ghost {
  border-color: var(--line);
  background: var(--surface);
}

.button-danger {
  background: var(--danger);
  color: #fff;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.import-button input {
  display: none;
}

main {
  width: min(calc(100% - 32px), var(--max-width));
  margin: 0 auto;
  padding: 58px 0 80px;
  outline: none;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-family: "Manrope", sans-serif;
}

h1 {
  max-width: 760px;
  margin-bottom: 14px;
  font-size: clamp(2.45rem, 7vw, 5.4rem);
  line-height: 0.96;
  letter-spacing: -0.055em;
}

h2 {
  letter-spacing: -0.035em;
}

.lead {
  max-width: 640px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 30px;
}

.library-toolbar h1 {
  margin-bottom: 4px;
  font-size: clamp(2rem, 5vw, 3.5rem);
}

.library-toolbar p {
  margin-bottom: 0;
}

.search {
  min-width: min(300px, 42vw);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 17px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.search:focus {
  border-color: var(--ink);
}

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

.section-row h2 {
  margin: 0;
  font-size: 1.4rem;
}

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

.subject-list {
  display: grid;
  gap: 38px;
}

.subject-section {
  display: grid;
  gap: 15px;
}

.subject-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

.subject-heading h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.subject-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

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

.deck-card {
  position: relative;
  min-height: 290px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 25px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(45, 42, 35, 0.04);
  display: flex;
  flex-direction: column;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.deck-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.deck-card::after {
  content: "";
  position: absolute;
  width: 130px;
  height: 130px;
  right: -30px;
  top: -35px;
  border-radius: 44% 56% 65% 35%;
  background: var(--card-color, var(--accent));
  opacity: 0.55;
  transform: rotate(18deg);
}

.card-top,
.card-footer,
.question-meta,
.study-footer,
.answer-topline,
.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.deck-number {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-weight: 800;
}

.menu-button {
  position: relative;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  cursor: pointer;
}

.deck-card h3 {
  max-width: 80%;
  margin: 45px 0 9px;
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.08;
}

.deck-card .subject {
  margin-bottom: 0;
  color: var(--muted);
}

.card-footer {
  margin-top: auto;
}

.progress-line {
  flex: 1;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.progress-line span {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: var(--ink);
}

.card-stats {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.card-actions {
  margin-top: 18px;
  display: flex;
  gap: 9px;
}

.card-actions .button:first-child {
  flex: 1;
}

.empty-state,
.drop-zone {
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 54px 25px;
  text-align: center;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

.drop-zone.dragging {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--accent) 20%, var(--surface));
}

.study-layout {
  max-width: 900px;
  margin: 0 auto;
}

.study-header {
  margin-bottom: 26px;
}

.study-header-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.back-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.study-title {
  flex: 1;
}

.study-title h2,
.study-title p {
  margin: 0;
}

.study-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.study-progress span {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: var(--accent-strong);
  transition: width 240ms ease;
}

.study-card {
  min-height: 540px;
  border: 1px solid var(--line);
  border-radius: 34px;
  padding: clamp(24px, 5vw, 52px);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.question-meta {
  margin-bottom: 34px;
}

.pill {
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.study-card h1 {
  max-width: none;
  margin-bottom: 30px;
  font-size: clamp(1.65rem, 4.2vw, 2.8rem);
  line-height: 1.12;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
  white-space: normal;
}

.study-card h1.long {
  font-size: clamp(1.35rem, 3.2vw, 2.1rem);
  line-height: 1.22;
  letter-spacing: -0.035em;
}

.study-card h1.very-long {
  font-size: clamp(1.15rem, 2.6vw, 1.65rem);
  line-height: 1.35;
  letter-spacing: -0.025em;
}

.code-block {
  margin: -8px 0 30px;
  overflow: auto;
  border-radius: var(--radius-md);
  padding: 20px;
  background: #1f231e;
  color: #f1f5ea;
  font-family: "SFMono-Regular", Consolas, monospace;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.question-image {
  max-width: 100%;
  max-height: 360px;
  margin-bottom: 30px;
  border-radius: var(--radius-md);
  object-fit: contain;
}

.options {
  display: grid;
  gap: 11px;
}

.option {
  width: 100%;
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 13px 16px;
  background: var(--surface-strong);
  color: var(--ink);
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 13px;
  text-align: left;
  cursor: pointer;
}

.option-text {
  min-width: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.rich-text .katex-display,
.question-text .katex-display {
  margin: 0.6em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.option:hover:not(:disabled),
.option.selected {
  border-color: var(--ink);
  transform: translateY(-1px);
}

.option.correct {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 11%, var(--surface));
}

.option.incorrect {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
}

.option-key {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--surface-muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.text-answer {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 17px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 1rem;
  outline: none;
}

.text-answer:focus {
  border-color: var(--ink);
}

.feedback {
  margin-top: 24px;
  border-radius: 18px;
  padding: 18px 20px;
  background: var(--surface-muted);
  line-height: 1.55;
}

.feedback.correct {
  background: color-mix(in srgb, var(--green) 12%, var(--surface));
}

.feedback.incorrect {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.feedback h3 {
  margin-bottom: 7px;
}

.feedback p:last-child {
  margin-bottom: 0;
}

.study-footer {
  margin-top: 26px;
}

.keyboard-hint {
  color: var(--muted);
  font-size: 0.8rem;
}

kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--surface);
  font: inherit;
}

.summary {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
}

.summary-mark {
  width: 90px;
  height: 90px;
  margin: 0 auto 26px;
  border-radius: 30px 30px 30px 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #1f211d;
  font: 800 2rem "Manrope", sans-serif;
  transform: rotate(-4deg);
}

.summary h1 {
  margin-inline: auto;
}

.summary-stats {
  margin: 38px 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 22px 12px;
  background: var(--surface);
}

.stat-card strong {
  display: block;
  margin-bottom: 5px;
  font: 800 1.8rem "Manrope", sans-serif;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.85rem;
}

.result-actions {
  justify-content: center;
  flex-wrap: wrap;
}

.progress-dashboard {
  display: grid;
  gap: 36px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.dashboard-card {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 22px;
  background: var(--surface);
}

.dashboard-card strong {
  display: block;
  margin: 18px 0 4px;
  font: 800 2rem "Manrope", sans-serif;
}

.mastery-list {
  display: grid;
  gap: 10px;
}

.mastery-row {
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 0.7fr) 80px;
  align-items: center;
  gap: 18px;
}

.mastery-row h3,
.mastery-row p {
  margin: 0;
}

.toast-region {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 9px;
}

.toast {
  max-width: 360px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 16px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow);
  animation: toast-in 180ms ease both;
}

.dialog {
  max-width: 420px;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 25px;
  background: var(--surface);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(20, 20, 18, 0.55);
  backdrop-filter: blur(3px);
}

.dialog-actions {
  margin-top: 22px;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 800px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .main-nav {
    position: fixed;
    z-index: 10;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
  }

  .library-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

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

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .study-card {
    min-height: 0;
  }
}

@media (max-width: 520px) {
  .topbar {
    width: min(calc(100% - 22px), var(--max-width));
  }

  .brand > span:last-child,
  .theme-toggle {
    display: none;
  }

  main {
    width: min(calc(100% - 22px), var(--max-width));
    padding-top: 40px;
  }

  .library-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .deck-card {
    min-height: 270px;
  }

  .study-card {
    border-radius: 24px;
  }

  .study-footer,
  .answer-topline {
    align-items: stretch;
    flex-direction: column;
  }

  .study-footer .button {
    width: 100%;
  }

  .keyboard-hint {
    display: none;
  }

  .summary-stats {
    grid-template-columns: 1fr;
  }

  .mastery-row {
    grid-template-columns: 1fr 64px;
  }

  .mastery-row .progress-line {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation-duration: 0.01ms !important;
  }
}
