/* =========================================================
   Recall — warm editorial study app
   ========================================================= */

:root {
  color-scheme: light;
  --bg: #f5efe3;
  --bg-2: #ece4d3;
  --surface: #fffcf5;
  --surface-2: #f8f2e6;
  --ink: #1e1b16;
  --ink-2: #3b362d;
  --muted: #7a7160;
  --line: #dbd0bc;
  --line-strong: #b9ac95;
  --accent: #bf4b2b;
  --accent-strong: #a53c1f;
  --accent-soft: #f5ddd3;
  --accent-ink: #fff9f3;
  --green: #1f6f4e;
  --green-soft: #dfeee4;
  --red: #a93226;
  --red-soft: #f7dfda;
  --gold: #a87a1f;
  --shadow: 0 20px 45px -28px rgba(55, 40, 20, 0.45);
  --shadow-lg: 0 35px 70px -35px rgba(55, 40, 20, 0.5);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 20px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14120e;
  --bg-2: #1a1712;
  --surface: #201c16;
  --surface-2: #262118;
  --ink: #f3ebda;
  --ink-2: #ded3bf;
  --muted: #9f9481;
  --line: #3a3328;
  --line-strong: #574c3b;
  --accent: #e2704b;
  --accent-strong: #ef825f;
  --accent-soft: #3a241c;
  --accent-ink: #1c0f0a;
  --green: #6cc79b;
  --green-soft: #1c3328;
  --red: #ef887d;
  --red-soft: #3a201d;
  --gold: #d2a84a;
  --shadow: 0 20px 45px -28px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 35px 70px -30px rgba(0, 0, 0, 0.8);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 520px at 12% -8%, rgba(191, 75, 43, 0.09), transparent 62%),
    radial-gradient(700px 480px at 96% 4%, rgba(168, 122, 31, 0.07), transparent 60%);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

html[data-theme="dark"] body {
  background-image:
    radial-gradient(900px 520px at 12% -8%, rgba(226, 112, 75, 0.08), transparent 62%),
    radial-gradient(700px 480px at 96% 4%, rgba(210, 168, 74, 0.05), transparent 60%);
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

svg {
  display: block;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app {
  width: min(1120px, 100% - 48px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------------- Topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 0 10px;
}

.brand {
  border: 0;
  background: none;
  padding: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1;
}

.brand-dot {
  color: var(--accent);
}

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

.deck-count {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-2);
  transition: border-color 0.2s, transform 0.2s, background 0.2s;
}

.icon-btn:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-moon {
  display: none;
}

html[data-theme="dark"] .icon-sun {
  display: none;
}

html[data-theme="dark"] .icon-moon {
  display: block;
}

/* ---------------- Shared type ---------------- */

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-meta {
  font-size: 13px;
  color: var(--muted);
}

.field-label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  transition: transform 0.18s, background 0.18s, border-color 0.18s, color 0.18s;
  white-space: nowrap;
}

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

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 24px -14px var(--accent);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-primary:disabled {
  opacity: 0.5;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-primary:disabled:hover {
  background: var(--accent);
}

.btn-lg {
  padding: 15px 26px;
  font-size: 15px;
}

.btn-soft {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
}

.btn-soft:hover {
  border-color: var(--line-strong);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-2);
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.btn-danger {
  color: var(--red);
}

.btn-danger:hover {
  border-color: var(--red);
  background: var(--red-soft);
}

.btn-danger-solid {
  background: var(--red);
  color: var(--accent-ink);
}

.btn-danger-solid:hover {
  filter: brightness(0.94);
}

.text-link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.text-link:hover {
  color: var(--accent-strong);
}

/* ---------------- Hero ---------------- */

.view {
  animation: viewIn 0.35s ease both;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.65fr);
  align-items: center;
  gap: 40px;
  padding: 46px 0 40px;
}

.hero-copy .eyebrow {
  margin-bottom: 18px;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(3rem, 6.4vw, 5.4rem);
  line-height: 0.96;
  letter-spacing: -0.045em;
  max-width: 9.5em;
}

.hero h1 em {
  color: var(--accent);
  font-style: italic;
  position: relative;
}

.lede {
  margin-top: 22px;
  max-width: 33em;
  font-size: clamp(15px, 1.5vw, 17px);
  color: var(--muted);
}

.hero-visual {
  position: relative;
  height: 290px;
  min-width: 260px;
}

.float-card {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.float-back {
  width: 250px;
  height: 170px;
  right: 4px;
  top: 6px;
  transform: rotate(7deg);
  opacity: 0.55;
  background: var(--surface-2);
}

.float-front {
  width: 300px;
  right: 26px;
  top: 54px;
  transform: rotate(-2.5deg);
  animation: floatIn 0.7s 0.1s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.float-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.float-front p {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.25;
  margin-top: 10px;
}

.float-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.float-tag {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 4px 8px;
}

.mini-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.mini-options span {
  font-size: 11.5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  color: var(--muted);
}

.mini-options .mini-correct {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 600;
}

.mini-correct b {
  float: right;
}

.spark {
  position: absolute;
  color: var(--gold);
  font-size: 22px;
  animation: twinkle 3s ease-in-out infinite;
}

.spark-a {
  left: 2px;
  top: 22px;
}

.spark-b {
  right: 4px;
  bottom: 12px;
  font-size: 16px;
  animation-delay: 1.2s;
}

/* ---------------- Import ---------------- */

.import-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.65fr);
  gap: 16px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 268px;
  padding: 34px 24px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 26px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
}

.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.008);
}

