/* Bookworm — uses :root vars from /styles.css. */

:root {
  /* 10% smaller than 88 (previous), rounded to a clean pixel. Combined
     with going back to 7 columns, the board is ~592px wide vs 556px at
     6 cols × 88 — still fits comfortably. */
  --bw-tile-size: 72px;
  --bw-tile-gap: 4px;
  /* Tile colours — desaturated enough to read letters clearly on all of
     them, punchy enough to be instantly distinguishable at a glance. */
  --bw-tile-bg:      #f3ecd8;   /* parchment */
  --bw-tile-fg:      #2a2418;
  --bw-tile-border:  #b0a684;
  --bw-tile-shadow:  rgba(0,0,0,0.18);

  --bw-emerald-bg:   #2ea866;
  --bw-emerald-fg:   #ffffff;
  --bw-gold-bg:      #e8b437;
  --bw-gold-fg:      #3a2a08;
  --bw-sapphire-bg:  #2a68d8;
  --bw-sapphire-fg:  #ffffff;
  --bw-ruby-bg:      #c72a3a;
  --bw-ruby-fg:      #ffffff;
  --bw-amethyst-bg:  #8a44c7;
  --bw-amethyst-fg:  #ffffff;
  --bw-diamond-bg:   #b7e8ff;
  --bw-diamond-fg:   #063a5a;

  --bw-burning-bg:   #ff5030;
  --bw-burning-fg:   #ffffff;
  --bw-burning-glow: rgba(255, 80, 48, 0.75);

  --bw-selected-outline: #f8de52;
}

:root[data-theme="dark"], :root:not([data-theme="light"]) {
  --bw-tile-bg:     #d8ceb0;
  --bw-tile-border: #7a715a;
}

.bookworm-app {
  max-width: 960px;
  padding-top: 0.5rem;
}

/* ── Header (title only) ───────────────────────────────────── */
.bw-h1 {
  font-family: 'Georgia', 'Book Antiqua', serif;
  font-weight: 400;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
  margin: 0.5rem 0 0.8rem;
  color: var(--text);
}

/* ── Two-column layout: left rail + board ─────────────────── */
.bw-layout {
  display: flex;
  gap: 1rem;
  /* Stretch so the rail matches the board-col height. Combined with a
     flex-grow on the mascot-wrap, the mascot expands to fill the extra
     vertical space and the bottom of Scramble lines up with the bottom
     of the 3-slot side-quest row. */
  align-items: stretch;
}
.bw-rail {
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 240px;
}
.bw-board-col {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;   /* board on top, quest panel underneath */
  align-items: center;
  min-width: 0;
  /* Safety net: if the viewport still can't fit the board, scroll inside
     the column rather than let the fixed-width board overflow left/right
     into the rail (which produced the 'tiles floating over the submit
     button' iPad bug). */
  overflow-x: auto;
}
/* Layout tiers — cascading, so later rules override earlier ones.
   Tightened aggressively for iPad Air 3rd gen (834px viewport) after
   the compressed v78 still clipped. Total needed at 1000px tier:
     8px padding × 2 + 170 rail + 6 gap + 7 × (60 + 3) + 4 border
     = 16 + 170 + 6 + 445 = 637px
   Well below 834 with 197px margin, so any browser chrome or safe-area
   inset can't push tiles off-screen. */
