/* Book Scramble. Base chrome (palette, body, header, actions, modals, share panel) copied from bookle/styles.css. */
:root {
  --em-deep: #071f14;
  --em-mid: #0e3b26;
  --em-glow: #1d6b45;
  --gold: #f5c451;
  --gold-bright: #ffd76a;
  --gold-deep: #a06b1c;
  --gold-shadow: #7a4c12;
  --cream: #fdf6e3;
  --cream-dim: rgba(253, 246, 227, 0.72);
  --glass: rgba(6, 26, 17, 0.55);
  --glass-line: rgba(245, 196, 81, 0.35);
  --good-glow: #8df0b4;
  --bad-glow: #ff9b9b;
  --brass-face: #d8a64c;
  --brass-mid: #b07c2e;
  --brass-dark: #96692a;
  --brass-edge: #74521a;
  --brass-press: #5d3a0e;
  --brass-ink: #3a2508;
  --font-display: "Lilita One", "Arial Rounded MT Bold", "Outfit", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--em-deep);
}

body {
  color: var(--cream);
  background:
    radial-gradient(circle at 12% 16%, rgba(255, 224, 130, 0.5) 0 2px, transparent 3px),
    radial-gradient(circle at 88% 10%, rgba(255, 224, 130, 0.4) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 24%, rgba(255, 224, 130, 0.45) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 26% 44%, rgba(255, 224, 130, 0.3) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 92% 56%, rgba(255, 224, 130, 0.35) 0 2px, transparent 3px),
    radial-gradient(circle at 8% 78%, rgba(255, 224, 130, 0.3) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 60% 88%, rgba(255, 224, 130, 0.3) 0 1.5px, transparent 2.5px),
    radial-gradient(ellipse at 50% 16%, var(--em-glow) 0%, var(--em-mid) 52%, var(--em-deep) 100%);
  background-repeat: no-repeat;
  background-size: cover;
}

main {
  width: min(96vw, 920px);
  margin: 1.1rem auto 2rem;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 1rem + 1.2vw, 2rem);
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--cream-dim);
  font-weight: 700;
}

.game-title-styled {
  background: none;
  -webkit-background-clip: initial;
  -webkit-text-fill-color: initial;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--gold-bright);
  text-shadow: 0 3px 0 var(--gold-shadow), 0 8px 18px rgba(0, 0, 0, 0.5);
}

.game-brand-logo {
  border-radius: 14px;
  border: 2px solid rgba(231, 180, 90, 0.55);
  box-shadow: 0 0 22px rgba(245, 196, 81, 0.35), 0 8px 16px rgba(0, 0, 0, 0.4);
}

.panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

/* --- Bottom actions --- */

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-top: 1rem;
  padding-bottom: 0.15rem;
}

.actions button {
  white-space: nowrap;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0.62rem 0.8rem;
  min-height: 2.85rem;
  background: var(--glass);
  color: var(--cream);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.actions button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.actions button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.actions .start-action {
  order: -1;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.07em;
  padding: 0.7rem 1.7rem;
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 5px 0 var(--gold-shadow), 0 0 26px rgba(245, 196, 81, 0.35);
}

.actions .start-action:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 var(--gold-shadow), 0 0 32px rgba(245, 196, 81, 0.5);
}

.actions .start-action:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--gold-shadow), 0 0 18px rgba(245, 196, 81, 0.35);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* --- Modals (arcade skin via scoped theme vars) --- */

/* leaderboard.js's gear handler injects inline display:block on this overlay,
   so the layout must center the card without relying on grid/flex */
.settings-modal,
.summary-modal {
  position: fixed;
  inset: 0;
  /* Above the fixed site header (.header-row, z-index 9999 in theme.css), which otherwise
     covers the top of the card: its title and close button. */
  z-index: 10000;
  background: rgba(4, 18, 12, 0.68);
  overflow-y: auto;
  padding: 1rem;
}

.summary-modal {
  z-index: 10001;
}

.settings-card,
.summary-card {
  --text: #fdf6e3;
  --muted: rgba(253, 246, 227, 0.65);
  --accent: #ffd76a;
  --accent-soft: rgba(6, 26, 17, 0.55);
  --line: rgba(245, 196, 81, 0.3);
  --panel: rgba(6, 26, 17, 0.55);
  --bg: rgba(6, 26, 17, 0.45);
  width: min(92vw, 520px);
  max-height: min(86vh, 700px);
  overflow: auto;
  margin: max(7vh, 1rem) auto;
  background: linear-gradient(180deg, #124631 0%, #0a2a1b 100%);
  border: 2px solid rgba(231, 180, 90, 0.55);
  border-radius: 14px;
  padding: 0.85rem;
  color: var(--cream);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.summary-card {
  width: min(92vw, 460px);
  padding: 1rem;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(245, 196, 81, 0.25);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
}

.settings-header h2,
.summary-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  font-size: 1.25rem;
  color: var(--gold-bright);
}

.summary-card h2 {
  margin-bottom: 0.55rem;
}

.popup-close {
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--cream-dim);
  font: inherit;
  font-weight: 800;
  font-size: 1.15rem;
  width: 1.9rem;
  height: 1.9rem;
  cursor: pointer;
}

