/* Barble — public styles.
 *
 * Scoped under .gw-barble throughout so the module cannot restyle the theme
 * it is dropped into, and so the theme cannot accidentally restyle it.
 *
 * TYPOGRAPHY IS SET, NOT INHERITED. The prototype's look is a serif display
 * face against warm paper with sans-serif chrome, and inheriting the host
 * theme's font produced something that read as neither. The stack is a system
 * one, so nothing is downloaded.
 *
 * DARK IS OPT-IN, NOT AUTOMATIC. An earlier build switched on
 * `prefers-color-scheme`, which fires on the visitor's operating system
 * setting and has nothing to do with the page the module is embedded in — a
 * light site rendered black tiles against white for anyone whose laptop was
 * in dark mode. A host that is genuinely dark opts in with
 * `.gw-barble--dark`, or by putting `data-theme="dark"` on an ancestor.
 */

.gw-barble {
  /* Dark is the default: it is what the site it lives on wants. Light is the
     opt-in, via [barble theme="light"] or the on-page toggle, which persists
     the visitor's choice. */
  --gwb-ink: #ece7dc;
  --gwb-soft: #b3ab9c;
  --gwb-faint: #8b8477;
  --gwb-paper: #1a1917;
  --gwb-card: #232120;
  --gwb-rule: #3b3833;
  --gwb-rule-soft: #2c2a27;
  --gwb-hit: #7fce9c;
  --gwb-hit-bg: #22372a;
  --gwb-near: #e0b95e;
  --gwb-near-bg: #3a3120;
  --gwb-miss-bg: #2a2825;
  --gwb-accent: #e0834f;
  /* Text that sits ON the accent, and the recessed field background. Declared
     as variables because the previous approach re-declared backgrounds further
     down the file, and a later rule of equal specificity silently won —
     which is how "Copy result" ended up dark text on a dark button. */
  --gwb-on-accent: #201a15;
  --gwb-field: #14130f;

  --gwb-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Palladio, Georgia, serif;
  --gwb-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  max-width: 900px;
  margin: 0 auto;
  /* Tightened throughout so the three pictures and all six guess rows fit one
     screen. A player who has to scroll to see the board has lost the thing
     the board is for — comparing this guess against the last. */
  padding: 16px 14px 20px;
  background: var(--gwb-paper);
  color: var(--gwb-ink);
  font-family: var(--gwb-serif);
  font-size: 16px;
  line-height: 1.5;
  border-radius: 12px;
}

.gw-barble *, .gw-barble *::before, .gw-barble *::after { box-sizing: border-box; }

/* Any `display` declaration outranks the user-agent [hidden] rule, so every
   element this stylesheet lays out would ignore the attribute the script uses
   to hide it — the legend and the difficulty control both rendered on a board
   that had not loaded. One blanket rule instead of remembering per selector. */
.gw-barble [hidden] { display: none !important; }

.gw-barble__sr {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── Header ─────────────────────────────────────────────────────── */

.gw-barble__head { text-align: center; margin-bottom: 10px; }

.gw-barble__title {
  margin: 0;
  font-family: var(--gwb-serif);
  font-size: 27px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--gwb-ink);
}

.gw-barble__tagline {
  margin: 2px 0 0;
  font-family: var(--gwb-serif);
  font-size: 13px;
  color: var(--gwb-soft);
}

.gw-barble__meta {
  margin: 6px 0 0;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-family: var(--gwb-sans);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--gwb-faint);
}

.gw-barble__link {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: var(--gwb-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.gw-barble__link:hover { color: var(--gwb-ink); }

/* ── Difficulty ─────────────────────────────────────────────────── */

/* One row rather than a stacked label — the label is four words and was
   costing a whole line of height. */
.gw-barble__level {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 8px 0 10px;
  font-family: var(--gwb-sans);
}

.gw-barble__level-label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gwb-faint);
}

.gw-barble__level [role="radiogroup"] {
  display: inline-flex;
  border: 1px solid var(--gwb-rule);
  border-radius: 999px;
  padding: 2px;
  background: var(--gwb-card);
}

