:root {
  --bg: #0f3d28;
  --bg-elevated: #144d33;
  --bg-panel: #f8faf8;
  --bg-card-page: #ffffff;
  --surface-subtle: #edf4ef;
  --border: #d5e2da;
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #13221a;
  --text-muted: #4b6155;
  --text-on-felt: #f4fbf6;
  --text-on-felt-muted: #c2dfd0;
  --accent: #d97706;
  --accent-strong: #b45309;
  --accent-soft: #fef3c7;
  --felt-grad: radial-gradient(circle at 50% 25%, #19613f 0%, #0d3a25 75%, #082819 100%);
  --wood-grain: linear-gradient(135deg, #5b3821 0%, #442816 50%, #56341e 100%);
  --wood-trim: #7c4d2d;
  --card-bg: #ffffff;
  --card-border: #cbd5e1;
  --card-red: #c81e1e;
  --card-black: #0f172a;
  --p1-color: #2563eb;
  --p2-color: #dc2626;
  --p3-color: #d97706;
  --p4-color: #059669;
  --radius: 14px;
  --shadow-sm: 0 2px 8px rgba(4, 24, 15, 0.08);
  --shadow-md: 0 10px 26px rgba(4, 24, 15, 0.16);
  --shadow-card: 0 3px 10px rgba(0, 0, 0, 0.24);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

html[data-theme="wood"] {
  --bg: #3b2416;
  --bg-elevated: #4c2f1d;
  --felt-grad: radial-gradient(circle at 50% 25%, #5c3a23 0%, #3d2516 75%, #2a180d 100%);
  --bg-panel: #fbf8f3;
  --surface-subtle: #f3ece2;
  --border: #dfd3c3;
  --text: #271910;
  --text-muted: #665040;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elevated: #111b2e;
  --felt-grad: radial-gradient(circle at 50% 20%, #16243d 0%, #0b1220 75%, #070b14 100%);
  --bg-panel: #111827;
  --bg-card-page: #182235;
  --surface-subtle: #1f2b40;
  --border: #2b3a55;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --card-bg: #f8fafc;
  --accent-soft: #422006;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-subtle);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: #0d6e47;
  text-decoration: underline;
  text-underline-offset: 2px;
}

html[data-theme="dark"] a {
  color: #34d399;
}

img,
svg {
  max-width: 100%;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Header & Navigation */
.site-header {
  background: #082719;
  color: #f8fafc;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  position: sticky;
  top: 0;
  z-index: 60;
}

html[data-theme="wood"] .site-header {
  background: #2c190e;
}

html[data-theme="dark"] .site-header {
  background: #060a12;
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: #ffffff !important;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: #d8ece1 !important;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.38rem 0.68rem;
  border-radius: 8px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-links a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff !important;
}

.nav-links a[aria-current="page"] {
  background: #d97706;
  color: #ffffff !important;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.theme-select {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 0.34rem 0.5rem;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-select option {
  color: #0f172a;
  background: #ffffff;
}

.nav-toggle {
  display: none;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 820px) {
  .nav-toggle {
    display: inline-flex;
    align-items: center;
  }

  .nav-links {
    display: none;
    width: 100%;
    padding-top: 0.4rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .nav-links.open {
    display: flex;
  }
}

/* Main Layout */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem;
}

.tool-stage {
  background: var(--felt-grad);
  color: var(--text-on-felt);
  border-bottom: 4px solid var(--wood-trim);
  padding: 1rem 0 1.35rem;
}

.stage-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Buttons & Chips */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg-card-page);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.52rem 0.95rem;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #d97706;
  border-color: #b45309;
  color: #ffffff !important;
}

.btn-primary:hover:not(:disabled) {
  background: #b45309;
}

.btn-emerald {
  background: #0f7649;
  border-color: #0a5a37;
  color: #ffffff !important;
}

.btn-emerald:hover:not(:disabled) {
  background: #0b5d39;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff !important;
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
}

.btn-sm {
  font-size: 0.82rem;
  padding: 0.36rem 0.7rem;
  border-radius: 8px;
}

.pill-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.pill-group {
  display: inline-flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.28);
  padding: 0.22rem;
  border-radius: 10px;
  gap: 0.2rem;
  flex-wrap: wrap;
}

.pill-group-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-on-felt-muted);
  padding: 0 0.45rem;
}

.pill-btn {
  border: 0;
  background: transparent;
  color: #e2efe8;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.32rem 0.62rem;
  border-radius: 7px;
  cursor: pointer;
}

.pill-btn.active {
  background: #d97706;
  color: #ffffff;
}

/* Playing Cards */
.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: center;
  min-height: 98px;
}

