.flashcard-study {
  width: 100%;
}

.study-error {
  color: var(--red);
  font-size: 0.9rem;
  background: rgba(183, 91, 77, 0.08);
  border: 1px solid rgba(183, 91, 77, 0.2);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  margin-bottom: 1rem;
}

.study-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 24px;
  align-items: start;
}

.study-panel {
  position: relative;
  min-height: 650px;
  padding: clamp(18px, 3vw, 34px);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(145deg, rgba(255,255,255,.54), rgba(255,240,202,.46)),
    radial-gradient(circle at 15% 20%, rgba(255, 201, 101, .25), transparent 35%),
    radial-gradient(circle at 90% 10%, rgba(63, 124, 172, .16), transparent 32%);
  border: 1px solid rgba(104, 69, 22, .13);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.study-panel::before,
.study-panel::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(2px);
  opacity: .5;
}

.study-panel::before {
  width: 220px;
  height: 220px;
  right: -92px;
  top: 100px;
  background: rgba(63, 124, 172, .13);
}

.study-panel::after {
  width: 180px;
  height: 180px;
  left: -70px;
  bottom: 60px;
  background: rgba(199, 149, 57, .18);
}

.study-session-header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.study-session-title h3 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: clamp(24px, 3vw, 36px);
  letter-spacing: -.04em;
  color: var(--ink);
}

.study-session-title p {
  max-width: 660px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 4px 0 0;
}

.study-score-pill {
  min-width: 76px;
  padding: 11px 12px;
  border-radius: 18px;
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(100, 65, 18, .12);
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72);
}

.study-score-pill b {
  display: block;
  font-size: 19px;
  color: var(--ink);
}

.study-score-pill span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.study-stage {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 390px;
  perspective: 1400px;
  padding: 22px 0;
}

.study-flashcard {
  position: relative;
  width: min(680px, 100%);
  min-height: 355px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform .78s var(--ease), filter .35s var(--ease);
  outline: none;
}

.study-flashcard:hover .study-card-face {
  border-color: rgba(63, 124, 172, .28);
}

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

.study-flashcard.is-reviewed {
  animation: studyCardExit .58s var(--ease);
}

.study-card-face {
  position: absolute;
  inset: 0;
  min-height: 355px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(24px, 5vw, 42px);
  border-radius: 30px;
  backface-visibility: hidden;
  background:
    linear-gradient(90deg, rgba(168, 111, 36, .09) 0 1px, transparent 1px 22px),
    linear-gradient(rgba(168, 111, 36, .08) 0 1px, transparent 1px 30px),
    linear-gradient(145deg, #fffaf0, #f5dfaa);
  border: 1px solid rgba(82, 54, 17, .18);
  box-shadow: var(--card-shadow), inset 0 0 0 8px rgba(255,255,255,.24);
  overflow: hidden;
}

.study-card-face::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px dashed rgba(82, 54, 17, .18);
  border-radius: 22px;
  pointer-events: none;
}

.study-card-face::after {
  content: "";
  position: absolute;
  width: 140px;
  height: 140px;
  right: -46px;
  bottom: -50px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(199,149,57,.25), transparent 66%);
  pointer-events: none;
}

.study-card-back {
  transform: rotateY(180deg);
  background:
    linear-gradient(90deg, rgba(63,124,172,.08) 0 1px, transparent 1px 22px),
    linear-gradient(rgba(63,124,172,.07) 0 1px, transparent 1px 30px),
    linear-gradient(145deg, #fffaf1, #dfeef2);
}

.study-card-meta {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.study-tag,
.study-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.54);
  border: 1px solid rgba(82, 54, 17, .12);
}

.study-status-badge {
  font-size: 11px;
  line-height: 1;
}

.study-status-icon {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(82, 54, 17, .10);
  font-size: 11px;
}

.study-status-badge.rag-red {
  color: var(--red-deep);
  background: rgba(183, 91, 77, 0.12);
  border-color: rgba(183, 91, 77, 0.22);
}

.study-status-badge.rag-amber {
  color: #74531c;
  background: rgba(199, 149, 57, 0.14);
  border-color: rgba(199, 149, 57, 0.24);
}

.study-status-badge.rag-green {
  color: var(--green-deep);
  background: rgba(79, 143, 90, 0.12);
  border-color: rgba(79, 143, 90, 0.22);
}

.study-status-badge.rag-grey {
  color: var(--muted);
  background: rgba(123, 106, 80, 0.10);
  border-color: rgba(123, 106, 80, 0.18);
}

