/* Letters: a big letter or a picture, a word with a gap, slots for building a word, big letter
   tiles. The menu reuses Klok kijken's menu cards and round grid (klok.css). */
.letters-case { font: 900 1.15rem/1 var(--font); color: var(--primary-dark); }
.letters-case[aria-pressed="true"] { background: var(--primary-light); }

#letters-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 12px 14px;
}
.letters-prompt { margin: 0; text-align: center; font-size: clamp(1.05rem, 4.6vw, 1.3rem); font-weight: 900; color: var(--primary); text-wrap: balance; }
.letters-picbox {
  flex: none; /* never squashed by the column: it shrinks with the screen height instead */
  width: min(60vw, 230px, 34vh);
  aspect-ratio: 1;
  padding: 10px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 5px 0 #d6cff7;
}
.letters-picbox { position: relative; }
.letters-picbox svg { width: 100%; height: 100%; display: block; }
#letters-stage.happy .letters-picbox { animation: klok-hop 0.5s ease-out; }
/* tap: the big letter to match, in the picture's place */
.letters-picbox.big-letter { display: grid; place-items: center; background: #fff; box-shadow: 0 5px 0 #c9c0f2; }
.letters-big { font: 900 calc(min(60vw, 230px, 34vh) * 0.62)/1 var(--font); color: var(--primary-dark); }
#letters-stage.happy .letters-picbox.big-letter { background: #eaffdc; box-shadow: 0 5px 0 #9be15d; }
/* build, tier 2: an eye in the corner once the word is hidden; a tap on the picture shows it again */
.letters-peek {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 44px;
  height: 44px;
  display: none;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-light, #ece8ff);
  color: var(--primary-dark);
  box-shadow: 0 3px 0 #c9c0f2;
}
.letters-peek svg { width: 28px; height: 28px; }
.letters-peekbtn { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; color: inherit; cursor: pointer; touch-action: manipulation; }
.letters-peekbtn:focus-visible { outline: 4px solid var(--bz-focus); outline-offset: 6px; border-radius: 22px; }
.letters-picbox.can-peek .letters-peek { display: grid; }

/* first letter: the word under the picture, its first letter a gap */
.letters-word {
  margin: 0;
  display: flex;
  align-items: flex-end;
  gap: 0.08em;
  font: 900 min(2.6rem, calc(min(100vw, 520px) * 0.85 / (var(--n, 4) * 0.66 + 0.6)))/1.1 var(--font);
  color: var(--ink);
  letter-spacing: 0.04em;
}
.letters-gap {
  display: inline-grid;
  place-items: center;
  min-width: 0.9em;
  height: 1.15em;
  border-bottom: 0.12em solid var(--primary);
  border-radius: 0.12em;
  background: rgba(255, 255, 255, 0.7);
  color: #3c8a12;
}
.letters-gap.filled { background: #eaffdc; border-color: #9be15d; }

.letters-slots { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.letters-slot {
  width: clamp(48px, 15vw, 64px);
  height: clamp(56px, 17vw, 74px);
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 3px dashed #c9c0f2;
  background: rgba(255, 255, 255, 0.6);
  font: 900 clamp(2rem, 9vw, 2.6rem)/1 var(--font);
  color: var(--ink);
}
.letters-slot.next { border-color: var(--primary); border-style: solid; }
/* build: the word in the empty slots, faint to trace (tier 1) or for a moment (tier 2) */
.letters-slot .ghost { opacity: 0; color: var(--primary); transition: opacity 0.35s; }
.letters-slots[data-hint="ghost"] .ghost { opacity: 0.3; }
.letters-slots.peek .ghost { opacity: 0.8; transition: none; }
.letters-slot.filled { border-style: solid; border-color: #9be15d; background: #eaffdc; }
.letters-slots.done .letters-slot { animation: klok-hop 0.5s ease-out; }

.letters-options { width: min(100%, 520px); display: grid; gap: 12px; justify-content: center; }
.letters-options.n3 { grid-template-columns: repeat(3, minmax(0, 104px)); }
.letters-options.n4 { grid-template-columns: repeat(4, minmax(0, 104px)); }
.letters-options.n5, .letters-options.n6 { grid-template-columns: repeat(3, minmax(0, 96px)); }
.letters-tile {
  aspect-ratio: 1;
  min-width: 0;
  border: 0;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  font: 900 clamp(2.3rem, 11vw, 3.4rem)/1 var(--font);
  box-shadow: 0 5px 0 #c9c0f2;
  cursor: pointer;
  touch-action: manipulation;
}
.letters-tile:nth-child(6n + 1) { background: #fff3c4; }
.letters-tile:nth-child(6n + 2) { background: #dcf2ff; }
.letters-tile:nth-child(6n + 3) { background: #ffe1ef; }
.letters-tile:nth-child(6n + 4) { background: #e2f8d6; }
.letters-tile:nth-child(6n + 5) { background: #ffe6d2; }
.letters-tile:nth-child(6n) { background: #ece8ff; }
.letters-tile:active { transform: translateY(3px); box-shadow: 0 2px 0 #c9c0f2; }
.letters-tile:focus-visible { outline: 4px solid var(--bz-focus); outline-offset: 3px; }
.letters-tile.right { background: #9be15d; box-shadow: 0 5px 0 #5aa82e; }
.letters-tile.wrong { animation: letters-shake 0.4s; opacity: 0.55; }
.letters-tile.used { visibility: hidden; }
@keyframes letters-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
/* tap: the drawn example of the letter just found, the picture with its word, the letter marked */
.letters-picbox.example {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  gap: 2px;
  background: #fff;
  box-shadow: 0 5px 0 #9be15d;
}
.letters-picbox.example > svg { width: 100%; height: 100%; min-height: 0; }
.letters-exword {
  font: 900 min(calc(min(60vw, 230px, 34vh) * 0.2), calc(min(60vw, 230px, 34vh) * 0.78 / (var(--n, 4) * 0.74 + 0.6)))/1.1 var(--font);
  color: var(--ink);
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.letters-exfirst { color: #2f730c; background: #eaffdc; border-bottom: 0.1em solid #9be15d; border-radius: 0.12em; padding: 0 0.06em; }
.letters-picbox.example > * { animation: letters-fade 0.35s ease-out; }
@keyframes letters-fade { from { opacity: 0; } to { opacity: 1; } }
/* a letter without a word to draw: traced, then filled in */
.letters-trace text { font: 900 70px/1 var(--font); }
.letters-trace .trace-guide { fill: #ece8ff; }
.letters-trace .trace-line { fill: none; stroke: var(--primary); stroke-width: 2.4; stroke-linejoin: round; stroke-dasharray: 420; stroke-dashoffset: 420; animation: letters-trace 1.3s ease-in-out forwards; }
.letters-trace .trace-fill { fill: #2f730c; opacity: 0; animation: letters-fade 0.45s ease-out 1.2s forwards; }
@keyframes letters-trace { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .letters-tile.wrong, #letters-stage.happy .letters-picbox, .letters-slots.done .letters-slot { animation: none; }
  .letters-slot .ghost { transition: none; }
  .letters-picbox.example > *, .letters-trace .trace-line, .letters-trace .trace-fill { animation: none; }
  .letters-trace .trace-line { stroke-dashoffset: 0; }
  .letters-trace .trace-fill { opacity: 1; }
}
@media (max-width: 360px) {
  .letters-options { gap: 9px; }
  /* four tiles stay one row (a tier-1 word with its extra tile): two rows push the dots off a 320x568 screen */
  .letters-options.n4 { grid-template-columns: repeat(4, minmax(0, 68px)); }
}

/* sideways phones: the picture on the left, everything else on the right */
@media (orientation: landscape) and (max-height: 560px) {
  #screen-letters { flex-direction: row; }
  #letters-stage {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "pic prompt" "pic word" "pic slots" "pic options" "pic dots" "pic status";
    grid-template-rows: auto auto auto 1fr auto auto;
    align-items: center;
    justify-items: center;
    gap: 6px 16px;
    padding: 6px 12px;
  }
  .letters-prompt { grid-area: prompt; font-size: 1rem; }
  .letters-picbox { grid-area: pic; width: auto; height: min(calc(100vh - 24px), 30vw); max-height: calc(100vh - 24px); }
  .letters-big { font-size: calc(min(100vh - 24px, 30vw) * 0.62); }
  .letters-exword { font-size: min(calc(min(100vh - 24px, 30vw) * 0.2), calc(min(100vh - 24px, 30vw) * 0.78 / (var(--n, 4) * 0.74 + 0.6))); }
  .letters-word { grid-area: word; font-size: min(2.2rem, 11vh, calc(55vw / (var(--n, 4) * 0.66 + 0.6))); }
  .letters-slots { grid-area: slots; flex-wrap: nowrap; gap: 6px; }
  .letters-options { grid-area: options; }
  #letters-dots { grid-area: dots; }
  #letters-status { grid-area: status; min-height: 1.2em; }
  .letters-tile { font-size: clamp(1.8rem, 9vh, 2.6rem); }
  .letters-options.n3, .letters-options.n4 { grid-template-columns: repeat(var(--cols, 4), minmax(0, min(74px, 18vh))); }
  .letters-options.n3 { --cols: 3; }
  .letters-options.n5, .letters-options.n6 { grid-template-columns: repeat(3, minmax(0, min(60px, 15vh))); gap: 8px; }
  .letters-options.n5 .letters-tile, .letters-options.n6 .letters-tile { font-size: clamp(1.5rem, 8vh, 2.2rem); }
  .letters-slot { width: min(52px, 13vh); height: min(60px, 15vh); font-size: min(2.2rem, 10vh); }
}
#letters-menu .level-cell.random-btn .random-label { white-space: normal; overflow: visible; }
.letters-picbox svg.pic { width: 100%; height: 100%; aspect-ratio: 1; }
