/* Admin Panel Styles */
.admin-container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 2rem;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #667eea;
}

.admin-header h1 {
  margin: 0;
  color: #667eea;
}

.notice {
  background: #48c774;
  color: white;
  padding: 1rem;
  border-radius: 5px;
  margin-bottom: 1rem;
}

.errors {
  background: #f14668;
  color: white;
  padding: 1rem;
  border-radius: 5px;
  margin-bottom: 1rem;
}

.errors ul {
  margin: 0.5rem 0 0 1.5rem;
}

/* Table Styles */
.bingos-table {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

thead {
  background: #667eea;
  color: white;
}

th, td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
}

tbody tr:hover {
  background: #f5f5f5;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Form Styles */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #333;
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #ddd;
  border-radius: 5px;
  font-size: 1rem;
  font-family: inherit;
}

.form-control:focus {
  border-color: #667eea;
}

.form-control-small {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 3px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
}

.form-control-small:focus {
  border-color: #667eea;
}

small {
  display: block;
  margin-top: 0.25rem;
  color: #666;
  font-size: 0.875rem;
}

.help-text {
  color: #666;
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

/* Cells Grid */
.cells-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1rem;
  background: #f9f9f9;
  border-radius: 5px;
}

.cell-input {
  display: flex;
  flex-direction: column;
}

.cell-input label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #667eea;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #667eea;
  color: white;
}

.btn-primary:hover {
  background: #5568d3;
}

.btn {
  background: #e0e0e0;
  color: #333;
}

.btn:hover {
  background: #d0d0d0;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn-small:hover {
  background: #5568d3;
}

.btn-danger {
  background: #f14668;
}

.btn-danger:hover {
  background: #e03456;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid #e0e0e0;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #667eea;
}

.header h1 {
  margin: 0;
  color: #667eea;
}

.back-link {
  padding: 0.75rem 1.5rem;
  background: #667eea;
  color: white;
  text-decoration: none;
  border-radius: 5px;
  font-weight: 600;
  transition: all 0.2s ease;
  display: inline-block;
}

.back-link:hover {
  background: #5568d3;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Live Preview Styles */
.preview-and-settings-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: start;
}

.color-settings-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  order: 1;
}

/*
 * Scoped to .admin-container, which is what these rules were written for.
 * admin.css is bundled on every page by application.css's require_tree, and
 * the dashboard bingo builder reuses the same .settings-card markup on the
 * design system's dark surface. Unscoped, these rules out-specified the
 * .kb- components inside them and broke three things at once:
 *
 *   - `.settings-card label` (0,1,1) beat `.kb-swatch` (0,1,0), so
 *     `display: block` won over `inline-flex`; the chip <span>s stayed
 *     `display: inline`, where width/height do not apply to a non-replaced
 *     box, and all 28 named colour chips rendered 2px x 18px instead of
 *     20x20 — a colour picker with no visible colours.
 *   - `.settings-card small` beat `.kb-hint`, putting #666 on --kb-surface:
 *     2.84:1, a hard WCAG 1.4.3 failure on six hint texts.
 *   - `.settings-card-title` beat components.css's zero-specificity heading
 *     default, putting #667eea on --kb-surface: 4.45:1 at 16px/700.
 *
 * Every admin page that uses .settings-card is inside .admin-container
 * (admin/bingos/new.html.erb and edit.html.erb both wrap the shared form in
 * one), so the admin rendering is unchanged; the builder is not, so it now
 * gets its own .kb- components. Prefer extending this scope over widening it
 * again — the builder styles itself in its own block.
 */
.admin-container .settings-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.2s ease;
}

.admin-container .settings-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.admin-container .settings-card-title {
  font-size: 16px;
  font-weight: 700;
  color: #667eea;
  margin: 0 0 1rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #667eea;
}

.admin-container .settings-card .form-group {
  margin-bottom: 1rem;
}

.admin-container .settings-card .form-group:last-child {
  margin-bottom: 0;
}

.admin-container .settings-card label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 0.25rem;
  display: block;
}

.admin-container .settings-card small {
  font-size: 12px;
  color: #666;
}

.preview-section {
  background: #f8f9fa;
  padding: 1.5rem;
  border-radius: 12px;
  position: sticky;
  top: 20px;
  order: 2;
}

.preview-container {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  border-radius: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.3s ease;
}