@media (max-width: 1000px) {
  /* Tiles: 54 -> 57 (+5%) so the letter and the point-value badge stop
     touching. Letter font size intentionally unchanged (1.6rem) — the
     extra room comes from the larger tile box, not a bigger letter. */
  :root              { --bw-tile-size: 57px; --bw-tile-gap: 3px; }
  /* #app.bookworm-app beats the global #app { padding: 2rem 1.5rem } —
     shave the padding to give the layout every horizontal pixel it can get. */
  #app.bookworm-app  { padding: 0.75rem 0.5rem; }
  .bw-rail           { flex: 0 0 205px; min-width: 205px; }
  .bw-layout         { gap: 0.4rem; flex-direction: row; }
  .bw-mascot         { min-height: 170px; }
  .bw-score-big      { font-size: 1.9rem; }
  .bw-word-text      { font-size: 1.4rem; }
  .bw-level-num      { font-size: 1.5rem; }
  /* Scale the letter down so it fits proportionally inside the smaller
     tile box — 2.3rem was fine at 72px but crowds the bevel at 49px. */
  .bw-tile           { font-size: 1.6rem; }
  .bw-tile.bw-tile-multi .bw-tile-letter { font-size: 1.05rem; }
}
@media (max-width: 640px) {
  .bw-layout { flex-direction: column; align-items: center; }
  .bw-rail   { flex: 1 1 auto; width: 100%; max-width: 480px; }
}

/* Shared rail card look — matches the boxed panels in the original */
.bw-rail-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  text-align: center;
}

/* 1. Total score */
.bw-score-card {
  padding: 0.5rem 0.6rem 0.4rem;
}
.bw-score-big {
  font-family: 'Georgia', serif;
  font-weight: 700;
  font-size: 2rem;
  line-height: 1.1;
  color: var(--text);
  letter-spacing: 0.02em;
}
.bw-best-small {
  font-size: 0.72rem;
  margin-top: 0.1rem;
}

