:root {
  --felt: #0B4F3F;
  --felt-deep: #063326;
  --felt-line: rgba(255,255,255,0.10);
  --cream: #FBF7EE;
  --paper: #F3EEE2;
  --ink: #1B1B1B;
  --ink-soft: rgba(27,27,27,0.62);
  --gold: #C9A227;
  --gold-soft: rgba(201,162,39,0.18);
  --red: #B23A2E;
  --white: #ffffff;
  --radius: 10px;
  --board-gap: 24px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-data: 'JetBrains Mono', 'Courier New', monospace;
  --dur: 200ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

[data-theme="blue"] { --felt: #123A5C; --felt-deep: #0A2540; }
[data-theme="dark"] { --felt: #16181C; --felt-deep: #0A0B0D; --felt-line: rgba(255,255,255,0.06); }
[data-theme="wood"] { --felt: #5C3A21; --felt-deep: #3E2714; }

[data-reduce-motion="true"] * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }

* { box-sizing: border-box; }

/* The overlay/modal/dropdown components below set their own `display: flex`,
   which (being an author rule) otherwise silently overrides the browser's
   built-in `[hidden] { display: none }` rule at equal specificity. This makes
   sure toggling the `hidden` attribute from JS always actually hides them. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--felt-deep);
  color: var(--cream);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--cream);
  color: var(--ink);
  padding: 10px 16px;
  z-index: 999;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

button {
  font-family: inherit;
  cursor: pointer;
}
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--felt-deep), rgba(6,51,38,0.85));
  border-bottom: 1px solid var(--felt-line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  color: var(--cream);
}
.brand-name-accent { color: var(--gold); }

.status-bar {
  display: flex;
  gap: 22px;
  margin-left: 8px;
  font-family: var(--font-data);
}
.status-item { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.status-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(251,247,238,0.55);
}
.status-value { font-size: 1rem; font-weight: 700; color: var(--gold); }
.btn-pause-inline { align-self: center; }

.btn-bookmark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: center;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--felt-line);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  padding: 9px 14px;
  border-radius: 8px;
  color: var(--cream);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-bookmark:hover { background: rgba(255,255,255,0.16); }
.btn-bookmark:active { transform: scale(0.96); }
.btn-bookmark .bookmark-icon { font-size: 1rem; line-height: 1; }
.btn-bookmark.bookmarked {
  background: var(--gold);
  border-color: var(--gold);
  color: #2b2200;
}
.btn-bookmark.bookmarked:hover { background: #ddb640; }

.bookmarks-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.bookmarks-empty { color: var(--ink-soft); font-size: 0.88rem; }
.bookmark-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--white);
  border-radius: 8px;
}
.bookmark-row-num { font-weight: 700; font-family: var(--font-data); flex: 1; }
.bookmark-row-date { font-size: 0.74rem; color: var(--ink-soft); }
.bookmark-play-btn { padding: 6px 14px; font-size: 0.82rem; }
.bookmark-remove-btn { padding: 6px 8px; color: var(--red); background: transparent; border: none; }

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  border: 1px solid var(--felt-line);
  background: rgba(255,255,255,0.06);
  color: var(--cream);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: rgba(255,255,255,0.12); }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #2b2200;
}
.btn-primary:hover { background: #ddb640; }
.btn-icon {
  padding: 8px 10px;
  font-size: 1rem;
  line-height: 1;
}
.btn-labeled {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 92px;
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 700;
}
.btn-labeled .btn-icon-glyph { font-size: 1rem; line-height: 1; }
.btn-undo {
  background: #2F6FED;
  border-color: #2F6FED;
  color: #ffffff;
}
.btn-undo:hover { background: #4C82F5; }
.btn-undo:active { background: #2559C9; }
.btn-hint {
  background: #B8860B;
  border-color: #B8860B;
  color: #ffffff;
}
.btn-hint:hover { background: #CC9713; }
.btn-hint:active { background: #9A7009; }
.btn-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover { background: rgba(178,58,46,0.12); }

.new-game-group { position: relative; display: flex; }
.btn-caret {
  border-left: 1px solid rgba(0,0,0,0.15);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding: 8px 8px;
}
.new-game-group .btn-primary:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
  min-width: 170px;
  z-index: 30;
}
.dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--ink);
}
.dropdown button:hover { background: var(--gold-soft); }

/* ---------- Board ---------- */
.table {
  min-height: calc(100vh - 60px);
  padding: 22px 18px 40px;
  overflow-x: auto;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.05), transparent 60%),
    var(--felt);
}

.board-top {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  justify-items: start;
  gap: var(--board-gap);
  /* Derived directly from the actual card width, not an independent fixed
     cap — a fixed cap can drift out of sync with card size (as happened
     before: raising this without raising cards to match just stretched
     each column wider than its card, reading as "too much gap"). Deriving
     it means the container can never be wider than the cards need. */
  max-width: min(calc(8 * var(--card-w) + 7 * var(--board-gap)), 98vw);
  margin: 0 auto 18px;
}
/* display:contents unwraps these groups so their .cell children become
   direct grid items — free cells occupy tracks 1-4, foundations 5-8,
   lining up with the tableau columns beneath them. */
.free-cells, .foundations {
  display: contents;
}

.cell {
  width: var(--card-w, 84px);
  height: var(--card-h, 118px);
  border-radius: calc(var(--card-w, 84px) * 0.06);
  border: 2px dashed var(--felt-line);
  position: relative;
}
.foundation::before {
  content: attr(data-suit);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: rgba(255,255,255,0.12);
  font-family: var(--font-display);
}
.foundation[data-suit="spades"]::before { content: "♠"; }
.foundation[data-suit="hearts"]::before { content: "♥"; }
.foundation[data-suit="clubs"]::before { content: "♣"; }
.foundation[data-suit="diamonds"]::before { content: "♦"; }

.tableau {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: var(--board-gap);
  max-width: min(calc(8 * var(--card-w) + 7 * var(--board-gap)), 98vw);
  margin: 0 auto;
}
.column {
  min-height: 200px;
  border-radius: calc(var(--card-w, 84px) * 0.06);
  position: relative;
  padding-bottom: 140px;
}

.btn-autofinish {
  display: block;
  margin: 22px auto 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--cream);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: min(90vw, 380px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Win overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,51,38,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}
.overlay-card {
  background: var(--paper);
  color: var(--ink);
  padding: 36px 44px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 30px 60px rgba(0,0,0,0.4);
  max-height: 90vh;
  overflow-y: auto;
}
.overlay-title {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0 0 10px;
}
.overlay-card p { font-family: var(--font-data); margin-bottom: 20px; color: var(--ink-soft); }

.win-image {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
  margin: 0 auto 16px;
  border-radius: 12px;
}
.win-image-daily { max-width: 170px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6,20,15,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  padding: 20px;
}
.modal {
  background: var(--paper);
  color: var(--ink);
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 14px;
  padding: 22px 24px 26px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin: 0;
}
.modal-close { background: transparent; border: none; color: var(--ink); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat-box {
  background: var(--white);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-num { font-family: var(--font-data); font-size: 1.5rem; font-weight: 700; color: var(--felt); }
.stat-name { font-size: 0.75rem; color: var(--ink-soft); }

/* ---------- SEO content ---------- */
.seo-content {
  background: var(--paper);
  color: var(--ink);
  padding: 50px 20px 30px;
}
.seo-content article { max-width: 880px; margin: 0 auto; }
.seo-content h1 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  line-height: 1.2;
  margin-bottom: 18px;
}
.seo-content h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-top: 34px;
}
.seo-content h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  margin: 32px 0 6px;
  color: var(--felt);
}
.seo-content h4 {
  font-family: var(--font-body);
  font-size: 1.02rem;
  margin: 22px 0 6px;
  color: var(--ink);
}
.seo-content p { line-height: 1.65; color: var(--ink-soft); }
.seo-intro-sub { color: var(--ink-soft); font-size: 1.05rem; margin-top: -8px; }
.faq-item + .faq-item { margin-top: 14px; }