.popup-close:hover {
  color: var(--cream);
}

.settings-grid {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.6rem;
}

.setting {
  display: grid;
  gap: 0.35rem;
  font-weight: 700;
  color: var(--cream);
}

.setting input[type="range"],
.setting select {
  width: 100%;
}

.setting input[type="checkbox"],
.setting input[type="range"] {
  accent-color: var(--gold);
}

.setting select {
  border: 1px solid var(--glass-line);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font: inherit;
  background: var(--glass);
  color: var(--cream);
}

.setting-help {
  color: var(--cream-dim);
  font-size: 0.82rem;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* --- Book Scramble --- */

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

.scramble-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.puzzle-label,
.clock {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  color: var(--gold-bright);
  font-size: 1.15rem;
}

.clock {
  min-width: 3.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.progress {
  list-style: none;
  display: flex;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
}

.progress-dot {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 5px;
  border: 2px solid rgba(253, 246, 227, 0.3);
  background: rgba(6, 26, 17, 0.4);
}

.progress-dot.is-current {
  border-color: var(--gold-bright);
  box-shadow: 0 0 10px rgba(255, 215, 106, 0.55);
}

.progress-dot.is-clean {
  background: #2f9e5b;
  border-color: #8df0b4;
}

.progress-dot.is-hint {
  background: #d9a521;
  border-color: #ffd76a;
}

.progress-dot.is-skipped {
  background: #b8413a;
  border-color: #ff9b9b;
}

.start-panel,
.play-panel {
  margin-top: 1rem;
  padding: 1rem !important;
  border-radius: 16px !important;
  background: var(--glass) !important;
  border: 1px solid var(--glass-line) !important;
  text-align: center;
}

.start-copy {
  margin: 0 0 0.9rem;
  font-weight: 700;
}

.start-panel .start-action {
  font-family: var(--font-display);
  font-size: 1.3rem;
  letter-spacing: 0.07em;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.7rem 2.2rem;
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 5px 0 var(--gold-shadow), 0 0 26px rgba(245, 196, 81, 0.35);
}

.book-count {
  margin: 0 0 0.7rem;
  color: var(--cream-dim);
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --tile is set by game.js so the longest word fits on one line. */
.play-panel {
  --tile: 44px;
  --pool-tile: 44px;
}

.answer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem 1rem;
}

.answer-word {
  display: flex;
  gap: var(--tile-gap, 5px);
}

.pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  margin-top: 1.1rem;
}

.tile {
  width: var(--tile);
  height: calc(var(--tile) * 1.15);
  padding: 0;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: calc(var(--tile) * 0.58);
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 100ms ease;
}

.tile:disabled {
  opacity: 1;
  cursor: default;
}

.tile-slot {
  background: rgba(253, 246, 227, 0.14);
  border: 2px solid rgba(253, 246, 227, 0.4);
  color: var(--cream);
}

.tile-slot.is-empty {
  background: rgba(6, 26, 17, 0.35);
  border-style: dashed;
}

.tile-slot.is-locked {
  background: #d9a521;
  border-color: #ffd76a;
  color: #3a2508;
}

.tile-fixed {
  background: transparent;
  border: 2px solid transparent;
  color: var(--gold-bright);
}

.tile-pool {
  width: var(--pool-tile);
  height: calc(var(--pool-tile) * 1.15);
  font-size: calc(var(--pool-tile) * 0.58);
  background: linear-gradient(180deg, #fdf6e3 0%, #ecdcb4 100%);
  border: 2px solid var(--gold-deep);
  color: #3a2508;
  box-shadow: 0 3px 0 var(--gold-shadow);
}

.tile-pool:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--gold-shadow);
}

.tile-pool.is-used {
  background: rgba(6, 26, 17, 0.3);
  border: 2px dashed rgba(253, 246, 227, 0.2);
  box-shadow: none;
}

.tile:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 2px;
}

.answer.is-solved .tile-slot {
  background: #2f9e5b;
  border-color: #8df0b4;
  color: #fff;
}

.answer.is-skipped .tile-slot {
  background: #b8413a;
  border-color: #ff9b9b;
  color: #fff;
}