/* 2. Current word card */
.bw-word-card {
  padding: 0.6rem 0.7rem;
  min-height: 3.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bw-current-word {
  width: 100%;
  font-family: 'Georgia', serif;
  color: var(--text);
  text-transform: uppercase;
  text-align: center;
}
.bw-word-text {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.15;
}
.bw-word-score {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  margin-top: 0.15rem;
  color: var(--text-muted);
}
.bw-word-score-valid  { color: #2ea866; font-weight: 600; }
.bw-word-score-bogus  { color: #c72a3a; }
.bw-word-score-neutral { color: var(--text-muted); }

/* 3. Mascot — grows to fill remaining rail height so Scramble bottom
      aligns with the side-quest row bottom on the right. */
.bw-mascot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.2rem 0;
  flex: 1 1 0;              /* eats leftover vertical space in the rail */
  min-height: 140px;
}
.bw-mascot {
  width: 100%;
  /* No max-width — let the mascot fill the (now 260px wide) rail column
     so the artwork reads at full scale rather than a small icon. */
  flex: 1 1 auto;
  min-height: 220px;
  position: relative;
  transition: transform 0.2s;
}
.bw-mascot.happy   { animation: bw-lex-bounce 0.5s ease-out; }
.bw-mascot.excited { animation: bw-lex-spin 0.7s ease-out; }
.bw-mascot.worried { animation: bw-lex-shake 0.35s ease-in-out 2; }
@keyframes bw-lex-bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes bw-lex-spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
@keyframes bw-lex-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.bw-mascot-speech {
  font-family: 'Georgia', serif;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.1rem;
  line-height: 1.25;
  transition: opacity 0.15s;
}

/* 4. Submit + Clear */
.bw-submit-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.bw-submit-block .bw-btn {
  width: 100%;
  font-size: 1.15rem;
  font-weight: 600;
  padding: 0.65rem 0.8rem;
}

/* 5. Level shelf — books stack up */
.bw-level-card {
  padding: 0.55rem 0.65rem 0.4rem;
}
.bw-level-head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.bw-level-lbl {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.bw-level-num {
  font-family: 'Georgia', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.bw-shelf {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2px;
  height: 34px;
  padding: 2px 4px 3px;
  background: linear-gradient(180deg, #6a4a2e 0%, #4a3018 100%);
  border: 1px solid #2a1a0a;
  border-radius: 4px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.15) inset;
}
.bw-book {
  flex: 1 1 0;
  height: 100%;
  border: 1px solid;
  border-radius: 1px;
  box-shadow: 0 0 2px rgba(0,0,0,0.3) inset;
  transition: background 0.25s ease-out, border-color 0.25s ease-out;
}
.bw-shelf-label {
  margin-top: 0.3rem;
  text-align: center;
}

/* 6. Scramble */

/* ── Board ─────────────────────────────────────────────────── */
.bw-board {
  position: relative;
  width: calc(7 * (var(--bw-tile-size) + var(--bw-tile-gap)) + 4px);
  height: calc(7 * (var(--bw-tile-size) + var(--bw-tile-gap)) + 4px);
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.bw-mascot {
  width: 100%;
  max-width: 110px;
  aspect-ratio: 1 / 1;
  position: relative;
  transition: transform 0.2s;
}
.bw-mascot.happy   { animation: bw-lex-bounce 0.5s ease-out; }
.bw-mascot.excited { animation: bw-lex-spin 0.7s ease-out; }
.bw-mascot.worried { animation: bw-lex-shake 0.35s ease-in-out 2; }
@keyframes bw-lex-bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes bw-lex-spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
@keyframes bw-lex-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.bw-mascot-speech {
  font-family: 'Georgia', serif;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.2rem;
  transition: opacity 0.15s;
}

/* ── Bonus tile legend — lives inside the How-to-Play modal ── */
.bw-legend {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.35;
}
.bw-legend-rows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.4rem 1rem;
}
.bw-legend-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.bw-legend-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
}
.bw-legend-swatch {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  border: 2px solid var(--bw-tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Georgia', serif;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow:
    inset 0 -2px 0 rgba(0,0,0,0.18),
    inset 0 2px 0 rgba(255,255,255,0.28);
}
.bw-legend-emerald  { background: var(--bw-emerald-bg);  color: var(--bw-emerald-fg);  border-color: #1e7d4b; }
.bw-legend-gold     { background: var(--bw-gold-bg);     color: var(--bw-gold-fg);     border-color: #a67c20; }
.bw-legend-sapphire { background: var(--bw-sapphire-bg); color: var(--bw-sapphire-fg); border-color: #1c4ba5; }
.bw-legend-ruby     { background: var(--bw-ruby-bg);     color: var(--bw-ruby-fg);     border-color: #8f1e2a; }
.bw-legend-amethyst { background: var(--bw-amethyst-bg); color: var(--bw-amethyst-fg); border-color: #5f2d90; }
.bw-legend-diamond  {
  background: linear-gradient(135deg, var(--bw-diamond-bg) 0%, #ffffff 50%, var(--bw-diamond-bg) 100%);
  color: var(--bw-diamond-fg);
  border-color: #6ab2d8;
}
.bw-legend-burning  {
  background: var(--bw-burning-bg);
  color: var(--bw-burning-fg);
  border-color: #a02010;
}
.bw-legend-text { flex: 1; min-width: 0; }
.bw-legend-text b { font-weight: 700; color: var(--text); }
.bw-legend-danger { color: var(--text); }

@media (max-width: 520px) {
  .bw-legend { font-size: 0.7rem; padding: 0.5rem 0.6rem; }
  .bw-legend-swatch { width: 22px; height: 22px; font-size: 0.75rem; }
}

/* ── Tiles ──────────────────────────────────────────────── */
.bw-tile {
  position: absolute;
  width: var(--bw-tile-size);
  height: var(--bw-tile-size);
  /* Square tiles with rounded corners + a proper bevel. The inset shadow
     gives the raised-tile feel; the outer shadow anchors it above the
     board. Border colour matches the tile family so bonus tiles read as
     a coherent 3D shape rather than a flat sticker. */
  border-radius: 10px;
  border: 2px solid var(--bw-tile-border);
  background: var(--bw-tile-bg);
  color: var(--bw-tile-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Georgia', serif;
  font-weight: 700;
  font-size: 2.3rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, box-shadow 0.15s;
  /* Deeper bevel on ALL four edges: bright inset on top-left, dark on
     bottom-right, plus an inner outline and an outer drop shadow so the
     tile visibly floats above the board from every angle. */
  box-shadow:
    /* top-left highlight (bright) */
    inset  4px  4px 0 rgba(255,255,255,0.42),
    /* bottom-right shadow (deep) */
    inset -4px -4px 0 rgba(0,0,0,0.32),
    /* subtle inner outline hugging all four sides */
    inset  0  0 0 1px rgba(0,0,0,0.14),
    /* outer drop shadow — lifts the tile off the board */
    0 3px 6px rgba(0,0,0,0.35),
    0 1px 2px rgba(0,0,0,0.25);
}
.bw-tile:hover { filter: brightness(1.08); }
.bw-tile.selected {
  /* Real outline works now that we're not clip-pathing the tile. */
  outline: 3px solid var(--bw-selected-outline);
  outline-offset: -1px;
  filter: brightness(1.15);
  transform: scale(1.06);
  z-index: 10;
}
.bw-tile.selected-order {
  position: absolute;
  top: 6%;
  left: 6%;
  font-size: 0.55rem;
  font-family: system-ui;
  font-weight: 700;
  background: var(--bw-selected-outline);
  color: #4a3200;
  border-radius: 999px;
  min-width: 14px;
  padding: 1px 4px;
  line-height: 1.2;
  text-align: center;
}
.bw-tile-value {
  /* Hugs the bottom-right corner just inside the bevel edge. */
  position: absolute;
  bottom: 5px;
  right: 6px;
  font-family: system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.65;
  line-height: 1;
}

/* Bonus tile types — same layout, punchier colour + matched border
   so the bevel reads coherently. */
.bw-tile.bonus-emerald  { background: var(--bw-emerald-bg);  color: var(--bw-emerald-fg);  border-color: #1e7d4b; }
.bw-tile.bonus-gold     { background: var(--bw-gold-bg);     color: var(--bw-gold-fg);     border-color: #a67c20; }
.bw-tile.bonus-sapphire { background: var(--bw-sapphire-bg); color: var(--bw-sapphire-fg); border-color: #1c4ba5; }
.bw-tile.bonus-ruby     { background: var(--bw-ruby-bg);     color: var(--bw-ruby-fg);     border-color: #8f1e2a; }
.bw-tile.bonus-amethyst { background: var(--bw-amethyst-bg); color: var(--bw-amethyst-fg); border-color: #5f2d90; }
.bw-tile.bonus-diamond  {
  background: linear-gradient(135deg, var(--bw-diamond-bg) 0%, #ffffff 50%, var(--bw-diamond-bg) 100%);
  color: var(--bw-diamond-fg);
  border-color: #6ab2d8;
  animation: bw-diamond-shimmer 1.4s ease-in-out infinite;
}
@keyframes bw-diamond-shimmer { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.15); } }

/* Burning tile — always red, always animating a pulse. Higher z when
   near-bottom so the operator can see the danger. */
.bw-tile.burning {
  background: var(--bw-burning-bg);
  color: var(--bw-burning-fg);
  border-color: #a02010;
  animation: bw-burn-pulse 0.6s ease-in-out infinite alternate;
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.25),
    inset 0 3px 0 rgba(255,255,255,0.3),
    0 0 12px var(--bw-burning-glow),
    0 2px 4px var(--bw-tile-shadow);
}
@keyframes bw-burn-pulse {
  0%   { filter: brightness(1)   drop-shadow(0 0 2px var(--bw-burning-glow)); }
  100% { filter: brightness(1.2) drop-shadow(0 0 10px var(--bw-burning-glow)); }
}

/* Multi-char tiles (QU mode) need a smaller letter font so both
   characters fit inside the tile without wrapping or overflowing. */
.bw-tile.bw-tile-multi .bw-tile-letter { font-size: 1.5rem; letter-spacing: -0.02em; }

/* Cell removal + drop animations */
.bw-tile.clearing { animation: bw-clear 0.35s ease-out forwards; pointer-events: none; }
@keyframes bw-clear {
  0%   { transform: scale(1);   opacity: 1; }
  100% { transform: scale(0.2); opacity: 0; }
}

/* Fall-in / slide-down animations use transform + a CSS custom property
   for the starting offset. Transform doesn't touch layout so we never
   race with the browser's paint schedule the way `transition: top` did.
   The tile is always positioned at its FINAL top; the animation shifts
   it via translate and ends at (0, 0).

   Note: --tile-fall-from is set inline per-tile by renderBoard. New
   tiles get a large negative value (falling from above the board);
   kept tiles that moved down get their (previous_top - new_top) delta
   as a negative offset so they visibly slide from where they were. */
.bw-tile.fall-in {
  animation: bw-fall-in 0.7s cubic-bezier(0.34, 1.15, 0.64, 1) both;
}
.bw-tile.slide-down {
  animation: bw-slide-down 0.55s cubic-bezier(0.32, 0.72, 0, 1) both;
}
@keyframes bw-fall-in {
  from { transform: translateY(var(--tile-fall-from, -700px)); }
  to   { transform: translateY(0); }
}
@keyframes bw-slide-down {
  from { transform: translateY(var(--tile-fall-from, 0)); }
  to   { transform: translateY(0); }
}
/* Legacy — retained so any lingering `.dropping` class is a no-op
   rather than a broken transition on `top` interfering with the new
   transform-based animation. */
.bw-tile.dropping { transition: none; }

/* ── Controls ─────────────────────────────────────────── */
.bw-btn {
  flex: 1;
  min-width: 90px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.6rem;
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.12s;
}
.bw-btn:hover:not(:disabled) { background: var(--bg); }
.bw-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.bw-btn-primary {
  background: #2ea866;
  color: white;
  border-color: #24884f;
  font-weight: 600;
}
.bw-btn-primary:hover:not(:disabled) { background: #2ab55f; }
.bw-btn-icon { flex: 0 0 auto; min-width: 42px; padding: 0.55rem 0.5rem; }

/* ── Overlays ────────────────────────────────────────── */
.bw-overlay[hidden] { display: none; }
.bw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.bw-overlay-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 1.8rem;
  max-width: 340px;
  text-align: center;
}
/* Wide variant for content-heavy modals (How-to-Play with the bonus-tile
   legend, Settings with multiple toggles). Prevents the modal from getting
   tall-and-skinny on iPad. */
.bw-overlay-card.bw-overlay-wide {
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  color: var(--text);
}
.bw-overlay-card h2 { font-weight: 400; margin: 0 0 0.4rem; font-size: 1.3rem; }
.bw-overlay-card p { font-size: 0.9rem; margin: 0.3rem 0 1rem; }
.bw-overlay-card button {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
}

/* ── Toast for "not a word" ──────────────────────────── */
.bw-toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  font-size: 0.9rem;
  z-index: 40;
  animation: bw-toast-in 0.2s ease-out, bw-toast-out 0.3s ease-in 1.7s forwards;
  pointer-events: none;
}
@keyframes bw-toast-in  { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes bw-toast-out { to { opacity: 0; transform: translate(-50%, -8px); } }

/* Floating "+N" score chip that flies from board to score */
.bw-score-fly {
  position: absolute;
  pointer-events: none;
  font-family: system-ui;
  font-weight: 700;
  font-size: 1.1rem;
  color: #d8b02c;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  z-index: 20;
  animation: bw-fly 1s ease-out forwards;
}
@keyframes bw-fly {
  0%   { opacity: 1; transform: translateY(0);    }
  100% { opacity: 0; transform: translateY(-40px); }
}

/* ── Narrow screens ─────────────────────────────────── */
@media (max-width: 520px) {
  :root { --bw-tile-size: 48px; }
  .bw-h1 { font-size: 1.4rem; }
  .bw-word-text { font-size: 1.25rem; }
  .bw-score-big { font-size: 1.7rem; }
  .bw-mascot { max-width: 100px; }
}

/* ── Welcome title card ────────────────────────────────
   Full-screen overlay shown on every fresh load, replacing (or
   preceding) the resume prompt. The subtitle is editable by the
   operator via localStorage so they can post custom special-mode
   messages ("Today all Italian words are worth 2× points"). */
.bw-welcome-card {
  text-align: center;
  padding: 2rem 1.8rem;
  max-width: 420px;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(184, 171, 140, 0.22) 0%, rgba(127, 168, 160, 0.15) 100%),
    var(--card);
  border: 2px solid var(--bw-tile-border);
}
.bw-welcome-title {
  font-family: 'Georgia', 'Book Antiqua', serif;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  margin-bottom: 0.6rem;
  line-height: 1.15;
}
.bw-welcome-title { margin-bottom: 1.4rem; }

/* ─────────────────────────────────────────────────────────────
   Side-quest panel + earned-powers row + status chips
   ───────────────────────────────────────────────────────────── */
.bw-side-panel {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.8rem auto 0;
}
.bw-quests-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}
@media (max-width: 540px) {
  .bw-quests-row { grid-template-columns: 1fr; }
}
.bw-quest-slot {
  background: var(--card, #fff);
  border: 1px solid var(--border, #ddd);
  border-radius: 10px;
  padding: 0.6rem 0.65rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  min-height: 130px;
  display: flex;
  flex-direction: column;
}
.bw-quest-slot.bw-quest-empty {
  align-items: center;
  justify-content: center;
  font-style: italic;
  min-height: 130px;
}
.bw-quest-slot .bw-quest-desc {
  flex: 1;
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: center;
  /* Clamp to 3 lines max — a 4th line looked bad in the operator's
     playtest. Excess text is truncated with an ellipsis. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bw-quest-slot .bw-quest-bar {
  margin-top: 0.2rem;
}

/* Earned-power slot — visually distinct so operator immediately spots
   there's a power ready to spend. */
.bw-quest-slot.bw-quest-earned {
  background: #fff8e1;
  border-color: #d4a017;
  box-shadow: 0 2px 6px rgba(212, 160, 23, 0.22);
  align-items: center;
  justify-content: space-between;
  text-align: center;
}
.bw-earned-label {
  color: #7a5a1a !important;
}
.bw-earned-power {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0;
  flex: 1;
}
.bw-earned-name {
  font-family: 'Georgia', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #5a4210;
  line-height: 1.25;
  text-align: center;
}
.bw-activate-btn {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
}
.bw-quest-slot.bw-quest-earned.picking {
  background: #ffe4b5;
  border-color: #b8860b;
  animation: bw-earned-pulse 1.2s ease-in-out infinite;
}
@keyframes bw-earned-pulse {
  0%, 100% { box-shadow: 0 2px 6px rgba(212, 160, 23, 0.3); }
  50%      { box-shadow: 0 2px 14px rgba(212, 160, 23, 0.7); }
}

/* Below-row: actions column (mirrors the 220px rail width) beside the
   bonus-tile chart (mirrors the board width). Matches the layout above
   so the two rows line up column-for-column. */
/* Bottom action strip: 4 buttons in a single horizontal row spanning the
   layout width. Bonus-tile legend has moved into the How-to-Play modal. */
.bw-below-row {
  display: flex;
  justify-content: center;
  margin: 1rem auto 0;
  max-width: 960px;
}
.bw-actions-col {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;              /* never wrap onto a second line */
  gap: 0.4rem;
  width: 100%;
}
.bw-actions-col .bw-btn {
  flex: 1 1 0;
  text-align: center;
  padding: 0.7rem 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  /* Override the base .bw-btn { min-width: 90px } so labels can shrink
     instead of pushing the row to wrap — critical with OpenDyslexic which
     renders text noticeably wider than Georgia/system fonts. */
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dark-theme adjustments for earned-power slot */
:root[data-theme="dark"] .bw-quest-slot.bw-quest-earned {
  background: #3a2f10;
  border-color: #d4a017;
  color: #ffe28a;
}
:root[data-theme="dark"] .bw-earned-label { color: #ffd88a !important; }
:root[data-theme="dark"] .bw-earned-name  { color: #ffe28a; }

/* Quest card */
.bw-quest {
  background: var(--card, #fff);
  border: 1px solid var(--border, #ddd);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.bw-quest-head {
  display: flex;
  justify-content: center;
  align-items: baseline;
  margin-bottom: 0.35rem;
}
.bw-quest-label {
  font-family: 'Georgia', serif;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text, #222);
  white-space: nowrap;
}
.bw-quest-desc {
  font-size: 0.95rem;
  line-height: 1.3;
  margin-bottom: 0.5rem;
  color: var(--text, #222);
  text-align: center;
}
.bw-quest-bar {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  overflow: hidden;
}
.bw-quest-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4aa350, #7cd070);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.bw-quest-progress {
  margin-top: 0.25rem;
  text-align: center;
}
.bw-quest-empty {
  padding: 0.7rem;
  text-align: center;
  font-style: italic;
}

/* Powers row */
.bw-powers-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}
.bw-power {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  background: var(--card, #fff);
  border: 1px solid var(--border, #ddd);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: transform 0.1s, background 0.1s, border-color 0.1s;
  min-height: 44px;
}
.bw-power:hover { background: rgba(74, 163, 80, 0.08); border-color: #4aa350; }
.bw-power:active { transform: scale(0.96); }
.bw-power.picking {
  background: #fff2cc;
  border-color: #d4a017;
  box-shadow: 0 0 0 2px #d4a01755;
}
.bw-power-icon { font-size: 1.15rem; }
.bw-power-count {
  font-size: 0.85rem;
  color: var(--text-muted, #666);
}
.bw-powers-empty {
  padding: 0.4rem;
  text-align: center;
}

/* Active-status chips (2× armed, ❄ window, targeting) */
.bw-status-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}
.bw-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.bw-chip-double  { background: #fff7db; border-color: #e8c76b; color: #7a5a1a; }
.bw-chip-freeze  { background: #dfefff; border-color: #7fb5e6; color: #1f4d7a; }
.bw-chip-picking { background: #ffe4b5; border-color: #d4a017; color: #6a4a10; }
.bw-chip-cancel {
  background: transparent;
  border: none;
  padding: 0 0.2rem;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Targeting mode — dim the board, highlight picked tiles */
.bw-board.targeting .bw-tile.target-eligible {
  opacity: 0.55;
  filter: saturate(0.6);
}
.bw-board.targeting .bw-tile.target-eligible:hover {
  opacity: 0.9;
  filter: none;
}
.bw-board.targeting .bw-tile.target-picked {
  outline: 3px solid #d4a017;
  outline-offset: -1px;
  box-shadow: 0 0 12px #d4a01799;
  opacity: 1;
  filter: none;
  z-index: 5;
}

/* Dark-theme adjustments */
:root[data-theme="dark"] .bw-quest,
:root[data-theme="dark"] .bw-power {
  background: #222;
  border-color: #444;
  color: #ddd;
}
:root[data-theme="dark"] .bw-quest-reward { color: #e8c76b; }
:root[data-theme="dark"] .bw-quest-bar { background: rgba(255, 255, 255, 0.1); }
:root[data-theme="dark"] .bw-power:hover { background: rgba(122, 205, 112, 0.15); }
:root[data-theme="dark"] .bw-power.picking { background: #4a3a10; color: #ffe28a; }
:root[data-theme="dark"] .bw-chip-double  { background: #4a3a10; border-color: #d4a017; color: #ffe28a; }
:root[data-theme="dark"] .bw-chip-freeze  { background: #1a3552; border-color: #4a7ea8; color: #b8dcff; }
:root[data-theme="dark"] .bw-chip-picking { background: #4a3010; border-color: #d4a017; color: #ffd88a; }