.playing-card {
  position: relative;
  width: 66px;
  height: 94px;
  border-radius: 10px;
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  box-shadow: var(--shadow-card);
  color: var(--card-black);
  user-select: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.3rem 0.36rem;
  cursor: default;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
  flex-shrink: 0;
}

.playing-card.red {
  color: var(--card-red);
}

.playing-card.clickable {
  cursor: pointer;
}

.playing-card.clickable:hover {
  transform: translateY(-4px);
}

.playing-card.selected {
  transform: translateY(-10px);
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.55), var(--shadow-card);
}

.playing-card.highlighted {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.65), var(--shadow-card);
  transform: translateY(-5px);
}

.playing-card.disabled-card {
  opacity: 0.48;
  cursor: not-allowed;
}

.playing-card.face-down {
  background: linear-gradient(135deg, #991b1b 0%, #7f1d1d 100%);
  border-color: #fef3c7;
  color: transparent;
  align-items: center;
  justify-content: center;
}

.playing-card.face-down::after {
  content: "";
  width: 78%;
  height: 82%;
  border-radius: 6px;
  border: 2px dashed rgba(254, 243, 199, 0.65);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.12) 0,
    rgba(255, 255, 255, 0.12) 4px,
    transparent 4px,
    transparent 8px
  );
}

.card-corner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1;
  font-weight: 800;
  font-size: 0.92rem;
}

.card-corner.bottom {
  align-items: flex-end;
  transform: rotate(180deg);
}

.card-center-suit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  pointer-events: none;
}

.playing-card.sm {
  width: 52px;
  height: 74px;
  padding: 0.22rem 0.26rem;
  border-radius: 8px;
}

.playing-card.sm .card-corner {
  font-size: 0.78rem;
}

.playing-card.sm .card-center-suit {
  font-size: 1.25rem;
}

@media (max-width: 560px) {
  .playing-card {
    width: 56px;
    height: 80px;
    padding: 0.24rem 0.28rem;
  }

  .playing-card .card-corner {
    font-size: 0.84rem;
  }

  .playing-card .card-center-suit {
    font-size: 1.38rem;
  }
}

.mini-card-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.08rem 0.36rem;
  font-weight: 800;
  font-size: 0.84rem;
  line-height: 1.3;
}

.mini-card-pill.red {
  color: #c81e1e;
}

/* Felt Table Layout */
.table-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 960px) {
  .table-grid {
    grid-template-columns: 1fr;
  }
}

.felt-surface {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  padding: 0.9rem;
}

.opponent-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.seat-box {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
}

.seat-box.active-turn {
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.35);
}

.seat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.74rem;
  font-weight: 800;
  padding: 0.14rem 0.48rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.badge-dealer {
  background: #f59e0b;
  color: #111827;
}

.badge-score {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.table-center {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  background: rgba(0, 0, 0, 0.18);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.75rem;
}

.cut-crib-zone {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.zone-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-on-felt-muted);
  text-align: center;
  margin-bottom: 0.25rem;
}

