/* Little Beans Learning: shared look for every screen.
   Layout: a toy shelf. The home screen is one column of labeled shelves
   (sections), each a grid of big square tiles. Play mode is a full-screen
   dark play mat with two corner controls and a word bar pinned to the bottom. */

:root {
  /* ground and ink (light) */
  --lb-bg: #F1F6F2;
  --lb-surface: #FFFFFF;
  --lb-ink: #16241C;
  --lb-ink-soft: #52655A;
  --lb-line: #D3DFD7;
  --lb-brand: #23915A;
  --lb-brand-ink: #FFFFFF;
  --lb-brand-deep: #176B41;
  --lb-focus: #1B62D6;

  /* jelly bean colors, one per section */
  --lb-grape: #7A5AF8;
  --lb-cherry: #E5484D;
  --lb-blueberry: #2F7DE1;
  --lb-tangerine: #EE8420;
  --lb-lime: #2FA36B;
  --lb-teal: #1A9C9C;
  --lb-lemon: #D2A106;
  --lb-bubblegum: #E255A1;

  /* the play mat looks the same in both themes */
  --lb-mat: #0D1522;
  --lb-mat-ink: #F3F6FA;
  --lb-mat-soft: rgba(243, 246, 250, 0.16);

  /* core word colors */
  --lb-w-more: #2F7DE1;
  --lb-w-stop: #D93A40;
  --lb-w-go: #1F9A5C;
  --lb-w-again: #7A5AF8;
  --lb-w-done: #5B6B7C;

  /* type and sizes */
  --lb-font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --lb-tile: 148px;
  --lb-corner: 56px;
  --lb-word: 84px;
  --lb-radius: 26px;
  --lb-bar: calc(var(--lb-word) + 28px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --lb-bg: #101713;
    --lb-surface: #1A251F;
    --lb-ink: #EAF2EC;
    --lb-ink-soft: #9DB0A4;
    --lb-line: #2C3B32;
    --lb-brand: #3CBF7C;
    --lb-brand-ink: #06140C;
    --lb-brand-deep: #23804F;
    --lb-focus: #8AB8FF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --lb-bg: #101713;
  --lb-surface: #1A251F;
  --lb-ink: #EAF2EC;
  --lb-ink-soft: #9DB0A4;
  --lb-line: #2C3B32;
  --lb-brand: #3CBF7C;
  --lb-brand-ink: #06140C;
  --lb-brand-deep: #23804F;
  --lb-focus: #8AB8FF;
  color-scheme: dark;
}

/* Settings: bigger targets */
:root.lb-big {
  --lb-tile: 196px;
  --lb-corner: 72px;
  --lb-word: 104px;
}

/* Settings: high contrast (comes last so it wins over both themes) */
:root.lb-contrast {
  --lb-bg: #000000;
  --lb-surface: #000000;
  --lb-ink: #FFFFFF;
  --lb-ink-soft: #FFFFFF;
  --lb-line: #FFFFFF;
  --lb-brand: #FFE600;
  --lb-brand-ink: #000000;
  --lb-brand-deep: #B3A100;
  --lb-focus: #FFE600;
  --lb-grape: #C4B3FF;
  --lb-cherry: #FF8A8E;
  --lb-blueberry: #7CC0FF;
  --lb-tangerine: #FFB25C;
  --lb-lime: #6EF0A8;
  --lb-teal: #5CEAEA;
  --lb-lemon: #FFE600;
  --lb-bubblegum: #FF9AD0;
  --lb-mat: #000000;
  --lb-mat-ink: #FFFFFF;
  --lb-mat-soft: rgba(255, 255, 255, 0.5);
  color-scheme: dark;
}

/* ---------- base ---------- */
:root {
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--lb-bg);
  color: var(--lb-ink);
  font-family: var(--lb-font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid var(--lb-focus); outline-offset: 3px; }

.lb-noselect, .lb-home button, .lb-play, .lb-play * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- home ---------- */
.lb-home {
  box-sizing: border-box;
  max-width: 1120px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 18px 48px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.lb-top {
  display: flex;
  align-items: center;
  gap: 14px;
}
.lb-logo { width: 56px; height: 56px; flex: none; }
.lb-brand { min-width: 0; flex: 1; }
.lb-brand h1 {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.9rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.lb-brand h1 span { color: var(--lb-brand); }
.lb-brand p {
  margin: 2px 0 0;
  color: var(--lb-ink-soft);
  font-size: 0.95rem;
}

/* the "surprise me" button: opens a random activity */
.lb-random {
  box-sizing: border-box;
  width: min(100%, 440px);
  min-height: calc(var(--lb-corner) + 28px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 22px;
  border: 0;
  border-radius: var(--lb-radius);
  background: var(--lb-brand);
  color: var(--lb-brand-ink);
  box-shadow: 0 7px 0 var(--lb-brand-deep);
  font-weight: 800;
  font-size: 1.35rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.lb-random:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--lb-brand-deep); }
.lb-random svg { width: calc(var(--lb-corner) - 4px); height: calc(var(--lb-corner) - 4px); flex: none; }
.lb-random .lb-pip { fill: var(--lb-brand); }

.lb-sections { display: flex; flex-direction: column; gap: 30px; }
.lb-section { display: flex; flex-direction: column; gap: 14px; }
.lb-section h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}
.lb-bean { width: 26px; height: 26px; flex: none; color: var(--c); }

.lb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--lb-tile), 42vw), 1fr));
  gap: 16px 14px;
}