.gw-barble__level-btn {
  font-family: var(--gwb-sans);
  font-size: 12.5px;
  padding: 4px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--gwb-soft);
  cursor: pointer;
}

.gw-barble__level-btn[aria-checked="true"] {
  background: var(--gwb-accent);
  color: var(--gwb-on-accent);
  font-weight: 600;
}

.gw-barble__level-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Reveal panel ───────────────────────────────────────────────── */

.gw-barble__reveal { margin-bottom: 10px; }

.gw-barble__reveal-heading {
  margin: 0 0 5px;
  font-family: var(--gwb-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gwb-faint);
  text-align: center;
}

/* A quarter narrower than the board, centred. The tiles stay square, so
   trimming the width is what makes them shorter too. */
.gw-barble__slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  /* Capped in absolute terms as well as proportionally: on a wide screen a
     percentage alone made the tiles tall enough to push the board off. */
  max-width: min(70%, 420px);
  margin: 0 auto;
}

.gw-barble__slot {
  margin: 0;
  padding: 6px 5px 5px;
  background: var(--gwb-card);
  border: 1px solid var(--gwb-rule);
  border-radius: 10px;
  text-align: center;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(27, 26, 23, .06);
}

.gw-barble__slot.is-text { border-style: dashed; box-shadow: none; }
.gw-barble__slot.is-locked { background: transparent; border-style: dashed; box-shadow: none; }
.gw-barble__slot.is-sharp { border-color: rgba(47, 125, 79, .4); }

.gw-barble__frame {
  /* Square, so a maker's mark shows whole rather than being letterboxed by a
     wide frame. object-fit keeps a wide silhouette from stretching to fill it. */
  aspect-ratio: 1 / 1;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 4px;
  color: var(--gwb-ink);
  overflow: hidden;
}

.gw-barble__frame svg, .gw-barble__slot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: filter .45s ease;
}

.gw-barble__lock { font-size: 22px; opacity: .45; }

.gw-barble__slot-text {
  margin: 0;
  padding: 0 6px;
  font-family: var(--gwb-sans);
  font-size: 13px;
  line-height: 1.35;
  color: var(--gwb-ink);
}

.gw-barble__slot-label {
  display: block;
  margin-top: 3px;
  font-family: var(--gwb-sans);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gwb-faint);
}

.gw-barble__slot-note {
  display: block;
  font-family: var(--gwb-sans);
  font-size: 10px;
  color: var(--gwb-faint);
}

/* ── Guess form ─────────────────────────────────────────────────── */

.gw-barble__guess {
  background: var(--gwb-card);
  border: 1px solid var(--gwb-rule);
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 1px 2px rgba(27, 26, 23, .06), 0 6px 20px rgba(27, 26, 23, .05);
}

/* The field is captioned by its placeholder; the label stays for screen
   readers but costs no height. */
.gw-barble__label {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.gw-barble__row { display: flex; gap: 8px; align-items: flex-start; }
.gw-barble__field { position: relative; flex: 1 1 auto; min-width: 0; }

.gw-barble__input {
  width: 100%;
  font-family: var(--gwb-serif);
  font-size: 15px;
  padding: 8px 11px;
  border: 1px solid var(--gwb-rule);
  border-radius: 8px;
  background: var(--gwb-field);
  /* -webkit-text-fill-color as well as color: a theme that styles inputs, or
     an autofill, can otherwise leave the chosen hook name invisible against
     the dark field — which it did. */
  color: var(--gwb-ink);
  -webkit-text-fill-color: var(--gwb-ink);
  opacity: 1;
}

.gw-barble__input::placeholder {
  color: var(--gwb-faint);
  -webkit-text-fill-color: var(--gwb-faint);
  opacity: 1;
}

.gw-barble__input:focus {
  color: var(--gwb-ink);
  -webkit-text-fill-color: var(--gwb-ink);
  border-color: var(--gwb-accent);
}

.gw-barble__list {
  position: absolute;
  z-index: 20;
  inset: calc(100% + 4px) 0 auto 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--gwb-card);
  border: 1px solid var(--gwb-rule);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(27, 26, 23, .12);
}

