:root {
  --board-1: #163227;
  --board-2: #0f241b;
  --chalk-white: #f4f1e6;
  --chalk-dim: #cfd9cf;
  --card-cream: #f6eed9;
  --card-cream-2: #ecdfc2;
  --card-cream-3: #e3d3ab;
  --ink: #2a2117;
  --ink-soft: #56493a;
  --red-chalk: #e2574c;
  --red-chalk-dim: #b5453c;
  --green-chalk: #6fbf7e;
  --green-chalk-dim: #4f9a5d;
  --amber: #e0a63e;
  --font-chalk: "Caveat", cursive;
  --font-hand: "Kalam", cursive;
  --font-mono: "Space Mono", monospace;
}

* { box-sizing: border-box; }

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 90% at 50% -10%, #1c3c2c 0%, var(--board-1) 45%, var(--board-2) 100%);
  color: var(--chalk-white);
  font-family: var(--font-hand);
  padding: max(20px, env(safe-area-inset-top)) 16px 32px;
  overflow-x: hidden;
}

.board {
  position: relative;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.review-list {
  -webkit-user-select: text;
  user-select: text;
}

.chalk-dust {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(244,241,230,.35), transparent 60%),
    radial-gradient(1px 1px at 80% 15%, rgba(244,241,230,.25), transparent 60%),
    radial-gradient(1.5px 1.5px at 60% 70%, rgba(244,241,230,.2), transparent 60%),
    radial-gradient(1px 1px at 30% 85%, rgba(244,241,230,.3), transparent 60%),
    radial-gradient(1px 1px at 90% 60%, rgba(244,241,230,.2), transparent 60%),
    radial-gradient(1.5px 1.5px at 45% 40%, rgba(244,241,230,.15), transparent 60%);
  mix-blend-mode: screen;
}

/* ---------- topbar ---------- */

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand-kicker {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
  border: 1px dashed rgba(224,166,62,0.55);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 6px;
}

.brand-title {
  margin: 0;
  font-family: var(--font-chalk);
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 3.4rem);
  line-height: 0.85;
  color: var(--chalk-white);
  text-shadow: 0 0 1px rgba(244,241,230,.5), 0 0 18px rgba(244,241,230,.12);
  transform: rotate(-1.5deg);
}

.brand-title .dot { color: var(--amber); }

.brand-sub {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--chalk-dim);
  letter-spacing: 0.03em;
}

.reshuffle-btn {
  flex: none;
  margin-top: 4px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px dashed rgba(244,241,230,0.4);
  background: transparent;
  color: var(--chalk-white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .25s ease, background .25s ease, border-color .25s ease;
}
.reshuffle-btn:hover {
  background: rgba(244,241,230,0.08);
  border-color: rgba(244,241,230,0.75);
  transform: rotate(45deg);
}
.reshuffle-btn:active { transform: rotate(90deg) scale(0.92); }

/* ---------- scoreboard ---------- */

.scoreboard {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-family: var(--font-mono);
}

.tally {
  display: flex;
  gap: 12px;
  flex: none;
}

.tally-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(244,241,230,0.06);
}
.tally-item--right { color: var(--green-chalk); }
.tally-item--wrong { color: var(--red-chalk); }
.tally-icon { font-size: 13px; }

.progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
}

.progress-label {
  font-size: 10px;
  color: var(--chalk-dim);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(244,241,230,0.14);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--amber), var(--green-chalk));
  border-radius: 999px;
  transition: width .35s cubic-bezier(.4,0,.2,1);
}

/* ---------- deck / card stack ---------- */

.deck-area {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding-top: 6px;
}

.card-stack {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 5 / 6.3;
  perspective: 1600px;
}

.deck-card {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}
.deck-card--back1 {
  background: var(--card-cream-2);
  transform: rotate(-6deg) translate(2px, 6px);
}
.deck-card--back2 {
  background: var(--card-cream-3);
  transform: rotate(5deg) translate(-4px, 10px);
}

.flashcard {
  position: absolute;
  inset: 0;
  cursor: pointer;
  outline: none;
  touch-action: pan-y;
  transition: transform .45s cubic-bezier(.22,1,.36,1), opacity .4s ease;
}

.flashcard.dragging {
  transition: none;
  cursor: grabbing;
}

.swipe-stamp {
  position: absolute;
  top: 18px;
  z-index: 5;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  padding: 5px 12px;
  border-radius: 8px;
  border: 2.5px solid currentColor;
  opacity: 0;
  pointer-events: none;
  transition: opacity .1s linear;
}
.swipe-stamp--right {
  left: 16px;
  color: var(--green-chalk);
  transform: rotate(-10deg);
}
.swipe-stamp--wrong {
  right: 16px;
  color: var(--red-chalk);
  transform: rotate(10deg);
}

