/* =================================================================
   BCDC Bingo — Stylesheet
   Discord-themed colour tokens, Bootstrap-inspired components.
   No external dependencies.
   ================================================================= */

/* ── Colour tokens ─────────────────────────────────────────────── */
:root {
  /* Discord Light */
  --c-bg:          #f2f3f5;
  --c-surface:     #ffffff;
  --c-surface-alt: #ebedef;
  --c-border:      #d4d7dc;
  --c-text:        #2e3338;
  --c-text-muted:  #747f8d;
  --c-accent:      #5865f2;
  --c-accent-h:    #4752c4;
  --c-selected:    #5865f2;
  --c-selected-fg: #ffffff;
  --c-free:        #4752c4;
  --c-free-fg:     #ffffff;
  --c-win:         #57f287;
  --c-win-fg:      #1a1a1a;
  --c-header-bg:   #5865f2;
  --c-header-fg:   #ffffff;
  --c-btn-ghost-bg:    transparent;
  --c-btn-ghost-border: var(--c-border);

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-sq: 0 1px 3px rgba(0, 0, 0, 0.06);
  --transition: 180ms ease;
}

[data-theme="dark"] {
  /* Discord Dark */
  --c-bg:          #313338;
  --c-surface:     #2b2d31;
  --c-surface-alt: #1e1f22;
  --c-border:      #3f4147;
  --c-text:        #dbdee1;
  --c-text-muted:  #949ba4;
  --c-accent:      #5865f2;
  --c-accent-h:    #7289da;
  --c-selected:    #5865f2;
  --c-selected-fg: #ffffff;
  --c-free:        #4752c4;
  --c-free-fg:     #c5c9ff;
  --c-win:         #57f287;
  --c-win-fg:      #0f2e1b;
  --c-header-bg:   #404481;
  --c-header-fg:   #c5c9ff;
  --c-btn-ghost-bg:    rgba(255, 255, 255, 0.04);
  --c-btn-ghost-border: var(--c-border);

  --shadow:    0 2px 16px rgba(0, 0, 0, 0.35);
  --shadow-sq: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  background-color: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

a {
  color: var(--c-accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 680px;
  margin-inline: auto;
  padding: 2rem 1rem 3rem;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  cursor: pointer;
  user-select: none;
  line-height: 1.4;
  transition: background-color var(--transition),
              border-color var(--transition),
              box-shadow var(--transition),
              transform 100ms ease;
}
.btn:active { transform: scale(0.96); }
.btn:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

.btn-primary {
  background-color: var(--c-accent);
  border-color: var(--c-accent);
  color: #fff;
}
.btn-primary:hover {
  background-color: var(--c-accent-h);
  border-color: var(--c-accent-h);
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.35);
}

/* square icon button for theme toggle */
.btn-icon {
  background: var(--c-btn-ghost-bg);
  border-color: var(--c-btn-ghost-border);
  color: var(--c-text);
  padding: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  font-size: 1.1rem;
}
.btn-icon:hover {
  background: var(--c-surface-alt);
  border-color: var(--c-text-muted);
}

/* ── Header ────────────────────────────────────────────────────── */
header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

/* board selector + new game button */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
  flex-wrap: wrap;
}

.board-select-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* custom caret via pseudo-element so it respects CSS token colours */
.board-select-wrapper::after {
  content: '';
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--c-text-muted);
  pointer-events: none;
}

.board-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.5rem 2.25rem 0.5rem 0.875rem;
  font-size: 0.9375rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.4;
  transition: border-color var(--transition), background-color var(--transition),
              box-shadow var(--transition);
}

.board-select:hover {
  border-color: var(--c-text-muted);
}

.board-select:focus {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
  border-color: var(--c-accent);
}

#game-title {
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--c-text);
  transition: color var(--transition);
}