.answer.is-wrong .tile-slot {
  border-color: var(--bad-glow);
  animation: shake 320ms ease;
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.feedback {
  min-height: 1.3em;
  margin: 0.7rem 0 0;
  color: var(--gold-bright);
  font-weight: 800;
}

.play-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  margin-top: 0.6rem;
}

.play-actions button {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.55rem 0.8rem;
  min-height: 2.6rem;
  background: rgba(6, 26, 17, 0.55);
  color: var(--cream);
  border: 1px solid var(--glass-line);
  touch-action: manipulation;
}

.play-actions #skip-btn.is-armed {
  background: #b8413a;
  border-color: #ff9b9b;
  color: #fff;
}

.result-books {
  list-style: none;
  margin: 0.7rem auto 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
  justify-content: center;
  text-align: left;
}

.result-books li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
}

.result-books a {
  color: var(--gold-bright);
}

.help-list .mark {
  margin-right: 0.35rem;
}

.stats-extra {
  margin: 0.9rem 0 0.2rem;
  text-align: center;
  color: var(--cream-dim);
  font-weight: 700;
}

.stats-extra strong {
  color: var(--gold-bright);
}

.result-panel {
  margin-top: 1rem;
  padding: 1rem 1.1rem !important;
  border-radius: 16px !important;
  background: var(--glass) !important;
  border: 1px solid var(--glass-line) !important;
  text-align: center;
}

.result-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--gold-bright);
  font-size: 1.7rem;
}

.result-copy {
  margin: 0.4rem 0;
  font-weight: 700;
}

.result-learn a {
  color: var(--gold-bright);
  font-weight: 800;
}

.result-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.result-actions button,
.help-modal-play {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  background: var(--glass);
  color: var(--cream);
  border: 1px solid var(--glass-line);
}

.result-actions .start-action,
#help-play-btn {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.05em;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 4px 0 var(--gold-shadow);
}

.share-status {
  min-height: 1.2em;
  margin: 0.6rem 0 0;
  white-space: pre-line;
  color: var(--cream-dim);
  font-weight: 600;
}

.next-puzzle {
  margin: 0.3rem 0 0;
  color: var(--cream-dim);
  font-weight: 700;
}

.help-list {
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.55rem;
}

.settings-profile-row,
.theme-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--glass-line);
  background: var(--glass);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  text-align: center;
}

.stats-row p {
  margin: 0;
  display: grid;
}

.stats-row strong {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.8rem;
  color: var(--gold-bright);
}

.stats-row span {
  font-size: 0.78rem;
  color: var(--cream-dim);
  font-weight: 700;
}

.challenge-banner {
  margin: 0.8rem 0 0;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 215, 106, 0.2), rgba(255, 215, 106, 0.08));
  border: 2px solid rgba(255, 215, 106, 0.6);
  color: var(--gold-bright);
  font-weight: 800;
  text-align: center;
}

.help-challenge {
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 215, 106, 0.55);
  color: var(--gold-bright);
  font-weight: 800;
}

.share-card {
  width: min(94vw, 560px);
}

.share-image {
  display: block;
  width: min(100%, 300px);
  aspect-ratio: 1;
  margin: 0 auto 0.7rem;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.share-text {
  margin: 0 0 0.8rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: rgba(6, 26, 17, 0.6);
  border: 1px solid var(--glass-line);
  font: 700 0.9rem/1.35 "Outfit", system-ui, sans-serif;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: all;
  color: var(--cream);
}

.share-native {
  display: block;
  width: 100%;
  margin-bottom: 0.7rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  background: linear-gradient(180deg, var(--gold-bright) 0%, #efa93d 100%);
  color: #4a2a08;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 4px 0 var(--gold-shadow);
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.share-target {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.8rem;
  padding: 0.5rem 0.6rem;
  border-radius: 12px;
  font: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  color: #fff;
  background: rgba(253, 246, 227, 0.12);
  border: 1px solid rgba(253, 246, 227, 0.3);
}

.share-target[hidden] {
  display: none;
}

.share-target:hover,
.share-target:focus-visible {
  filter: brightness(1.12);
  outline: 2px solid var(--gold-bright);
  outline-offset: 1px;
}

.share-x { background: #000; border-color: #444; }
.share-facebook { background: #1877f2; border-color: #1877f2; }
.share-whatsapp { background: #1fa855; border-color: #1fa855; }
.share-reddit { background: #ff4500; border-color: #ff4500; }

.share-facebook span {
  font-family: Georgia, serif;
  font-weight: 900;
}

@media (max-width: 560px) {
  .stats-row strong {
    font-size: 1.4rem;
  }

  .share-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .play-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .start-panel,
  .play-panel {
    padding: 0.8rem 0.6rem !important;
  }
}
