/* Word Buddies — emerald green on royal blue.
   Mobile first: everything is sized so a whole level fits on a phone screen
   without scrolling, with big tap targets for small fingers. */

/* ------------------------------------------------------------- tokens -- */
:root {
  --royal-deep:  #0a1550;
  --royal:       #132a86;
  --royal-mid:   #1d3fb8;
  --royal-lift:  #2b55d8;
  --emerald-deep:#046c4e;
  --emerald:     #10b981;
  --emerald-lift:#34d399;
  --cream:       #f4f8ff;
  --ink:         #14245c;
  --ink-soft:    #4a5a90;

  --group-emerald: #10b981;
  --group-royal:   #4d7cff;
  --group-sun:     #f5b73d;
  --group-coral:   #ff7d6b;

  --radius-card: 18px;
  --radius-pill: 999px;
  --gap: 8px;
  --shadow-card: 0 4px 0 rgba(12, 30, 100, .22), 0 8px 18px rgba(5, 15, 60, .28);
  --shadow-lift: 0 8px 0 rgba(4, 90, 66, .38), 0 14px 26px rgba(5, 15, 60, .34);

  --pad-top: max(10px, env(safe-area-inset-top));
  --pad-bottom: max(10px, env(safe-area-inset-bottom));
  --pad-side: max(12px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

/* Several components set display explicitly, which would otherwise beat the
   hidden attribute's user-agent rule. */
[hidden] { display: none !important; }

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

body {
  font-family: "Baloo 2", "Nunito", "Quicksand", "Segoe UI Rounded",
               "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  color: var(--cream);
  background: var(--royal-deep);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  /* Sliding across cards must never start a text selection. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.is-loading #app { opacity: 0; }

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------- background -- */
.sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--royal-mid) 0%, var(--royal) 42%, var(--royal-deep) 100%);
  z-index: 0;
  overflow: hidden;
}

.sky__stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 18%, rgba(255,255,255,.9), transparent),
    radial-gradient(1.4px 1.4px at 78% 12%, rgba(255,255,255,.75), transparent),
    radial-gradient(1.8px 1.8px at 36% 34%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.3px 1.3px at 88% 44%, rgba(255,255,255,.65), transparent),
    radial-gradient(1.5px 1.5px at 22% 62%, rgba(255,255,255,.5), transparent),
    radial-gradient(1.2px 1.2px at 62% 72%, rgba(255,255,255,.45), transparent),
    radial-gradient(1.6px 1.6px at 50% 8%, rgba(255,255,255,.55), transparent);
  animation: twinkle 5s ease-in-out infinite alternate;
}

.sky__glow {
  position: absolute;
  left: 50%;
  bottom: -22vh;
  width: 130vw;
  height: 60vh;
  transform: translateX(-50%);
  background: radial-gradient(50% 50% at 50% 50%, rgba(16, 185, 129, .32), transparent 70%);
  filter: blur(6px);
}

.sky__hills {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 34vh;
}

@keyframes twinkle {
  from { opacity: .55; }
  to   { opacity: 1; }
}

/* ------------------------------------------------------------ screens -- */
#app {
  position: relative;
  z-index: 1;
  height: 100%;
  transition: opacity .25s ease;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: var(--pad-top) var(--pad-side) var(--pad-bottom);
}

.screen.is-active {
  display: flex;
  animation: screen-in .3s ease both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- home -- */
.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  height: 100%;
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
  padding: 12px 4px;
}

.home__head { text-align: center; }

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}

.logo__card {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: var(--cream);
  color: var(--royal);
  font-size: 28px;
  font-weight: 800;
  box-shadow: var(--shadow-card);
}

.logo__card--a { transform: rotate(-8deg); }
.logo__card--b { transform: rotate(8deg); color: var(--emerald-deep); }
.logo__link { font-size: 22px; }

.home__title {
  margin: 0;
  font-size: clamp(2rem, 9vw, 2.8rem);
  font-weight: 800;
  letter-spacing: .5px;
  text-shadow: 0 3px 0 rgba(4, 12, 50, .45);
}