.preview-card {
  background: #f8f9ff;
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.preview-image-placeholder {
  flex-shrink: 0;
  width: 80px;
  height: 100px;
}

.preview-image-placeholder svg {
  width: 100%;
  height: 100%;
}

.preview-header-text {
  flex: 1;
  text-align: center;
}

.preview-title {
  font-size: 20px;
  font-weight: 700;
  color: #667eea;
  margin-bottom: 4px;
  transition: color 0.3s ease;
}

.preview-subtitle {
  font-size: 12px;
  color: #666;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.preview-cell {
  aspect-ratio: 1;
  background: #f9f9f9;
  border: 2px solid #ddd;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  color: #333;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

.preview-cell span {
  z-index: 1;
  position: relative;
}

.preview-cell.scratched span {
  opacity: 0;
}

.preview-cell.scratched::before,
.preview-cell.scratched::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 6px;
}

.preview-cell.scratched::before {
  background: rgba(102, 126, 234, 0.4);
  background-image: linear-gradient(45deg, rgba(102, 126, 234, 0.3) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(102, 126, 234, 0.3) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(102, 126, 234, 0.3) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(102, 126, 234, 0.3) 75%);
  background-size: 8px 8px;
  z-index: 2;
}

.preview-cell.scratched::after {
  background: rgba(102, 126, 234, 0.2);
  background-image: linear-gradient(-45deg, rgba(102, 126, 234, 0.2) 25%, transparent 25%),
    linear-gradient(45deg, rgba(102, 126, 234, 0.2) 25%, transparent 25%);
  background-size: 10px 10px;
  z-index: 3;
}

.preview-progress-section {
  text-align: center;
}

.preview-progress-label {
  font-size: 14px;
  font-weight: 900;
  color: #667eea;
  margin-bottom: 10px;
  transition: color 0.3s ease;
}

.preview-progress-wrapper {
  display: flex;
  align-items: center;
  padding-left: 20px;
}

.preview-progress-circle {
  width: 36px;
  height: 36px;
  background: white;
  border: 3px solid #667eea;
  border-radius: 50%;
  margin-right: -18px;
  z-index: 1;
  transition: border-color 0.3s ease;
}

.preview-progress-bar-container {
  flex: 1;
  height: 24px;
  background: white;
  border: 3px solid #667eea;
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.3s ease;
}

.preview-progress-bar {
  height: 100%;
  width: 12%;
  background: #667eea;
  border-radius: 10px;
  transition: background 0.3s ease;
}

/* Responsive */
@media (max-width: 768px) {
  .admin-container {
    margin: 0;
    padding: 1rem;
    border-radius: 0;
  }

  .admin-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

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

  table {
    font-size: 0.875rem;
  }

  th, td {
    padding: 0.5rem;
  }

  .actions {
    flex-direction: column;
  }
}

/* Publish Status Toggle */
.publish-status-group {
  background: #e8f5e9;
  border: 2px solid #4caf50;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}

.publish-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.publish-toggle .form-check-input {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.publish-toggle .form-check-label {
  font-weight: 600;
  font-size: 1.1rem;
  color: #2e7d32;
  cursor: pointer;
  margin: 0;
}

.publish-status-group small {
  display: block;
  margin-top: 0.5rem;
  color: #666;
}
/*
 * Shared components. Built only from tokens.css — no literal colour, radius or
 * shadow values below this line.
 *
 * One interaction idiom, "the press", is shared by every raised element and is
 * the only motion in the design.
 */

.kb-page {
  min-height: 100vh;
  /*
   * body keeps its legacy 20px padding (application.css) because dashboard and
   * admin still depend on it, so a dark wrapper placed inside it renders as a
   * purple frame with a colour seam at the viewport fold. Cancel the gutter
   * with a negative margin — never `width: 100%`, which adds the 40px straight
   * back and produces a horizontal scrollbar. The wrappers that are not
   * .kb-page (.bingos-index, .lp) do the same in their own view <style>
   * blocks, because application.css's `require_self` puts its legacy
   * `.bingos-index { margin: 0 auto }` after this file and would win at equal
   * specificity.
   */
  margin: calc(var(--kb-body-gutter) * -1);
  background: var(--kb-canvas);
  color: var(--kb-body);
  font-family: var(--kb-font-body);
  line-height: var(--kb-leading-body);
}

.kb-container {
  max-width: var(--kb-container);
  margin: 0 auto;
  padding: 0 var(--kb-space-4);
}

/*
 * :where() contributes zero specificity, which is load-bearing here. Written as
 * `.kb-page h1` this rule scores (0,1,1) and beats any single-class component
 * selector like `.settings-card-title` (0,1,0) — so every component that styles
 * a heading has to out-specify the base instead of simply overriding it. That
 * trap has already cost three separate patches in this project. At (0,0,0)
 * these are true defaults: any component class wins by being a class at all.
 */
:where(.kb-page) :where(h1, h2, h3) {
  font-family: var(--kb-font-display);
  color: var(--kb-ink);
  line-height: var(--kb-leading-display);
}

/* --- The press -------------------------------------------------------- */

.kb-raised {
  border: 2px solid var(--kb-primary-deep);
  box-shadow: var(--kb-shadow);
  transition: var(--kb-transition);
}

.kb-raised:hover {
  transform: translate(-1px, -1px);
  box-shadow: var(--kb-shadow-hover);
}

.kb-raised:active {
  transform: translate(2px, 2px);
  box-shadow: var(--kb-shadow-active);
}

.kb-raised:focus-visible,
.kb-btn:focus-visible,
.kb-chip:focus-visible,
.kb-search input:focus-visible {
  outline: 2px solid var(--kb-cta);
  outline-offset: 2px;
}

/* --- Buttons ---------------------------------------------------------- */

.kb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--kb-space-2);
  padding: var(--kb-space-3) var(--kb-space-5);
  border: 2px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-sm);
  box-shadow: var(--kb-shadow);
  transition: var(--kb-transition);
  font-family: var(--kb-font-body);
  font-size: var(--kb-text-sm);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: var(--kb-surface);
  color: var(--kb-ink);
}

.kb-btn:hover { transform: translate(-1px, -1px); box-shadow: var(--kb-shadow-hover); }
.kb-btn:active { transform: translate(2px, 2px); box-shadow: var(--kb-shadow-active); }

.kb-btn--primary { background: var(--kb-primary); color: #fff; }
.kb-btn--cta { background: var(--kb-cta); color: var(--kb-canvas); }

/*
 * The CTA's edge inside the nav only.
 *
 * Scoped deliberately. Elsewhere the --kb-primary-deep ring is load-bearing:
 * bingos/_actions.html.erb puts this same button on the creator's card, whose
 * card_color accepts custom:#hex, so the yellow fill can land on an arbitrary
 * — even yellow — surface and the border is the only thing delimiting the
 * control (WCAG 1.4.11). Inside the nav that is not so: the button sits on the
 * chrome, never the page, where the fill alone measures 8.52:1 at worst across
 * every gradient. There the ring is decoration, so it can follow the page.
 *
 * (0,2,0) beats .kb-btn's (0,1,0) — this project has been bitten three times by
 * assuming a single-class selector wins.
 */
.kb-nav .kb-btn--cta {
  border-color: var(--kb-chrome-cta-edge, var(--kb-primary-deep));
  box-shadow: 4px 4px 0 var(--kb-chrome-cta-edge, var(--kb-primary-deep));
}
/* The hard offset shadow carries the same colour, so it needs the same
 * treatment or the purple simply reappears on hover. (0,3,0) over .kb-btn's
 * (0,2,0). The offsets restate --kb-shadow's geometry because a custom
 * property cannot be partially overridden; if those px values ever change in
 * tokens.css, change them here too. */
.kb-nav .kb-btn--cta:hover  { box-shadow: 5px 5px 0 var(--kb-chrome-cta-edge, var(--kb-primary-deep)); }
.kb-nav .kb-btn--cta:active { box-shadow: 2px 2px 0 var(--kb-chrome-cta-edge, var(--kb-primary-deep)); }
.kb-btn--ghost { background: transparent; border-color: var(--kb-muted); color: var(--kb-body); box-shadow: none; }
/* The nav's height is set by its tallest child, which is a button (45px at
 * --kb-space-3). Trimming only the bar's padding would leave it bloated, so
 * the buttons and the pill links shrink with it. Still well above the 24px
 * WCAG 2.5.8 target minimum. */
.kb-nav .kb-navgroup a { padding-block: var(--kb-space-2); }

/* On the play page's glass the bar is 55% transparent, so --kb-body (#A9A3C0)
 * and --kb-muted (#8D88A8) are midtones that cannot reach 4.5:1 / 3:1 over the
 * lighter gradients. Scoped to .kb-nav so ghost buttons elsewhere are untouched. */
.kb-nav .kb-btn--ghost {
  color: var(--kb-chrome-ink, var(--kb-body));
  border-color: var(--kb-chrome-control-edge, var(--kb-muted));
}
.kb-btn--ghost:hover { transform: none; box-shadow: none; border-color: var(--kb-ink); color: var(--kb-ink); }

/*
 * Ghost button for light surfaces — the creator's bingo card. --kb-body is
 * tuned for the dark canvas and drops to ~2:1 on every card_background_value,
 * so this variant takes dark ink and borrows the creator's accent for its
 * border, which is what the card was designed around.
 */
.kb-btn--ghost-light {
  background: transparent;
  border-color: var(--main-color, var(--kb-primary-deep));
  color: var(--kb-canvas);
  box-shadow: none;
}

.kb-btn--ghost-light:hover {
  transform: none;
  box-shadow: none;
  background: rgba(var(--main-color-rgb, 98, 72, 201), 0.08);
}

.kb-btn--block { display: flex; width: 100%; }

/* --- Cards ------------------------------------------------------------ */

.kb-card {
  background: var(--kb-surface);
  border: 2px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-md);
  box-shadow: var(--kb-shadow);
  padding: var(--kb-space-5);
}

