@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka.woff2') format('woff2');
  font-weight: 500 700;
  font-display: swap;
}

@font-face {
  font-family: 'Andika';
  src: url('fonts/andika-bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --yellow: #FFC400;
  --yellow-dark: #E0A800;
  --orange: #FF7A00;
  --ink: #263238;
  --ink-soft: #546E7A;
  --paper: #FFFDF6;
  --sky-top: #8FD3FF;
  --sky-bottom: #DFF3FF;
  --dirt: #D9B47A;
  --dirt-dark: #B98B4E;
  --hazard: repeating-linear-gradient(-45deg, var(--yellow) 0 14px, var(--ink) 14px 28px);
  --radius: 28px;
  --shadow: 0 6px 0 rgba(38, 50, 56, .25), 0 14px 30px rgba(38, 50, 56, .18);
  --ui-font: 'Fredoka', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --letter-font: 'Andika', 'Fredoka', 'Arial Rounded MT Bold', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--ui-font);
  font-weight: 600;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 68%, var(--dirt) 68%, var(--dirt-dark) 100%) fixed;
  background-color: var(--sky-bottom);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

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

#app {
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen[hidden] { display: none; }

/* ---------- Home ---------- */

#home {
  gap: 18px;
  padding: 18px 0 24px;
  overflow-y: auto;
}

.sign {
  position: relative;
  background: var(--yellow);
  border: 4px solid var(--ink);
  border-radius: 22px;
  padding: 26px 18px 14px;
  text-align: center;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tape {
  position: absolute;
  inset: 0 0 auto;
  height: 14px;
  background: var(--hazard);
}

.sign h1 {
  margin: 4px 0 0;
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 700;
  line-height: 1.05;
}

.sign p {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 500;
}

.sign-art {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}

.sign-art svg { width: 30%; max-width: 120px; height: auto; }

.decks {
  display: grid;
  gap: 14px;
}

.deck {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 84px;
  padding: 12px 20px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink);
  font-size: 28px;
  font-weight: 700;
  text-align: left;
  transition: transform .08s, box-shadow .08s;
}

.deck:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--ink);
}

.deck-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 64px;
  height: 56px;
  border-radius: 14px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  font-family: var(--letter-font);
  font-size: 26px;
}

.deck-numbers .deck-icon { background: var(--orange); color: #fff; font-family: var(--ui-font); }

.swatches {
  display: flex !important;
  gap: 4px;
  background: var(--paper) !important;
}

.swatches i {
  width: 14px;
  height: 30px;
  border-radius: 7px;
  border: 2px solid var(--ink);
}

.swatches i:nth-child(1) { background: #E53935; }
.swatches i:nth-child(2) { background: #FDD835; }
.swatches i:nth-child(3) { background: #1E88E5; }

.options {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: rgba(255, 253, 246, .85);
  border: 3px solid var(--ink);
  border-radius: 20px;
}

.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.option-label {
  font-size: 18px;
  font-weight: 600;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: #ECEFF1;
  border: 2px solid var(--ink);
}

.seg button {
  min-width: 92px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-soft);
}

.seg button[aria-checked="true"] {
  background: var(--yellow);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}

/* ---------- Cards screen ---------- */

#cards {
  padding: 10px 0 8px;
  gap: 10px;
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bar-title {
  flex: 1;
  text-align: center;
  line-height: 1.1;
}

.bar-title h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

.counter {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-soft);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
}

.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.icon-btn svg { width: 28px; height: 28px; fill: var(--ink); }

#order-toggle[aria-pressed="true"] { background: var(--yellow); }

.progress {
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  border: 2px solid var(--ink);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--hazard);
  transition: width .25s ease;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  touch-action: none;
}

.card {
  position: absolute;
  inset: 4px 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 16px 16px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  container-type: size;
  will-change: transform;
  cursor: grab;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 16px;
  background: var(--hazard);
  border-bottom: 3px solid var(--ink);
}

.card.under {
  transform: scale(.94);
  filter: brightness(.96);
  pointer-events: none;
}

.card.bounce { animation: bounce .35s ease; }

@keyframes bounce {
  40% { transform: scale(1.04); }
}

/* Letters */
.letter-pair {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6cqw;
  font-family: var(--letter-font);
  font-weight: 700;
  line-height: 1;
}

.letter-pair .upper { font-size: min(44cqw, 36cqh); color: var(--ink); }
.letter-pair .lower { font-size: min(38cqw, 31cqh); color: var(--orange); }

.letter-card .card-art { width: min(92cqw, 62cqh); }

.letter-word {
  max-width: 100%;
  /* Long words shrink to stay on one line. */
  font-size: min(13cqw, 10cqh, calc(150cqw / var(--len)));
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}

.letter-word b { color: var(--orange); }

.card-art {
  width: min(70cqw, 60cqh);
  height: auto;
  flex: none;
}

.card-art svg { display: block; width: 100%; height: auto; }

/* Numbers */
.big-number {
  font-size: min(48cqw, 32cqh);
  font-weight: 700;
  line-height: .95;
  color: var(--ink);
}

.number-word,
.color-word {
  font-size: min(13cqw, 9cqh);
  font-weight: 700;
  line-height: 1.1;
  text-transform: capitalize;
}

.count-grid {
  --s: 12cqmin;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--s));
  gap: 1.2cqmin;
  justify-content: center;
}

.count-grid svg { display: block; width: var(--s); height: var(--s); }

.count-grid.empty {
  width: 44cqmin;
  height: 18cqmin;
  border: 4px dashed var(--ink-soft);
  border-radius: 16px;
}

/* Colors */
.color-card .card-art { width: min(88cqw, 100cqh); }

.color-word {
  font-size: min(18cqw, 13cqh);
  color: var(--swatch);
  -webkit-text-stroke: .12em var(--ink);
  paint-order: stroke fill;
}

/* Bottom controls */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
}

.nav-btn {
  display: grid;
  place-items: center;
  border: 4px solid var(--ink);
  box-shadow: 0 5px 0 var(--ink);
}

.nav-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

.nav-btn {
  width: 76px;
  height: 64px;
  border-radius: 20px;
  background: var(--yellow);
}

.nav-btn svg { width: 36px; height: 36px; fill: var(--ink); }

.hint {
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  opacity: .75;
}

@media (max-height: 640px) {
  .hint { display: none; }
  .nav-btn { height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .card.bounce { animation: none; }
  .progress-fill { transition: none; }
}