.dropzone.is-busy {
  opacity: 0.65;
  pointer-events: none;
}

.drop-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 16px;
}

.drop-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone h2 {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.drop-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 6px;
}

.dropzone .btn {
  margin-top: 18px;
}

.drop-note {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 14px;
}

.import-side {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 16px;
}

.side-card {
  display: flex;
  align-items: center;
  gap: 15px;
  text-align: left;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.side-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.side-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--accent);
}

.side-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.side-text strong {
  font-size: 14.5px;
}

.side-text span {
  font-size: 12px;
  color: var(--muted);
}

.side-arrow {
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.2s, color 0.2s;
}

.side-card:hover .side-arrow {
  transform: translateX(3px);
  color: var(--accent);
}

/* ---------------- Status ---------------- */

.status {
  margin-top: 18px;
  padding: 13px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13.5px;
  color: var(--ink-2);
}

.status[data-tone="error"] {
  border-color: color-mix(in srgb, var(--red) 45%, var(--line));
  background: var(--red-soft);
  color: var(--red);
}

.status[data-tone="loading"] {
  border-color: var(--line);
  color: var(--muted);
}

.status[data-tone="loading"]::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 9px;
  vertical-align: -1px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---------------- Library ---------------- */

.library {
  padding: 58px 0 30px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.section-head h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

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

.deck-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.deck-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22px;
  width: 42px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--deck-accent, var(--accent));
}

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

.deck-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.deck-badge {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.deck-delete {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.18s, background 0.18s, color 0.18s;
}

.deck-card:hover .deck-delete,
.deck-delete:focus-visible {
  opacity: 1;
}

.deck-delete:hover {
  background: var(--red-soft);
  color: var(--red);
}

.deck-delete svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.deck-title {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.deck-source {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.deck-stat {
  font-size: 11.5px;
  color: var(--muted);
}

.deck-open-hint {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.empty-library {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 46px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
}

.empty-mark {
  color: var(--gold);
  font-size: 22px;
}

.empty-library strong {
  color: var(--ink);
}

/* ---------------- Builder ---------------- */

.builder-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 30px 0 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: none;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.18s, gap 0.18s;
}

.back-link:hover {
  color: var(--ink);
  gap: 10px;
}

.source-pill {
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  background: var(--surface);
}

.builder-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 30px;
  padding: 34px 0 26px;
}

.title-input {
  width: 100%;
  border: 0;
  border-bottom: 1px dashed var(--line-strong);
  background: transparent;
  padding: 2px 0 8px;
  font-family: var(--serif);
  font-size: clamp(2rem, 4.2vw, 3.2rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.05;
  border-radius: 0;
}

.title-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.builder-meta {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

.builder-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
}

.study-prefs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  margin-bottom: 34px;
}

.prefs-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.check input {
  appearance: none;
  width: 17px;
  height: 17px;
  margin: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  display: grid;
  place-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.check input::after {
  content: "";
  width: 9px;
  height: 5px;
  border-left: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: rotate(-45deg) translateY(-1px) scale(0);
  transition: transform 0.15s;
}

.check input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.check input:checked::after {
  transform: rotate(-45deg) translateY(-1px) scale(1);
}

.preview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.preview-head h2 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.card-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding-bottom: 60px;
}

.preview-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  padding: 20px;
  min-width: 0;
}

.preview-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.kind-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-2);
}

