:root {
  --color-bg: #fdf6ea;
  --color-surface: #ffffff;
  --color-text: #3a2e26;
  --color-primary: #e0568c;
  --color-primary-dark: #c23f70;
  --color-secondary: #2f9fb8;
  --color-accent: #4caf7d;
  --color-border: #ecdfc8;
  --color-muted: #a89882;
  --radius: 16px;
  --shadow: 0 3px 10px rgba(58, 46, 38, 0.14);
  --shadow-glow: 0 2px 10px rgba(224, 86, 140, 0.35);

  /* per-card color families, echoing the physical deck's own color-coding */
  --card-cream-bg: #fff3d6;    --card-cream-ink: #8a6a1f;   --card-cream-accent: #f0b429;
  --card-lavender-bg: #ece2ff; --card-lavender-ink: #5b3ea6; --card-lavender-accent: #9b7fe0;
  --card-salmon-bg: #ffe1da;   --card-salmon-ink: #a3442a;  --card-salmon-accent: #f0806a;
  --card-mint-bg: #dcf5e6;     --card-mint-ink: #2b7a53;    --card-mint-accent: #4caf7d;
  --card-tan-bg: #fbe6cd;      --card-tan-ink: #93611c;     --card-tan-accent: #d9924e;
  --card-lightblue-bg: #dcf0fb; --card-lightblue-ink: #2a6f8f; --card-lightblue-accent: #4fa3d1;
  --card-green-bg: #e4f5da;    --card-green-ink: #3d7a2a;   --card-green-accent: #7ab854;
  --card-yellow-bg: #fff3b8;   --card-yellow-ink: #8a6f10;  --card-yellow-accent: #f0c33e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1c1712;
    --color-surface: #2a2119;
    --color-text: #f5eada;
    --color-primary: #ff7fae;
    --color-primary-dark: #ffa0c4;
    --color-secondary: #6cc8e0;
    --color-accent: #7bd6a5;
    --color-border: #4a3c2c;
    --color-muted: #b3a385;
    --shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 2px 12px rgba(255, 127, 174, 0.4);

    --card-cream-bg: #4a3c17;    --card-cream-ink: #ffe38a;    --card-cream-accent: #f0b429;
    --card-lavender-bg: #3a2c5c; --card-lavender-ink: #d8c8ff; --card-lavender-accent: #b39bff;
    --card-salmon-bg: #522c22;   --card-salmon-ink: #ffbfa8;   --card-salmon-accent: #ff8f70;
    --card-mint-bg: #1f4430;     --card-mint-ink: #a8e8c4;     --card-mint-accent: #5fcf92;
    --card-tan-bg: #4a3418;      --card-tan-ink: #f0c98a;      --card-tan-accent: #e0a25c;
    --card-lightblue-bg: #1c3c4a; --card-lightblue-ink: #a8e0f5; --card-lightblue-accent: #5fbbe0;
    --card-green-bg: #2c4420;    --card-green-ink: #c0e8a0;    --card-green-accent: #8fce62;
    --card-yellow-bg: #4a3f10;   --card-yellow-ink: #ffe98a;   --card-yellow-accent: #f0c33e;
  }
}

/* Named theme palettes, picked from the settings drawer — same palettes as
   Letrópolis and Chocaletras so a theme choice feels consistent across the
   family's games. Only the app chrome is reskinned; the per-card color
   families above stay put since they echo the physical deck's own fixed
   color-coding regardless of theme. */
:root[data-theme="candy"] {
  --color-bg: #fff0f5;
  --color-surface: #ffffff;
  --color-text: #6b3a4a;
  --color-primary: #ff6fa5;
  --color-primary-dark: #e0568c;
  --color-secondary: #2f9fb8;
  --color-accent: #4fae7a;
  --color-border: #ffd0e1;
  --color-muted: #c98aa3;
}