/* ── Win banner ─────────────────────────────────────────────────── */
.win-banner {
  display: inline-block;
  background: var(--c-win);
  color: var(--c-win-fg);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.5rem 1.75rem;
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
  animation: pop 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hidden { display: none !important; }

@keyframes pop {
  from { transform: scale(0.75); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ── Bingo board ────────────────────────────────────────────────── */
.bingo-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: var(--c-surface-alt);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 5px;
  box-shadow: var(--shadow);
  max-width: 600px;
  margin-inline: auto;
  transition: border-color var(--transition);
}

/* B I N G O header row */
.bingo-header {
  background: var(--c-header-bg);
  color: var(--c-header-fg);
  font-size: clamp(1rem, 3vw, 1.4rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  user-select: none;
  transition: background-color var(--transition), color var(--transition);
}

/* ── Bingo squares ─────────────────────────────────────────────── */
.bingo-square {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 5px;
  /* scales with cell size across all viewports */
  font-size: clamp(0.65rem, 2vw, 0.8rem);
  font-weight: 500;
  line-height: 1.2;
  aspect-ratio: 1;
  /* safety net for long strings */
  overflow: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
  min-height: 56px; /* never drop below comfortable tap target */
  box-shadow: var(--shadow-sq);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color var(--transition),
              color var(--transition),
              border-color var(--transition),
              box-shadow var(--transition),
              transform 100ms ease;
}

.bingo-square:hover:not(.free) {
  background: var(--c-surface-alt);
  border-color: var(--c-text-muted);
}

.bingo-square:active:not(.free) {
  transform: scale(0.94);
}

.bingo-square.selected {
  background: var(--c-selected);
  color: var(--c-selected-fg);
  border-color: var(--c-selected);
  box-shadow: none;
}

.bingo-square.free {
  background: var(--c-free);
  color: var(--c-free-fg);
  border-color: var(--c-free);
  cursor: default;
  font-weight: 700;
  font-size: clamp(0.6rem, 1.3vw, 0.75rem);
  opacity: 0.9;
}

.bingo-square.win {
  background: var(--c-win) !important;
  color: var(--c-win-fg) !important;
  border-color: var(--c-win) !important;
  animation: winPulse 400ms ease;
}

@keyframes winPulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ── Footer ─────────────────────────────────────────────────────── */
footer {
  text-align: center;
  margin-top: 2rem;
  color: var(--c-text-muted);
  font-size: 0.8125rem;
}

footer a { color: var(--c-text-muted); }
footer a:hover { color: var(--c-accent); text-decoration: underline; }

/* subtle inline link button used in footer */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  color: var(--c-text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: color var(--transition), text-decoration-color var(--transition);
}
.btn-link:hover {
  color: var(--c-accent);
  text-decoration-color: var(--c-accent);
}

/* ── Creator panel ───────────────────────────────────────────────── */
.creator-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow-y: auto;
  animation: fadeIn 180ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.creator-inner {
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  margin-block: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  animation: slideUp 240ms cubic-bezier(0.34, 1.2, 0.64, 1);
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.creator-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 0;
}

.creator-hd h2 {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--c-text);
}

.creator-bd {
  padding: 1.125rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* ── Form fields ─────────────────────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-group label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 0.375rem;
  font-size: 0.75rem;
}

.hint-warn { color: var(--c-danger); }
.hint-ok   { color: var(--c-win);    }

.field-input,
.field-textarea {
  background: var(--c-surface-alt);
  color: var(--c-text);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field-input:focus,
.field-textarea:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.2);
}

.field-textarea {
  resize: vertical;
  min-height: 180px;
  font-size: 0.875rem;
  font-family: 'Menlo', 'Consolas', 'Courier New', monospace;
  line-height: 1.65;
}

/* ── Advanced options (details/summary) ─────────────────────────── */
.creator-advanced {
  border-top: 1px solid var(--c-border);
  padding-top: 0.75rem;
}

.creator-advanced summary {
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-text-muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.creator-advanced summary::before {
  content: '▶';
  font-size: 0.6rem;
  transition: transform var(--transition);
  display: inline-block;
}

.creator-advanced[open] summary::before {
  transform: rotate(90deg);
}

.creator-advanced-inner {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 0.75rem;
}

/* ── Error / result states ───────────────────────────────────────── */
.creator-error {
  background: rgba(237, 66, 69, 0.12);
  border: 1px solid var(--c-danger);
  color: var(--c-danger);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.creator-submit {
  width: 100%;
}

.creator-result {
  background: var(--c-surface-alt);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  animation: pop 260ms cubic-bezier(0.34, 1.4, 0.64, 1);
}

.creator-result-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.creator-link-row {
  display: flex;
  gap: 0.375rem;
}

.creator-link-input {
  flex: 1;
  font-family: 'Menlo', 'Consolas', 'Courier New', monospace;
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.creator-result-note {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  line-height: 1.4;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .bingo-board {
    gap: 3px;
    padding: 4px;
    border-radius: var(--radius);
  }

  .bingo-square {
    padding: 3px;
    border-radius: var(--radius-sm);
  }

  .bingo-header {
    height: 32px;
    border-radius: var(--radius-sm);
  }

  .container {
    padding-top: 1.25rem;
  }
}

/* ── Accessibility: reduced motion ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}