.kb-card--tinted { background: var(--kb-accent, var(--kb-primary-bright)); }

.kb-character-card {
  display: flex;
  flex-direction: column;
  gap: var(--kb-space-3);
  background: var(--kb-surface);
  border: 2px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-md);
  box-shadow: var(--kb-shadow);
  padding: var(--kb-space-3);
  transition: var(--kb-transition);
  text-decoration: none;
}

.kb-character-card:hover { transform: translate(-1px, -1px); box-shadow: var(--kb-shadow-hover); }

/*
 * Uploaded artwork often has a white or light background, which glares on a
 * dark card. Seating every image in its own light tile makes inconsistent
 * source images look deliberate and needs no reprocessing of uploads.
 */
.kb-character-card__tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--kb-radius-sm);
  background: #F3E9FF;
  overflow: hidden;
}

.kb-character-card__tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/*
 * text-align is declared here deliberately. Until now the only thing centring
 * this text was the legacy `.bingos-index { text-align: center }` in
 * application.css, which reads as dead and would take the whole grid with it
 * if someone deleted it.
 */
.kb-character-card__name,
.kb-character-card__meta {
  text-align: center;
}

.kb-character-card__name {
  font-family: var(--kb-font-display);
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--kb-ink);
  margin: 0;
}

.kb-character-card__meta {
  font-size: var(--kb-text-xs);
  color: var(--kb-muted);
  margin: 0;
}

/* --- Badge, chip, stat ------------------------------------------------ */

.kb-badge {
  position: absolute;
  top: var(--kb-space-2);
  right: var(--kb-space-2);
  padding: var(--kb-space-1) var(--kb-space-2);
  border-radius: var(--kb-radius-pill);
  background: var(--kb-badge);
  color: var(--kb-canvas);
  font-size: 0.6875rem;
  font-weight: 700;
}

.kb-chip {
  display: inline-flex;
  align-items: center;
  padding: var(--kb-space-2) var(--kb-space-4);
  border: 1px solid var(--kb-muted);
  border-radius: var(--kb-radius-pill);
  background: var(--kb-surface);
  color: var(--kb-body);
  font-size: 0.8125rem;
  text-decoration: none;
  white-space: nowrap;
}

.kb-chip.is-active {
  background: var(--kb-primary);
  border-color: var(--kb-primary);
  color: #fff;
}

.kb-chiprow {
  display: flex;
  gap: var(--kb-space-2);
  overflow-x: auto;
  padding-bottom: var(--kb-space-2);
  scrollbar-width: none;
}

.kb-chiprow::-webkit-scrollbar { display: none; }

.kb-stat {
  display: inline-flex;
  align-items: center;
  gap: var(--kb-space-2);
  padding: var(--kb-space-2) var(--kb-space-4);
  border: 1px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-pill);
  background: var(--kb-surface);
  font-size: var(--kb-text-sm);
  color: var(--kb-body);
}

.kb-stat strong { color: var(--kb-ink); font-weight: 700; }

/* --- Search ----------------------------------------------------------- */

.kb-search {
  display: flex;
  align-items: center;
  gap: var(--kb-space-2);
  padding: var(--kb-space-2);
  padding-left: var(--kb-space-4);
  border: 2px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-pill);
  background: var(--kb-surface);
}

.kb-search svg { flex: none; color: var(--kb-muted); }

.kb-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--kb-ink);
  font-family: var(--kb-font-body);
  font-size: var(--kb-text-base);
  padding: var(--kb-space-2);
}

.kb-search input::placeholder { color: var(--kb-muted); }
/*
 * Suppress only the UA ring for pointer focus. Plain `:focus` here would
 * outrank `.kb-search input:focus-visible` above at equal specificity by
 * source order and cancel the brand ring for keyboard users.
 */
.kb-search input:focus:not(:focus-visible) { outline: none; }

.kb-search button {
  flex: none;
  border: 0;
  border-radius: var(--kb-radius-pill);
  background: var(--kb-primary);
  color: #fff;
  font-family: var(--kb-font-body);
  font-weight: 600;
  font-size: var(--kb-text-sm);
  padding: var(--kb-space-3) var(--kb-space-5);
  cursor: pointer;
}

/* --- Nav and footer --------------------------------------------------- */

/*
 * Both nav and footer set their own font-family: bingos/show.html.erb renders
 * them as direct children of <body>, outside any .kb-page / .bingos-index /
 * .lp wrapper, so anything they inherit from a wrapper is missing there.
 */
.kb-nav {
  display: flex;
  font-family: var(--kb-font-body);
  align-items: center;
  justify-content: space-between;
  gap: var(--kb-space-4);
  max-width: var(--kb-container);
  margin: 0 auto var(--kb-space-6);
  padding: var(--kb-space-3) var(--kb-space-5);
  /*
   * The nav sets its own typography instead of inheriting the page's. It was
   * inheriting line-height 1.6 on the Devise pages and `normal` everywhere
   * else, which made the same bar 160px on /users/sign_in and 148px on / at
   * 390px. A shared component that changes size depending on which page hosts
   * it is a component in name only.
   */
  font-size: var(--kb-text-base);
  line-height: 1.4;
  /* Glass chrome.
   * --kb-chrome-bg is set only by the play page, which paints the body with the
   * creator's chosen gradient. Everywhere else the fallback keeps today's
   * opaque surface, so the dark public pages and the dashboard are unchanged.
   * 0.82 alpha is not a taste choice: at 0.72 the footer's muted text measured
   * 2.65:1 over the orange gradient's #fee140 stop, below AA. See show.html.erb. */
  background: var(--kb-chrome-bg, var(--kb-surface));
  backdrop-filter: var(--kb-chrome-blur, none);
  -webkit-backdrop-filter: var(--kb-chrome-blur, none);
  border: 2px solid var(--kb-chrome-border, var(--kb-primary-deep));
  border-radius: var(--kb-radius-md);
}