:root[data-theme="space"] {
  --color-bg: #0b0f2b;
  --color-surface: #161b3d;
  --color-text: #e8ecff;
  --color-primary: #7c5cff;
  --color-primary-dark: #b3a1ff;
  --color-secondary: #35d0ff;
  --color-accent: #ff5da2;
  --color-border: #2a3166;
  --color-muted: #6b74a8;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

:root[data-theme="kpop"] {
  --color-bg: #fdf1ff;
  --color-surface: #ffffff;
  --color-text: #34204a;
  --color-primary: #ff2d78;
  --color-primary-dark: #d61463;
  --color-secondary: #7b2ff7;
  --color-accent: #0891a8;
  --color-border: #ecd2ff;
  --color-muted: #b48fce;
}

:root[data-theme="unicorn"] {
  --color-bg: #f6f1ff;
  --color-surface: #ffffff;
  --color-text: #4a3b66;
  --color-primary: #b355f0;
  --color-primary-dark: #9333ea;
  --color-secondary: #0d9488;
  --color-accent: #ec4899;
  --color-border: #e3d4ff;
  --color-muted: #a897c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 32px;
}

#app-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 16px 32px;
}

#app-header .mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

#app-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

#settings-btn {
  width: 40px;
  height: 40px;
  margin-left: 4px;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 30;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--color-surface);
  box-shadow: var(--shadow);
  z-index: 31;
  padding: 20px;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.2s ease;
}

.drawer.hidden {
  display: block;
  transform: translateX(100%);
  pointer-events: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.drawer-header h2 {
  font-size: 1.2rem;
  color: var(--color-primary-dark);
  margin: 0;
}

.drawer-section { margin-bottom: 24px; }

.drawer-section h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin: 0 0 12px;
}

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

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-radius: var(--radius);
  border: 2px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-swatch.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(224, 86, 140, 0.25);
}

.theme-swatch-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.theme-swatch-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.theme-swatch-preview {
  width: 100%;
  height: 32px;
  border-radius: 6px;
}

#case-picker {
  display: flex;
  gap: 12px;
}

.case-option {
  flex: 1;
  height: 56px;
  border-radius: 14px;
  border: 3px solid var(--color-border);
  background: var(--color-tile-bg, #f2cc8f);
  color: var(--color-text);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
}

.case-option.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(224, 86, 140, 0.3);
}

#style-picker {
  display: flex;
  gap: 12px;
}

.style-option {
  flex: 1;
  height: 56px;
  border-radius: 14px;
  border: 3px solid var(--color-border);
  background: var(--color-tile-bg, #f2cc8f);
  color: var(--color-text);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
}

.style-option-cursive {
  font-family: "Playwrite PT", cursive;
  font-weight: 400;
  font-size: 1.6rem;
}

.style-option.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(224, 86, 140, 0.3);
}

body.picker-cursive .picker-key {
  font-family: "Playwrite PT", cursive;
  font-weight: 400;
  font-size: 1.6rem;
}

body.picker-cursive .letter-box {
  font-family: "Playwrite PT", cursive;
  font-weight: 400;
}

body.case-upper .letter-box,
body.case-upper .picker-key {
  text-transform: uppercase;
}

main {
  width: 100%;
  max-width: 960px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* The round view stays at a narrower, focused reading width even on wide
   screens — the shelf is a browsing grid and benefits from the extra
   room, but the letter picker/word display don't. */
#view-round {
  max-width: 640px;
}

.hidden { display: none !important; }

/* ---------- Shelf (card grid) ---------- */

#view-shelf {
  width: 100%;
}

#shelf-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}

.shelf-card {
  border: none;
  border-radius: var(--radius);
  padding: 16px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
  background: var(--card-bg);
  color: var(--card-ink);
  position: relative;
}

.shelf-card:hover { transform: translateY(-3px); }
.shelf-card:active { transform: scale(0.97); }

.shelf-card .icon {
  font-size: 2.2rem;
  line-height: 1;
}

.shelf-card .label {
  font-family: "Playwrite PT", cursive;
  font-size: 1.3rem;
  font-weight: 400;
  text-align: center;
  letter-spacing: 0.02em;
}

.shelf-card .dots {
  display: flex;
  gap: 4px;
}

.shelf-card .dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(0,0,0,0.15);
}

.shelf-card .dots .dot.filled {
  background: var(--card-accent);
}

.shelf-card.needs-practice::after {
  content: "★";
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 1rem;
  color: var(--card-accent);
}

/* ---------- Round view ---------- */

#view-round {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

#round-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.nav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--color-text);
}

