/* ============================================================
   Set Card Game — Shared Stylesheet
   ============================================================ */

/* ── Custom Properties ── */
:root {
  --color-red:    #C93030;
  --color-green:  #2A7A2A;
  --color-purple: #7040A0;

  --bg-table:     #2d5a27;
  --bg-table-alt: #3a6b32;

  --card-bg:      #ffffff;
  --card-border:  #ddd;
  --card-radius:  11px;
  --card-w:       108px;
  --card-h:       156px;
  --card-gap:     14px;

  --selected-color:   #2563eb;
  --selected-shadow:  0 0 0 3px #2563eb, 0 0 16px 4px rgba(37,99,235,0.45);

  --font-sans:   'Source Sans 3', system-ui, sans-serif;
  --font-serif:  'Playfair Display', Georgia, serif;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Base ── */
html {
  font-size: 16px;
  /* Prevent deal-in animation (which starts cards off-screen to the right)
     from triggering a horizontal scrollbar on Windows. Using html rather than
     body so that position:fixed elements (modals, toasts) are unaffected. */
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-table);
  background-image:
    radial-gradient(ellipse at 20% 20%, rgba(60,120,50,0.4) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(20,60,15,0.5) 0%, transparent 60%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 4px,
      rgba(0,0,0,0.04) 4px,
      rgba(0,0,0,0.04) 8px
    );
  min-height: 100vh;
  color: #f0ebe0;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── Site Header / Nav ── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: rgba(0,0,0,0.25);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-wrap: wrap;
  gap: 12px;
}

.site-header .logo {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  color: #f5e6c8;
  text-shadow: 1px 2px 6px rgba(0,0,0,0.5);
  letter-spacing: 0.5px;
}

.site-nav {
  display: flex;
  gap: 8px;
}

.site-nav a {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 7px 18px;
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,0.25);
  color: #d8efd4;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.site-nav a:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.4);
  color: #fff;
}

.site-nav a.active {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.5);
  color: #fff;
}

/* ── Page Content ── */
.page-content {
  padding: 28px 20px 48px;
  max-width: 1100px;
  margin: 0 auto;
}

/* ── Section Labels ── */
.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #88bb80;
  margin-bottom: 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(136,187,128,0.3);
}

/* ============================================================
   Card Component
   ============================================================ */
.card {
  width: var(--card-w);
  height: var(--card-h);
  background: var(--card-bg);
  border-radius: var(--card-radius);
  border: 1.5px solid var(--card-border);
  box-shadow:
    0 2px 4px rgba(0,0,0,0.15),
    0 6px 20px rgba(0,0,0,0.25),
    inset 0 1px 0 rgba(255,255,255,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 10px;
  cursor: pointer;
  transform: rotate(var(--card-rotate, 0deg));
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  position: relative;
}

.card svg {
  height: 38px;
  width: auto;
  display: block;
  overflow: visible;
}

.card:hover {
  transform: translateY(-3px) scale(1.03) rotate(var(--card-rotate, 0deg));
  box-shadow:
    0 4px 8px rgba(0,0,0,0.2),
    0 12px 32px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.8);
}

/* Selected state */
.card.selected {
  border-color: var(--selected-color);
  box-shadow: var(--selected-shadow);
  transform: translateY(-4px) scale(1.04) rotate(var(--card-rotate, 0deg));
}