.kb-nav__brand {
  display: flex;
  align-items: center;
  gap: var(--kb-space-3);
  color: var(--kb-ink);
  text-decoration: none;
  font-family: var(--kb-font-display);
  font-weight: 700;
}

.kb-nav__tagline {
  display: block;
  font-family: var(--kb-font-body);
  font-weight: 400;
  font-size: var(--kb-text-xs);
  color: var(--kb-chrome-ink, var(--kb-muted));
}

.kb-navgroup {
  display: flex;
  gap: var(--kb-space-1);
  padding: var(--kb-space-1);
  border: 1px solid var(--kb-chrome-border, var(--kb-primary-deep));
  border-radius: var(--kb-radius-pill);
}

.kb-navgroup a {
  padding: var(--kb-space-2) var(--kb-space-4);
  border-radius: var(--kb-radius-pill);
  color: var(--kb-chrome-ink, var(--kb-body));
  text-decoration: none;
  font-size: var(--kb-text-sm);
  font-weight: 500;
}

.kb-navgroup a.is-active { background: var(--kb-primary); color: #fff; }

.kb-nav__actions { display: flex; gap: var(--kb-space-2); align-items: center; }

.kb-footer {
  background: var(--kb-chrome-bg, var(--kb-canvas));
  backdrop-filter: var(--kb-chrome-blur, none);
  -webkit-backdrop-filter: var(--kb-chrome-blur, none);
  font-family: var(--kb-font-body);
  max-width: var(--kb-container);
  margin: var(--kb-space-8) auto var(--kb-chrome-gap, 0);
  padding: var(--kb-space-5) var(--kb-space-4);
  /* Longhand, so the play page can turn a top rule into a full rounded frame
   * by setting --kb-chrome-side-w. A `border` shorthand here would reset
   * whichever side was declared after it. */
  border-top: var(--kb-chrome-edge-w, 1px) solid var(--kb-chrome-border, var(--kb-primary-deep));
  border-right: var(--kb-chrome-side-w, 0) solid var(--kb-chrome-border, var(--kb-primary-deep));
  border-bottom: var(--kb-chrome-side-w, 0) solid var(--kb-chrome-border, var(--kb-primary-deep));
  border-left: var(--kb-chrome-side-w, 0) solid var(--kb-chrome-border, var(--kb-primary-deep));
  border-radius: var(--kb-chrome-radius, 0);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--kb-space-4);
  color: var(--kb-chrome-ink, var(--kb-muted));
  font-size: var(--kb-text-sm);
}

.kb-footer__social { display: flex; gap: var(--kb-space-2); }

.kb-footer__social a {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--kb-radius-pill);
  background: var(--kb-chrome-control-bg, var(--kb-surface));
  color: var(--kb-chrome-ink, var(--kb-body));
}

/*
 * The nav wraps to three rows on a phone — brand, actions, pill — and at
 * 16px gaps plus 12px padding that came to 170px, with another 32px of margin
 * under it. On the builder that is 200px of chrome before the page's own
 * heading, which pushed the first colour swatch to y=887 on an 844px screen:
 * you landed on a colour step and could not see a single colour.
 *
 * Same token-with-fallback shape as the play page, so the values show.html.erb
 * sets still win there.
 */
/*
 * One nav geometry per breakpoint, for every page.
 *
 * This had drifted into four different bars: 148px on /, 160px on
 * /users/sign_in, 89px on a card, and a fifth shape in the builder — because
 * the compaction had been applied page by page as each complaint came up.
 * Sizing belongs to the breakpoint. Only the SURFACE varies by page, and only
 * on the play page, where the creator's gradient is behind it.
 */
@media (max-width: 720px) {
  .kb-nav {
    gap: var(--kb-space-2);
    padding: var(--kb-space-2) var(--kb-space-3);
    margin-bottom: var(--kb-space-4);
  }

  /* --kb-space-5 is desktop-sized here: at 390px it made the actions 237px
   * against 326px of usable width, so brand and actions could not share a
   * row. */
  .kb-nav .kb-btn {
    padding: var(--kb-space-2) var(--kb-space-3);
  }

  /*
   * The Browse/Create pill is hidden on phones on every page, not on some.
   * An existing @media (max-width: 900px) rule gives it width: 100%, so it
   * always takes a row of its own — that row is a third of the bar. Browse
   * stays reachable from the brand, which links home, and from the footer's
   * search link. Navigation that appears on one page and not another is worse
   * than navigation that is consistently one tap further away.
   */
  .kb-navgroup { display: none; }
}

/* --- Section heading -------------------------------------------------- */

.kb-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--kb-space-4);
  margin: var(--kb-space-7) 0 var(--kb-space-4);
}

.kb-section-head h2 {
  display: flex;
  align-items: center;
  gap: var(--kb-space-2);
  margin: 0;
  font-size: var(--kb-text-xl);
}

/* --- Responsive ------------------------------------------------------- */

@media (max-width: 900px) {
  .kb-nav { flex-wrap: wrap; justify-content: center; text-align: center; }
  .kb-navgroup { order: 3; width: 100%; justify-content: center; }
  .kb-nav__tagline { display: none; }
}

@media (max-width: 560px) {
  .kb-footer { flex-direction: column; text-align: center; }
  .kb-search { flex-wrap: wrap; border-radius: var(--kb-radius-md); }
  .kb-search button { width: 100%; }
}

/* --- Reduced motion --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .kb-raised,
  .kb-btn,
  .kb-character-card {
    transition: none;
  }

  .kb-raised:hover,
  .kb-btn:hover,
  .kb-character-card:hover,
  .kb-raised:active,
  .kb-btn:active {
    transform: none;
  }
}

/* --- Forms -------------------------------------------------------------- */

.kb-field { margin-bottom: var(--kb-space-5); }

.kb-label {
  display: block;
  margin-bottom: var(--kb-space-2);
  color: var(--kb-body);
  font-family: var(--kb-font-body);
  font-size: var(--kb-text-sm);
  font-weight: 600;
}

