:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2f3d;
  --text: #e8eaed;
  --text-muted: #8b919e;
  --accent: #6c9eff;
  --accent-hover: #8ab4ff;
  --accent-dim: rgba(108, 158, 255, 0.12);
  --success: #4ade80;
  --success-dim: rgba(74, 222, 128, 0.12);
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.12);
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 158, 255, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(108, 158, 255, 0.06), transparent);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  min-height: 100vh;
}

.app.hidden {
  display: none;
}

.auth-gate {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card .logo {
  font-size: 2rem;
  color: var(--accent);
  display: block;
  margin-bottom: 8px;
}

.auth-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.auth-subtitle {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.auth-card input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

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

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.btn-block {
  width: 100%;
}

.nav-lock {
  margin-left: 4px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 1.5rem;
  color: var(--accent);
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.nav-btn {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

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

/* Views */
.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

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

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.deck-title-wrap {
  flex: 1;
  min-width: 0;
}

.card-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.back-btn {
  margin-right: auto;
}

/* Buttons */
.btn {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #0f1117;
}

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

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

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

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

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

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid transparent;
}

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

.btn-study {
  flex: 1;
  padding: 16px 24px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

.btn-study:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-wrong:disabled:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

.btn-correct:disabled:hover {
  background: var(--success-dim);
  color: var(--success);
}

.btn-wrong {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.btn-wrong:hover {
  background: var(--danger);
  color: white;
}

.btn-correct {
  background: var(--success-dim);
  color: var(--success);
  border: 1px solid rgba(74, 222, 128, 0.2);
}

.btn-correct:hover {
  background: var(--success);
  color: #0f1117;
}

/* Deck Grid */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

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

.deck-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.deck-card .meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.deck-card .deck-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.deck-card:hover .deck-actions {
  opacity: 1;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--surface-hover);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

/* Card List */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 20px;
  align-items: start;
  transition: border-color 0.15s;
}

.card-item:hover {
  border-color: rgba(108, 158, 255, 0.3);
}

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

.card-side .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.card-side .text {
  font-size: 0.95rem;
  word-break: break-word;
}

.editable-side {
  cursor: pointer;
  border-radius: 8px;
  padding: 4px;
  margin: -4px;
  transition: background 0.15s;
}

.editable-side:hover {
  background: var(--surface-hover);
}

.editable-side:hover .text {
  color: var(--accent);
}

.study-header-actions {
  display: flex;
  gap: 4px;
}

.card-item-actions {
  display: flex;
  gap: 4px;
  align-self: center;
}

/* Study */
.study-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.study-info {
  text-align: center;
  flex: 1;
}

.study-info span:first-child {
  display: block;
  font-weight: 600;
  font-size: 1rem;
}

.study-progress {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.study-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
}

.flashcard-container {
  perspective: 1200px;
  width: 100%;
  max-width: 520px;
  height: 320px;
  cursor: pointer;
}

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

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

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.flashcard-back {
  transform: rotateY(180deg);
  border-color: rgba(108, 158, 255, 0.3);
}

.face-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 20px;
}

.face-text {
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.5;
  flex: 1;
  display: flex;
  align-items: center;
  letter-spacing: -0.01em;
}

.flip-hint {
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.interval-preview {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--accent);
  font-family: var(--mono);
}

.btn-study {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.btn-interval {
  font-size: 0.75rem;
  opacity: 0.75;
  font-family: var(--mono);
}

.due-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--mono);
  margin-left: 8px;
  vertical-align: middle;
}

.due-badge.caught-up {
  background: var(--success-dim);
  color: var(--success);
}

.srs-status {
  font-size: 0.75rem;
  font-family: var(--mono);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  align-self: center;
}

.srs-status.due {
  background: var(--accent-dim);
  color: var(--accent);
}

.srs-status.new {
  background: rgba(250, 204, 21, 0.12);
  color: #facc15;
}

.srs-status.scheduled {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.study-controls {
  display: flex;
  gap: 16px;
  max-width: 520px;
  margin: 0 auto;
}

.study-complete {
  text-align: center;
  padding: 48px 24px;
  animation: fadeIn 0.4s ease;
}

.complete-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--success-dim);
  color: var(--success);
  font-size: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.study-complete h3 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.study-complete p {
  color: var(--text-muted);
  margin-bottom: 28px;
}

.complete-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.storage-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--mono);
  margin: -12px 0 20px;
}

.storage-hint.storage-error {
  color: var(--danger);
}

.deck-limit-hint {
  margin: -8px 0 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: rgba(124, 111, 247, 0.12);
  border: 1px solid rgba(124, 111, 247, 0.25);
  color: var(--text);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #f9fafb;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 2000;
  max-width: min(90vw, 420px);
  text-align: center;
}

/* Empty State */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 24px;
  font-size: 0.95rem;
}

.empty-state.hidden,
.hidden {
  display: none !important;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 0;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-form {
  padding: 20px 24px 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  resize: vertical;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

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

/* Responsive */
@media (max-width: 640px) {
  .card-item {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card-item-actions {
    justify-content: flex-end;
  }

  .flashcard-container {
    height: 280px;
  }

  .face-text {
    font-size: 1.15rem;
  }

  .study-controls {
    flex-direction: column;
  }

  .view-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    justify-content: stretch;
  }

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