/* Error flash — red pulse */
@keyframes flash-error {
  0%   { background: #fff; }
  20%  { background: #fde8e8; box-shadow: 0 0 0 3px #C93030, 0 0 16px 4px rgba(201,48,48,0.4); }
  60%  { background: #fde8e8; }
  100% { background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.15), 0 6px 20px rgba(0,0,0,0.25); }
}

.card.flash-error {
  animation: flash-error 0.6s ease forwards;
}

/* Original card hidden while clone flies — keeps grid space intact */
.card.flying {
  opacity: 0;
  pointer-events: none;
}

/* Deal-in animation — cards fly in from off-screen top-right (deck position).
   translate() is relative to the card's final grid slot, so 120vw guarantees
   the starting point is off-screen regardless of column position.
   transform does not affect layout, so no scrollbars are triggered. */
@keyframes card-deal-in {
  from {
    opacity: 0;
    transform: translate(120vw, -60vh) rotate(-20deg) scale(0.5);
  }
  to {
    opacity: 1;
    transform: rotate(var(--card-rotate, 0deg));
  }
}

.card.dealing {
  /* fill-mode "both": applies the `from` keyframe during the delay period so the
     card stays invisible and off-screen while waiting, not at its final position. */
  animation: card-deal-in 0.45s cubic-bezier(0.15, 0.85, 0.35, 1) both;
}

/* Score panel pulse when cards arrive */
@keyframes score-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.score-card.score-pulse {
  animation: score-pulse 0.35s ease-out forwards;
}

/* Hint highlight */
.card.hint {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px #f59e0b, 0 0 16px 4px rgba(245,158,11,0.45);
}

/* Hinted AND selected — orange inner ring, blue outer ring */
.card.hint.selected {
  border-color: var(--selected-color);
  box-shadow:
    0 0 0 2px #f59e0b,
    0 0 0 5px #2563eb,
    0 0 18px 4px rgba(37,99,235,0.4);
  transform: translateY(-4px) scale(1.04) rotate(var(--card-rotate, 0deg));
}

/* ============================================================
   Card Grid (play board)
   ============================================================ */
#board {
  display: grid;
  grid-template-columns: repeat(4, var(--card-w));
  gap: var(--card-gap);
  justify-content: center;
  margin-bottom: 24px;
}

/* ============================================================
   Controls Bar
   ============================================================ */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 24px;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 9px 22px;
  border-radius: 22px;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: #f5e6c8;
  color: #2d3a1e;
}

.btn-primary:hover {
  opacity: 0.88;
}

.btn-secondary {
  background: rgba(255,255,255,0.15);
  color: #f0ebe0;
  border: 1.5px solid rgba(255,255,255,0.25);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.22);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================================
   Score Panel
   ============================================================ */
.score-panel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.score-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 10px 20px;
  min-width: 100px;
  text-align: center;
}

#score-p1-card       { justify-self: start; }
#score-timer-card    { justify-self: center; }
#score-computer-card { justify-self: end; }

.score-card .player-name {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #88bb80;
  margin-bottom: 2px;
}

.difficulty-label {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #a8c8a0;
  margin-bottom: 4px;
}

.score-card .player-score {
  font-size: 2rem;
  font-weight: 700;
  color: #f5e6c8;
  line-height: 1;
}

.score-card .score-label {
  font-size: 0.7rem;
  color: #a8c8a0;
  margin-top: 2px;
}

.timer-display {
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Deck / Status Info
   ============================================================ */
.game-status {
  font-size: 0.8rem;
  color: #a8c8a0;
  margin-left: auto;
  align-self: center;
}

/* ============================================================
   Toast Notifications
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0);   }
  to   { opacity: 0; transform: translateY(-6px); }
}

.toast {
  background: rgba(20, 14, 4, 0.88);
  color: #f5e6c8;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 24px;
  padding: 10px 22px;
  font-size: 0.85rem;
  font-style: italic;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  animation: toast-in 0.22s ease forwards;
}

.toast.hiding {
  animation: toast-out 0.28s ease forwards;
}

/* ============================================================
   Game Over Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.hidden {
  display: none !important;
}

#pause-overlay {
  background: var(--bg-table);
}

.modal {
  background: #2a4a22;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 36px 40px;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal h2 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  color: #f5e6c8;
  margin-bottom: 16px;
}

.modal .final-scores {
  margin: 20px 0;
}

.modal .final-score-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 1rem;
  color: #d8efd4;
}

.modal .final-score-row:last-child {
  border-bottom: none;
}

.modal .winner-label {
  color: #f5e6c8;
  font-weight: 700;
}

.set-times-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #88bb80;
  margin: 14px 0 6px;
}

.set-times-breakdown {
  max-height: 160px;
  overflow-y: auto;
  border-top: 1px solid rgba(255,255,255,0.1);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding: 4px 0;
  margin-bottom: 4px;
}

.set-time-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 2px;
  font-size: 0.85rem;
  color: #d8efd4;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Mode & Difficulty Selection Modals
   ============================================================ */
.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}

