:root {
  --navy: #13235a;
  --navy-2: #1c3175;
  --navy-3: #243c8a;
  --ink: #101b45;
  --cream: #fbf4e6;
  --cream-2: #f1e6cf;
  --red: #ef4b3f;
  --red-dark: #c8362c;
  --sun: #ffc93c;
  --sky: #8fb4ff;

  --font: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;

  --card-w: min(72vw, 320px);
  --card-h: 230px;
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
}

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

body {
  font-family: var(--font);
  font-size: 15px;
  background: var(--navy);
  color: var(--cream);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; }

/* ---------- Header ---------- */
.top {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variation-settings: "opsz" 96;
}
.brand .dot { color: var(--red); }

.progress-track {
  width: calc(100% - 40px);
  max-width: 440px;
  margin: 0 auto;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--sun);
  border-radius: 6px;
  transition: width 0.4s var(--ease);
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px 36px;
}

/* ---------- Buttons ---------- */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--navy-2);
  color: var(--cream);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--navy-3); }
.icon-btn:active { transform: scale(0.93); }
.icon-btn.round { width: 48px; height: 48px; border-radius: 50%; }
#next { background: var(--red); }
#next:hover { background: var(--red-dark); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 9px; background: var(--navy-3); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  background: var(--sun);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #c99a1c;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c99a1c; }
.btn:disabled { opacity: 0.6; cursor: default; }

:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }

/* ---------- Card carousel ---------- */
.deck { padding-top: 20px; }

.stage {
  position: relative;
  height: calc(var(--card-h) + 30px);
  /* break out of the column so side cards reach the screen edges */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  overflow: hidden;
  perspective: 1400px;
  touch-action: pan-y;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}

.slide {
  --o: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--card-w);
  height: var(--card-h);
  transform:
    translate(-50%, -50%)
    translateX(calc(var(--o) * 96%))
    rotate(var(--r, 0deg))
    scale(var(--s, 1));
  opacity: var(--a, 1);
  transition: transform 0.5s var(--ease), opacity 0.5s var(--ease);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.slide[data-offset="-2"] { --o: -2; --s: 0.8;  --a: 0;   --r: -6deg; pointer-events: none; }
.slide[data-offset="-1"] { --o: -1; --s: 0.88; --a: 0.5; --r: -4deg; }
.slide[data-offset="0"]  { --o: 0;  --s: 1;    --a: 1;   --r: 0deg; z-index: 2; }
.slide[data-offset="1"]  { --o: 1;  --s: 0.88; --a: 0.5; --r: 4deg; }
.slide[data-offset="2"]  { --o: 2;  --s: 0.8;  --a: 0;   --r: 6deg; pointer-events: none; }
.slide.no-anim, .slide.no-anim .flip { transition: none; }
.slide.hidden { visibility: hidden; }

.flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s var(--ease);
}
.slide.flipped .flip { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border-radius: 22px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 8px 0 rgba(6, 12, 40, 0.35);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.back {
  transform: rotateY(180deg);
  background: var(--red);
  color: var(--cream);
}

.face-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.lang {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--cream);
}
.back .lang { background: var(--cream); color: var(--red-dark); }
.level { font-size: 0.78rem; font-weight: 600; opacity: 0.85; }

.phrase {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 1.55rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 48;
  text-wrap: balance;
  padding: 6px 4px;
}
.phrase { white-space: pre-line; }
.phrase.long { font-size: 1.2rem; }
.phrase.xlong { font-size: 1rem; line-height: 1.3; font-weight: 600; }

.face-hint {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s;
}
.front .face-hint { color: rgba(16, 27, 69, 0.45); }
.slide[data-offset="0"] .face-hint { opacity: 1; }

.face-bottom { display: flex; justify-content: center; }
.speak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 6px 14px 6px 11px;
  background: var(--cream);
  color: var(--red-dark);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 2px 0 var(--red-dark);
  transition: transform 0.1s, box-shadow 0.1s;
}
.speak:active { transform: translateY(2px); box-shadow: 0 0 0 var(--red-dark); }
.no-speech .speak { display: none; }

.deck-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin-top: 14px;
}
.counter {
  min-width: 72px;
  text-align: center;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: rgba(251, 244, 230, 0.6);
}
.counter b { color: var(--cream); font-weight: 700; }

/* ---------- Translate ---------- */
.translate {
  margin-top: 36px;
  border-radius: 22px;
  background: var(--navy-2);
  overflow: hidden;
}
.translate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
}
.translate-head h2 {
  font-size: 1.1rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.translate-langs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}
#lang-from { color: var(--sky); }
#lang-to { color: var(--sun); }

.translate textarea {
  display: block;
  width: calc(100% - 24px);
  margin: 12px 12px 0;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--navy);
  color: var(--cream);
  font-family: var(--font);
  font-size: 1.1rem; /* stays above 16px so iOS doesn't zoom */
  line-height: 1.4;
  padding: 12px 14px;
  resize: none;
  transition: border-color 0.15s;
}
.translate textarea::placeholder { color: rgba(251, 244, 230, 0.35); }
.translate textarea:focus { outline: none; border-color: var(--sky); }

.translate-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px;
}
.kbd-hint { font-size: 0.78rem; color: rgba(251, 244, 230, 0.4); }
@media (hover: none) { .kbd-hint { display: none; } }

.translate-output {
  margin: 0 12px 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.35;
}
.translate-output:empty { display: none; }
.translate-output.error {
  background: var(--red);
  color: var(--cream);
  font-size: 0.88rem;
  font-weight: 500;
}

@media (min-width: 700px) {
  :root { --card-h: 250px; }
  .stage { width: 720px; margin-left: calc(50% - 360px); }
}

@media (prefers-reduced-motion: reduce) {
  .slide, .flip, .progress-bar { transition: none !important; }
}