.home__tagline {
  margin: 6px 0 0;
  font-size: 1rem;
  color: #bfd4ff;
}

.home__scores {
  display: flex;
  gap: 10px;
}

.score {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 104px;
  padding: 10px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .16);
}

.score__value { font-size: 1.3rem; font-weight: 800; }
.score__label { font-size: .78rem; color: #b9cdf7; }

.big-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  max-width: 320px;
  padding: 16px 22px;
  border-radius: 22px;
  background: linear-gradient(180deg, var(--emerald-lift), var(--emerald));
  color: #04352a;
  box-shadow: var(--shadow-lift);
  transition: transform .12s ease, box-shadow .12s ease;
}

.big-button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 rgba(4, 90, 66, .38), 0 6px 12px rgba(5, 15, 60, .3);
}

.big-button__label { font-size: 1.5rem; font-weight: 800; }
.big-button__sub { font-size: .85rem; opacity: .8; }
.big-button--compact { padding: 13px 20px; }
.big-button--compact .big-button__label { font-size: 1.2rem; }

.home__row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.pill-button {
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .13);
  border: 1px solid rgba(255, 255, 255, .22);
  font-weight: 700;
  font-size: .95rem;
  transition: transform .12s ease, background .2s ease;
}

.pill-button:active { transform: scale(.96); background: rgba(255, 255, 255, .2); }
.pill-button--danger { color: #ffd7d1; border-color: rgba(255, 125, 107, .5); }

.how {
  width: 100%;
  max-width: 340px;
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  font-size: .88rem;
}

.how summary { cursor: pointer; font-weight: 700; }
.how ol { margin: 10px 0 0; padding-left: 18px; color: #d6e3ff; line-height: 1.5; }
.how li + li { margin-top: 6px; }

/* ------------------------------------------------------------- topbar -- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 10px;
  flex: 0 0 auto;
}

.topbar__middle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.topbar__tag {
  font-size: .72rem;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--emerald-lift);
  font-weight: 800;
}

.topbar__title {
  font-size: 1.12rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.topbar__sub { font-size: .78rem; color: #b9cdf7; }

.topbar__right { display: flex; align-items: center; gap: 8px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .2);
  font-size: 1.15rem;
  transition: transform .12s ease;
}

.icon-button:active { transform: scale(.92); }
.icon-button--small { width: 38px; height: 38px; font-size: 1rem; }

.stars { display: flex; gap: 1px; }
.star { font-size: 1rem; color: rgba(255, 255, 255, .22); transition: color .3s ease; }
.star--on { color: var(--group-sun); text-shadow: 0 0 8px rgba(245, 183, 61, .6); }

/* ---------------------------------------------------------- level map -- */
.map-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px 20px;
  -webkit-overflow-scrolling: touch;
}

.tier { margin-bottom: 22px; }

.tier__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: .95rem;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: #c6d8ff;
}

.tier__title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255,255,255,.25), transparent);
}

.tier__emoji { font-size: 1.1rem; }

.tier__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}

.level-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 92px;
  padding: 10px 8px;
  border-radius: var(--radius-card);
  background: linear-gradient(180deg, #ffffff, #e8efff);
  color: var(--ink);
  box-shadow: var(--shadow-card);
  transition: transform .12s ease;
}

.level-chip:active { transform: translateY(3px) scale(.98); }

.level-chip__num { font-size: 1.35rem; font-weight: 800; line-height: 1; }

.level-chip__title {
  font-size: .72rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.15;
}

