:root {
  --cream: #fdfaf4;
  --surface: #ffffff;
  --surface-soft: #f5f0e7;
  --ink: #182b46;
  --navy: #0c2340;
  --navy-soft: #173f69;
  --emerald: #0d5c3a;
  --emerald-light: #e6f4ec;
  --violet: #6750a4;
  --violet-soft: #f0ecfb;
  --amber: #b45309;
  --error: #9a3412;
  --muted: #536276;
  --border: rgba(24, 43, 70, 0.14);
  --border-strong: rgba(24, 43, 70, 0.28);
  --shadow: 0 22px 54px -34px rgba(12, 35, 64, 0.43);
  --radius-lg: 24px;
  --font-display: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-width: 0;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: radial-gradient(circle at 8% 13%, rgba(103, 80, 164, 0.10), transparent 25rem), radial-gradient(circle at 89% 87%, rgba(13, 92, 58, 0.10), transparent 27rem), var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
}
button, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 20; border-radius: 10px; padding: 0.75rem 1rem; background: var(--navy); color: #fff; font-weight: 800; text-decoration: none; transition: top 160ms ease; }
.skip-link:focus { top: 1rem; }
.background-orb { position: fixed; z-index: -1; width: 22rem; height: 22rem; border-radius: 50%; filter: blur(72px); opacity: 0.24; pointer-events: none; }
.orb-one { top: -11rem; left: -10rem; background: #8f78c2; }
.orb-two { right: -10rem; bottom: -12rem; background: #53af80; }

.app-shell { width: min(100% - 2rem, 1180px); min-height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; }
.app-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--border); }
.brand { min-width: 0; display: inline-flex; align-items: center; gap: 0.7rem; color: var(--navy); text-decoration: none; }
.brand-mark { width: 42px; height: 42px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 13px; background: linear-gradient(135deg, var(--navy), var(--violet)); box-shadow: 0 8px 18px rgba(12, 35, 64, 0.20); color: #fff; }
.brand-mark svg { width: 27px; height: 27px; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: var(--font-display); font-size: 1.05rem; font-weight: 800; letter-spacing: 0.035em; line-height: 1.1; }
.brand small { margin-top: 0.18rem; color: var(--muted); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.back-link { min-height: 44px; display: inline-flex; align-items: center; flex: 0 0 auto; color: var(--muted); font-size: 0.88rem; font-weight: 700; text-underline-offset: 3px; }
.back-link:hover { color: var(--navy); }

.flashcard-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(330px, 0.88fr); align-items: center; gap: clamp(1.5rem, 5vw, 5rem); padding: clamp(2.25rem, 6vw, 5.7rem) 0; }
.study-panel, .deck-panel { min-width: 0; }
.eyebrow { margin: 0 0 0.65rem; color: var(--emerald); font-size: 0.72rem; font-weight: 850; letter-spacing: 0.13em; }
h1, h2 { font-family: var(--font-display); }
h1 { max-width: 13ch; margin: 0; color: var(--navy); font-size: clamp(2.5rem, 5vw, 4.6rem); font-weight: 800; letter-spacing: -0.055em; line-height: 0.98; }
.intro { max-width: 37rem; margin: 1.2rem 0 0; color: var(--muted); font-size: 1.03rem; }
.study-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.7rem; }
.deck-count, .privacy-note { margin: 0; }
.deck-count { color: var(--navy); font-size: 0.88rem; font-weight: 800; }
.privacy-note { display: inline-flex; align-items: center; gap: 0.38rem; color: var(--muted); font-size: 0.8rem; font-weight: 650; }
.privacy-note svg { width: 16px; height: 16px; color: var(--emerald); }
.study-stage { margin-top: 0.8rem; }
.card-position { min-height: 1.3rem; margin: 0 0 0.55rem; color: var(--violet); font-size: 0.72rem; font-weight: 850; letter-spacing: 0.12em; }
.flashcard { width: 100%; min-height: 280px; display: grid; align-content: center; gap: 1.35rem; border: 1px solid rgba(12, 35, 64, 0.18); border-radius: var(--radius-lg); padding: clamp(1.65rem, 5vw, 3rem); overflow: hidden; background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 52%), linear-gradient(145deg, var(--navy), var(--navy-soft)); box-shadow: var(--shadow); color: #fff; text-align: left; transition: transform 180ms ease, box-shadow 180ms ease; }
.flashcard:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 27px 57px -34px rgba(12, 35, 64, 0.56); }
.flashcard:active:not(:disabled) { transform: translateY(1px); }
.flashcard.is-empty { cursor: default; opacity: 0.88; }
.card-side { display: block; }
.card-answer { padding-top: 1.15rem; border-top: 1px solid rgba(255, 255, 255, 0.28); }
.card-label { display: block; color: #c9d7e8; font-size: 0.68rem; font-weight: 850; letter-spacing: 0.15em; }
.card-text { display: block; margin-top: 0.45rem; overflow-wrap: anywhere; color: #fff; font-family: var(--font-display); font-size: clamp(1.45rem, 3.5vw, 2.65rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.12; }
.card-answer .card-text { font-family: var(--font-body); font-size: clamp(1.05rem, 2.15vw, 1.4rem); font-weight: 650; letter-spacing: 0; }
.card-hint { color: #c9d7e8; font-size: 0.9rem; }
.study-status { min-height: 1.4rem; margin: 0.65rem 0 0; color: var(--muted); font-size: 0.84rem; }

.primary-actions { margin-top: 1rem; }
.primary-button, .secondary-button, .add-button { min-height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem; border: 0; border-radius: 14px; font-weight: 850; transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease; }
.primary-button { width: 100%; padding: 0.8rem 1.2rem; background: linear-gradient(135deg, var(--emerald), #147649); box-shadow: 0 12px 22px -14px rgba(13, 92, 58, 0.72); color: #fff; }
.primary-button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 16px 25px -14px rgba(13, 92, 58, 0.78); }
.primary-button svg, .secondary-button svg, .add-button svg { width: 20px; height: 20px; }
.primary-button:active:not(:disabled), .secondary-button:active:not(:disabled), .add-button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.5; }
.study-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 0.75rem; }
.secondary-button { padding: 0.75rem 1rem; background: rgba(255, 255, 255, 0.75); border: 1px solid var(--border-strong); color: var(--navy); }
.secondary-button:hover:not(:disabled) { background: #fff; }
.quiet-actions, .tool-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; }
.quiet-actions { justify-content: center; margin-top: 0.6rem; }
.text-button { min-height: 44px; border: 0; border-radius: 9px; padding: 0.45rem 0.6rem; background: transparent; color: var(--emerald); font-size: 0.86rem; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover:not(:disabled) { background: rgba(13, 92, 58, 0.09); }
.danger-button { color: var(--error); }
.danger-button:hover:not(:disabled) { background: rgba(154, 52, 18, 0.09); }
.undo-button { color: var(--navy); }
.keyboard-hint { max-width: 39rem; margin: 1rem auto 0; color: var(--muted); font-size: 0.79rem; text-align: center; }

.deck-panel { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: clamp(1.25rem, 3.4vw, 2rem); background: rgba(255, 255, 255, 0.86); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.panel-heading .eyebrow { margin-bottom: 0.35rem; }
h2 { margin: 0; color: var(--navy); font-size: 1.5rem; line-height: 1.1; }
.deck-badge { flex: 0 0 auto; border: 1px solid rgba(103, 80, 164, 0.22); border-radius: 999px; padding: 0.35rem 0.65rem; background: var(--violet-soft); color: var(--violet); font-size: 0.78rem; font-weight: 850; }
#card-form { margin-top: 1.5rem; }
.entry-fields { display: grid; gap: 0.9rem; }
label { display: block; margin-bottom: 0.45rem; color: var(--ink); font-size: 0.9rem; font-weight: 800; }
input, textarea { width: 100%; border: 1px solid var(--border-strong); border-radius: 14px; padding: 0.82rem 0.9rem; background: #fff; color: var(--ink); font-size: 1rem; line-height: 1.5; }
input { min-height: 52px; }
textarea { min-height: 100px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #64748b; opacity: 1; }
input:focus, textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(103, 80, 164, 0.16); }
.field-help { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.82rem; }
.field-help strong { color: var(--navy); }
.add-button { width: 100%; margin-top: 1rem; padding: 0.75rem 1.1rem; background: var(--navy); color: #fff; }
.add-button:hover { background: var(--navy-soft); transform: translateY(-1px); }
.deck-feedback { min-height: 1.4rem; margin: 0.6rem 0 0; color: var(--muted); font-size: 0.84rem; }
.deck-feedback.is-error { color: var(--error); font-weight: 700; }
.bulk-entry { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.bulk-entry summary { min-height: 44px; display: flex; align-items: center; color: var(--navy); font-size: 0.88rem; font-weight: 800; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.bulk-entry summary:hover { color: var(--emerald); }
#bulk-deck-form { margin-top: 0.7rem; }
#bulk-deck-input { min-height: 132px; }
.deck-tools { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin-top: 1.15rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.list-copy { margin: 0; color: var(--muted); font-size: 0.82rem; }
.deck-list-details { margin-top: 0.6rem; }
.deck-list-details summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; border-radius: 11px; padding: 0.5rem 0.65rem; color: var(--navy); font-size: 0.88rem; font-weight: 800; cursor: pointer; }
.deck-list-details summary:hover { background: var(--surface-soft); }
.deck-list-details summary span:last-child { min-width: 1.65rem; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 0.75rem; text-align: center; }
.deck-list { display: grid; gap: 0.55rem; margin: 0.35rem 0 0; padding: 0; list-style: none; }
.deck-item { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.5rem; border: 1px solid var(--border); border-radius: 12px; padding: 0.55rem 0.5rem 0.55rem 0.75rem; background: #fff; }
.deck-item-text { min-width: 0; }
.deck-item-term, .deck-item-answer { display: block; overflow-wrap: anywhere; }
.deck-item-term { color: var(--navy); font-size: 0.88rem; font-weight: 800; }
.deck-item-answer { margin-top: 0.08rem; color: var(--muted); font-size: 0.78rem; }
.remove-button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--navy); }
.remove-button:hover { background: rgba(12, 35, 64, 0.09); }
.remove-button svg { width: 18px; height: 18px; }
.empty-list { display: grid; justify-items: center; padding: 1.8rem 1rem 0.75rem; color: var(--muted); text-align: center; }
.empty-list svg { width: 42px; height: 42px; color: #9caabb; }
.empty-list p { margin: 0.45rem 0 0; font-size: 0.84rem; }
.app-footer { padding: 1.5rem 0 2rem; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.83rem; text-align: center; }
.app-footer p { margin: 0 0 0.35rem; }
.app-footer nav { line-height: 1.9; }
.app-footer a { color: var(--navy); font-weight: 700; text-underline-offset: 2px; }
.app-footer span { margin: 0 0.18rem; color: #94a3b8; }

@media (max-width: 900px) {
  .flashcard-layout { grid-template-columns: minmax(0, 640px); justify-content: center; }
  h1 { max-width: none; }
}
@media (max-width: 560px) {
  .app-shell { width: min(100% - 1.25rem, 1180px); }
  .app-header { min-height: 74px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
  .brand strong { font-size: 0.93rem; }
  .brand small { font-size: 0.62rem; }
  .back-link { font-size: 0.78rem; }
  .flashcard-layout { padding: 1.5rem 0 2.5rem; }
  .flashcard { min-height: 235px; padding: 1.5rem; }
  .study-actions { gap: 0.55rem; }
  .secondary-button { padding: 0.7rem 0.45rem; font-size: 0.88rem; }
  .deck-panel { padding: 1.25rem; }
  .deck-tools { align-items: flex-start; flex-direction: column; }
  .tool-actions { width: 100%; justify-content: space-between; }
}
:root[data-theme="dark"] { --cream: #101827; --surface: #152337; --surface-soft: #1b2d45; --ink: #eef4fa; --navy: #f1f6fb; --navy-soft: #d2e2f2; --emerald: #75d2a5; --emerald-light: #153d30; --violet: #c9b9f4; --violet-soft: #2e2745; --amber: #f6c66b; --error: #ffb195; --muted: #bbc9d8; --border: rgba(216, 232, 246, 0.18); --border-strong: rgba(216, 232, 246, 0.38); --shadow: 0 22px 54px -34px rgba(0, 0, 0, 0.82); }
:root[data-theme="dark"] body { background: radial-gradient(circle at 8% 13%, rgba(151, 122, 223, 0.13), transparent 25rem), radial-gradient(circle at 89% 87%, rgba(50, 184, 119, 0.12), transparent 27rem), var(--cream); }
:root[data-theme="dark"] .brand-mark { background: linear-gradient(135deg, #183b63, #6750a4); }
:root[data-theme="dark"] .flashcard { background: linear-gradient(145deg, #132b4b, #1d3d66); border-color: rgba(216, 232, 246, 0.22); }
:root[data-theme="dark"] .secondary-button,
:root[data-theme="dark"] .deck-panel,
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .deck-item { background: var(--surface); color: var(--ink); }
:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder { color: #9cacbf; }
:root[data-theme="dark"] .secondary-button:hover:not(:disabled) { background: #1e324a; }
:root[data-theme="dark"] .deck-list-details summary:hover { background: var(--surface-soft); }
:root[data-theme="dark"] .deck-item-term,
:root[data-theme="dark"] .field-help strong,
:root[data-theme="dark"] .app-footer a { color: var(--navy); }
:root[data-theme="dark"] .add-button { background: #dceaf6; color: #10233d; }
:root[data-theme="dark"] .add-button:hover { background: #fff; }
:root[data-theme="dark"] .primary-button { background: linear-gradient(135deg, #218256, #379f71); }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
