:root {
  --ink: #1f2440;
  --flip-ms: 600ms;
  --radius: 28px;
  --tone: #5b3df5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #ffe9b8, #ffc6e0 55%, #c9b8ff) fixed;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 4px solid var(--ink);
  outline-offset: 3px;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

/* Top bar: title, mode switch, shuffle */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.topbar h1 {
  flex: 1 1 100%;
  margin: 0;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.01em;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.6);
}

.segmented button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
}

.segmented button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.toggle {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.6);
  font-weight: 700;
  color: inherit;
  text-decoration: none;
}

.toggle[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

/* Error banner */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 16px;
  background: #fff;
  border: 3px solid #d6336c;
  font-weight: 700;
}

.banner[hidden] {
  display: none;
}

.banner button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: #d6336c;
  color: #fff;
  font-weight: 700;
}

/* Progress */

.progress p {
  margin: 0 0 6px;
  font-weight: 800;
  text-align: center;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.6);
  overflow: hidden;
}

#bar-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--ink);
  transition: width 300ms ease;
}

/* The card */

.card {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 320px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  perspective: 1400px;
}

.card:focus-visible {
  outline-offset: 6px;
}

.card-inner {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transition: transform var(--flip-ms) cubic-bezier(0.4, 0.2, 0.2, 1);
}

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

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: 0 10px 0 rgb(31 36 64 / 0.22);
  text-align: center;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.face-front {
  background: var(--tone);
  color: #fff;
}

.face-back {
  background: #fff;
  color: var(--ink);
  border: 6px solid var(--tone);
  transform: rotateY(180deg);
}

.face-label {
  padding: 4px 14px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.25);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.face-back .face-label {
  background: var(--tone);
  color: #fff;
}

.face-text {
  display: block;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  font-weight: 900;
  line-height: 1.2;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.face-text[data-size="long"] {
  font-size: clamp(1.15rem, 4vw, 1.7rem);
  font-weight: 700;
  line-height: 1.35;
}

.card[data-tone="0"] { --tone: #5b3df5; }
.card[data-tone="1"] { --tone: #d6336c; }
.card[data-tone="2"] { --tone: #0b7f7a; }
.card[data-tone="3"] { --tone: #c2410c; }
.card[data-tone="4"] { --tone: #1c64c8; }

/* Controls */

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  min-height: 60px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 5px 0 rgb(31 36 64 / 0.25);
  font-size: 1.15rem;
  font-weight: 800;
}

.btn.primary {
  background: var(--ink);
  color: #fff;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgb(31 36 64 / 0.25);
}

.hint {
  margin: 0;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0.75;
}

/* Reduced motion: crossfade instead of a spinning card */

@media (prefers-reduced-motion: reduce) {
  :root {
    --flip-ms: 250ms;
  }

  .card-inner,
  .card.flipped .card-inner {
    transform: none;
    transition: none;
  }

  .face,
  .face-back {
    transform: none;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    transition: opacity var(--flip-ms) ease;
  }

  .face-back,
  .card.flipped .face-front {
    opacity: 0;
  }

  .card.flipped .face-back {
    opacity: 1;
  }

  .btn:active {
    transform: none;
  }

  #bar-fill {
    transition: none;
  }
}

.deck-select {
  max-width: 100%;
  cursor: pointer;
}

.deck-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.deck-picker[hidden] {
  display: none;
}

/* Word bank */

.wordbank-toggle {
  gap: 8px;
  cursor: pointer;
}

.wordbank-toggle[hidden] {
  display: none;
}

.wordbank-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--ink);
}

.wordbank {
  padding: 12px 16px;
  border: 3px dashed var(--ink);
  border-radius: 20px;
  background: rgb(255 255 255 / 0.6);
}

.wordbank[hidden] {
  display: none;
}

.wordbank h2 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.wordbank-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 9.5rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.wordbank-terms li {
  padding: 4px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
}