.difficulty-btn {
  width: 100%;
}

/* ============================================================
   All Sets Overlay (play page)
   ============================================================ */
.sets-overlay-modal {
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
}

.sets-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.sets-overlay-header h2 {
  margin-bottom: 0;
}

.sets-overlay-close {
  padding: 5px 13px;
  font-size: 0.85rem;
  line-height: 1;
  flex-shrink: 0;
}

/* ============================================================
   Solve Page
   ============================================================ */
.solve-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
}

@media (min-width: 900px) {
  .solve-layout {
    grid-template-columns: 1fr 340px;
  }
}

.solve-board-area {
  min-height: 200px;
}

.solve-board {
  display: grid;
  grid-template-columns: repeat(4, var(--card-w));
  gap: var(--card-gap);
  min-height: 100px;
}

.solve-board-empty {
  grid-column: 1 / -1;
  color: #7aaa72;
  font-size: 0.875rem;
  padding: 20px 0;
  font-style: italic;
}

/* Sets results */
.sets-result-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.set-result-item {
  background: rgba(0,0,0,0.15);
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,0.08);
}

.set-result-item .set-number {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #88bb80;
  margin-bottom: 10px;
}

.set-result-cards {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Mini cards in solve results */
.set-result-cards .card {
  --card-w: 72px;
  --card-h: 104px;
  cursor: default;
  pointer-events: none;
}

.set-result-cards .card:hover {
  transform: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15), 0 6px 20px rgba(0,0,0,0.25);
}

.set-result-cards .card svg {
  height: 26px;
}

/* Card picker */
.card-picker-panel {
  display: flex;
  flex-direction: column;
  align-self: start;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 130px);
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 16px;
}

.card-picker-panel .section-label {
  margin-bottom: 12px;
}

.card-picker-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* Picker cards are smaller */
.card-picker-grid .card {
  --card-w: 68px;
  --card-h: 98px;
  gap: 4px;
  padding: 8px 6px;
}

.card-picker-grid .card svg {
  height: 24px;
}

/* Card on board (in solve picker) is visually muted */
.card-picker-grid .card.on-board {
  opacity: 0.35;
  transform: none !important;
}

/* No-sets message */
.no-sets-msg {
  color: #a8c8a0;
  font-size: 0.875rem;
  font-style: italic;
  padding: 12px 0;
}

/* ============================================================
   Index / Landing Page
   ============================================================ */
.hero {
  text-align: center;
  padding: 52px 20px 40px;
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.4rem, 6vw, 4rem);
  color: #f5e6c8;
  text-shadow: 1px 2px 8px rgba(0,0,0,0.5);
  margin-bottom: 16px;
}

.hero p {
  font-size: 1rem;
  color: #a8c8a0;
  max-width: 500px;
  margin: 0 auto 32px;
  line-height: 1.65;
}

.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.hero-actions .btn {
  font-size: 1rem;
  padding: 12px 32px;
}

.decorative-spread {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 32px 20px 0;
}

.rules-section {
  max-width: 640px;
  margin: 48px auto 0;
  padding: 0 20px;
}

.rules-section h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: #f5e6c8;
  margin-bottom: 16px;
}

.rules-section p,
.rules-section li {
  color: #c8e0c4;
  font-size: 0.9rem;
  line-height: 1.7;
}

.rules-section ul {
  padding-left: 1.4em;
  margin: 10px 0;
}

.rules-section .rule-example {
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  border-left: 3px solid #88bb80;
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 0.85rem;
  color: #a8c8a0;
}

/* ============================================================
   Auth Widget (nav)
   ============================================================ */
.auth-widget {
  position: relative;
  display: flex;
  align-items: center;
}

.auth-sign-in-btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 7px 18px;
  border-radius: 20px;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: transparent;
  color: #d8efd4;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.auth-sign-in-btn:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.4);
  color: #fff;
}

.auth-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #f5e6c8;
  color: #2d3a1e;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.auth-avatar:hover {
  opacity: 0.85;
}

.auth-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: #2a4a22;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 16px;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  z-index: 50;
}

.auth-dropdown-name {
  font-size: 0.85rem;
  color: #d8efd4;
  margin-bottom: 12px;
  word-break: break-all;
}