.gw-barble__option {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
}

.gw-barble__option small {
  font-family: var(--gwb-sans);
  color: var(--gwb-faint);
  font-size: 11px;
  white-space: nowrap;
}

.gw-barble__option.is-used { opacity: .45; }
.gw-barble__option[aria-selected="true"], .gw-barble__option:hover { background: var(--gwb-rule-soft); }

.gw-barble__submit {
  font-family: var(--gwb-sans);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border: 1px solid var(--gwb-accent);
  border-radius: 8px;
  background: var(--gwb-accent);
  color: var(--gwb-on-accent);
  cursor: pointer;
  white-space: nowrap;
}

/* Disabled, not invisible: this is the state the button spends most of its
   life in, and faint-on-faint made it unreadable in light mode. */
.gw-barble__submit:disabled {
  background: var(--gwb-rule-soft);
  border-color: var(--gwb-rule);
  color: var(--gwb-soft);
  -webkit-text-fill-color: var(--gwb-soft);
  opacity: 1;
  cursor: not-allowed;
}

.gw-barble__help {
  margin: 6px 0 0;
  font-family: var(--gwb-sans);
  font-size: 12px;
  color: var(--gwb-faint);
}

/* ── Hints ──────────────────────────────────────────────────────── */

/* Five hints stacked two rows deep; as pills they wrap into one. */
.gw-barble__hints { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }

.gw-barble__hint {
  flex: 1 1 auto;
  font-family: var(--gwb-sans);
  font-size: 11.5px;
  line-height: 1.25;
  text-align: left;
  padding: 5px 9px;
  border: 1px dashed var(--gwb-rule);
  border-radius: 999px;
  background: transparent;
  color: var(--gwb-soft);
  cursor: pointer;
}

.gw-barble__hint strong { color: var(--gwb-ink); font-weight: 600; }
.gw-barble__hint:disabled { opacity: .55; cursor: not-allowed; }

/* Unlocked and unspent. These were easy to miss entirely — a dashed outline
   in the same colour as a locked one reads as decoration, not as a control. */
.gw-barble__hint.is-ready {
  border-style: solid;
  border-color: var(--gwb-accent);
  background: color-mix(in srgb, var(--gwb-accent) 14%, transparent);
  color: var(--gwb-ink);
}

.gw-barble__hint.is-ready strong { color: var(--gwb-accent); }

.gw-barble__hint.is-ready:hover {
  background: color-mix(in srgb, var(--gwb-accent) 26%, transparent);
}

/* Browsers without color-mix still get the accent outline above. */
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .gw-barble__hint.is-ready { background: transparent; }
}

.gw-barble__hint.is-open {
  border-style: solid;
  background: var(--gwb-card);
  color: var(--gwb-accent);
}

/* ── Board ──────────────────────────────────────────────────────── */

/* Wide content scrolls inside its own container; the page never does. */
.gw-barble__board-wrap { margin-top: 10px; overflow-x: auto; }

.gw-barble__board {
  border-collapse: separate;
  border-spacing: 3px;
  min-width: 600px;
  width: 100%;
  table-layout: fixed;
  background: transparent;
}

.gw-barble__board th {
  font-family: var(--gwb-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--gwb-faint);
  text-align: center;
  padding-bottom: 2px;
  border: 0;
  background: transparent;
}

.gw-barble__col-name { text-align: left; width: 150px; }

.gw-barble__cell {
  border-radius: 7px;
  padding: 5px 5px;
  text-align: center;
  vertical-align: middle;
  background: var(--gwb-miss-bg);
  border: 1px solid transparent;
  height: 42px;
}

.gw-barble__cell--name {
  text-align: left;
  background: var(--gwb-card);
  border-color: var(--gwb-rule);
  padding: 5px 8px;
  font-family: var(--gwb-sans);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--gwb-ink);
}

.gw-barble__cell--name small {
  display: block;
  color: var(--gwb-faint);
  font-size: 11px;
  font-weight: 400;
}

