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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #080f1e;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Header ── */
header {
  width: 100%;
  max-width: 760px;
  padding: 1.8rem 1.5rem 0.8rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  gap: 1rem;
  flex-wrap: wrap;
}

header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

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

.stats-badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  background: #10b981;
  color: #fff;
  border-radius: 999px;
}

.tool-btn {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border: 1px solid #334155;
  background: #1e293b;
  color: #94a3b8;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.tool-btn:hover { background: #334155; color: #e2e8f0; }

.quiz-space-btn {
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  white-space: nowrap;
}
.quiz-space-btn:hover { background: #dc2626; transform: scale(1.05); }

.progress-bar-container {
  width: 100%;
  height: 7px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.45rem;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border-radius: 999px;
  transition: width 0.4s ease;
  width: 0%;
}
.progress-indicator {
  font-size: 0.8rem;
  color: #64748b;
  text-align: right;
}

/* ── Subject Menu ── */
.subject-menu {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 760px;
  border-bottom: 1px solid #1e293b;
}

/* Each group row */
.subject-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.5rem;
  flex-wrap: wrap;
}

/* Group label pill */
.group-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1.5px solid;
  background: transparent;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 5.5rem;
  text-align: center;
  opacity: 0.85;
}

/* Buttons row within a group */
.group-btns {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Thin divider line between groups */
.group-divider {
  height: 1px;
  background: #1e293b;
  margin: 0 1.5rem;
}

.subject-btn {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.38rem 0.9rem;
  border-radius: 0.55rem;
  border: 1.5px solid #1e293b;
  background: #0f172a;
  color: #64748b;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.subject-btn:hover { background: #1e293b; }
.subject-btn.active { font-weight: 800; border-color: transparent; }

@media (max-width: 520px) {
  .subject-group { padding: 0.45rem 1rem; }
  .group-label   { font-size: 0.6rem; min-width: 4.5rem; padding: 0.2rem 0.5rem; }
  .subject-btn   { font-size: 0.72rem; padding: 0.3rem 0.65rem; }
}

/* ── Category Filter ── */
.category-filter {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0.9rem 1.5rem;
  width: 100%;
  max-width: 760px;
}
.filter-btn {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1.5px solid #1e293b;
  background: #0f172a;
  color: #64748b;
  cursor: pointer;
  transition: all 0.18s;
}
.filter-btn:hover { border-color: #334155; color: #e2e8f0; }
.filter-btn.active {
  color: #fff;
  border-color: transparent;
}

/* ── Main / Card Container ── */
main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0 1.5rem 1.5rem;
  width: 100%;
}
.flashcard-container {
  perspective: 1400px;
  width: 100%;
  max-width: 700px;
}

/* ── Card — grid stacking trick (auto-height) ── */
.card {
  display: grid;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: default;
}
.card.flipped { transform: rotateY(180deg); }

.card-face {
  grid-area: 1 / 1;            /* both faces share same grid cell */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 1.4rem;
  padding: 1.6rem 1.8rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
  min-height: 380px;
}

.card-front {
  background: linear-gradient(150deg, #111827, #0d1f35);
  border: 1px solid #1e3a5f;
}
.card-back {
  background: linear-gradient(150deg, #0e0a2a, #130d38);
  border: 1px solid #3730a3;
  transform: rotateY(180deg);
}

/* ── Card Meta Row ── */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.badge-category,
.badge-difficulty {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
}

/* ── Got It Button ── */
.btn-known {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.28rem 0.75rem;
  border-radius: 999px;
  border: 1.5px solid #334155;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-known:hover { border-color: #10b981; color: #10b981; }
.btn-known.is-known {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}
.btn-known.is-known:hover { background: #059669; border-color: #059669; }

/* ── Face Label ── */
.face-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: #38bdf8;
}
.card-back .face-label { color: #818cf8; }

/* ── Card Image (mind-map / overview cards) ── */
.card-image {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 0.5rem;
  flex: 1;
}

/* ── Card Text ── */
.card-text {
  font-size: 1.1rem;
  line-height: 1.75;
  color: #cbd5e1;
  flex: 1;
}
.card-text code {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9em;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  padding: 0.1em 0.35em;
  border-radius: 0.3em;
  border: 1px solid rgba(56, 189, 248, 0.18);
}
.card-back .card-text code {
  background: rgba(129, 140, 248, 0.12);
  color: #a5b4fc;
  border-color: rgba(129, 140, 248, 0.18);
}

/* ── Tip / Code Block ── */
.tip-block {
  background: #0a0e1a;
  border: 1px solid #1e293b;
  border-left: 3px solid #818cf8;
  border-radius: 0.6rem;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  display: none;           /* shown by JS when tip exists */
}
.tip-block code {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.65;
  color: #a5b4fc;
  white-space: pre;
}

/* ── Nav Buttons ── */
.nav-buttons {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: auto;
}
.nav-buttons button {
  padding: 0.5rem 1.15rem;
  border-radius: 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid #1e293b;
  background: #111827;
  color: #64748b;
  transition: background 0.18s, color 0.18s, transform 0.1s;
}
.nav-buttons button:hover { background: #1e293b; color: #e2e8f0; }
.nav-buttons button:active { transform: scale(0.96); }
.nav-buttons button:disabled { opacity: 0.3; cursor: not-allowed; }

.nav-buttons .btn-action {
  background: #38bdf8;
  border-color: #38bdf8;
  color: #0a0e1a;
}
.nav-buttons .btn-action:hover { background: #7dd3fc; border-color: #7dd3fc; }

.card-back .nav-buttons .btn-action {
  background: #818cf8;
  border-color: #818cf8;
  color: #0a0e1a;
}
.card-back .nav-buttons .btn-action:hover { background: #a5b4fc; border-color: #a5b4fc; }

/* ── Footer ── */
footer {
  padding: 1rem;
  text-align: center;
}
.keyboard-hint {
  font-size: 0.75rem;
  color: #334155;
}
.author-credit {
  font-size: 0.72rem;
  color: #1e293b;
  margin-top: 0.4rem;
}
kbd {
  display: inline-block;
  font-family: inherit;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid #334155;
  border-radius: 0.3rem;
  background: #111827;
  color: #64748b;
  margin: 0 0.1rem;
}

/* ── Responsive ── */
@media (max-width: 520px) {
  header h1 { font-size: 1.3rem; }
  .card-face { padding: 1.3rem 1.3rem 1.2rem; min-height: 340px; }
  .card-text { font-size: 1rem; }
  .keyboard-hint { display: none; }
}