.auth-dropdown .btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  text-align: center;
}

/* ============================================================
   Auth Modal
   ============================================================ */
.auth-modal {
  max-width: 360px;
  padding: 32px 36px 28px;
  position: relative;
  text-align: left;
}

.auth-modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.15s;
}

.auth-modal-close:hover {
  color: #fff;
}

/* Tabs */
.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.auth-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  padding: 8px 16px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.auth-tab.active {
  color: #f5e6c8;
  border-bottom-color: #f5e6c8;
}

.auth-tab:hover:not(.active) {
  color: rgba(255,255,255,0.75);
}

/* Google button */
.btn-google {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 22px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn-google:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.btn-google:active {
  background: #f1f3f4;
}

.google-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* "or" divider */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: rgba(255,255,255,0.3);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.12);
}

/* Form inputs */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-input {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
  color: #f0ebe0;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.auth-input::placeholder {
  color: rgba(255,255,255,0.3);
}

.auth-input:focus {
  border-color: rgba(255,255,255,0.45);
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

/* Error / success messages */
.auth-error {
  font-size: 0.82rem;
  color: #f87171;
  padding: 4px 0 2px;
}

.auth-error.auth-success {
  color: #88bb80;
}

/* Forgot password */
.auth-forgot-link {
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 10px 0 0;
  display: block;
  width: 100%;
  text-align: center;
  transition: color 0.15s;
}

.auth-forgot-link:hover {
  color: rgba(255,255,255,0.7);
}

/* ── Save-game nudge (game-over modal) ─────────────────────── */
.save-nudge {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.8rem;
  color: rgba(168, 200, 160, 0.65);
  text-align: center;
}

.save-nudge--saved {
  color: #88bb80;
}

.save-nudge-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 0.8rem;
  color: rgba(168, 200, 160, 0.9);
  text-decoration: underline;
  font-family: var(--font-sans);
  transition: color 0.15s;
}

.save-nudge-btn:hover {
  color: #f5e6c8;
}

.modal-home-link {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 0.8rem;
  color: rgba(168, 200, 160, 0.4);
  text-decoration: none;
  transition: color 0.15s;
}

.modal-home-link:hover {
  color: rgba(168, 200, 160, 0.8);
}

/* ============================================================
   Responsive Tweaks
   ============================================================ */
@media (max-width: 600px) {
  :root {
    --card-w: 90px;
    --card-h: 130px;
    --card-gap: 10px;
  }

  .card svg {
    height: 30px;
  }

  .site-header .logo {
    font-size: 1.3rem;
  }

  .modal {
    padding: 28px 24px;
  }
}

@media (max-width: 400px) {
  :root {
    --card-w: 78px;
    --card-h: 113px;
    --card-gap: 8px;
  }

  .card svg {
    height: 26px;
  }
}

/* ============================================================
   Profile Page
   ============================================================ */
.profile-page {
  max-width: 480px;
  margin: 60px auto;
  padding: 0 20px;
}

.profile-card {
  background: rgba(0,0,0,0.2);
  border-radius: 16px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.profile-avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #f5e6c8;
  color: #2d3a1e;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.profile-fields {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.profile-field-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #88bb80;
  margin-bottom: 6px;
}

.profile-email-value {
  font-size: 0.95rem;
  color: #c0d8bb;
  padding: 10px 14px;
  background: rgba(0,0,0,0.15);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  word-break: break-all;
}

.profile-name-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.profile-name-row .auth-input {
  flex: 1;
  min-width: 0;
}

.profile-signed-out-card {
  gap: 20px;
  color: #a8c8a0;
  text-align: center;
}

.profile-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin: 4px 0;
  width: 100%;
}

.profile-password-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-history-link {
  display: inline-block;
  margin-bottom: 20px;
  text-decoration: none;
}

/* ============================================================
   History Page
   ============================================================ */
.history-page {
  max-width: 860px;
  margin: 40px auto;
  padding: 0 20px;
}

.history-heading {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  color: #f5e6c8;
  margin: 0 0 24px;
}

.history-status-msg {
  text-align: center;
  color: #a8c8a0;
  margin-top: 60px;
  font-size: 1rem;
}

