/* =============== BASE ROOT =============== */
:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

/* =============== LIGHT MODE (DEFAULT) =============== */

body {
  min-height: 100vh;
  background: radial-gradient(circle at top, #dbeafe 0, #f3f4f6 45%);
  color: #111827;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: none;
}

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

/* Focus visible */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid #fbbf24;
  outline-offset: 2px;
}

/* Remove default focus outline for mouse users */
a:focus,
button:focus,
input:focus,
textarea:focus {
  outline: none;
}

/* =============== HEADER =============== */

.header {
  background: linear-gradient(90deg, #1d4ed8, #38bdf8, #0ea5e9);
  color: #f9fafb;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header__container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header__title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.header__nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  flex: 1;
  flex-wrap: wrap;
}

.header__link {
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.18);
  color: #e5f0ff;
  transition: background 150ms ease, transform 150ms ease;
}

.header__link:hover {
  background: rgba(15, 23, 42, 0.3);
  transform: translateY(-1px);
}

/* HEADER SEARCH */

.header__search {
  position: relative;
}

.header__search-wrapper {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(219, 234, 254, 0.9);
  box-shadow: 0 3px 12px rgba(15, 23, 42, 0.6);
}

.header__search-icon {
  font-size: 0.9rem;
}

.header__search-input {
  background: transparent;
  border: none;
  color: #e0f2fe;
  font-size: 0.85rem;
  min-width: 180px;
}

.header__search-input::placeholder {
  color: #bfdbfe;
}

/* HEADER BUTTONS */

.header__btn {
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease,
    border-color 150ms ease, color 150ms ease;
}

.header__btn--outline {
  background: #0f172a;
  color: #e5f0ff;
  border: 1px solid rgba(219, 234, 254, 0.9);
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.6);
}

.header__btn--outline:hover {
  background: #020617;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.75);
}

.header__btn:not(.header__btn--outline) {
  background: #f97316;
  color: #111827;
  border: 1px solid #ea580c;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.5);
}

.header__btn:not(.header__btn--outline):hover {
  background: #ea580c;
  transform: translateY(-1px);
  box-shadow: 0 7px 16px rgba(15, 23, 42, 0.7);
}

/* =============== LAYOUT: FIXED SIDEBAR + MAIN =============== */

.layout {
  display: block;
  flex: 1;
  position: relative;
}

/* SIDEBAR */