.site-footer {
  background: var(--felt-deep);
  color: rgba(251,247,238,0.5);
  text-align: center;
  font-size: 0.78rem;
  padding: 22px 18px;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.footer-links a {
  color: rgba(251,247,238,0.75);
  text-decoration: none;
  font-size: 0.82rem;
}
.footer-links a:hover { color: var(--gold); text-decoration: underline; }
.footer-social {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 14px;
}
.footer-social-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(251,247,238,0.08);
  color: rgba(251,247,238,0.75);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.footer-social-link:hover { background: var(--gold); color: #2b2200; }

.footer-lang-selector {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.8rem;
}
.footer-lang-link {
  color: rgba(251,247,238,0.6);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px 4px;
}
.footer-lang-link:hover { color: var(--gold); }
.footer-lang-active {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.footer-lang-sep { color: rgba(251,247,238,0.3); }

/* ---------- Static content pages (privacy/terms/contact) ---------- */
.static-page-header {
  justify-content: space-between;
}
.brand-link { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.static-back-link {
  color: var(--cream);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(251,247,238,0.1);
}
.static-back-link:hover { background: rgba(251,247,238,0.18); }
.static-page-content { min-height: 50vh; }
.static-page-note {
  display: inline-block;
  background: rgba(201,162,39,0.12);
  border: 1px dashed var(--gold);
  color: var(--felt);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 18px;
}