.history-status-msg a {
  color: #f5e6c8;
}

.history-load-error {
  color: #f08080;
}

/* ── Summary panel ── */
.history-summary-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}

.summary-stat {
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  padding: 16px 18px;
  text-align: center;
  min-width: 120px;
}

.summary-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f5e6c8;
  line-height: 1.2;
}

.summary-stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #88bb80;
  margin-top: 4px;
}

/* ── Table wrapper (horizontal scroll on narrow screens) ── */
.history-table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  background: rgba(0,0,0,0.2);
}

/* ── Table ── */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  color: #c0d8bb;
}

.history-table thead th {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #88bb80;
  padding: 14px 16px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  white-space: nowrap;
}

.history-table .col-chevron {
  width: 28px;
  padding-right: 0;
}

.history-table .col-sets,
.history-table .col-outcome {
  text-align: center;
}

/* ── Sortable column headers ── */
.history-table thead th[data-sort] {
  cursor: pointer;
}

.history-table thead th[data-sort]::after {
  content: ' ⇅';
  opacity: 0.35;
  font-size: 0.8em;
}

.history-table thead th[data-sort].sort-active::after {
  opacity: 1;
}

.history-table thead th[data-sort].sort-active[aria-sort="ascending"]::after {
  content: ' ▲';
}

.history-table thead th[data-sort].sort-active[aria-sort="descending"]::after {
  content: ' ▼';
}

/* ── Summary rows ── */
.history-row td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  white-space: nowrap;
}

.history-row {
  cursor: pointer;
  transition: background 0.1s;
}

.history-row:hover {
  background: rgba(255,255,255,0.04);
}

.history-row.expanded {
  background: rgba(255,255,255,0.04);
}

.history-row .col-chevron {
  font-size: 0.65rem;
  color: #88bb80;
  user-select: none;
  padding-right: 0;
}

/* ── Detail rows ── */
.history-detail td {
  padding: 0 16px 16px 44px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: rgba(0,0,0,0.15);
}

.history-detail-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 0;
  padding-top: 10px;
}

.history-detail-grid div {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
}

.history-detail-grid dt {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #88bb80;
  margin-bottom: 2px;
}

.history-detail-grid dd {
  margin: 0;
  font-size: 0.9rem;
  color: #c0d8bb;
}

/* ── Outcome badges ── */
.outcome-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.4px;
}

.outcome-win  { background: rgba(42, 122, 42, 0.35); color: #7edd7e; }
.outcome-loss { background: rgba(180, 40, 40, 0.3);  color: #f08080; }
.outcome-tie  { background: rgba(255,255,255,0.08);   color: #a8c8a0; }
.outcome-none { color: rgba(168, 200, 160, 0.4); }

/* ── Filters ── */
.history-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: rgba(112, 64, 160, 0.18);
  border: 1px solid rgba(140, 90, 200, 0.3);
  border-radius: 12px;
  padding: 12px 16px;
}

.filter-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #88bb80;
  white-space: nowrap;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  color: #a8c8a0;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  user-select: none;
}

.filter-pill:hover {
  background: rgba(112, 64, 160, 0.25);
  color: #d0b8f0;
}

.filter-pill.active {
  background: rgba(112, 64, 160, 0.55);
  border-color: rgba(180, 130, 230, 0.7);
  color: #e0c8f8;
}

/* ── Pagination ── */
.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
  color: #a8c8a0;
  font-size: 0.9rem;
}

.history-pagination .btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* ============================================================
   Multiplayer Lobby
   ============================================================ */

/* ── Sections ── */
.lobby-section {
  margin-bottom: 32px;
}

/* ── Create row ── */
.lobby-create-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.lobby-count-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lobby-count-label {
  font-size: 0.85rem;
  color: #a8c8a0;
  white-space: nowrap;
}

.lobby-count-radios {
  display: flex;
  gap: 6px;
}

.lobby-count-option {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 18px;
  border: 1.5px solid rgba(255,255,255,0.2);
  font-size: 0.9rem;
  color: #d8efd4;
  transition: background 0.12s, border-color 0.12s;
}

.lobby-count-option:has(input:checked) {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.5);
  color: #fff;
}

.lobby-count-option input[type="radio"] {
  display: none;
}