.kb-input,
.kb-select,
.kb-textarea {
  width: 100%;
  padding: var(--kb-space-3) var(--kb-space-4);
  border: 2px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-sm);
  background: var(--kb-canvas);
  color: var(--kb-ink);
  font-family: var(--kb-font-body);
  font-size: var(--kb-text-base);
}

.kb-textarea { resize: vertical; }

.kb-input::placeholder,
.kb-textarea::placeholder { color: var(--kb-muted); }

.kb-input:focus-visible,
.kb-select:focus-visible,
.kb-textarea:focus-visible {
  outline: 2px solid var(--kb-cta);
  outline-offset: 2px;
}

.kb-hint {
  display: block;
  margin-top: var(--kb-space-2);
  color: var(--kb-muted);
  font-size: var(--kb-text-xs);
}

.kb-fieldset {
  border: 2px solid var(--kb-primary-deep);
  border-radius: var(--kb-radius-md);
  padding: var(--kb-space-5);
  margin: 0 0 var(--kb-space-5);
}

.kb-fieldset > legend {
  padding: 0 var(--kb-space-3);
  color: var(--kb-ink);
  font-family: var(--kb-font-display);
  font-size: var(--kb-text-lg);
}

/* --- Colour swatches ---------------------------------------------------- */

.kb-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--kb-space-2);
}

/*
 * The radio itself stays in the accessibility tree and keeps native keyboard
 * behaviour — arrow keys move within the group — but is visually replaced by
 * the chip. Never display:none it: that removes it from the tab order and
 * reintroduces the defect this component exists to fix.
 */
/*
 * The border and the darker fill are both load-bearing. A swatch sits on
 * --kb-surface containers, so a transparent border and a --kb-surface fill left
 * the control with no visible boundary at all — measured 1.00:1 against its own
 * card. WCAG 1.4.11 asks for 3:1 between a component's boundary and adjacent
 * colour, and of the candidates only --kb-muted clears it (4.82:1); a
 * --kb-canvas fill alone is 1.17:1. The fill is kept as well because it reads
 * as an inset control and lifts the label from 6.74:1 to 7.86:1.
 */
.kb-swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--kb-space-2);
  padding: var(--kb-space-2) var(--kb-space-3);
  border: 2px solid var(--kb-muted);
  border-radius: var(--kb-radius-pill);
  background: var(--kb-canvas);
  color: var(--kb-body);
  font-size: var(--kb-text-xs);
  cursor: pointer;
}

.kb-swatch input[type="radio"] {
  position: absolute;
  opacity: 0;
  /* inset, not width/height: with no offsets the box stayed at its static
   * position — inside the label's padding — and 100% of the padding box then
   * ran 6px past the label's right edge. Harmless while the gap between pills
   * is wider than the overhang, but it is a hit area in the wrong place. */
  inset: 0;
  margin: 0;
  cursor: pointer;
}

/*
 * position/z-index are load-bearing. The radio above is a transparent overlay
 * covering the whole label, and the custom swatch puts an <input type="color">
 * inside that same label — without this the radio swallows every click and the
 * colour picker can never be opened with a mouse.
 */
/*
 * `display: block` is load-bearing too, not redundant with the swatch's
 * inline-flex. A chip is a <span>, and width/height are ignored on a
 * non-replaced inline box — so any ancestor rule that stops .kb-swatch being a
 * flex container (admin.css's `.settings-card label { display: block }` did
 * exactly that, and collapsed all 28 chips to 2px x 18px) silently un-sizes
 * every chip. Declaring the display here makes the chip's geometry independent
 * of what container it lands in.
 */
.kb-swatch__chip {
  position: relative;
  z-index: 1;
  display: block;
  width: 20px;
  height: 20px;
  border-radius: var(--kb-radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: none;
}

.kb-swatch:has(input:checked) {
  border-color: var(--kb-cta);
  color: var(--kb-ink);
}

.kb-swatch:has(input:focus-visible) {
  outline: 2px solid var(--kb-cta);
  outline-offset: 2px;
}
/*
 * Design tokens. Values only — no selectors beyond :root.
 *
 * The --kb- prefix is load-bearing: bingos/show.html.erb injects creator-chosen
 * colours as --main-color, --card-background and --scratch-color-rgb into its
 * own :root block. The prefix keeps design-system values and creator values in
 * separate namespaces.
 */
:root {
  /* Surfaces */
  --kb-canvas: #0D0F1F;
  --kb-surface: #1A1D3E;

  /* Text */
  --kb-ink: #F5F3FF;
  --kb-body: #A9A3C0;
  --kb-muted: #8D88A8;

  /* Brand */
  --kb-primary: #6248C9;
  --kb-primary-bright: #785AF3; /* FILL ONLY — 4.12:1 on canvas, unsafe as text */
  --kb-primary-deep: #4A38A0;
  --kb-link: #9179F8;           /* link text: 5.70:1 canvas, 4.88:1 surface */
  --kb-cta: #FBD34C;
  --kb-badge: #E4B044;

  /* Hero glow. Needs alpha, so it cannot be derived from the opaque tokens. */
  --kb-glow-purple: rgba(120, 90, 243, 0.28);
  --kb-glow-teal: rgba(63, 185, 169, 0.18);

  /* Card accents */
  --kb-accent-green: #3DA963;
  --kb-accent-teal: #3FB9A9;
  --kb-accent-magenta: #B362B8;
  --kb-accent-coral: #BB4F51;
  --kb-accent-gold: #E4B044;

  /* Type */
  --kb-font-display: 'Fredoka', system-ui, sans-serif;
  --kb-font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --kb-text-xs: 0.75rem;    /* 12 */
  --kb-text-sm: 0.875rem;   /* 14 */
  --kb-text-base: 1rem;     /* 16 */
  --kb-text-lg: 1.25rem;    /* 20 */
  --kb-text-xl: 1.5625rem;  /* 25 */
  --kb-text-2xl: 1.9375rem; /* 31 */
  --kb-text-3xl: 2.4375rem; /* 39 */
  --kb-text-4xl: 3.5rem;    /* 56 */
  --kb-leading-body: 1.6;
  --kb-leading-display: 1.15;
  --kb-measure: 65ch;

  /* Space, 4px base */
  --kb-space-1: 4px;
  --kb-space-2: 8px;
  --kb-space-3: 12px;
  --kb-space-4: 16px;
  --kb-space-5: 24px;
  --kb-space-6: 32px;
  --kb-space-7: 48px;
  --kb-space-8: 64px;

  /* Radius */
  --kb-radius-sm: 10px;
  --kb-radius-md: 14px;
  --kb-radius-pill: 999px;

  /* The signature device: a hard, unblurred offset shadow. */
  --kb-shadow: 4px 4px 0 var(--kb-primary-deep);
  --kb-shadow-hover: 5px 5px 0 var(--kb-primary-deep);
  --kb-shadow-active: 2px 2px 0 var(--kb-primary-deep);

  --kb-transition: transform 0.12s ease, box-shadow 0.12s ease;

  --kb-container: 1200px;

  /*
   * Mirrors the legacy `body { padding: 20px }` in application.css, which
   * dashboard and admin still rely on. The dark public wrappers cancel it with
   * a negative margin of this size so the canvas reaches the viewport edge.
   */
  --kb-body-gutter: 20px;
}
/*


 */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  min-height: 100%;
  min-height: -webkit-fill-available;
  background: #667eea;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--screenshot-background, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
  background-attachment: fixed;
  background-size: cover;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: 20px;
  color: #333;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* Hide nav in screenshot mode */
body.screenshot-mode .kb-nav {
  display: none !important;
}

/* Index Page */
.bingos-index {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
  color: white;
}

/*
 * Legacy. The restyled hero overrides font-size in the view; the text-shadow
 * this rule used to carry was still landing on the new headline and has been
 * removed rather than left to be inherited by accident.
 */
.bingos-index h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.bingos-index > p {
  font-size: 1.2rem;
  margin-bottom: 3rem;
  opacity: 0.9;
}

.bingos-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.bingo-card {
  background: white;
  border-radius: 15px;
  padding: 2rem;
  text-decoration: none;
  color: #333;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.bingo-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
}

.bingo-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 1rem;
}

