:root {
  --bg: #f4f4f5;
  --panel: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --border: #e4e4e7;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --panel: #18181b;
    --text: #fafafa;
    --muted: #a1a1aa;
    --border: #27272a;
    --accent: #3b82f6;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Top bar ---------- */
.topbar {
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar h1 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: end;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.controls label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  color: var(--text);
  padding-bottom: 6px;
}

.controls select {
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.controls input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  position: relative;
}

.scene {
  width: min(78vw, 360px);
  perspective: 1400px;
  touch-action: pan-y;
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  transform-style: preserve-3d;
  transition: transform 0.38s cubic-bezier(0.4, 0.2, 0.2, 1);
  cursor: pointer;
}

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

/* Used to jump to a new card without animating the un-flip. */
.card.no-anim {
  transition: none;
}

.card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card__face--back {
  transform: rotateY(180deg);
}

.card__face-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px;
  border-radius: var(--radius);
  overflow: hidden;
}

/* Image face */
.card__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__img-fallback {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--muted);
  padding: 16px;
  word-break: break-word;
}

/* Word face */
.card__emoji {
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  line-height: 1;
}

.card__vi {
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  font-weight: 700;
  line-height: 1.15;
}

.card__en {
  font-size: 1.05rem;
  color: var(--muted);
}

.card__note {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  max-width: 26ch;
}

.speak {
  margin-top: 4px;
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.speak:active {
  transform: scale(0.94);
}

/* ---------- Nav arrows ---------- */
.nav {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.nav:active {
  transform: scale(0.94);
}

.empty {
  position: absolute;
  color: var(--muted);
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.9rem;
}

#counter {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 4ch;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.btn:first-of-type {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
}

.btn:active {
  transform: translateY(1px);
}

.hint {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
}

@media (max-width: 560px) {
  .hint {
    display: none;
  }
  .nav {
    display: none;
  }
  .scene {
    width: min(86vw, 380px);
  }
}