.lb-tile {
  position: relative;
  box-sizing: border-box;
  aspect-ratio: 1;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: center;
  gap: 4px;
  padding: 12px 10px 12px;
  background: var(--lb-surface);
  border: 2px solid var(--lb-line);
  border-radius: var(--lb-radius);
  box-shadow: 0 7px 0 var(--c);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.lb-tile:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--c); }
.lb-tile img, .lb-tile .lb-tile-glyph {
  width: 62%;
  height: auto;
  aspect-ratio: 1;
  min-height: 0;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.lb-tile .lb-tile-glyph { color: var(--c); width: 44%; }
.lb-tile-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.15;
  text-align: center;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.lb-big .lb-tile-name { font-size: 1.1rem; }

.lb-tile.is-soon {
  box-shadow: none;
  border-style: dashed;
  cursor: default;
  color: var(--lb-ink-soft);
}
.lb-tile.is-soon .lb-tile-glyph { opacity: 0.45; }
.lb-tile.is-soon:active { transform: none; }
.lb-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--lb-ink-soft);
}
.lb-lock {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  color: var(--lb-ink-soft);
}

.lb-foot {
  color: var(--lb-ink-soft);
  font-size: 0.9rem;
  border-top: 2px solid var(--lb-line);
  padding-top: 14px;
}
.lb-msg {
  padding: 18px;
  border: 2px dashed var(--lb-line);
  border-radius: var(--lb-radius);
  color: var(--lb-ink-soft);
}

/* ---------- round control buttons (home screen and play mat) ---------- */
.lb-round {
  position: relative;
  box-sizing: border-box;
  width: var(--lb-corner);
  height: var(--lb-corner);
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--lb-line);
  background: var(--lb-surface);
  color: var(--lb-ink);
  cursor: pointer;
  touch-action: none;
}
.lb-round > svg.lb-ico { width: 52%; height: 52%; }
.lb-round .lb-ring {
  position: absolute;
  inset: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  transform: rotate(-90deg);
  pointer-events: none;
}
.lb-round .lb-ring circle {
  fill: none;
  stroke: var(--lb-brand);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  opacity: 0;
}
.lb-round.is-holding .lb-ring circle { opacity: 1; }
.lb-round.is-holding .lb-ring circle {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset var(--lb-hold, 700ms) linear;
}
.lb-round.is-hint { animation: lb-nudge 320ms ease; }
@keyframes lb-nudge {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.14); }
}

/* ---------- play mat ---------- */
.lb-play {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--lb-mat);
  color: var(--lb-mat-ink);
  overflow: hidden;
  touch-action: none;
}
.lb-stage, .lb-fx, .lb-veil {
  position: absolute;
  inset: 0;
}
.lb-play.has-words .lb-stage,
.lb-play.has-words .lb-fx,
.lb-play.has-words .lb-veil {
  bottom: calc(var(--lb-bar) + env(safe-area-inset-bottom, 0px));
}
.lb-stage { overflow: hidden; touch-action: none; }
.lb-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.lb-fx { pointer-events: none; overflow: hidden; }
.lb-veil { background: rgba(4, 8, 14, 0.62); }
.lb-contrast .lb-veil { background: rgba(0, 0, 0, 0.8); }

.lb-fx i {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  border-radius: 50%;
  will-change: transform, opacity;
}
.lb-fx i.is-bean { border-radius: 60% 40% 55% 45% / 50% 60% 40% 50%; }
.lb-fx i.is-ring { background: none; border: 6px solid currentColor; }