/* ── Private-game checkbox ── */
.lobby-private-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #a8c8a0;
  cursor: pointer;
  white-space: nowrap;
}

.lobby-private-option input[type="checkbox"] {
  accent-color: #88bb80;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ── Private-game notice in the waiting room ── */
.lobby-private-notice {
  font-size: 0.82rem;
  color: #a8c8a0;
  font-style: italic;
  margin-top: 8px;
}

/* ── Join row ── */
.lobby-join-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.lobby-join-row .auth-input {
  flex: 1;
  min-width: 0;
}

/* ── Game list ── */
.lobby-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.lobby-refresh-btn {
  font-size: 0.8rem;
  padding: 5px 14px;
}

.lobby-game-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 10px;
}

.lobby-game-host {
  font-weight: 600;
  color: #f5e6c8;
  font-size: 0.95rem;
}

.lobby-game-count {
  color: #88bb80;
  font-size: 0.8rem;
  margin-top: 3px;
}

.lobby-empty-msg,
.lobby-loading-msg {
  color: #88bb80;
  font-style: italic;
  font-size: 0.9rem;
  padding: 16px 0;
}

/* ── Waiting room ── */
.lobby-link-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.lobby-link-input {
  flex: 1;
  min-width: 0;
  opacity: 0.75;
  cursor: text;
}

/* Player cards in waiting room */
.lobby-player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  color: #c8e0c4;
}

.lobby-player-card:last-child {
  border-bottom: none;
}

.lobby-player-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #f5e6c8;
  flex-shrink: 0;
}

.lobby-player-name {
  font-size: 0.95rem;
  flex: 1;
}

.lobby-player-tags {
  display: flex;
  gap: 6px;
}

.lobby-tag {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
}

.lobby-tag--host    { background: rgba(245,230,200,0.15); color: #f5e6c8; }
.lobby-tag--you     { background: rgba(37,99,235,0.25);   color: #93c5fd; }
.lobby-tag--offline { background: rgba(255,255,255,0.07); color: #88bb80; }

.lobby-waiting-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin-top: 8px;
}

.lobby-waiting-msg {
  color: #88bb80;
  font-style: italic;
  font-size: 0.9rem;
}

/* ============================================================
   Multiplayer Game Board
   ============================================================ */

/* Score panel overrides for variable player count.
   grid-template-columns is set inline by JS to repeat(N, auto). */
.mp-score-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
  justify-content: center;
}

/* Highlight the current player's score card */
.score-card--you {
  border-color: rgba(37, 99, 235, 0.5);
  background: rgba(37, 99, 235, 0.12);
}

/* Dim disconnected players */
.score-card--offline {
  opacity: 0.55;
}

.offline-badge {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.07);
  color: #88bb80;
  display: inline-block;
  margin-bottom: 4px;
}

/* Controls row — single status line, right-aligned */
.mp-controls {
  justify-content: flex-end;
  margin-bottom: 20px;
}

.mp-timer {
  font-variant-numeric: tabular-nums;
  margin-left: 0; /* override the solo-mode auto margin */
}

/* Penalty banner — shown when the local player submits an invalid set */
.penalty-bar {
  position: fixed;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, #7a1c1c 0%, #a83232 50%, #7a1c1c 100%);
  border-top: 1px solid rgba(255, 100, 100, 0.75);
  border-bottom: 1px solid rgba(255, 100, 100, 0.75);
  padding: 15px 20px;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 12px rgba(180, 40, 40, 0.4);
  z-index: 40;
}

/* Full-screen red tint overlay — separate element avoids stacking-context issues */
.penalty-overlay {
  position: fixed;
  inset: 0;
  background: rgba(220, 20, 20, 0.25);
  pointer-events: none;
  z-index: 39; /* just below penalty-bar at 40 */
}

.penalty-bar:not(.hidden) {
  animation: penalty-bar-in 0.22s ease forwards;
}

@keyframes penalty-bar-in {
  from { opacity: 0; transform: translateY(calc(-50% - 8px)); }
  to   { opacity: 1; transform: translateY(-50%);             }
}

/* Board dimmed during penalty — pointer-events:none prevents click-through */
.board--penalized {
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
