/* ==========================================================================
   StudyCards.app
   Light and dark themes follow the visitor's system setting, unless a signed-in
   user picks one: <html data-theme> is auto, light or dark (inc/global/head.inc.php).
   The dark colors are in style-dark.css.
   ========================================================================== */

/* Poppins, self-hosted (fonts/OFL.txt). The browser only fetches a subset a page actually uses. */
@font-face {
  font-family: "Poppins";
  font-weight: 400;
  font-display: swap;
  src: url("fonts/poppins-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-weight: 500;
  font-display: swap;
  src: url("fonts/poppins-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-weight: 600;
  font-display: swap;
  src: url("fonts/poppins-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-weight: 700;
  font-display: swap;
  src: url("fonts/poppins-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Poppins";
  font-weight: 400;
  font-display: swap;
  src: url("fonts/poppins-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-weight: 500;
  font-display: swap;
  src: url("fonts/poppins-latin-ext-500-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-weight: 600;
  font-display: swap;
  src: url("fonts/poppins-latin-ext-600-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Poppins";
  font-weight: 700;
  font-display: swap;
  src: url("fonts/poppins-latin-ext-700-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light dark;

  /* Brand */
  --brand: #e1062c;
  --brand-hover: #c40425;
  --brand-soft: #fde8ec;
  --brand-text: #c40425;
  --on-brand: #fff;

  /* Surfaces and text (light) */
  --bg: #f6f6f7;
  --surface: #fff;
  --surface-2: #f1f1f3;
  --border: #e3e3e7;
  --border-strong: #cfcfd5;
  --text: #17171a;
  --text-muted: #5b5b66;
  --text-faint: #6b6b76;
  /* Form field outlines: at least 3:1 against the page (WCAG 1.4.11) */
  --border-input: #868690;

  --star: #d97706;
  --success: #15803d;
  --danger: #c40425;
  --on-danger: #fff;

  --shadow-sm: 0 1px 2px rgb(16 16 24 / 0.06), 0 1px 1px rgb(16 16 24 / 0.04);
  --shadow-md: 0 4px 12px rgb(16 16 24 / 0.08), 0 2px 4px rgb(16 16 24 / 0.05);
  --shadow-lg: 0 18px 40px rgb(16 16 24 / 0.14), 0 6px 12px rgb(16 16 24 / 0.08);

  /* The footer's white logo needs flipping on a light page */
  --logo-filter: invert(1);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --pill: 999px;

  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --container: 1180px;
  --gutter: clamp(16px, 4vw, 32px);
  --header-h: 64px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

:root[data-theme="light"] {
  color-scheme: light;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body.no-scroll {
  overflow: hidden;
}

main {
  flex: 1;
}

img,
svg {
  display: block;
  max-width: 100%;
}

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

button {
  cursor: pointer;
}

a {
  color: var(--brand-text);
  text-underline-offset: 3px;
}

h1,
h2,
h3,
h4 {
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection {
  background: var(--brand);
  color: var(--on-brand);
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--narrow {
  max-width: 760px;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--sm {
  width: 16px;
  height: 16px;
}

.icon--lg {
  width: 28px;
  height: 28px;
}

.eyebrow {
  color: var(--brand-text);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--pill);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s,
    transform 0.15s var(--ease),
    box-shadow 0.15s;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: 0 2px 8px rgb(225 6 44 / 0.25);
}

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

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

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.875rem;
}

.btn-lg {
  min-height: 52px;
  padding: 14px 28px;
  font-size: 1.05rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--pill);
  background: transparent;
  color: var(--text-muted);
  text-decoration: none;
  transition:
    background-color 0.15s,
    color 0.15s,
    transform 0.15s var(--ease);
}

.btn-icon:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-icon:active:not(:disabled) {
  transform: scale(0.92);
}

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-icon.is-active .icon {
  fill: currentColor;
}

.btn-icon.js-fav.is-active {
  color: var(--star);
}

.btn-icon.js-like.is-active,
.btn-icon.js-dislike.is-active {
  color: var(--brand-text);
}

.btn-icon--danger:hover:not(:disabled) {
  background: var(--brand-soft);
  color: var(--danger);
}

/* --------------------------------------------------------------------------
   Site announcement (inc/global/site-notice.inc.php)
   -------------------------------------------------------------------------- */

.site-notice {
  background: var(--brand-soft);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.5;
}

.site-notice__inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-block: 10px;
}

.site-notice__icon {
  margin-top: 1px;
  color: var(--brand-text);
}

.site-notice__text {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.site-notice__text a {
  color: var(--brand-text);
  font-weight: 600;
  text-decoration: underline;
}

.site-notice__close {
  flex: none;
  width: 32px;
  height: 32px;
  margin: -4px -6px -4px 0;
}

/* The mobile menu is positioned right under the header, so get the notice out of the way while it's open */
body.no-scroll .site-notice {
  display: none;
}

/* --------------------------------------------------------------------------
   Header and navigation
   -------------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.wordmark img {
  width: 32px;
  height: 32px;
}

.wordmark__text span {
  color: var(--brand-text);
}

.wordmark small {
  color: var(--text-faint);
  font-size: 0.75em;
  font-weight: 500;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.site-nav a,
.site-nav .nav-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--pill);
  background: none;
  color: var(--text-muted);
  font-size: 0.925rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 0.15s,
    color 0.15s;
}

/* Medium widths: text-only links so the signed-in menu fits on one line */
@media (min-width: 901px) and (max-width: 1180px) {
  .site-nav .icon {
    display: none;
  }
}

.site-nav a:hover,
.site-nav .nav-button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.site-nav a[aria-current="page"] {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.site-nav .btn {
  margin-left: 4px;
  padding: 8px 16px;
  background: var(--brand);
  color: var(--on-brand);
}

.site-nav .btn:hover {
  background: var(--brand-hover);
  color: var(--on-brand);
}

.nav-toggle {
  display: none;
  margin-left: auto;
}

@media (max-width: 900px) {
  .nav-toggle {
    display: inline-grid;
  }

  .site-nav {
    position: fixed;
    inset: var(--header-h) 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    max-height: calc(100dvh - var(--header-h));
    overflow-y: auto;
    padding: 12px var(--gutter) 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-8px);
    /* Closing: fade first, then hide (visibility switches after 0.2s) */
    transition:
      opacity 0.2s,
      transform 0.2s var(--ease),
      visibility 0s linear 0.2s;
  }

  .site-nav.is-open {
    visibility: visible;
    opacity: 1;
    transform: none;
    /* Opening: visible (and focusable) at once, without waiting on an animation */
    transition:
      opacity 0.2s,
      transform 0.2s var(--ease),
      visibility 0s;
  }

  .site-nav a,
  .site-nav .nav-button {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 1rem;
  }

  .site-nav .btn {
    margin: 8px 0 0;
  }
}

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

.site-footer {
  margin-top: 80px;
  padding-block: 32px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 32px;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--text);
}

.site-footer__credit {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.site-footer__credit img {
  width: 34px;
  height: auto;
  opacity: 0.7;
  filter: var(--logo-filter);
}

/* --------------------------------------------------------------------------
   Page structure
   -------------------------------------------------------------------------- */

.page {
  padding-block: clamp(28px, 5vw, 48px) 0;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 28px;
}

.page-head h1 {
  font-size: clamp(1.75rem, 3.5vw, 2.35rem);
  font-weight: 700;
}

.page-head p {
  margin-top: 4px;
  color: var(--text-muted);
}

.page-head__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--brand {
  background: var(--brand-soft);
  color: var(--brand-text);
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.form {
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.field legend {
  font-size: 0.9rem;
  font-weight: 600;
}

.field__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.field__hint,
.counter {
  color: var(--text-faint);
  font-size: 0.8rem;
}

.counter.is-near {
  color: var(--brand-text);
  font-weight: 600;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

.input:hover,
.textarea:hover {
  border-color: var(--text-faint);
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input-with-action {
  position: relative;
}

.input-with-action .input {
  padding-right: 48px;
}

.input-with-action .btn-icon {
  position: absolute;
  top: 3px;
  right: 3px;
}

/* Public / Private choice, and the Auto / Light / Dark theme choice */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 0;
  padding: 0;
}

.segmented--three {
  grid-template-columns: repeat(3, 1fr);
}

/* Three columns don't fit inside a panel on a phone */
@media (max-width: 400px) {
  .segmented--three {
    grid-template-columns: 1fr;
  }
}

.segmented legend {
  margin-bottom: 6px;
  padding: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.segmented label {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 14px 16px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition:
    border-color 0.15s,
    background-color 0.15s;
}

.segmented label strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.segmented label span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

/* The thicker border shows the choice without relying on color alone */
.segmented label:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.segmented label:has(input:focus-visible) {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.honeypot {
  display: none;
}

.form-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 0.925rem;
  line-height: 1.45;
}

.form-alert .icon {
  margin-top: 1px;
}

.form-alert--error {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: var(--brand-soft);
  color: var(--text);
}

.form-alert--error .icon {
  color: var(--danger);
}

.form-alert--success {
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  background: color-mix(in srgb, var(--success) 10%, var(--surface));
  color: var(--text);
}

.form-alert--success .icon {
  color: var(--success);
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

/* --------------------------------------------------------------------------
   Panels (auth, account, deck forms)
   -------------------------------------------------------------------------- */

.panel {
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.panel + .panel {
  margin-top: 24px;
}

.auth {
  display: grid;
  place-items: center;
  padding-block: clamp(32px, 8vw, 72px) 0;
}

.auth .panel {
  width: 100%;
  max-width: 440px;
}

.auth__head {
  margin-bottom: 24px;
  text-align: center;
}

.auth__head img {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
}

.auth__head h1 {
  font-size: 1.6rem;
}

.auth__head p {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.auth__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 20px;
  font-size: 0.9rem;
}

.auth__links a {
  color: var(--text-muted);
  text-decoration: none;
}

.auth__links a:hover {
  color: var(--brand-text);
}

.password-rules {
  display: grid;
  gap: 4px;
  padding: 0;
  list-style: none;
  color: var(--text-faint);
  font-size: 0.8rem;
}

.password-rules li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.password-rules li.is-met {
  color: var(--success);
}

.panel__head {
  margin-bottom: 20px;
}

.panel__head h2 {
  font-size: 1.2rem;
}

.panel__head p {
  margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Search and toolbar
   -------------------------------------------------------------------------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.search {
  position: relative;
  flex: 1 1 320px;
  max-width: 520px;
}

.search .icon {
  position: absolute;
  top: 50%;
  left: 14px;
  color: var(--text-faint);
  transform: translateY(-50%);
  pointer-events: none;
}

.search .input {
  padding-left: 44px;
  padding-right: 44px;
  border-radius: var(--pill);
}

.search .btn-icon {
  position: absolute;
  top: 3px;
  right: 3px;
}

.result-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Deck grid
   -------------------------------------------------------------------------- */

.deck-grid:focus,
.card-list:focus {
  outline: none;
}

.deck-grid:focus-visible,
.card-list:focus-visible {
  outline: 2px dashed var(--border-input);
  outline-offset: 8px;
}

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

.deck-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition:
    box-shadow 0.2s,
    transform 0.2s var(--ease),
    border-color 0.2s;
  animation: rise 0.35s var(--ease) both;
}

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

.deck-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.deck-card__title {
  font-size: 1.1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.deck-card__title a {
  color: inherit;
  text-decoration: none;
}

.deck-card__title a:hover,
.deck-card__title a:focus-visible {
  text-decoration: underline;
}

.deck-card__by {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.deck-card__desc {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.925rem;
  overflow-wrap: anywhere;
}

.deck-card__more {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-text);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.deck-card__more:hover {
  text-decoration: underline;
}

.deck-card__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 0;
  list-style: none;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.deck-card__stats li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.deck-card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.deck-card__icons {
  display: flex;
  gap: 2px;
}

.skeleton {
  pointer-events: none;
  animation: none;
}

.skeleton .bone {
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 56px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
}

.empty-state > .icon {
  width: 40px;
  height: 40px;
  color: var(--text-faint);
}

.empty-state h2 {
  color: var(--text);
  font-size: 1.15rem;
}

.empty-state .btn {
  margin-top: 8px;
}

.deck-grid > .empty-state {
  grid-column: 1 / -1;
}

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 32px;
}

.pagination:empty {
  display: none;
}

.pagination button,
.pagination span {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding-inline: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}

.pagination span {
  border-color: transparent;
  background: none;
  color: var(--text-faint);
}

.pagination button:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.pagination button[aria-current="page"] {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--on-brand);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Card list (deck owner's card manager)
   -------------------------------------------------------------------------- */

.card-list {
  display: grid;
  gap: 12px;
  padding: 0;
  list-style: none;
}

.card-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 20px;
  align-items: start;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  animation: rise 0.3s var(--ease) both;
}

.card-row__side {
  min-width: 0;
}

.card-row__label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-faint);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card-row__text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.card-row__actions {
  display: flex;
  gap: 2px;
}

.card-row--read-only {
  grid-template-columns: 1fr 1fr;
  animation: none;
}

@media (max-width: 640px) {
  .card-row {
    grid-template-columns: 1fr auto;
  }

  .card-row--read-only {
    grid-template-columns: 1fr;
  }

  .card-row__side:nth-child(2) {
    grid-column: 1;
  }

  .card-row__actions {
    grid-row: 1;
    grid-column: 2;
  }
}

/* Public deck page */

.deck-page__title,
.deck-page__desc {
  overflow-wrap: anywhere;
}

.deck-page__stats {
  margin-top: 16px;
}

.deck-page__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.deck-page__heading {
  margin: 36px 0 14px;
  font-size: 1.25rem;
}

.deck-page__cta {
  margin-top: 36px;
}

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

.dialog {
  /* The global margin reset removes the browser's centering of <dialog>; put it back */
  margin: auto;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.dialog[open] {
  animation: pop 0.2s var(--ease);
}

.dialog::backdrop {
  background: rgb(8 8 12 / 0.55);
  backdrop-filter: blur(3px);
}

.dialog__body {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog__head h2 {
  font-size: 1.2rem;
}

.dialog__head p {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.925rem;
}

.dialog__head .btn-icon {
  margin: -8px -8px 0 0;
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* Study mode picker */
.mode-list {
  display: grid;
  gap: 10px;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  transition:
    border-color 0.15s,
    background-color 0.15s;
}

.mode-option:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.mode-option .icon {
  width: 24px;
  height: 24px;
  color: var(--brand-text);
}

.mode-option strong {
  display: block;
}

.mode-option span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  display: grid;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 0.925rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.25s var(--ease);
}

.toast--error .icon {
  color: var(--brand);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}

/* Toasts can be hovered to keep them open */
.toast-region .toast {
  pointer-events: auto;
}

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

/* --------------------------------------------------------------------------
   Home
   -------------------------------------------------------------------------- */

.hero {
  position: relative;
  overflow: hidden;
  padding-block: clamp(48px, 9vw, 104px);
}

.hero::before {
  content: "";
  position: absolute;
  inset: -40% -10% auto auto;
  width: 70%;
  aspect-ratio: 1;
  background: radial-gradient(closest-side, var(--brand-soft), transparent);
  pointer-events: none;
}

.hero__inner {
  position: relative;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  align-items: center;
  gap: 48px;
}

.hero h1 {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.hero h1 span {
  color: var(--brand-text);
}

.hero__lead {
  max-width: 34rem;
  margin-top: 18px;
  color: var(--text-muted);
  font-size: clamp(1.05rem, 2vw, 1.2rem);
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

/* Decorative card stack */
.hero__art {
  position: relative;
  height: 340px;
}

.demo-card {
  position: absolute;
  inset: 0;
  margin: auto;
  display: grid;
  align-content: center;
  gap: 10px;
  width: min(360px, 90%);
  height: 220px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.demo-card:nth-child(1) {
  transform: rotate(-9deg) translate(-30px, 14px);
  opacity: 0.55;
}

.demo-card:nth-child(2) {
  transform: rotate(5deg) translate(26px, -8px);
  opacity: 0.8;
}

.demo-card:nth-child(3) {
  /* Two short cycles (under 5 seconds), then it stays still */
  animation: float 2.4s ease-in-out 2;
}

.demo-card .eyebrow {
  font-size: 0.7rem;
}

.demo-card p {
  font-size: 1.3rem;
  font-weight: 600;
}

@keyframes float {
  50% {
    transform: translateY(-10px);
  }
}

.section {
  padding-block: clamp(48px, 8vw, 88px);
}

.section__head {
  max-width: 640px;
  margin-bottom: 36px;
}

.section__head h2 {
  margin-top: 8px;
  font-size: clamp(1.75rem, 4vw, 2.4rem);
}

.section__head p {
  margin-top: 10px;
  color: var(--text-muted);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  gap: 18px;
}

.feature {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.feature__icon {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--brand-soft);
  color: var(--brand-text);
}

.feature h3 {
  font-size: 1.05rem;
}

.feature p {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.925rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 18px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.stat .feature__icon {
  margin: 0;
}

.stat strong {
  display: block;
  font-size: 1.75rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

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

.cta {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: clamp(36px, 6vw, 64px) 24px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--brand), #8f0019);
  color: #fff;
  text-align: center;
}

.cta h2 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.cta p {
  max-width: 32rem;
  opacity: 0.9;
}

.cta .btn {
  margin-top: 8px;
  background: #fff;
  color: #8f0019;
}

.cta .btn:hover {
  background: #ffe4e9;
}

@media (max-width: 860px) {
  .hero__inner {
    grid-template-columns: 1fr;
  }

  .hero__art {
    height: 280px;
  }
}

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

.study__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 14px;
}

.study__head h1 {
  font-size: clamp(1.5rem, 3.5vw, 2rem);
  overflow-wrap: anywhere;
}

.study__count {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 6px;
  margin-bottom: 24px;
  overflow: hidden;
  border-radius: var(--pill);
  background: var(--surface-2);
}

.progress__bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.35s var(--ease);
}

.flashcard {
  display: block;
  width: 100%;
  min-height: clamp(260px, 45vh, 380px);
  padding: 0;
  border: 0;
  background: none;
  perspective: 1400px;
  text-align: center;
}

.flashcard__inner {
  position: relative;
  display: grid;
  min-height: inherit;
  transform-style: preserve-3d;
  /* Height snaps to the new face as it starts turning; animating it repainted both faces every frame */
  transition: transform 0.5s var(--ease);
}

.flashcard.is-flipped .flashcard__inner {
  transform: rotateY(180deg);
}

.flashcard__face {
  grid-area: 1 / 1;
  display: grid;
  align-content: center;
  /* The face turning away takes the new face's height; clip it from the top, not the middle */
  align-content: safe center;
  overflow: hidden;
  gap: 14px;
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flashcard__face--back {
  transform: rotateY(180deg);
  border-color: color-mix(in srgb, var(--brand) 40%, var(--border));
}

/* The face turned away is out of the layout, so only the showing face sets the card's height */
.flashcard:not(.is-flipped) .flashcard__face--back,
.flashcard.is-flipped .flashcard__face--front {
  position: absolute;
  inset: 0;
}

.flashcard__label {
  color: var(--brand-text);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.flashcard__text {
  font-size: clamp(1.15rem, 2.6vw, 1.6rem);
  font-weight: 500;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.flashcard:hover .flashcard__face {
  box-shadow: var(--shadow-lg);
}

.study__controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.study__controls .btn-icon {
  width: 52px;
  height: 52px;
  border-color: var(--border-strong);
  background: var(--surface);
}

.study__controls .btn-icon .icon {
  width: 24px;
  height: 24px;
}

.study__hint {
  margin-top: 14px;
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: center;
}

.study__hint kbd {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  font: inherit;
  font-size: 0.75rem;
}

/* Keyboard hint only where there is a keyboard */
@media (hover: none) {
  .study__hint {
    display: none;
  }
}

.study-done {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 48px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}

.study-done .feature__icon {
  width: 60px;
  height: 60px;
  margin: 0;
}

.study-done h2 {
  font-size: 1.5rem;
}

.study-done p {
  color: var(--text-muted);
}

.study-done__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

/* --------------------------------------------------------------------------
   Legal pages
   -------------------------------------------------------------------------- */

.prose {
  max-width: 760px;
}

.prose h1 {
  margin: 8px 0 24px;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
}

.prose h2 {
  margin: 36px 0 10px;
  font-size: 1.3rem;
}

.prose p,
.prose li {
  color: var(--text-muted);
}

.prose p + p {
  margin-top: 14px;
}

.prose ul,
.prose ol {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  padding-left: 1.4em;
}

.external-link .icon {
  display: inline-block;
  margin-left: 3px;
  vertical-align: -2px;
}

/* --------------------------------------------------------------------------
   404
   -------------------------------------------------------------------------- */

.not-found {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding-block: clamp(56px, 12vw, 120px) 0;
  text-align: center;
}

.not-found__code {
  font-size: clamp(5rem, 18vw, 9rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.05em;
  background: linear-gradient(135deg, var(--brand), #8f0019);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.not-found h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.not-found p:not(.not-found__code) {
  max-width: 30rem;
  color: var(--text-muted);
}

.not-found__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

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