.pegging-pile-zone {
  flex: 1;
  min-width: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.running-count-pill {
  background: #111827;
  color: #fbbf24;
  border: 1px solid #f59e0b;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.24rem 0.72rem;
  border-radius: 999px;
  margin-bottom: 0.45rem;
}

.table-status-bar {
  background: rgba(255, 255, 255, 0.11);
  border-radius: 10px;
  padding: 0.58rem 0.8rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.status-message {
  font-weight: 700;
  font-size: 0.95rem;
}

.manual-count-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: #fef3c7;
  color: #1f2937;
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.75rem;
}

.manual-count-bar input {
  width: 76px;
  padding: 0.38rem 0.5rem;
  border: 1px solid #d97706;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 800;
}

/* Sidebar / Live Board & Show Breakdown */
.felt-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-card {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  padding: 0.85rem;
}

.sidebar-card h2,
.sidebar-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.action-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 190px;
  overflow-y: auto;
  font-size: 0.82rem;
  color: #dcece3;
}

.action-log li {
  padding: 0.28rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.combo-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.combo-chip {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.28rem 0.55rem;
  border-radius: 8px;
  cursor: pointer;
}

.combo-chip:hover,
.combo-chip.active {
  background: #10b981;
  border-color: #34d399;
  color: #052e16;
}

/* Content Cards & Grids */
.panel {
  background: var(--bg-card-page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}

.panel h1,
.panel h2,
.panel h3 {
  margin-top: 0;
  line-height: 1.28;
}

.section-heading {
  font-size: 1.45rem;
  margin: 0 0 0.75rem;
}

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

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

/* 52-Card Selector Matrix (Calculator & Discard Analyzer) */
.deck-picker-grid {
  display: flex;
  flex-direction: column;
  gap: 0.36rem;
}

.suit-row {
  display: grid;
  grid-template-columns: 28px repeat(13, minmax(0, 1fr));
  gap: 0.25rem;
  align-items: center;
}

@media (max-width: 720px) {
  .suit-row {
    grid-template-columns: 24px repeat(7, minmax(0, 1fr));
  }

  .suit-row-icon {
    grid-row: 1 / span 2;
  }
}

.suit-row-icon {
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
  color: #f8fafc;
}

.suit-row-icon.red {
  color: #fca5a5;
}

.deck-btn {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #ffffff;
  color: #0f172a;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.42rem 0.15rem;
  border-radius: 7px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s ease, background-color 0.12s ease;
}

.deck-btn.red {
  color: #c81e1e;
}

.deck-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: #f59e0b;
}

.deck-btn.picked-hand {
  background: #d97706;
  border-color: #fef3c7;
  color: #ffffff;
}

.deck-btn.picked-cut {
  background: #10b981;
  border-color: #ffffff;
  color: #052e16;
}

/* Data Tables */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface-subtle);
  font-weight: 800;
}

.data-table tr.top-pick {
  background: rgba(16, 185, 129, 0.12);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--bg-card-page);
  color: var(--text);
  border-radius: var(--radius);
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.modal-header h2 {
  margin: 0;
}

.code-hash {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  word-break: break-all;
  background: var(--surface-subtle);
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Standalone Peg Board Controls */
.board-player-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.peg-control-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 0.8rem;
}

.peg-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.55rem;
}

/* FAQ Accordion */
.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

.faq-item summary {
  font-weight: 700;
  cursor: pointer;
}

/* Footer */
.site-footer {
  background: #082719;
  color: #cbd5e1;
  padding: 1.5rem 1rem;
  margin-top: 2rem;
  font-size: 0.88rem;
}

html[data-theme="wood"] .site-footer {
  background: #2c190e;
}

html[data-theme="dark"] .site-footer {
  background: #060a12;
}

.footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.footer-links a {
  color: #d8ece1;
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

/* Print Layout for /printable/ */
.print-sheet {
  background: #ffffff;
  color: #111827;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

@media print {
  .site-header,
  .site-footer,
  .no-print {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .container {
    max-width: 100% !important;
    padding: 0 !important;
  }

  .print-sheet {
    border: none !important;
    box-shadow: none !important;
    page-break-after: always;
    margin: 0;
    padding: 0.25in;
  }

  .print-sheet:last-child {
    page-break-after: auto;
  }
}