.preview-num {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

.preview-q {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.3;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}

.preview-options {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.preview-opt {
  width: 100%;
  font: inherit;
  font-size: 12px;
  text-align: left;
  color: var(--muted);
  background: transparent;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid transparent;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.preview-opt:hover {
  color: var(--ink);
  background: var(--surface-2);
  border-color: var(--line);
}

.preview-opt.is-answer {
  color: var(--green);
  background: var(--green-soft);
  border-color: color-mix(in srgb, var(--green) 30%, transparent);
  font-weight: 600;
}

.preview-card.needs-answer {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
}

.preview-hint {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.card-preview.is-long .preview-card {
  padding: 16px;
}

.card-preview.is-long .preview-q {
  font-size: 16px;
  margin-bottom: 10px;
}

/* ---------------- Answer key ---------------- */

.answer-key {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  padding: 20px 22px;
  margin-bottom: 34px;
}

.answer-key-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}

.answer-key-head h2 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.answer-key-copy {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.answer-key-row {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.answer-key-input {
  flex: 1 1 240px;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 10px 13px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.answer-key-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.answer-key-help {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}

.answer-key-help code {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.preview-more {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

/* ---------------- Study ---------------- */

.study-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 28px 0 0;
}

.study-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  max-width: 42ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-score {
  justify-self: end;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.study-score strong {
  color: var(--green);
  font-size: 15px;
}

.progress-track {
  height: 4px;
  border-radius: 99px;
  background: var(--line);
  margin-top: 18px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.study-stage {
  display: flex;
  justify-content: center;
  padding: 48px 0 80px;
}

.study-card {
  width: min(780px, 100%);
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--surface);
  padding: clamp(24px, 4.5vw, 42px);
  box-shadow: var(--shadow-lg);
  animation: cardIn 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.study-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-counter {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.question-text {
  font-family: var(--serif);
  font-size: clamp(23px, 3.1vw, 33px);
  font-weight: 500;
  line-height: 1.24;
  letter-spacing: -0.02em;
  margin: 20px 0 28px;
  overflow-wrap: anywhere;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color 0.16s, background 0.16s, transform 0.16s;
}

.option:hover:not(:disabled) {
  border-color: var(--ink);
  transform: translateX(2px);
}

.option:disabled {
  opacity: 1;
}

.option-key {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}

.option-text {
  font-size: 15.5px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.option.is-selected {
  border-color: var(--ink);
}

.option.is-correct {
  border-color: var(--green);
  background: var(--green-soft);
}

.option.is-correct .option-key {
  background: var(--green);
  border-color: var(--green);
  color: var(--surface);
}

.option.is-correct .option-text {
  color: var(--green);
  font-weight: 600;
}

.option.is-wrong {
  border-color: var(--red);
  background: var(--red-soft);
  animation: shake 0.35s ease;
}

.option.is-wrong .option-key {
  background: var(--red);
  border-color: var(--red);
  color: var(--surface);
}

.option.is-wrong .option-text {
  color: var(--red);
  font-weight: 600;
}

.option.is-muted {
  opacity: 0.55;
}

.feedback {
  margin-top: 24px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  animation: feedbackIn 0.25s ease both;
}

.feedback[data-tone="correct"] {
  border-color: color-mix(in srgb, var(--green) 40%, var(--line));
  background: var(--green-soft);
}

.feedback[data-tone="wrong"] {
  border-color: color-mix(in srgb, var(--red) 40%, var(--line));
  background: var(--red-soft);
}

.feedback-head {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
}

.feedback[data-tone="correct"] .feedback-head {
  color: var(--green);
}

.feedback[data-tone="wrong"] .feedback-head {
  color: var(--red);
}

.feedback-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: currentColor;
  color: var(--surface);
  font-size: 12px;
  line-height: 1;
}

.feedback[data-tone="correct"] .feedback-icon {
  background: var(--green);
  color: var(--surface);
}

.feedback[data-tone="wrong"] .feedback-icon {
  background: var(--red);
  color: var(--surface);
}

.feedback-text {
  margin-top: 7px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}

.feedback-explanation {
  margin-top: 7px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.feedback-explanation:empty {
  display: none;
}

.study-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.hint {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------- Results ---------------- */

.results-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 54px 0 80px;
  text-align: center;
}

.score-ring {
  position: relative;
  width: 154px;
  height: 154px;
  margin: 0 auto 28px;
}

.score-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track,
.ring-fill {
  fill: none;
  stroke-width: 8;
}

.ring-track {
  stroke: var(--line);
}

.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 377;
  stroke-dashoffset: 377;
  transition: stroke-dashoffset 1.1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.score-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.score-ring-label strong {
  font-family: var(--serif);
  font-size: 36px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
}

.score-ring-label span {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.results-wrap .eyebrow {
  margin-bottom: 12px;
}

.results-title {
  font-family: var(--serif);
  font-size: clamp(2.3rem, 5vw, 3.4rem);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.results-sub {
  margin: 14px auto 0;
  max-width: 32em;
  color: var(--muted);
  font-size: 15px;
}

.results-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 30px;
}

.missed-list {
  margin-top: 46px;
  text-align: left;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

.missed-list:empty {
  display: none;
}

.missed-list h3 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.missed-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}

.missed-item:last-child {
  border-bottom: 0;
}

.missed-item .missed-index {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--red);
  padding-top: 3px;
}

.missed-item strong {
  display: block;
  font-weight: 600;
  line-height: 1.4;
}

.missed-item span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 12.5px;
}

/* ---------------- Dialogs ---------------- */

.dialog {
  width: min(560px, calc(100% - 32px));
  max-height: min(90vh, 900px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: auto;
}

.dialog::backdrop {
  background: rgba(20, 15, 8, 0.45);
  backdrop-filter: blur(4px);
}

.dialog-wide {
  width: min(820px, calc(100% - 32px));
}

.dialog-small {
  width: min(420px, calc(100% - 32px));
}

.dialog-inner {
  padding: 28px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.dialog-head h2,
.dialog-small h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-top: 5px;
}

.dialog-close {
  flex: 0 0 auto;
}

.text-input,
.text-area {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 12px 14px;
  font-size: 14px;
  transition: border-color 0.16s, background 0.16s;
}

.text-input:focus,
.text-area:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.text-area {
  resize: vertical;
  min-height: 180px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}

.dialog-inner .field-label + .text-input {
  margin-bottom: 18px;
}

.paste-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
}

.paste-count {
  font-size: 12px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.dialog-actions-right {
  margin-top: 24px;
}

.dialog-error {
  margin-top: 14px;
  padding: 10px 13px;
  border-radius: 10px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 12.5px;
}

.confirm-message {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

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

.help-block h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 650;
  margin-bottom: 10px;
}

.help-tag {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 3px 7px;
}

.help-block pre {
  margin: 0 0 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  overflow-x: auto;
}

.help-block code {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-2);
}

.help-block p {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.help-block p code {
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 4px;
  border-radius: 4px;
}

.help-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------------- Toast & confetti ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 100;
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.25s, transform 0.25s;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  left: var(--x);
  width: 7px;
  height: 11px;
  border-radius: 2px;
  background: var(--c);
  opacity: 0.95;
  animation: confettiFall var(--d) cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
  animation-delay: var(--delay);
}

/* ---------------- Footer ---------------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: auto;
  padding: 36px 0 30px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------- Motion ---------------- */

@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes feedbackIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes floatIn {
  from {
    transform: translateY(16px) rotate(-2.5deg);
  }
  to {
    transform: translateY(0) rotate(-2.5deg);
  }
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

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

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--drift), 105vh, 0) rotate(var(--rot));
    opacity: 0.9;
  }
}

/* ---------------- Responsive ---------------- */

@media (hover: none) {
  .deck-delete {
    opacity: 1;
  }
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    gap: 8px;
    padding-top: 34px;
  }

  .hero-visual {
    display: none;
  }

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

  .import-side {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }

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

  .builder-head {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .builder-actions {
    padding-bottom: 0;
  }

  .card-preview {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app {
    width: calc(100% - 32px);
  }

  .topbar {
    padding-top: 20px;
  }

  .deck-count {
    display: none;
  }

  .hero h1 {
    font-size: clamp(2.7rem, 14vw, 3.8rem);
  }

  .hero {
    padding-bottom: 28px;
  }

  .dropzone {
    min-height: 240px;
    padding: 28px 18px;
  }

  .import-side {
    grid-template-columns: 1fr;
  }

  .section-head h2 {
    font-size: 24px;
  }

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

  .answer-key {
    padding: 18px;
  }

  .answer-key-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }

  .answer-key-row .btn {
    flex: 1 1 auto;
  }

  .deck-delete {
    opacity: 1;
  }

  .study-top {
    grid-template-columns: 1fr auto;
    padding-top: 20px;
  }

  .study-title {
    display: none;
  }

  .study-stage {
    padding: 28px 0 50px;
  }

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

  .study-card-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .study-card-foot .btn {
    width: 100%;
  }

  .hint {
    text-align: center;
  }

  .option {
    gap: 11px;
    padding: 12px 13px;
  }

  .option-text {
    font-size: 14.5px;
  }

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

  .results-actions .btn {
    width: 100%;
  }

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

  .dialog-inner {
    padding: 22px;
  }

  .paste-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions {
    width: 100%;
  }

  .dialog-actions .btn {
    flex: 1;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