.sidebar {
  position: fixed;
  top: 64px;                  /* header height */
  bottom: 56px;               /* footer height */
  left: 0;
  width: 260px;
  background: radial-gradient(circle at top, rgba(219, 234, 254, 0.6), #ffffff);
  border-right: 1px solid #e5e7eb;
  box-shadow: 4px 0 16px rgba(15, 23, 42, 0.15);
  overflow-y: auto;
}

.sidebar__inner {
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar__section {
}

.sidebar__header {
  margin-bottom: 0.75rem;
}

.sidebar__header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.sidebar__empty {
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 0.3rem;
}

.sidebar__list {
  list-style: none;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Deck buttons */

.sidebar__item {
}

.sidebar__btn {
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-radius: 0.7rem;
  border: 1px solid #cbd5f5;
  font-size: 0.85rem;
  background: linear-gradient(
    90deg,
    rgba(59, 130, 246, 0.08),
    rgba(59, 130, 246, 0.02)
  );
  color: #374151;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  transition: background 150ms ease, border-color 150ms ease,
    transform 150ms ease, box-shadow 150ms ease;
}

.sidebar__btn:hover {
  background: rgba(59, 130, 246, 0.16);
  border-color: #2563eb;
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18);
}

.sidebar__item--active .sidebar__btn {
  background: linear-gradient(120deg, #1d4ed8, #0ea5e9);
  color: #f9fafb;
  border-color: rgba(219, 234, 254, 0.9);
}

/* Cards in sidebar */

.sidebar__section--cards {
  border-top: 1px solid #e5e7eb;
  padding-top: 1rem;
}

.sidebar__cards-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: #4b5563;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.sidebar__card-list {
  list-style: none;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar__card-item {
}

.sidebar__card-btn {
  width: 100%;
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid transparent;
  font-size: 0.8rem;
  background-color: #f9fafb;
  color: #374151;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  transition: background 150ms ease, border-color 150ms ease,
    transform 150ms ease, box-shadow 150ms ease;
}

.sidebar__card-btn:hover {
  background-color: #e5f0ff;
  border-color: #93c5fd;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.18);
}

.sidebar__card-btn--active {
  background-color: #2563eb;
  color: #f9fafb;
  border-color: #1d4ed8;
}

.sidebar__card-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__card-icon {
  font-size: 0.9rem;
  opacity: 0.7;
}

/* MAIN */

.main {
  margin-left: 260px; /* sidebar width */
  padding: 2rem;
  min-height: calc(100vh - 64px - 56px); /* full height minus header/footer */
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.deck-view,
.empty-state {
  max-width: 720px;
  width: 100%;
}

/* =============== EMPTY STATE =============== */

.empty-state {
  margin-top: 3rem;
  background: #ffffff;
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15);
  text-align: center;
  border: 1px dashed #e5e7eb;
}

.empty-state h2 {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 0.95rem;
  color: #4b5563;
  margin-bottom: 1.25rem;
}

/* =============== DECK HEADER =============== */

.deck-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.deck-header__info {
  flex: 1;
}

.deck-title {
  font-size: 1.3rem;
  margin-bottom: 0.25rem;
}

.deck-meta {
  font-size: 0.8rem;
  color: #6b7280;
}

.deck-search-status {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: #6b7280;
}

.deck-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

/* =============== STUDY AREA & CARD =============== */

.study-area {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Card with 3D flip */

.card {
  perspective: 1200px;
}

.card__inner {
  position: relative;
  border-radius: 1.25rem;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
  aspect-ratio: 4 / 2;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
  cursor: pointer;
  background: linear-gradient(135deg, #1d4ed8, #22c55e);
}

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

.card__face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  backface-visibility: hidden;
}

.card__front {
  background: radial-gradient(
    circle at top left,
    rgba(59, 130, 246, 0.5),
    rgba(22, 163, 74, 0.5)
  );
}

.card__back {
  background: radial-gradient(
    circle at bottom right,
    rgba(244, 63, 94, 0.5),
    rgba(251, 146, 60, 0.5)
  );
  transform: rotateY(180deg);
}

.card__face p {
  font-size: 1.15rem;
  color: #f9fafb;
}

/* Card controls */

.card-controls {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.card-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
  color: #6b7280;
}

.card-meta-row__right {
  display: flex;
  gap: 0.4rem;
}

.card-count {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background-color: rgba(15, 23, 42, 0.06);
  color: #111827;
}

/* Messages */

.no-cards-message {
  font-size: 0.85rem;
  color: #6b7280;
}

.card-hint {
  font-size: 0.8rem;
  color: #6b7280;
}

.card-hint kbd {
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  font-size: 0.75rem;
}

/* =============== BUTTONS =============== */

.btn {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease,
    box-shadow 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn--primary {
  background: linear-gradient(90deg, #1d4ed8, #38bdf8);
  color: #f9fafb;
  border-color: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.5);
}

.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(37, 99, 235, 0.7);
}

.btn--secondary {
  background-color: #e5e7eb;
  color: #111827;
  border-color: #9ca3af;
}

.btn--secondary:hover {
  background-color: #d1d5db;
  border-color: #6b7280;
}

.btn--ghost {
  background: transparent;
  border-color: #d1d5db;
  color: #374151;
}

.btn--ghost:hover {
  background-color: rgba(15, 23, 42, 0.06);
  border-color: #9ca3af;
}

.btn--danger {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

.btn--danger:hover {
  background: #fecaca;
  border-color: #ef4444;
}

/* =============== FOOTER =============== */

.footer {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #6b7280;
  background-color: #ffffff;
  border-top: 1px solid #e5e7eb;
}

/* =============== MODAL =============== */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.6);
  z-index: 40;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
}

.modal__dialog {
  position: relative;
  z-index: 1;
  max-width: 420px;
  width: 92vw;
  border-radius: 1rem;
  background: #ffffff;
  padding: 1rem 1.1rem 1rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.35);
  border: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal__title {
  font-size: 1.1rem;
}

.modal__form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.modal__form label {
  font-size: 0.85rem;
  font-weight: 500;
}

.modal__form input,
.modal__form textarea {
  border-radius: 0.75rem;
  border: 1px solid #d1d5db;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  background: #f9fafb;
  color: #111827;
}

.modal__help {
  font-size: 0.8rem;
  color: #6b7280;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.modal__close {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #6b7280;
}

/* =============== DARK MODE OVERRIDES =============== */

html[data-theme="dark"] body {
  background: radial-gradient(circle at top, #1d4ed8 0, #020617 45%);
  color: #e5e7eb;
}

html[data-theme="dark"] .header {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .header__btn--outline {
  background: #020617;
  color: #e0f2fe;
  border-color: #60a5fa;
}

html[data-theme="dark"] .header__btn--outline:hover {
  background: #0b1120;
}

html[data-theme="dark"] .header__btn:not(.header__btn--outline) {
  background: #fb923c;
  color: #111827;
  border-color: #f97316;
}

html[data-theme="dark"] .sidebar {
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), #020617);
  border-right-color: #1f2937;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .sidebar__btn {
  background: linear-gradient(
    90deg,
    rgba(59, 130, 246, 0.14),
    rgba(59, 130, 246, 0.05)
  );
  color: #e5e7eb;
  border-color: #1f2937;
}

html[data-theme="dark"] .sidebar__btn:hover {
  background: rgba(59, 130, 246, 0.25);
}

html[data-theme="dark"] .sidebar__item--active .sidebar__btn {
  border-color: rgba(191, 219, 254, 0.9);
}

html[data-theme="dark"] .sidebar__empty {
  color: #9ca3af;
}

html[data-theme="dark"] .sidebar__card-btn {
  background-color: #020617;
  color: #e5e7eb;
  border-color: #1f2937;
}

html[data-theme="dark"] .sidebar__card-btn:hover {
  background-color: #0b1120;
  border-color: #60a5fa;
}

html[data-theme="dark"] .sidebar__card-btn--active {
  background-color: #2563eb;
  border-color: #1d4ed8;
  color: #e5e7eb;
}

html[data-theme="dark"] .main {
  background: radial-gradient(circle at top left, rgba(30, 64, 175, 0.3), #020617);
}

html[data-theme="dark"] .empty-state {
  background: #020617;
  border-color: #1f2937;
}

html[data-theme="dark"] .deck-meta,
html[data-theme="dark"] .deck-search-status,
html[data-theme="dark"] .no-cards-message,
html[data-theme="dark"] .card-hint {
  color: #9ca3af;
}

html[data-theme="dark"] .card-count {
  background-color: rgba(15, 23, 42, 0.7);
  color: #e5e7eb;
}

html[data-theme="dark"] .btn--secondary {
  background-color: #111827;
  color: #e5e7eb;
  border-color: #4b5563;
}

html[data-theme="dark"] .btn--secondary:hover {
  background-color: #020617;
  border-color: #60a5fa;
}

html[data-theme="dark"] .btn--ghost {
  border-color: #4b5563;
  color: #e5e7eb;
}

html[data-theme="dark"] .btn--ghost:hover {
  background-color: rgba(15, 23, 42, 0.7);
}

html[data-theme="dark"] .btn--danger {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.9);
  color: #fecaca;
}

html[data-theme="dark"] .footer {
  background-color: #020617;
  border-top-color: #1f2937;
  color: #9ca3af;
}

html[data-theme="dark"] .modal__dialog {
  background: #020617;
  border-color: #1f2937;
}

html[data-theme="dark"] .modal__form input,
html[data-theme="dark"] .modal__form textarea {
  background: #0b1120;
  border-color: #1f2937;
  color: #e5e7eb;
}

/* =============== RESPONSIVE =============== */

@media (max-width: 900px) {
  .header__container {
    padding-inline: 1rem;
  }

  .main {
    padding: 1.5rem;
  }

  .card__face {
    padding: 1.5rem;
  }

  .sidebar {
    width: 220px;
  }

  .main {
    margin-left: 220px;
  }
}

@media (max-width: 720px) {
  .sidebar {
    display: none;
  }

  .main {
    margin-left: 0;
  }

  .header__container {
    flex-wrap: wrap;
    height: auto;
    padding-block: 0.5rem;
  }

  .header__nav {
    justify-content: flex-start;
  }

  .header__search-input {
    min-width: 140px;
  }

  .deck-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .card__inner {
    aspect-ratio: 3 / 2;
  }
}
