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

body {
  font-family: 'Segoe UI', system-ui, Arial, sans-serif;
  background: linear-gradient(160deg, #e8f4fd 0%, #c9e8f7 40%, #daeef8 100%);
  background-attachment: fixed;
  color: #1a2a3a;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */

header {
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.7);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 1rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: #4aa8d8;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.back-link:hover { color: #1a3a5c; }

#deck-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1a3a5c;
  text-align: center;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Progress ── */

.progress-area {
  padding: 0.25rem 0 0.5rem;
  width: 100%;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #4a7a9b;
  margin-bottom: 0.4rem;
}

.progress-bar-track {
  height: 5px;
  background: rgba(255,255,255,0.5);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: #4aa8d8;
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* ── Study area ── */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1.5rem;
  width: 100%;
}

.study-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: min(600px, 100%);
}

/* ── Flip card ── */

.card-scene {
  width: 100%;
  min-height: 300px;
  perspective: 1000px;
  cursor: pointer;
}

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

.card-scene.flipped .card-flipper {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 32px rgba(30, 90, 150, 0.12);
}

.card-face.back {
  transform: rotateY(180deg);
  background: rgba(235, 248, 255, 0.88);
}

.face-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #4aa8d8;
  margin-bottom: 1rem;
}

.face-text {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.5;
  color: #1a2a3a;
}

.tap-hint {
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: #8ab4cc;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* ── Mark buttons ── */

.mark-buttons {
  display: flex;
  gap: 0.75rem;
}

.btn-mark {
  padding: 0.55rem 1.3rem;
  border-radius: 99px;
  border: 2px solid transparent;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn-mark:active { transform: scale(0.96); }

.btn-known {
  background: rgba(255,255,255,0.7);
  border-color: #5cc08a;
  color: #2d7a52;
}

.btn-known:hover, .btn-known.active {
  background: #5cc08a;
  color: #fff;
}

.btn-learning {
  background: rgba(255,255,255,0.7);
  border-color: #f0a05a;
  color: #a05a10;
}

.btn-learning:hover, .btn-learning.active {
  background: #f0a05a;
  color: #fff;
}

/* ── Nav buttons ── */

.nav-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.btn-nav {
  padding: 0.55rem 1.4rem;
  border-radius: 99px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.65);
  color: #1a3a5c;
  transition: background 0.15s, transform 0.1s;
}

.btn-nav:hover:not(:disabled) { background: rgba(255,255,255,0.9); }
.btn-nav:active:not(:disabled) { transform: scale(0.96); }
.btn-nav:disabled { opacity: 0.35; cursor: default; }

.btn-nav.primary {
  background: #4aa8d8;
  color: #fff;
}

.btn-nav.primary:hover:not(:disabled) { background: #2d8ab8; }

/* ── Summary screen ── */

#summary {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  text-align: center;
  max-width: 480px;
  width: 100%;
}

#summary h2 {
  font-size: 1.6rem;
  color: #1a3a5c;
}

.score-row {
  display: flex;
  gap: 2rem;
  justify-content: center;
}

.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.score-number {
  font-size: 2.5rem;
  font-weight: 700;
}

.score-number.known  { color: #5cc08a; }
.score-number.still  { color: #f0a05a; }
.score-number.unseen { color: #8ab4cc; }

.score-label {
  font-size: 0.75rem;
  color: #4a7a9b;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.btn-retake {
  padding: 0.75rem 2.5rem;
  border-radius: 99px;
  border: none;
  background: #4aa8d8;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-retake:hover { background: #2d8ab8; }
.btn-retake:active { transform: scale(0.97); }

/* ── Multiple-choice answers ── */

.answers {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
}

.btn-answer {
  width: 100%;
  padding: 0.8rem 1.25rem;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 1.05rem;
  font-weight: 500;
  color: #1a2a3a;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  line-height: 1.4;
}

.btn-answer:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.92);
  border-color: #4aa8d8;
}

.btn-answer:active:not(:disabled) { transform: scale(0.98); }

.btn-answer:disabled { cursor: default; }

.btn-answer.correct {
  background: rgba(92, 192, 138, 0.2);
  border-color: #5cc08a;
  color: #1a5a34;
  font-weight: 700;
}

.btn-answer.wrong {
  background: rgba(240, 100, 80, 0.12);
  border-color: #f06450;
  color: #7a2010;
}

/* ── Mobile ── */

@media (max-width: 640px) {
  main {
    justify-content: flex-start;
    padding: 1rem 0.75rem;
  }

  .study-container {
    gap: 1rem;
    width: 100%;
  }

  .card-face {
    padding: 1.25rem;
  }

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

  .btn-answer {
    font-size: 0.95rem;
    padding: 0.75rem 1rem;
  }

  .nav-buttons {
    justify-content: space-between;
    width: 100%;
  }

  .btn-nav {
    flex: 1;
    text-align: center;
  }
}

/* ── Error state ── */

#error-msg {
  display: none;
  background: rgba(255,235,235,0.8);
  border: 1px solid #f5a;
  border-radius: 12px;
  padding: 1.5rem 2rem;
  color: #a02020;
  text-align: center;
  max-width: 480px;
}
