/* Bookle. Base chrome (palette, body, header, actions, modals) copied from book-number-blitz/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;
  }
}

/* --- Bookle --- */

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

.bookle-badge {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  font-size: 2.2rem;
  border-radius: 14px;
  background: var(--glass);
  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);
}

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

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

.bookle-legend,
.bookle-row {
  display: grid;
  grid-template-columns: minmax(7rem, 1.3fr) 0.7fr 1.4fr 0.9fr 0.9fr;
  gap: 0.4rem;
  align-items: stretch;
}

.bookle-legend {
  margin-top: 0.7rem;
  padding: 0 0.1rem;
  color: var(--cream-dim);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bookle-board {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.bookle-row {
  min-height: 2.9rem;
  animation: row-in 260ms ease-out;
}

.bookle-row.is-empty {
  display: block;
  border: 1px dashed var(--glass-line);
  border-radius: 10px;
  background: rgba(6, 26, 17, 0.3);
  animation: none;
}

.row-book {
  display: flex;
  align-items: center;
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  font-weight: 800;
  color: var(--cream);
}

.bookle-row.is-correct .row-book {
  border-color: var(--good-glow);
  box-shadow: 0 0 14px rgba(141, 240, 180, 0.45);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.3rem 0.4rem;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.85rem;
  line-height: 1.15;
  border: 2px solid transparent;
}

.chip-exact {
  background: #2f9e5b;
  border-color: #8df0b4;
  color: #fff;
}

.chip-near {
  background: #d9a521;
  border-color: #ffd76a;
  color: #3a2508;
}

.chip-far {
  background: rgba(253, 246, 227, 0.12);
  border-color: rgba(253, 246, 227, 0.25);
  color: var(--cream);
}

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

.guess-panel {
  margin-top: 1rem;
}

.guess-form {
  display: flex;
  gap: 0.5rem;
}

.guess-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 2px solid var(--glass-line);
  background: var(--glass);
  color: var(--cream);
}

.guess-input::placeholder {
  color: var(--cream-dim);
}

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

.guess-btn {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  border-radius: 12px;
  padding: 0.6rem 1.1rem;
  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);
}

.suggestions {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.suggestion {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: var(--glass);
  color: var(--cream);
}

.suggestion:hover,
.suggestion:focus-visible {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
}

.feedback {
  min-height: 1.3em;
  margin: 0.5rem 0 0;
  color: var(--bad-glow);
  font-weight: 700;
}

.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;
}

.help-list .chip {
  min-width: 4.5rem;
  margin-right: 0.35rem;
}

.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(4, 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;
}

.dist-title {
  margin: 1rem 0 0.4rem;
  font-size: 1rem;
}

.distribution {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
}

.distribution li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.dist-label {
  width: 1rem;
  font-weight: 800;
}

.dist-bar {
  display: inline-block;
  text-align: right;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(253, 246, 227, 0.18);
  font-weight: 800;
}

.dist-bar.is-today {
  background: #2f9e5b;
}

@media (max-width: 560px) {
  .bookle-legend,
  .bookle-row {
    grid-template-columns: 1fr 1fr 1fr 1fr;
  }

  .bookle-legend span:first-child {
    display: none;
  }

  .row-book {
    grid-column: 1 / -1;
    padding: 0.25rem 0.6rem;
  }

  .chip {
    font-size: 0.78rem;
  }

  .stats-row strong {
    font-size: 1.4rem;
  }
}