.flashcard:focus-visible .flashcard-inner {
  box-shadow: 0 0 0 3px rgba(224,166,62,0.7), 0 14px 28px rgba(0,0,0,0.4);
}

.flashcard.leaving-right { transform: translateX(140%) rotate(14deg); opacity: 0; }
.flashcard.leaving-left  { transform: translateX(-140%) rotate(-14deg); opacity: 0; }

.flashcard.entering {
  animation: cardEnter .42s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes cardEnter {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1) translateX(0); opacity: 1; }
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.22, 1, .36, 1);
  box-shadow: 0 16px 30px rgba(0,0,0,0.4);
}

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

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  background: var(--card-cream);
  padding: 26px 22px 20px 54px;
  display: flex;
  flex-direction: column;
  background-image:
    repeating-linear-gradient(rgba(90,110,140,0.08) 0 1px, transparent 1px 34px);
  background-position: 0 56px;
}

.flashcard-face::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 36px;
  width: 1.5px;
  background: rgba(198,86,74,0.35);
}

.flashcard-face--back {
  transform: rotateY(180deg);
  background: var(--card-cream);
}

.card-label {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--red-chalk-dim);
  border: 1.5px solid var(--red-chalk-dim);
  border-radius: 6px;
  padding: 1px 8px;
  margin-bottom: 12px;
  transform: rotate(-3deg);
}
.card-label--back {
  color: var(--green-chalk-dim);
  border-color: var(--green-chalk-dim);
}

.card-text {
  margin: 0;
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1.05rem, 4.6vw, 1.28rem);
  line-height: 1.42;
  color: var(--ink);
}

.tap-hint {
  align-self: center;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  opacity: 0.65;
  margin-top: 10px;
}

/* ---------- judge controls ---------- */

.judge-controls {
  display: flex;
  gap: 14px;
  width: 100%;
  max-width: 340px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}

.judge-controls.is-active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.judge-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  padding: 13px 10px;
  border-radius: 10px;
  cursor: pointer;
  background: transparent;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}

.judge-mark { font-size: 15px; }

.judge-btn--wrong {
  color: var(--red-chalk);
  border: 1.5px dashed var(--red-chalk-dim);
}
.judge-btn--wrong:hover { background: rgba(226,87,76,0.12); }
.judge-btn--wrong:active { transform: scale(0.96) rotate(-1deg); }

.judge-btn--correct {
  color: var(--green-chalk);
  border: 1.5px dashed var(--green-chalk-dim);
}
.judge-btn--correct:hover { background: rgba(111,191,126,0.14); }
.judge-btn--correct:active { transform: scale(0.96) rotate(1deg); }

.judge-btn.pop {
  animation: judgePop .38s ease;
}
@keyframes judgePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ---------- end screen ---------- */

.end-screen {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 34px 20px 10px;
  animation: fadeUp .5s ease both;
}
.end-screen[hidden] { display: none; }

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

.stamp {
  font-family: var(--font-chalk);
  font-weight: 700;
  font-size: clamp(2.2rem, 9vw, 2.8rem);
  color: var(--amber);
  border: 3px solid var(--amber);
  border-radius: 10px;
  padding: 4px 22px;
  transform: rotate(-4deg);
  text-shadow: 0 0 12px rgba(224,166,62,0.35);
}

.end-score {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--chalk-white);
  letter-spacing: 0.03em;
}

.end-remark {
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1.15rem;
  color: var(--chalk-dim);
}

.review-panel {
  width: 100%;
  max-width: 360px;
  margin-top: 6px;
  background: var(--card-cream);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 12px 24px rgba(0,0,0,0.32);
  text-align: left;
}

.review-heading {
  margin: 0 0 10px;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
}

.review-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.review-item {
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(90,73,58,0.25);
}
.review-item:last-child { border-bottom: none; padding-bottom: 0; }

.review-q {
  display: block;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.35;
}

.review-a {
  display: block;
  margin-top: 3px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--green-chalk-dim);
  line-height: 1.4;
}

.restart-btn {
  margin-top: 14px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--board-1);
  background: var(--chalk-white);
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
  box-shadow: 0 8px 18px rgba(0,0,0,0.3);
}
.restart-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 22px rgba(0,0,0,0.35); }
.restart-btn:active { transform: translateY(0) scale(0.97); }

/* ---------- footer ---------- */

.hint-footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: rgba(207,217,207,0.55);
  padding-top: 2px;
}
.hint-footer kbd {
  font-family: var(--font-mono);
  border: 1px solid rgba(207,217,207,0.4);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 4px;
}

@media (max-width: 380px) {
  .hint-footer { display: none; }
}

.is-hidden { display: none !important; }