.level-chip__stars { display: flex; gap: 1px; font-size: .8rem; color: #c8d3ee; }
.level-chip__stars .on { color: var(--group-sun); }

.level-chip.is-locked {
  background: rgba(255, 255, 255, .08);
  color: #8fa5d8;
  box-shadow: none;
  border: 1px dashed rgba(255, 255, 255, .2);
  cursor: not-allowed;
}

.level-chip__lock { font-size: 1.1rem; opacity: .8; }
.level-chip.is-done { border-top: 4px solid var(--emerald); }

.level-chip--easy   .level-chip__num { color: var(--emerald-deep); }
.level-chip--medium .level-chip__num { color: var(--royal-mid); }
.level-chip--hard   .level-chip__num { color: #b8791a; }
.level-chip--expert .level-chip__num { color: #c4503d; }

/* Must come after the tier colours above, which are equally specific. */
.level-chip.is-locked .level-chip__num { color: #8fa5d8; }

/* --------------------------------------------------------- game board -- */
/* Solved rows and the cards still in play move as one centred stack, so the
   board never drifts away from the rows above it. */
.play {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  position: relative;
}

.solved {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
}

/* Each group is a named tab sitting on a tinted band. The band bleeds to the
   screen edges while its cards keep the board's side inset, so a solved group
   lines up with the columns still in play. */
.solved-group {
  position: relative;
  padding-top: 22px;
}

.solved-group--emerald { --band: #a3e2c7; --chip: #c8f0de; --band-ink: #05432f; }
.solved-group--royal   { --band: #b6c8ff; --chip: #d6e0ff; --band-ink: #16265e; }
.solved-group--sun     { --band: #ffdda0; --chip: #ffedc9; --band-ink: #5b3f06; }
.solved-group--coral   { --band: #ffc7bd; --chip: #ffddd6; --band-ink: #642419; }
.solved-group--violet  { --band: #d5c2f7; --chip: #e8ddfd; --band-ink: #3b2168; }
.solved-group--teal    { --band: #a5e0e6; --chip: #cbeff3; --band-ink: #06414a; }
.solved-group--pink    { --band: #ffc4dd; --chip: #ffdcec; --band-ink: #63194a; }
.solved-group--lime    { --band: #cfe6a0; --chip: #e5f2c8; --band-ink: #34430a; }

.solved-group__tab {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 88%;
  /* The bottom padding tucks under the band, which shares its colour, so the
     tab and the band read as one shape. */
  padding: 4px 16px 14px;
  border-radius: 14px 14px 0 0;
  background: var(--band);
  color: var(--band-ink);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  white-space: nowrap;
}

.solved-group__name { overflow: hidden; text-overflow: ellipsis; }
.solved-group__ornament { font-size: .8rem; opacity: .65; flex: 0 0 auto; }

.solved-group__cards {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), 1fr);
  gap: var(--gap);
  margin-inline: calc(var(--pad-side) * -1);
  padding: 8px calc(var(--pad-side) + 2px);
  background: var(--band);
}

.solved-card {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 9px 4px;
  border-radius: 11px;
  background: var(--chip);
  color: var(--band-ink);
  font-size: clamp(.58rem, 2.9vw, .84rem);
  font-weight: 800;
  letter-spacing: .2px;
  line-height: 1.05;
  text-align: center;
  overflow: hidden;
  box-shadow: 0 2px 0 rgba(10, 30, 60, .12);
}

.solved-card--long   { font-size: clamp(.52rem, 2.5vw, .74rem); letter-spacing: 0; }
.solved-card--longer { font-size: clamp(.44rem, 2.1vw, .64rem); letter-spacing: -.2px; }

.solved-group.is-new { animation: row-in .45s cubic-bezier(.2, 1.4, .5, 1) both; }

@keyframes row-in {
  from { opacity: 0; transform: scale(.86) translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

/* Sits in the spare space below the board, so it never hides a solved row or
   the cards still in play. */
.board-message {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translate(-50%, 8px);
  margin: 0;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: rgba(8, 20, 70, .92);
  border: 1px solid rgba(255, 255, 255, .18);
  font-size: .88rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  width: max-content;
  max-width: 94%;
  box-shadow: 0 6px 16px rgba(3, 10, 40, .45);
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: opacity .2s ease, transform .2s ease;
}

.board-message.is-visible { opacity: 1; transform: translate(-50%, -4px); }
.board-message--correct { background: var(--emerald-deep); border-color: var(--emerald-lift); }
.board-message--close   { background: #8a6412; border-color: var(--group-sun); }
.board-message--wrong   { background: #8e3a2e; border-color: var(--group-coral); }
.board-message--hint    { background: #14357f; border-color: var(--group-royal); }

/* Rows share out whatever height is left, but a card never stretches into a
   tall column on a roomy screen. --rows follows the cards still in play, and
   the height cap is tuned per column count so cards stay card-shaped. */
.board--c3 { --card-max-h: 128px; }
.board--c4 { --card-max-h: 102px; }

.board {
  flex: 1;
  min-height: 0;
  max-height: calc(var(--rows, 4) * var(--card-max-h, 116px) + (var(--rows, 4) - 1) * var(--gap));
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), 1fr);
  grid-auto-rows: minmax(0, 1fr);
  gap: var(--gap);
  padding: 4px 2px;
  touch-action: none;
}

/* --------------------------------------------------------------- card -- */
.card {
  position: relative;
  perspective: 900px;
  min-height: 0;
  outline: none;
  animation: card-in .3s ease both;
}

@keyframes card-in {
  from { opacity: 0; transform: scale(.9); }
  to   { opacity: 1; transform: none; }
}

.card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3, .9, .3, 1);
}

.card__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 5px;
  border-radius: var(--radius-card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.card__face--front {
  background: linear-gradient(180deg, #ffffff, #e9f0ff);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}

.card__face--back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #14357f, #0d2467);
  color: var(--cream);
  border: 2px solid var(--emerald);
  box-shadow: var(--shadow-card);
  padding: 8px 7px;
}

.card__emoji { font-size: clamp(1.05rem, 5vw, 1.6rem); line-height: 1; }
.card__emoji--big { font-size: clamp(1.9rem, 9vw, 2.9rem); }

.card__word {
  font-size: clamp(.66rem, 3.5vw, 1rem);
  font-weight: 800;
  letter-spacing: .3px;
  text-align: center;
  line-height: 1.05;
  overflow-wrap: break-word;
}

/* Long words step down a size rather than snapping mid-word. */
.card--long .card__word   { font-size: clamp(.58rem, 3vw, .88rem); letter-spacing: 0; }
.card--longer .card__word { font-size: clamp(.48rem, 2.45vw, .76rem); letter-spacing: -.2px; }

.card__word--back {
  color: var(--emerald-lift);
  font-size: clamp(.6rem, 3vw, .82rem);
  margin-bottom: 3px;
}

.card__hint {
  font-size: clamp(.5rem, 2.5vw, .72rem);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  color: #d8e5ff;
  overflow: hidden;
}

/* Tucked inside the card corner so it can never be clipped by the board edge. */
.card__info {
  position: absolute;
  top: 3px;
  right: 3px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(29, 63, 184, .82);
  color: #fff;
  border: 1.5px solid rgba(255, 255, 255, .9);
  font-size: .7rem;
  font-weight: 800;
  font-style: italic;
  box-shadow: 0 1px 4px rgba(5, 15, 60, .35);
  transition: transform .15s ease, background .2s ease;
}

.card__info:active { transform: scale(.86); background: var(--emerald); }
.card__info:focus-visible { outline: 3px solid var(--group-sun); outline-offset: 2px; }
.card.is-flipped .card__inner { transform: rotateY(180deg); }
.card.is-flipped .card__info { background: var(--emerald); }

/* Picked. The lift lives on the front face, not on .card — the entry
   animation holds a transform on .card and would win against it. */
.card.is-picked .card__face--front {
  background: linear-gradient(180deg, var(--emerald-lift), var(--emerald));
  color: #04352a;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .85), var(--shadow-lift);
  transform: translateY(-3px) scale(1.03);
}

.card.is-picked { z-index: 2; }
.card__face--front { transition: transform .14s ease, background .18s ease, box-shadow .18s ease; }

/* Clue glow: a thick ring in the group's colour, plus a halo so it still
   stands out against the blue background. */
.card.is-hinted .card__face--front {
  box-shadow:
    0 0 0 4px var(--hint-color, var(--group-royal)),
    0 0 14px 4px var(--hint-color, var(--group-royal)),
    var(--shadow-card);
  animation: hint-pulse 1.4s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .72; }
}

/* right */
.card.is-correct { animation: pop .5s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: var(--pop-delay, 0ms); }

@keyframes pop {
  0%   { transform: scale(1.03); }
  45%  { transform: scale(1.14); }
  100% { transform: scale(.7); opacity: 0; }
}

/* wrong */
.card.is-wrong { animation: wobble .45s ease both; }

.card.is-wrong .card__face--front {
  background: linear-gradient(180deg, #ffd9d2, #ffbdb1);
  box-shadow: 0 0 0 3px var(--group-coral), var(--shadow-card);
}

@keyframes wobble {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px) rotate(-2deg); }
  45%      { transform: translateX(6px) rotate(2deg); }
  70%      { transform: translateX(-3px); }
}

.card:focus-visible { outline: 3px solid var(--group-sun); outline-offset: 3px; border-radius: var(--radius-card); }

/* ------------------------------------------------------------ toolbar -- */
.toolbar {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding-top: 10px;
  flex: 0 0 auto;
}

.tool-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .24);
  font-weight: 700;
  font-size: .92rem;
  transition: transform .12s ease, background .2s ease;
}

.tool-button:active { transform: scale(.95); background: rgba(16, 185, 129, .35); }
.tool-button__icon { font-size: 1.15rem; }

/* ------------------------------------------------------------ frenzy --- */
.big-button__tag {
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  opacity: .62;
}

.big-button--frenzy {
  background: linear-gradient(180deg, #6f8dff, var(--royal-lift));
  color: #fff;
  box-shadow: 0 8px 0 rgba(12, 30, 110, .5), 0 14px 26px rgba(5, 15, 60, .34);
}

.big-button--frenzy:active {
  box-shadow: 0 3px 0 rgba(12, 30, 110, .5), 0 6px 12px rgba(5, 15, 60, .3);
}

.how__mode {
  margin: 12px 0 0;
  font-weight: 800;
  font-size: .8rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--emerald-lift);
}

.frenzy-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 2px 8px;
  flex: 0 0 auto;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 2px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .16);
  min-width: 0;
}

.stat__value { font-size: 1rem; font-weight: 800; }
.stat__label { font-size: .6rem; color: #b9cdf7; letter-spacing: .5px; }

.frenzy-next {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  flex: 0 0 auto;
  min-width: 74px;
  padding: 5px 8px;
  border-radius: 12px;
  background: rgba(16, 185, 129, .22);
  border: 1px solid var(--emerald);
}

.frenzy-next__emoji { font-size: 1rem; line-height: 1; }
.frenzy-next__word { font-size: .58rem; font-weight: 800; letter-spacing: .3px; }

.frenzy-play {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

/* The well is the falling area. Tiles inside are absolutely positioned, with
   separate transitions for steering (quick) and falling (one tick long). */
.well {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 16px;
  background: rgba(4, 12, 48, .34);
  border: 1px solid rgba(255, 255, 255, .12);
  overflow: hidden;
  touch-action: none;
}

.well.is-paused::after {
  content: "Paused";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 16, 60, .72);
  font-size: 1.2rem;
  font-weight: 800;
}

.ftile {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 3px;
  border-radius: 13px;
  background: linear-gradient(180deg, #ffffff, #e9f0ff);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(12, 30, 100, .22);
  transition: left .09s ease-out, top .16s ease-in, opacity .2s ease, transform .2s ease;
  overflow: hidden;
}

.ftile--active {
  transition: left .09s ease-out, top var(--fall, 900ms) linear;
  box-shadow: 0 0 0 3px var(--emerald-lift), 0 4px 0 rgba(12, 30, 100, .25);
  z-index: 2;
}

.ftile__emoji { font-size: clamp(.9rem, 4.5vw, 1.3rem); line-height: 1; }

.ftile__word {
  font-size: clamp(.54rem, 2.9vw, .82rem);
  font-weight: 800;
  text-align: center;
  line-height: 1.02;
  overflow-wrap: break-word;
}

.ftile--long .ftile__word   { font-size: clamp(.48rem, 2.5vw, .72rem); }
.ftile--longer .ftile__word { font-size: clamp(.4rem, 2.05vw, .6rem); letter-spacing: -.2px; }

.ftile.is-gone { opacity: 0; transform: scale(.6); }
.ftile.is-joined { animation: joined .5s cubic-bezier(.2, 1.5, .4, 1) both; }

@keyframes joined {
  0%   { transform: scale(.5); }
  55%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* The cleared row, shown as a band and then pushed down out of the well. */
.frenzy-clear {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  transition: transform .62s cubic-bezier(.5, 0, .8, .3), opacity .62s ease;
}

/* A vertical line stacks its words instead of laying them out across. */
.frenzy-clear--v .solved-group__cards { grid-auto-rows: 1fr; }

.frenzy-clear--v .solved-group__tab {
  font-size: .55rem;
  letter-spacing: .6px;
  max-width: none;      /* the band is one cell wide; the name is not */
}

.frenzy-clear.is-leaving { transform: translateY(120%); opacity: 0; }
.frenzy-clear .solved-group { padding-top: 0; height: 100%; }

/* The tab rides just above the row it names, so it never covers a word. */
.frenzy-clear .solved-group__tab {
  top: -3px;
  transform: translate(-50%, -100%);
  padding: 3px 12px;
  border-radius: 999px;
  z-index: 2;
  font-size: .6rem;
  box-shadow: 0 2px 8px rgba(4, 12, 48, .4);
}

/* A row cleared at the very top has no room above it inside the well. */
.frenzy-clear--top .solved-group__tab {
  top: auto;
  bottom: -3px;
  transform: translate(-50%, 100%);
}

.frenzy-clear .solved-group__cards {
  height: 100%;
  align-content: center;
  margin-inline: 0;
  padding: 0;
  gap: 6px;
  background: transparent;
}

.frenzy-clear .solved-card {
  height: 100%;
  border-radius: 13px;
  box-shadow: 0 0 0 2px var(--band), 0 3px 0 rgba(10, 30, 60, .16);
}

.unlocks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  padding: 8px 0 2px;
  flex: 0 0 auto;
}

.unlock-chip {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .3px;
  background: var(--band, rgba(255, 255, 255, .16));
  color: var(--band-ink, #fff);
}

.unlock-chip--emerald { --band: #a3e2c7; --band-ink: #05432f; }
.unlock-chip--royal   { --band: #b6c8ff; --band-ink: #16265e; }
.unlock-chip--sun     { --band: #ffdda0; --band-ink: #5b3f06; }
.unlock-chip--coral   { --band: #ffc7bd; --band-ink: #642419; }
.unlock-chip--violet  { --band: #d5c2f7; --band-ink: #3b2168; }
.unlock-chip--teal    { --band: #a5e0e6; --band-ink: #06414a; }
.unlock-chip--pink    { --band: #ffc4dd; --band-ink: #63194a; }
.unlock-chip--lime    { --band: #cfe6a0; --band-ink: #34430a; }

.unlock-chip.is-locked {
  background: rgba(255, 255, 255, .1);
  color: #8fa5d8;
  border: 1px dashed rgba(255, 255, 255, .22);
}

.toolbar--frenzy { gap: 10px; }
.tool-button--round { padding: 11px 16px; font-size: 1.05rem; }

/* Tiles pile up from the floor, so the toast lives at the top of the well
   where it has empty space to sit in. */
.screen--frenzy .board-message { bottom: auto; top: 10px; }
.screen--frenzy .board-message.is-visible { transform: translate(-50%, 0); }

/* ----------------------------------------------------------- overlays -- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 12, 45, .72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.overlay.is-open { display: flex; animation: fade-in .2s ease both; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-radius: 26px;
  background: linear-gradient(180deg, #1b3ba5, #101f68);
  border: 1px solid rgba(255, 255, 255, .2);
  box-shadow: 0 18px 44px rgba(2, 8, 35, .6);
  text-align: center;
  animation: panel-in .32s cubic-bezier(.2, 1.3, .4, 1) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: scale(.9) translateY(16px); }
  to   { opacity: 1; transform: none; }
}

.panel__title { margin: 0; font-size: 1.55rem; font-weight: 800; }
.panel__sub { margin: 0; font-size: .95rem; color: #c6d8ff; }
.panel__notes { margin: 0; font-size: .82rem; color: #9fb8f0; }
.panel__notes--big { font-size: .95rem; color: var(--emerald-lift); font-weight: 700; }
.panel__actions { display: flex; flex-direction: column; gap: 10px; width: 100%; align-items: center; margin-top: 4px; }
.panel__row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.win-stars { display: flex; gap: 6px; }

.win-star {
  font-size: 2.6rem;
  color: rgba(255, 255, 255, .18);
  animation: star-in .5s cubic-bezier(.2, 1.6, .4, 1) both;
}

.win-star--on { color: var(--group-sun); text-shadow: 0 0 16px rgba(245, 183, 61, .7); }

@keyframes star-in {
  from { opacity: 0; transform: scale(.2) rotate(-40deg); }
  to   { opacity: 1; transform: none; }
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .18);
  text-align: left;
}

.toggle__icon { font-size: 1.3rem; }
.toggle__text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.toggle__name { font-weight: 700; font-size: .95rem; }
.toggle__hint { font-size: .74rem; color: #a9c0f0; }

.toggle__state {
  padding: 5px 13px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .16);
  font-size: .8rem;
  font-weight: 800;
}

.toggle[aria-checked="true"] .toggle__state { background: var(--emerald); color: #04352a; }

/* ---------------------------------------------------------- confetti --- */
/* Below the overlay (z-index 20) so the falling bits never sit on top of the
   words in the win panel. */
.confetti {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}

.confetti__bit {
  position: absolute;
  top: -6%;
  animation-name: fall;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

@keyframes fall {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to   { transform: translateY(112vh) rotate(560deg); opacity: .1; }
}

/* ------------------------------------------------ calm / reduced motion */
body.calm .sky__stars,
body.calm .card.is-hinted .card__face--front { animation: none; }

body.calm .screen.is-active,
body.calm .card,
body.calm .panel,
body.calm .solved-group.is-new,
body.calm .win-star { animation-duration: .01s; }

body.calm .card__inner { transition-duration: .2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ------------------------------------------------------------ sizing --- */
/* Short phones: claw back vertical space so 4x4 boards still fit. */
@media (max-height: 700px) {
  .topbar { padding-bottom: 6px; }
  .topbar__title { font-size: 1rem; }
  .solved { gap: 8px; }
  .solved-group { padding-top: 19px; }
  .solved-group__tab { padding: 3px 13px 13px; font-size: .62rem; letter-spacing: .8px; }
  .solved-group__cards { padding-block: 6px; }
  .solved-card { padding: 7px 3px; }
  .play { --gap: 6px; }   /* board and solved bands must share it to stay aligned */
  .toolbar { padding-top: 6px; }
  .tool-button { padding: 9px 16px; }
}

/* Tablets and desktop: keep the board phone-shaped and centred. */
@media (min-width: 620px) {
  .screen--game, .screen--map { max-width: 520px; margin: 0 auto; width: 100%; }
  .board--c3 { --card-max-h: 152px; }
  .board--c4 { --card-max-h: 126px; }
  .card__word { font-size: 1rem; }
  .card--long .card__word { font-size: .88rem; }
  .card--longer .card__word { font-size: .76rem; }
  .card__hint { font-size: .74rem; }
  .card__emoji { font-size: 1.6rem; }
}

@media (min-width: 900px) and (min-height: 700px) {
  .screen--game { max-width: 620px; }
}

/* Tall phones: a little more room, but never so much that a card stops
   looking like a card. Cards stay close to square. */
@media (min-height: 780px) {
  .board--c3 { --card-max-h: 144px; }
  .board--c4 { --card-max-h: 112px; }
}