.gw-barble__cell.is-hit { background: var(--gwb-hit-bg); border-color: rgba(47, 125, 79, .35); }
.gw-barble__cell.is-near { background: var(--gwb-near-bg); border-color: rgba(154, 107, 18, .35); }
.gw-barble__cell.is-unknown { background: transparent; border: 1px dashed var(--gwb-rule); }

.gw-barble__value {
  display: block;
  font-family: var(--gwb-sans);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
}

.gw-barble__sub {
  display: block;
  font-family: var(--gwb-sans);
  font-size: 10.5px;
  color: var(--gwb-soft);
  margin-top: 1px;
}

.gw-barble__mark {
  display: block;
  font-family: var(--gwb-sans);
  font-size: 11px;
  font-weight: 700;
  margin-top: 2px;
}

.gw-barble__cell.is-hit .gw-barble__mark { color: var(--gwb-hit); }
.gw-barble__cell.is-near .gw-barble__mark { color: var(--gwb-near); }
.gw-barble__cell.is-miss .gw-barble__mark,
.gw-barble__cell.is-unknown .gw-barble__mark { color: var(--gwb-faint); }

.gw-barble__row--empty .gw-barble__cell {
  background: transparent;
  border: 1px dashed var(--gwb-rule-soft);
}

.gw-barble__hooklink {
  color: inherit;
  text-decoration: none;
  display: block;
}

.gw-barble__hooklink:hover { color: var(--gwb-accent); text-decoration: underline; }
.gw-barble__hooklink:hover small { color: var(--gwb-accent); }

.gw-barble__external {
  font-size: 9px;
  vertical-align: super;
  opacity: .6;
  margin-left: 2px;
}

/* ── Test mode ──────────────────────────────────────────────────── */

.gw-barble__test {
  margin: 0 0 8px;
  padding: 5px 10px;
  border: 1px solid var(--gwb-near);
  border-radius: 999px;
  background: var(--gwb-near-bg);
  color: var(--gwb-ink);
  font-family: var(--gwb-sans);
  font-size: 11.5px;
  text-align: center;
}

.gw-barble__test-btn {
  font: inherit;
  font-size: 11px;
  margin-left: 8px;
  padding: 2px 10px;
  border: 1px solid var(--gwb-near);
  border-radius: 999px;
  background: transparent;
  color: var(--gwb-ink);
  cursor: pointer;
}

.gw-barble__test-btn:hover { background: var(--gwb-card); }

/* ── Legend, status, outcome ────────────────────────────────────── */

.gw-barble__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 8px 0 0;
  font-family: var(--gwb-sans);
  font-size: 11px;
  color: var(--gwb-soft);
}

.gw-barble__legend > span { display: inline-flex; align-items: center; gap: 6px; }

