/* ── Reset & Variables ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface-alt: #252836;
  --text: #e4e6eb;
  --text-muted: #9ca3af;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --border: #2d3042;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", monospace;
  --card-bg: #ffffff;
  --card-text: #1a1a2e;
  --card-border: #e2e4e9;
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #eaecf0;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --border: #e2e4e9;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --card-bg: #ffffff;
  --card-text: #1a1a2e;
  --card-border: #e2e4e9;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-icon {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 1.1rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--border);
}

.btn-nav {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.btn-nav:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.btn-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-nav:disabled:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: none;
  color: var(--danger);
  border: none;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

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

.btn-edit {
  background: none;
  color: var(--primary);
  border: none;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

.btn-edit:hover {
  background: var(--primary);
  color: #fff;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

footer a:hover {
  text-decoration: underline;
}

/* ── Layout ── */
main {
  display: flex;
  height: calc(100vh - 60px - 40px);
}

/* ── Sidebar ── */
#sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#addCardForm {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

#addCardForm input,
#addCardForm textarea,
.modal input,
.modal textarea {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  transition: border var(--transition);
  outline: none;
}

#addCardForm textarea,
.modal textarea {
  resize: vertical;
  font-family: var(--font);
}

#addCardForm input:focus,
#addCardForm textarea:focus,
.modal input:focus,
.modal textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

#cardList {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

#cardList li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.875rem;
}

#cardList li:hover {
  border-color: var(--border);
}

#cardList li.active {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.08);
}

.card-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 0.5rem;
}

.card-item-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* ── Presentation Area ── */
#presentation {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 1.5rem;
}

.card-container {
  perspective: 1200px;
  width: 100%;
  max-width: 700px;
}

.flashcard {
  width: 100%;
  aspect-ratio: 16 / 10;
  cursor: pointer;
  position: relative;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

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

.flashcard-front,
.flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  text-align: center;
  overflow-y: auto;
}

.flashcard-front {
  background: var(--card-bg);
  color: var(--card-text);
  border: 1px solid var(--card-border);
}

.flashcard-back {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  transform: rotateY(180deg);
}

.card-label {
  position: absolute;
  top: 1rem;
  left: 1.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.5;
}

.flashcard-front p,
.flashcard-back p {
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 600;
  line-height: 1.4;
  word-break: break-word;
}

/* ── Nav Controls ── */
.nav-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

#cardCounter {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  text-align: center;
}

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

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 90%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

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

/* ── Empty State ── */
.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  main {
    flex-direction: column;
    height: auto;
  }

  #sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 280px;
  }

  #presentation {
    min-height: 60vh;
    padding: 1.5rem 1rem;
  }

  .flashcard-front p,
  .flashcard-back p {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
  }

  .header-actions .btn-secondary span {
    display: none;
  }
}