.study-card-question,
.study-card-answer {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: center;
  gap: 16px;
  min-height: 190px;
  color: var(--ink);
  font-family: "Segoe UI", Inter, Avenir, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.study-card-question {
  font-size: clamp(20px, 2.65vw, 24px);
  line-height: 1.5;
}

.study-back-question,
.study-back-answer {
  display: grid;
  gap: 6px;
}

.study-back-question span,
.study-back-answer span {
  color: var(--blue-deep);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.study-back-question p,
.study-back-answer p {
  margin: 0;
  color: var(--ink);
}

.study-back-question p {
  color: #66543d;
  font-size: clamp(15px, 1.7vw, 18px);
  line-height: 1.45;
}

.study-back-answer p {
  font-size: clamp(20px, 2.65vw, 24px);
  line-height: 1.5;
}

.study-card-details {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.study-card-footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.study-spacebar {
  padding: 4px 9px;
  border-radius: 8px;
  color: #4f3a1d;
  background: rgba(255,255,255,.58);
  border: 1px solid rgba(82, 54, 17, .14);
  box-shadow: inset 0 -2px 0 rgba(82, 54, 17, .08);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.study-controls {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  opacity: .36;
  transform: translateY(10px);
  pointer-events: none;
  transition: .35s var(--ease);
  margin-top: 20px;
}

.study-controls.ready {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.study-review-button {
  position: relative;
  min-width: 170px;
  min-height: 60px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 20px;
  color: white;
  font-family: inherit;
  font-weight: 950;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 16px 34px rgba(63, 44, 20, .18), inset 0 1px 0 rgba(255,255,255,.32);
  overflow: hidden;
  transition: .25s var(--ease);
}

.study-review-button.correct {
  background: linear-gradient(135deg, var(--green), var(--green-deep));
}

.study-review-button.wrong {
  background: linear-gradient(135deg, var(--red), var(--red-deep));
}

.study-review-button:hover {
  transform: translateY(-4px);
  box-shadow: 0 22px 42px rgba(63, 44, 20, .22), inset 0 1px 0 rgba(255,255,255,.32);
}

.study-review-button::before {
  content: "";
  position: absolute;
  inset: -90% -40%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.32), transparent);
  transform: rotate(20deg) translateX(-80%);
  transition: .55s var(--ease);
}

.study-review-button:hover::before {
  transform: rotate(20deg) translateX(80%);
}

.study-review-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.study-stamp {
  position: absolute;
  right: 38px;
  top: 36px;
  z-index: 4;
  padding: 12px 18px;
  border: 4px double currentColor;
  border-radius: 10px;
  font-family: Georgia, serif;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: 0;
  transform: rotate(-12deg) scale(1.3);
  pointer-events: none;
}

.study-stamp.correct {
  color: var(--green-deep);
}

.study-stamp.wrong {
  color: var(--red-deep);
}

.study-stamp.show {
  animation: studyStampIn .7s var(--ease);
}

.study-nav-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  justify-content: center;
}

.study-side-panel {
  display: grid;
  gap: 18px;
}

.study-panel-card {
  padding: 20px;
  border-radius: 26px;
  background: rgba(255, 250, 239, .68);
  border: 1px solid rgba(104, 69, 22, .13);
  box-shadow: 0 18px 48px rgba(86, 57, 17, .09);
  backdrop-filter: blur(16px);
}

.study-panel-card h3 {
  margin: 0 0 14px;
  font-family: Georgia, serif;
  font-size: 22px;
  letter-spacing: -.03em;
  color: var(--ink);
}

.study-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.study-stat {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.52);
  border: 1px solid rgba(82, 54, 17, .10);
}

.study-stat b {
  display: block;
  font-size: 24px;
  letter-spacing: -.04em;
  color: var(--ink);
}

.study-stat span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .10em;
  text-transform: uppercase;
}

.study-track {
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(80, 54, 18, .12);
  margin-top: 8px;
}

.study-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
}

.study-queue {
  display: grid;
  gap: 10px;
}

.study-queue-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 16px;
  background: rgba(255,255,255,.48);
  border: 1px solid rgba(82, 54, 17, .10);
}

.study-queue-item strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  font-size: 13px;
}

.study-queue-item span {
  color: var(--muted);
  font-size: 11px;
}

.study-queue-number {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: #fff5d8;
  border: 1px solid rgba(82, 54, 17, .12);
  color: #74531c;
  font-family: Georgia, serif;
  font-weight: 900;
  font-size: 14px;
}

.study-queue-more {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 4px;
}

.study-confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

.study-session-end {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.study-session-end h3 {
  font-family: Georgia, serif;
  font-size: 28px;
  color: var(--ink);
  margin: 0 0 0.5rem;
}

.study-session-end-actions {
  margin-top: 16px;
}

@keyframes studyCardExit {
  0%   { transform: translateX(0) rotateY(180deg) rotateZ(0); opacity: 1; }
  45%  { transform: translateX(28px) rotateY(180deg) rotateZ(2deg); opacity: .9; }
  100% { transform: translateX(-32px) rotateY(180deg) rotateZ(-2deg); opacity: 0; }
}

@keyframes studyStampIn {
  0%   { opacity: 0; transform: rotate(-18deg) scale(1.8); }
  38%  { opacity: 1; transform: rotate(-10deg) scale(.9); }
  58%  { transform: rotate(-12deg) scale(1.04); }
  100% { opacity: 0; transform: rotate(-12deg) scale(1); }
}

@media (max-width: 1120px) {
  .study-content-grid {
    grid-template-columns: 1fr;
  }

  .study-side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .study-session-header {
    flex-direction: column;
  }

  .study-panel {
    min-height: auto;
  }

  .study-stage {
    min-height: 420px;
  }

  .study-flashcard,
  .study-card-face {
    min-height: 380px;
  }

  .study-side-panel {
    grid-template-columns: 1fr;
  }

  .study-review-button {
    width: 100%;
  }

  .study-controls {
    flex-direction: column;
    align-items: stretch;
  }
}