.gw-barble__chip {
  display: inline-grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.gw-barble__chip.is-hit { background: var(--gwb-hit-bg); color: var(--gwb-hit); }
.gw-barble__chip.is-near { background: var(--gwb-near-bg); color: var(--gwb-near); }
.gw-barble__chip.is-miss { background: var(--gwb-miss-bg); color: var(--gwb-faint); }

.gw-barble__status {
  margin-top: 14px;
  font-family: var(--gwb-sans);
  font-size: 13px;
  color: var(--gwb-faint);
}

.gw-barble__outcome {
  margin-top: 22px;
  padding: 18px;
  background: var(--gwb-card);
  border: 1px solid var(--gwb-rule);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(27, 26, 23, .06), 0 6px 20px rgba(27, 26, 23, .05);
  text-align: center;
}

.gw-barble__outcome h3 {
  margin: 0 0 6px;
  font-family: var(--gwb-serif);
  font-size: 22px;
  color: var(--gwb-ink);
}

.gw-barble__outcome p { margin: 0 0 8px; font-size: 17px; }
.gw-barble__outcome strong { color: var(--gwb-accent); }

.gw-barble__summary {
  margin: 0 auto 14px;
  /* 46ch broke "Short (1X-2X Short)" across two lines with room to spare. */
  max-width: 72ch;
  text-wrap: balance;
  font-family: var(--gwb-sans);
  color: var(--gwb-soft);
  font-size: 14.5px;
}

.gw-barble__actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.gw-barble__btn {
  font-family: var(--gwb-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border: 1px solid var(--gwb-rule);
  border-radius: 8px;
  background: var(--gwb-field);
  color: var(--gwb-ink);
  cursor: pointer;
  text-decoration: none;
}

.gw-barble__btn:hover { border-color: var(--gwb-faint); }

.gw-barble__btn--primary {
  background: var(--gwb-accent);
  border-color: var(--gwb-accent);
  color: var(--gwb-on-accent);
}

/* ── Dialog ─────────────────────────────────────────────────────── */

/* Covered by the blanket [hidden] rule above; restated because the scrim is
   the one element where getting this wrong blocks the entire game. */
.gw-barble__sheet[hidden] { display: none !important; }

.gw-barble__sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(27, 26, 23, .5);
}

.gw-barble__panel {
  position: relative;
  width: min(480px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  padding: 22px;
  background: var(--gwb-card);
  color: var(--gwb-ink);
  font-family: var(--gwb-sans);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

.gw-barble__panel h3 {
  margin: 0 0 12px;
  font-family: var(--gwb-serif);
  font-size: 21px;
}

.gw-barble__close {
  position: absolute;
  top: 10px; right: 10px;
  width: 32px; height: 32px;
  font: inherit;
  border: 0;
  border-radius: 8px;
  background: var(--gwb-rule-soft);
  color: var(--gwb-soft);
  cursor: pointer;
}

.gw-barble__stats-heading {
  margin: 14px 0 6px;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gwb-faint);
}

.gw-barble__stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 0 10px;
  text-align: center;
}

.gw-barble__stats dt {
  grid-row: 2;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gwb-faint);
}

.gw-barble__stats dd {
  grid-row: 1;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.gw-barble__dist { display: grid; gap: 4px; }

.gw-barble__dist-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.gw-barble__dist-bar {
  background: var(--gwb-rule-soft);
  border-radius: 4px;
  padding: 2px 6px;
  text-align: right;
  color: var(--gwb-soft);
  min-width: 28px;
}

.gw-barble__archive-note { margin: 0 0 10px; font-size: 12px; color: var(--gwb-faint); }
.gw-barble__archive { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }

.gw-barble__archive-btn {
  width: 100%;
  font: inherit;
  font-size: 13px;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--gwb-rule);
  border-radius: 8px;
  background: transparent;
  color: var(--gwb-ink);
  cursor: pointer;
}

.gw-barble__archive-btn:hover { background: var(--gwb-rule-soft); }

/* Focus must stay visible for keyboard users even where a theme removes it. */
.gw-barble :focus-visible {
  outline: 2px solid var(--gwb-accent);
  outline-offset: 2px;
}

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .gw-barble__slots { max-width: 100%; }
  .gw-barble { padding: 14px 10px 20px; }
  .gw-barble__title { font-size: 32px; }
  .gw-barble__board { min-width: 560px; }
  .gw-barble__col-name { width: 120px; }
  .gw-barble__stats { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .gw-barble__frame svg, .gw-barble__slot-img { transition: none; }
}

/* ── Light, when asked for ──────────────────────────────────────── */

.gw-barble--light {
  --gwb-on-accent: #fff;
  --gwb-field: #faf7f0;
  --gwb-ink: #1b1a17;
  --gwb-soft: #5d574c;
  --gwb-faint: #8a8377;
  --gwb-paper: #faf7f0;
  --gwb-card: #fff;
  --gwb-rule: #ddd6c7;
  --gwb-rule-soft: #ece5d8;
  --gwb-hit: #2f7d4f;
  --gwb-hit-bg: #e3f2e8;
  --gwb-near: #9a6b12;
  --gwb-near-bg: #fbf0d6;
  --gwb-miss-bg: #f0ece2;
  --gwb-accent: #7a3410;
}

/* Nothing here re-declares a background: the variables above carry the theme,
   so a primary button cannot be overwritten by a later generic rule. */