.icon-btn {
  border: none;
  background: var(--color-surface);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--color-text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.icon-btn:active { transform: scale(0.92); }

.icon-btn-large {
  width: 60px;
  height: 60px;
}

.icon-svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.icon-btn-large .icon-svg {
  width: 28px;
  height: 28px;
}

.btn .icon-svg {
  width: 20px;
  height: 20px;
}

.nav-btn:active { transform: scale(0.92); }

/* A horizontal filmstrip of every card, macOS Finder gallery-view style:
   the active thumbnail sits enlarged and labeled in the middle, neighbors
   trail off dimmed either side, arrows/clicks scroll-snap the strip so the
   selection re-centers. */
#card-filmstrip-outer {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

#card-filmstrip {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  padding: 8px 46%;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

#card-filmstrip::-webkit-scrollbar { display: none; }

.filmstrip-item {
  flex-shrink: 0;
  scroll-snap-align: center;
  border: none;
  border-radius: 14px;
  background: var(--card-bg);
  color: var(--card-ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 40px;
  height: 40px;
  opacity: 0.4;
  transform: scale(0.85);
  transition: all 0.15s ease;
}

.filmstrip-item .icon { font-size: 1.2rem; line-height: 1; }
.filmstrip-item .label {
  font-size: 0.6rem;
  font-weight: 800;
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filmstrip-item.active {
  opacity: 1;
  transform: scale(1);
  width: 150px;
  height: auto;
  min-height: 96px;
  padding: 10px 8px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filmstrip-item.active .icon { font-size: 2.4rem; }
.filmstrip-item.active .label {
  display: block;
  font-size: 0.85rem;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: 134px;
  line-height: 1.15;
  text-align: center;
}
.filmstrip-item:not(.active) .label { display: none; }

#round-progress {
  display: flex;
  gap: 8px;
  row-gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 8px;
}

#round-progress .step {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-border);
}

#round-progress .step.done { background: var(--color-accent); }
#round-progress .step.current { background: var(--color-primary); transform: scale(1.3); }

#word-stage {
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  min-height: 130px;
}

#word-hint-image {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 14px;
  background: white;
  box-shadow: var(--shadow);
}

#word-display {
  display: flex;
  gap: 8px;
  row-gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.letter-box {
  min-width: 36px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 800;
}

.letter-box.literal {
  color: var(--color-text);
}

.letter-box.blank {
  border-bottom: 5px solid var(--color-border);
  color: var(--color-primary);
}

.letter-box.blank.filled {
  border-bottom-color: var(--color-accent);
  animation: pop 0.25s ease;
}

.letter-box.blank.hinted {
  color: var(--color-secondary);
}

.letter-box.blank.skipped {
  color: var(--color-muted);
}

@keyframes pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.letter-box.word-space {
  width: 14px;
}

#picker {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}

.picker-key {
  height: 54px;
  border: none;
  border-radius: 10px;
  background: var(--color-tile-bg, #f2cc8f);
  color: var(--color-text);
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.picker-key:active { transform: scale(0.92); }

.picker-key.wrong-shake {
  animation: shake 0.5s ease;
  background: var(--color-primary-dark);
  color: white;
}

#word-stage.word-correct {
  animation: word-correct 0.7s ease;
}

@keyframes word-correct {
  0% { transform: scale(1); box-shadow: var(--shadow); }
  35% { transform: scale(1.06); box-shadow: 0 0 0 6px rgba(76, 175, 125, 0.35), var(--shadow); }
  100% { transform: scale(1); box-shadow: var(--shadow); }
}

.sparkle {
  position: fixed;
  font-size: 1.4rem;
  pointer-events: none;
  z-index: 40;
  transform: translate(-50%, -50%);
  animation: sparkle-burst 0.7s ease forwards;
}

@keyframes sparkle-burst {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1);
    opacity: 0;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-10px); }
  30%, 60%, 90% { transform: translateX(10px); }
}

#action-row {
  width: 100%;
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 999px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
  box-shadow: var(--shadow);
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-hint { background: var(--color-accent); color: white; }
.btn-skip { background: var(--color-secondary); color: white; }
.btn-replay { background: var(--color-secondary); color: white; }

/* ---------- Celebration ---------- */

#celebration {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#celebration .card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 32px 26px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 320px;
}

#celebration .emoji {
  font-size: 3rem;
  margin-bottom: 8px;
}

#celebration h2 {
  margin: 0 0 6px;
}

#celebration .btn {
  margin-top: 18px;
}

@media (max-width: 420px) {
  .letter-box { min-width: 30px; height: 48px; font-size: 1.4rem; }
  #picker { grid-template-columns: repeat(5, 1fr); gap: 10px; }
  .picker-key { height: 50px; }
  main { gap: 22px; }
}