.bingo-card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--main-color, #667eea);
}

/* Bingo Show Page */
.bingo-container {
  max-width: 800px;
  margin: 0 auto;
  background: var(--card-background, #f8f9ff);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.bingo-header {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
}

.character-image {
  width: 300px;
  height: 300px;
  object-fit: cover;
  flex-shrink: 0;
}

.bingo-header-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.bingo-header h1 {
  font-size: 3rem;
  color: var(--main-color, #667eea);
  margin-bottom: 0.5rem;
  margin-top: 0;
}

.bingo-header p {
  margin: 0;
  /*
   * Derived per card: card_color accepts custom:#hex, so this text can land on
   * a dark or mid-luminance surface. Bingo#card_ink_muted keeps #666 wherever
   * it already meets AA and only substitutes where it does not, so cards that
   * were already legible are unchanged. The fallback matches the old value.
   */
  color: var(--card-ink-muted, #666);
  font-size: 1.1rem;
}

/* Layout: Classic centered (header_centered) */
.layout-header-centered .bingo-header {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.layout-header-centered .character-image {
  margin-bottom: 1.5rem;
}

/* Layout: Sidebar layouts (sidebar_left and sidebar_right) */
.layout-sidebar-left .bingo-container,
.layout-sidebar-right .bingo-container {
  display: flex;
  position: relative;
}

.layout-sidebar-left .bingo-main,
.layout-sidebar-right .bingo-main {
  flex: 1;
  position: relative;
  z-index: 2;
}

.layout-sidebar-left .character-image,
.layout-sidebar-right .character-image {
  width: 400px;
  height: 600px;
  object-fit: cover;
  object-position: top;
  position: sticky;
  top: 20px;
  flex-shrink: 0;
  z-index: 1;
}

/* Screenshot mode - colorful background wrapper with fixed aspect ratio */
body.screenshot-mode > div:not(.screenshot-loading) {
  background: var(--screenshot-background, linear-gradient(135deg, #667eea 0%, #764ba2 100%)) !important;
  padding: 2rem !important;
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  width: 940px !important;
  min-height: 1175px !important;
  box-sizing: border-box !important;
}

/* Ensure loading overlay stays full screen even in screenshot mode */
body.screenshot-mode .screenshot-loading {
  width: 100vw !important;
  height: 100vh !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
}

/* Screenshot mode - white card */
body.screenshot-mode .bingo-container {
  width: 900px !important;
  max-width: 900px !important;
  min-width: 900px !important;
  padding: 2rem !important;
  position: relative !important;
  display: block !important;
  background: #f8f9ff !important;
  border-radius: 20px !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
  margin: 0 !important;
}

/* Reset all positioning */
body.screenshot-mode .bingo-header,
body.screenshot-mode .character-image,
body.screenshot-mode .bingo-main,
body.screenshot-mode .bingo-grid,
body.screenshot-mode .progress-section {
  position: relative !important;
}

/* Header - default horizontal layout */
body.screenshot-mode .bingo-header {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 2rem !important;
  margin-bottom: 2rem !important;
}

body.screenshot-mode .character-image {
  width: 300px !important;
  height: auto !important;
  max-height: 400px !important;
  object-fit: contain !important;
  flex-shrink: 0 !important;
}

body.screenshot-mode .bingo-header-text {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  text-align: center !important;
}

body.screenshot-mode .bingo-header h1 {
  font-size: 3rem !important;
  line-height: 1.2 !important;
  margin: 0 0 0.5rem 0 !important;
}

body.screenshot-mode .bingo-header p {
  font-size: 1.1rem !important;
  line-height: 1.4 !important;
  margin: 0 !important;
}

/* Grid */
body.screenshot-mode .bingo-grid {
  display: grid !important;
  gap: 10px !important;
  margin-bottom: 2rem !important;
}

body.screenshot-mode .bingo-cell {
  min-height: 100px !important;
  padding: 8px !important;
}

body.screenshot-mode .cell-text {
  font-size: 1.2rem !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
}

/* Progress section */
body.screenshot-mode .progress-section {
  margin-bottom: 0 !important;
}

body.screenshot-mode .progress-label {
  font-size: 1.8rem !important;
  font-weight: 900 !important;
}

body.screenshot-mode .progress-text {
  font-size: 1.1rem !important;
}

body.screenshot-mode .progress-bar-wrapper {
  position: relative !important;
  padding-left: 30px !important;
}

body.screenshot-mode .progress-bar {
  position: relative !important;
  height: 40px !important;
}

body.screenshot-mode .progress-bar::before {
  position: absolute !important;
  left: -30px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  width: 60px !important;
  height: 60px !important;
}

body.screenshot-mode .progress-fill::before {
  left: -30px !important;
  width: 60px !important;
  height: 60px !important;
}

body.screenshot-mode .breakpoint-marker {
  height: 50px !important;
}

body.screenshot-mode .progress-status-label {
  font-size: 1.1rem !important;
  top: 68% !important;
}

/* Left sidebar: Image overlaps 50% into grid area */
.layout-sidebar-left .bingo-container {
  flex-direction: row;
}

.layout-sidebar-left .character-image {
  margin-right: -200px; /* 50% of image width */
}

.layout-sidebar-left .bingo-main {
  padding-left: 2rem;
}

/* Right sidebar: Image overlaps 50% into grid area */
.layout-sidebar-right .bingo-container {
  flex-direction: row-reverse;
}

.layout-sidebar-right .character-image {
  margin-left: -200px; /* 50% of image width */
}

.layout-sidebar-right .bingo-main {
  padding-right: 2rem;
}

.layout-sidebar-left .bingo-header,
.layout-sidebar-right .bingo-header {
  flex-direction: column;
  text-align: center;
}

/* Bingo Grid */
.bingo-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 2rem;
}

.bingo-cell {
  aspect-ratio: 1;
  border: 2px solid #ddd;
  border-radius: 10px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #f9f9f9;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.bingo-cell:hover {
  background: #f0f0f0;
  transform: scale(1.05);
  border-color: var(--main-color, #667eea);
}

.bingo-cell.selected {
  background: #f9f9f9;
  border-color: var(--main-color, #667eea);
}

.scratch-layer-1,
.scratch-layer-2 {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
  background-size: 10px 10px;
  background-repeat: repeat;
  z-index: 1;
}

/* Diagonal Stripes Pattern (Default) */
.scratch-layer-1 {
  background-image:
    linear-gradient(45deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px 0px, 0px 0px;
}

.scratch-layer-2 {
  background-image:
    linear-gradient(-45deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 25%, transparent 25%),
    linear-gradient(45deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 25%, transparent 25%),
    linear-gradient(-45deg, transparent 75%, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 75%),
    linear-gradient(45deg, transparent 75%, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px 0px, 0px 0px;
}

.bingo-cell.selected .scratch-layer-1,
.bingo-cell.selected .scratch-layer-2 {
  opacity: 1;
}

.bingo-cell.selected .scratch-layer-1 {
  animation: scratch 0.4s ease-out;
}

.bingo-cell.selected .scratch-layer-2 {
  animation: scratch 0.4s ease-out 0.1s;
}

@keyframes scratch {
  from {
    opacity: 0;
    transform: scale(0.8) rotate(-5deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

/* Dots Pattern */
.scratch-style-dots .scratch-layer-1 {
  background-image: radial-gradient(circle, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.4) 2px, transparent 2px);
  background-size: 8px 8px;
  background-position: 0 0;
}

.scratch-style-dots .scratch-layer-2 {
  background-image: radial-gradient(circle, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.25) 1.5px, transparent 1.5px);
  background-size: 8px 8px;
  background-position: 4px 4px;
}

/* Circles Pattern */
.scratch-style-circles .scratch-layer-1 {
  background-image: radial-gradient(circle, transparent 3px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 3px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 5px, transparent 5px);
  background-size: 12px 12px;
  background-position: 0 0;
}

.scratch-style-circles .scratch-layer-2 {
  background-image: radial-gradient(circle, transparent 2px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 2px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 4px, transparent 4px);
  background-size: 12px 12px;
  background-position: 6px 6px;
}

/* Crosshatch Pattern */
.scratch-style-crosshatch .scratch-layer-1 {
  background-image:
    linear-gradient(0deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 1px, transparent 1px);
  background-size: 10px 10px;
  background-position: 0 0;
}

.scratch-style-crosshatch .scratch-layer-2 {
  background-image:
    linear-gradient(45deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 1px, transparent 1px),
    linear-gradient(-45deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 1px, transparent 1px);
  background-size: 8px 8px;
  background-position: 0 0;
}

/* Waves Pattern */
.scratch-style-waves .scratch-layer-1 {
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 3px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.3) 6px);
  background-size: 100% 12px;
}

.scratch-style-waves .scratch-layer-2 {
  background-image:
    repeating-linear-gradient(90deg, transparent, transparent 3px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 3px, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.2) 6px);
  background-size: 12px 100%;
}

/* Grid Pattern */
.scratch-style-grid .scratch-layer-1 {
  background-image:
    linear-gradient(0deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.35) 1px, transparent 1px);
  background-size: 12px 12px;
  background-position: 0 0;
}

.scratch-style-grid .scratch-layer-2 {
  background-image:
    linear-gradient(0deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--scratch-color-rgb, 102, 126, 234), 0.15) 1px, transparent 1px);
  background-size: 6px 6px;
  background-position: 0 0;
}

.cell-text {
  font-size: 1.4rem;
  font-weight: 700;
  z-index: 2;
  line-height: 1.15;
  padding: 0;
  position: relative;
  word-break: keep-all;
  overflow-wrap: normal;
  white-space: normal;
  max-width: 100%;
  max-height: 100%;
  display: block;
  overflow: hidden;
  text-align: center;
}

.cell-text:has(+ *) {
  font-size: clamp(0.9rem, 1.4rem, 1.4rem);
}

@supports not (selector(:has(*))) {
  .bingo-cell {
    font-size: 1.4rem;
  }

  .bingo-cell[data-long-text] .cell-text {
    font-size: 1.1rem;
  }
}

/* Progress Section */
.progress-section {
  margin-bottom: 2rem;
}

.progress-label {
  text-align: center;
  font-weight: 900;
  color: var(--main-color, #667eea);
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  text-transform: capitalize;
}

.progress-bar-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  padding-left: 30px;
}

.progress-bar {
  position: relative;
  width: 100%;
  height: 40px;
  background: white;
  border-radius: 20px;
  overflow: visible;
  border: 3px solid var(--main-color, #667eea);
}

.progress-bar::before {
  content: '';
  position: absolute;
  left: -30px;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  background: white;
  border-radius: 50%;
  border: 3px solid var(--main-color, #667eea);
  z-index: 0;
}

.progress-fill {
  position: relative;
  height: 100%;
  background: var(--main-color, #667eea);
  width: 0%;
  transition: width 0.5s ease;
  border-radius: 18px;
  z-index: 2;
}

.progress-fill::before {
  content: '';
  position: absolute;
  left: -30px;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  background: white;
  border-radius: 50%;
  border: 3px solid var(--main-color, #667eea);
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.progress-fill.has-progress::before {
  background: var(--main-color, #667eea);
  opacity: 1;
}

.progress-circle {
  display: none;
}

.progress-breakpoint {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.breakpoint-marker {
  width: 2px;
  height: 50px;
  background: var(--main-color, #667eea);
  margin: 0 auto;
  opacity: 0.3;
}

.progress-status-label {
  position: absolute;
  top: 58%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  font-weight: 900;
  color: white;
  white-space: nowrap;
  z-index: 4;
  pointer-events: none;
  -webkit-text-stroke: 5px var(--main-color, #667eea);
  text-stroke: 5px var(--main-color, #667eea);
  paint-order: stroke fill;
}

.progress-text {
  text-align: center;
  font-weight: bold;
  color: var(--main-color, #667eea);
  font-size: 1.1rem;
}

/* Screenshot Loading Overlay */
.screenshot-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  background: rgb(102, 126, 234);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.loading-content {
  text-align: center;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.loading-content p {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 1.5rem 0 0 0;
  animation: pulse 1.5s ease-in-out infinite;
  text-align: center;
  white-space: nowrap;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* Actions */
.actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
}

.btn {
  padding: 1rem 2rem;
  border: none;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-block;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 5px 15px rgba(var(--main-color-rgb, 102, 126, 234), 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(var(--main-color-rgb, 102, 126, 234), 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-pinterest {
  background: #E60023;
  color: white;
  box-shadow: 0 4px 12px rgba(230, 0, 35, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 200px;
}

.btn-pinterest:hover {
  background: #BD081C;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(230, 0, 35, 0.4);
}

.btn-pinterest:active {
  transform: translateY(0);
}

.btn-pinterest:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  background: #E60023;
}

.btn-pinterest svg {
  flex-shrink: 0;
}

.btn-create {
  background: transparent;
  color: rgb(var(--main-color-rgb, 102, 126, 234));
  border: 2px solid rgb(var(--main-color-rgb, 102, 126, 234));
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  text-decoration: none;
  text-align: center;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-create:hover {
  background: rgb(var(--main-color-rgb, 102, 126, 234));
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(var(--main-color-rgb, 102, 126, 234), 0.35);
}

.btn-create:active {
  transform: translateY(0);
}

.btn-create:focus-visible {
  outline: 2px solid rgb(var(--main-color-rgb, 102, 126, 234));
  outline-offset: 2px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .bingo-container {
    padding: 1rem;
  }

  .bingo-grid {
    gap: 5px;
  }

  /*
   * Cells grow to their text on phones.
   *
   * A 5x5 grid at 390px gives 60px cells, 48px of that usable once padding is
   * taken. `.cell-text` caps itself at max-height: 100% with overflow: hidden,
   * so anything needing a fourth line was silently cut off mid-sentence —
   * measured across five published cards, 20 of 116 cells (17%), and 11 of 25
   * on one of them. Published cells run to 94 characters with a median of 31,
   * so this was never going to fit a fixed square.
   *
   * aspect-ratio is dropped rather than the font shrunk to nothing: rows
   * stretch to their tallest cell, so a card with long traits gets taller
   * instead of unreadable. min-height keeps short cells square-ish.
   */
  .bingo-cell {
    padding: 4px;
    aspect-ratio: auto;
    min-height: 60px;
    height: auto;
  }

  .cell-text {
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.2;
    max-height: none;
    overflow: visible;
    /* The base rule sets word-break: keep-all / overflow-wrap: normal, which in
     * a 60px column lets one long word run out of the cell sideways.
     *
     * break-word, not anywhere: `anywhere` counts break points when working out
     * the minimum width, so it split words that would have fitted whole and
     * produced "relationsh / ips" and "misunder / stood". break-word only
     * splits a word that genuinely cannot fit, and hyphens marks the split so
     * it reads as a hyphenation rather than a mistake. */
    overflow-wrap: break-word;
    hyphens: auto;
  }

  /*
   * Only the centred layout stacks.
   *
   * This rule used to be unscoped, so every layout stacked and centred on
   * mobile — which made "Current (Image left in header)" render identically to
   * "Classic (Image centered above)". Whatever the creator chose, phones showed
   * the same card, and 194 of 195 bingos are header_horizontal, so almost every
   * card on the site was being drawn as a layout nobody picked.
   */
  /* 2rem under the header is desktop spacing; on a phone it is a sixth of the
   * room the grid needs to land on the first screen. */
  .bingo-header { margin-bottom: 1.25rem; }

  .layout-header-centered .bingo-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  /* Genuinely side by side, with an image small enough to leave the title room
   * at 390px — at the 200px used elsewhere the text got about 118px and wrapped
   * to shreds, which is presumably why this was stacked in the first place. */
  .layout-header-horizontal .bingo-header {
    flex-direction: row;
    align-items: center;
    text-align: left;
    gap: 1rem;
  }

  .layout-header-horizontal .character-image {
    width: 120px;
    height: 150px;
    max-height: 150px;
    flex-shrink: 0;
  }

  /* At 320px a 120px image plus the 1rem gap pushed the title 7px out of the
   * header. Shrink the image rather than stack, so the chosen layout still
   * holds on the narrowest phones. */
  @media (max-width: 360px) {
    .layout-header-horizontal .bingo-header { gap: 0.5rem; }
    .layout-header-horizontal .character-image {
      width: 88px;
      height: 110px;
      max-height: 110px;
    }
  }

  .character-image {
    width: 200px;
    height: 250px;
    max-height: 250px;
    object-fit: cover;
    object-position: top;
  }

  .bingo-header h1 {
    font-size: 1.5rem;
  }

  /* Mobile: Stack sidebar layouts vertically */
  .layout-sidebar-left .bingo-container,
  .layout-sidebar-right .bingo-container {
    flex-direction: column;
    align-items: center;
  }

  .layout-sidebar-left .character-image,
  .layout-sidebar-right .character-image {
    width: 200px;
    height: auto;
    max-height: 300px;
    margin: 0 0 1.5rem 0;
    position: relative;
  }

  /* A sidebar beside a 5-column grid does not fit 390px, so both stack — but
   * they then looked identical too. Ordering the image after the grid keeps the
   * left/right choice legible instead of discarding it. */
  .layout-sidebar-right .character-image {
    order: 2;
    margin: 1.5rem 0 0;
  }

  .layout-sidebar-left .bingo-main,
  .layout-sidebar-right .bingo-main {
    padding: 0;
    width: 100%;
  }

  .progress-bar-wrapper {
    padding-left: 20px;
  }

  .progress-bar {
    height: 30px;
  }

  .progress-bar::before {
    left: -20px;
    width: 45px;
    height: 45px;
  }

  .progress-fill::before {
    left: -20px;
    width: 45px;
    height: 45px;
  }

  .progress-label {
    font-size: 1.4rem;
    font-weight: 900;
  }

  .breakpoint-marker {
    height: 35px;
  }

  .progress-status-label {
    font-size: 0.9rem;
  }
}