.lb-corner {
  position: absolute;
  z-index: 5;
  top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(20, 30, 46, 0.72);
  border-color: var(--lb-mat-soft);
  color: var(--lb-mat-ink);
}
.lb-corner .lb-ring circle { stroke: var(--lb-mat-ink); }
.lb-corner-home { left: calc(10px + env(safe-area-inset-left, 0px)); }
.lb-corner-words { right: calc(10px + env(safe-area-inset-right, 0px)); }
.lb-corner-words[aria-pressed="true"] { background: var(--lb-mat-ink); color: var(--lb-mat); }
.lb-corner-words[aria-pressed="true"] .lb-ring circle { stroke: var(--lb-mat); }
.lb-contrast .lb-corner { background: #000; border-color: #fff; }
/* word bar on, high contrast: white button, black icon (it used to turn black on black) */
.lb-contrast .lb-corner-words[aria-pressed="true"] { background: #fff; color: #000; }

/* ---------- core word bar ---------- */
.lb-words {
  position: absolute;
  z-index: 6;
  left: 0;
  right: 0;
  bottom: 0;
  box-sizing: border-box;
  height: calc(var(--lb-bar) + env(safe-area-inset-bottom, 0px));
  padding: 14px max(12px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  display: flex;
  justify-content: center;
  gap: clamp(6px, 2vw, 18px);
  background: #060B13;
  border-top: 2px solid var(--lb-mat-soft);
}
.lb-contrast .lb-words { background: #000; }
.lb-word {
  box-sizing: border-box;
  flex: 1 1 0;
  min-width: 0;
  max-width: calc(var(--lb-word) * 1.5);
  height: var(--lb-word);
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 7px;
  border: 3px solid var(--w);
  border-radius: 18px;
  background: #FFFFFF;
  color: #101820;
  font-weight: 800;
  font-size: clamp(0.72rem, 2.6vw, 1rem);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  touch-action: none;
  transition: transform 70ms ease;
}
.lb-word svg { width: auto; height: 100%; max-height: 44px; min-height: 0; aspect-ratio: 1; color: var(--w); }
.lb-big .lb-word svg { max-height: 56px; }
.lb-word:active { transform: scale(0.94); }
.lb-word[data-word="more"] { --w: var(--lb-w-more); }
.lb-word[data-word="stop"] { --w: var(--lb-w-stop); }
.lb-word[data-word="go"] { --w: var(--lb-w-go); }
.lb-word[data-word="again"] { --w: var(--lb-w-again); }
.lb-word[data-word="all-done"] { --w: var(--lb-w-done); }
/* a word button pulses when it is the one to press next */
.lb-play.is-paused .lb-word[data-word="go"],
.lb-word.is-prompt { animation: lb-pulse 1.1s ease-in-out infinite; }
.lb-calm .lb-play.is-paused .lb-word[data-word="go"],
.lb-calm .lb-word.is-prompt { animation: none; box-shadow: 0 0 0 7px var(--w); }
@keyframes lb-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--w); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px var(--w); transform: scale(1.06); }
}

/* ---------- tap to start (first screen of each visit) ---------- */
.lb-start {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--lb-bg);
  touch-action: manipulation;
}
.lb-start-btn {
  width: min(56vmin, 300px);
  height: min(56vmin, 300px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--lb-surface);
  box-shadow: 0 10px 0 var(--lb-brand-deep), 0 0 0 10px var(--lb-line);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  animation: lb-start-pulse 1.6s ease-in-out infinite;
}
.lb-start-btn .lb-start-bean { width: 70%; height: 70%; }
.lb-start-btn.is-tapped { transform: translateY(6px); box-shadow: 0 4px 0 var(--lb-brand-deep), 0 0 0 10px var(--lb-line); animation: none; }
.lb-start-note { margin: 0; color: var(--lb-ink-soft); font-weight: 700; font-size: 1.1rem; }
.lb-calm .lb-start-btn { animation: none; }
@keyframes lb-start-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@media (prefers-reduced-motion: reduce) { .lb-start-btn { animation: none; } }

/* ---------- settings sheet ---------- */
.lb-sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 14, 10, 0.55);
  overflow: auto;
}
.lb-sheet {
  box-sizing: border-box;
  width: min(480px, 100%);
  background: var(--lb-surface);
  color: var(--lb-ink);
  border: 2px solid var(--lb-line);
  border-radius: var(--lb-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.lb-sheet-head h2 { margin: 0; flex: 1; font-size: 1.3rem; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 8px 4px;
  background: none;
  border: 0;
  border-top: 2px solid var(--lb-line);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.lb-row-text { flex: 1; min-width: 0; }
.lb-row-text b { display: block; font-size: 1.05rem; }
.lb-row-text small { display: block; color: var(--lb-ink-soft); font-size: 0.85rem; }
.lb-switch {
  flex: none;
  width: 58px;
  height: 34px;
  border-radius: 17px;
  background: var(--lb-line);
  border: 2px solid var(--lb-ink-soft);
  box-sizing: border-box;
  position: relative;
}
.lb-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--lb-ink);
  transition: transform 120ms ease;
}
.lb-row[aria-checked="true"] .lb-switch { background: var(--lb-brand); border-color: var(--lb-brand); }
.lb-row[aria-checked="true"] .lb-switch::after { transform: translateX(24px); background: var(--lb-brand-ink); }
.lb-row-go { flex: none; width: 28px; height: 28px; color: var(--lb-ink-soft); }

@media (prefers-reduced-motion: reduce) {
  .lb-tile, .lb-word, .lb-random, .lb-switch::after { transition: none; }
  .lb-round.is-hint { animation: none; }
}
