/* ===== Variables ===== */
:root {
  --bg: #0f1117;
  --bg-elevated: #181b24;
  --bg-card: #1e2230;
  --border: #2a3040;
  --text: #e8eaef;
  --text-muted: #8b93a7;
  --accent: #6c9eff;
  --accent-hover: #8ab4ff;
  --success: #3ecf8e;
  --error: #f07178;
  --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", ui-monospace, monospace;
  --transition: 0.25s ease;
}

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

html { font-size: 16px; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--bg-elevated);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* ===== Layout ===== */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--text);
}
.logo:hover { color: var(--text); }
.logo-icon { font-size: 1.4rem; }

.nav-link {
  margin-left: 1.25rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.nav-link:hover { color: var(--text); }
.nav-link.muted { opacity: 0.6; }

.main { flex: 1; padding: 2rem 0 3rem; }

.footer {
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Flash messages ===== */
.flash-messages { margin-top: 1rem; }

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}
.flash-success {
  background: rgba(62, 207, 142, 0.12);
  border: 1px solid rgba(62, 207, 142, 0.3);
  color: var(--success);
}
.flash-error {
  background: rgba(240, 113, 120, 0.12);
  border: 1px solid rgba(240, 113, 120, 0.3);
  color: var(--error);
}

/* ===== Hero & upload ===== */
.hero {
  text-align: center;
  margin-bottom: 2.5rem;
}
.hero h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}
.lead {
  color: var(--text-muted);
  font-size: 1.1rem;
  max-width: 480px;
  margin: 0 auto;
}

.upload-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.upload-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.dropzone {
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(108, 158, 255, 0.06);
}
.dropzone.has-file {
  border-color: var(--success);
  border-style: solid;
  background: rgba(62, 207, 142, 0.06);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.dropzone-icon { font-size: 2rem; }
.dropzone-text { color: var(--text); }
.dropzone-hint { font-size: 0.85rem; color: var(--text-muted); }

.divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.4rem;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
}
.btn-ghost:hover { color: var(--text); background: var(--bg-card); }

/* ===== Format help ===== */
.format-help {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
}
.format-help h2 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}
.format-help p { color: var(--text-muted); margin-bottom: 0.75rem; }
.hint { font-size: 0.9rem; }

.code-block {
  background: var(--bg);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 0.75rem;
}
.code-block pre {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}

/* ===== Study page ===== */
.study-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.study-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.source-badge {
  font-size: 0.8rem;
  font-family: var(--mono);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  color: var(--text-muted);
}

.progress {
  font-weight: 600;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.study-controls { display: flex; gap: 0.35rem; }

/* Card stage */
.card-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
  min-height: 320px;
}

.nav-arrow {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-arrow:hover:not(:disabled) {
  background: var(--bg-card);
  border-color: var(--text-muted);
}
.nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.card-wrapper {
  flex: 1;
  max-width: 480px;
  perspective: 1200px;
}

/* Flashcard 3D flip */
.flashcard {
  width: 100%;
  aspect-ratio: 4 / 3;
  cursor: pointer;
  outline: none;
}
.flashcard:focus-visible .flashcard-inner {
  box-shadow: 0 0 0 3px var(--accent);
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

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

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.75rem;
  text-align: center;
  border: 1px solid var(--border);
}

.flashcard-front {
  background: linear-gradient(145deg, #1e2230 0%, #252a3a 100%);
}
.flashcard-back {
  background: linear-gradient(145deg, #1a2438 0%, #1e2a45 100%);
  transform: rotateY(180deg);
}

.face-label {
  position: absolute;
  top: 1rem;
  left: 1.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  opacity: 0.7;
}

.face-text {
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.4;
  max-width: 100%;
  word-wrap: break-word;
}

.hint-tap {
  position: absolute;
  bottom: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.5;
}

/* Study footer */
.study-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.keyboard-hints {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

kbd {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  color: var(--text);
}

.dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  max-width: 360px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.dot:hover { transform: scale(1.3); }
.dot.active { background: var(--accent); }
.dot.seen { background: rgba(108, 158, 255, 0.35); }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .hero h1 { font-size: 1.5rem; }
  .card-stage { gap: 0.5rem; min-height: 280px; }
  .nav-arrow { width: 36px; height: 36px; font-size: 1.25rem; }
  .face-text { font-size: 1.15rem; }
  .keyboard-hints { display: none; }
  .upload-panel { padding: 1.5rem 1rem; }
}
