:root {
  --bg: #f3efe6;
  --bg-elevated: #fffdf8;
  --felt: #2d5a46;
  --felt-dark: #1f4535;
  --text: #1d2433;
  --text-muted: #56606f;
  --border: #d9d0bf;
  --primary: #2f5a47;
  --primary-hover: #254a39;
  --gold: #b8923a;
  --accent: #b8923a;
  --danger: #a3302f;
  --success: #2e6b4a;
  --shadow: 0 1px 2px rgba(29, 36, 51, 0.08), 0 4px 14px rgba(29, 36, 51, 0.08);
  --radius: 10px;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-base: 1.125rem;
  --line: 1.6;
  --tap-min: 44px;
  --max-width: 1040px;
  --header-h: 3.6rem;
}

[data-theme="dark"] {
  --bg: #161d1b;
  --bg-elevated: #212b28;
  --felt: #25503e;
  --felt-dark: #183629;
  --text: #ebeee8;
  --text-muted: #a5afa8;
  --border: #37443f;
  --primary: #3f7a60;
  --primary-hover: #4a8b6d;
  --gold: #d1a94a;
  --accent: #d1a94a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
}

[data-text-size="large"] {
  --text-base: 1.3rem;
}

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

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

a { color: var(--primary); }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.wrap {
  width: min(100% - 2rem, var(--max-width));
  margin-inline: auto;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.5rem 1rem;
  background: var(--gold);
  color: #fff;
  z-index: 1000;
}

.skip-link:focus { left: 0; }

/* ---------- header ---------- */

.site-header {
  background: linear-gradient(180deg, #2f5d48, #24493a);
  color: #f4f0e8;
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.site-header { position: relative; z-index: 60; }

.header-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-h);
  gap: 1rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--font-serif);
  font-size: 1.4rem;
  color: inherit;
  text-decoration: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.logo-mark {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.site-nav a {
  color: #ece9df;
  text-decoration: none;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
}

.site-nav a:hover { background: rgba(255, 255, 255, 0.1); }

.nav-muted { font-size: 0.85rem; opacity: 0.85; }

/* Games menu (a <details>, so it also works without JavaScript) */
.nav-menu { position: static; }

.nav-menu > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.nav-menu > summary::-webkit-details-marker { display: none; }

.nav-menu > summary svg { transition: transform 0.15s; }
.nav-menu[open] > summary { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.7); }
.nav-menu[open] > summary svg { transform: rotate(180deg); }

.nav-menu-panel {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.7rem;
  width: min(21rem, 100%);
  padding: 0.5rem;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
}

.nav-menu-panel ul { list-style: none; margin: 0; padding: 0; }

.site-nav .nav-menu-panel a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.site-nav .nav-menu-panel a:hover,
.site-nav .nav-menu-panel a:focus-visible { background: color-mix(in srgb, var(--gold) 16%, transparent); }

.site-nav .nav-menu-panel a[aria-current="page"] { background: color-mix(in srgb, var(--primary) 14%, transparent); font-weight: 600; }

.nav-menu-all {
  margin-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0 !important;
  font-size: 0.9rem;
  color: var(--text-muted) !important;
}

.nm-title { font-family: var(--font-serif); font-size: 1.1rem; }

.nm-cat {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

/* ---------- buttons & form controls ---------- */

.btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  min-height: var(--tap-min);
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-elevated), color-mix(in srgb, var(--bg-elevated) 88%, var(--border)));
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  transition: border-color 0.12s, transform 0.05s;
}

.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-hover));
  border-color: var(--primary-hover);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { border-color: var(--gold); }

/* Header buttons (declared after .btn so they override it) */
.btn.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #f4f0e8;
  min-width: var(--tap-min);
  padding: 0.3rem 0.7rem;
  box-shadow: none;
}

.btn.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.7);
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
}

.field-label { color: var(--text-muted); }

.select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 0.95rem;
  min-height: var(--tap-min);
  padding: 0.3rem 2.1rem 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2356606f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  color: var(--text);
  cursor: pointer;
}

select:not(.select) {
  font: inherit;
  font-size: 0.95rem;
  min-height: var(--tap-min);
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap-min);
  cursor: pointer;
  font-size: 0.95rem;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 2.5rem;
  height: 1.45rem;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s;
  flex-shrink: 0;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 0.18rem;
  left: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.switch-input:checked + .switch-track { background: var(--primary); }
.switch-input:checked + .switch-track::after { transform: translateX(1.05rem); }
.switch-input:focus-visible + .switch-track { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- home ---------- */

.hero {
  padding: 2.5rem 0 1.25rem;
}

.hero h1 {
  font-family: var(--font-serif);
  font-weight: normal;
  font-size: clamp(2rem, 5vw, 2.8rem);
  margin: 0 0 0.4rem;
  color: var(--primary);
  letter-spacing: 0.01em;
}

.hero-lead {
  font-size: 1.2em;
  margin: 0 0 0.5rem;
}

.hero-sub {
  color: var(--text-muted);
  margin: 0;
  max-width: 40em;
}

.game-grid-section h2 {
  font-family: var(--font-serif);
  font-weight: normal;
  font-size: 1.4rem;
  margin: 1.5rem 0 1rem;
}

.game-grid {
  list-style: none;
  padding: 0;
  margin: 0 0 2.5rem;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.game-card a {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.game-card a:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.game-card-thumb {
  display: block;
  background: radial-gradient(ellipse at 50% 30%, #3b6b55, #25503e 70%);
  border-bottom: 3px solid var(--gold);
}

.game-card-thumb svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 160 / 100;
}

.game-card-body { display: block; padding: 1rem 1.25rem 1.25rem; }

.game-card-category {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.game-card-title {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  margin-bottom: 0.3rem;
  color: var(--primary);
}

.game-card-desc {
  display: block;
  font-size: 0.95em;
  color: var(--text-muted);
}

.prose h2 {
  font-family: var(--font-serif);
  font-weight: normal;
  color: var(--primary);
}

.prose h3 { margin-bottom: 0.3rem; }
.prose ul { padding-left: 1.25rem; }
.prose li { margin-bottom: 0.3rem; }

.home-about { max-width: 46rem; padding-bottom: 1rem; }

/* ---------- game page ---------- */

.breadcrumb {
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 1rem 0 0;
}

.breadcrumb a { color: var(--primary); }

.game-header h1 {
  font-family: var(--font-serif);
  font-weight: normal;
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  margin: 0.4rem 0;
  color: var(--primary);
}

.game-intro {
  color: var(--text-muted);
  max-width: 48em;
  margin-top: 0;
}

/* Felt table */
.game-root {
  position: relative;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255, 255, 255, 0.1), transparent 60%),
    radial-gradient(ellipse at 50% 40%, var(--felt) 0%, var(--felt-dark) 100%);
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  padding: 1rem;
  margin: 1.25rem 0 1.5rem;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.35), 0 6px 22px rgba(0, 0, 0, 0.22);
  min-height: 220px;
  container-type: inline-size;
  overflow: hidden;
  overflow: clip; /* clip, unlike hidden, keeps position: sticky working inside */
}

.game-root::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.12;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .7 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.game-root > * { position: relative; }

.game-loading { color: #e8ebe6; text-align: center; padding: 3rem 0; }

/* Toolbar */
.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1.25rem;
  margin-bottom: 1.1rem;
  padding: 0.55rem 0.8rem;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.toolbar-stats {
  display: flex;
  align-items: center;
  gap: 1.4rem;
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.6rem;
}

.stat {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.stat small {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.stat b {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
}

.game-toolbar > .stat { margin-right: 0.5rem; }

@media (max-width: 480px) {
  .logo { font-size: 1.2rem; gap: 0.45rem; }
  .logo-mark { width: 1.7rem; height: 1.7rem; }
  .site-nav { gap: 0.4rem; }
  .site-nav .btn.btn-ghost { padding-inline: 0.55rem; }
}

@media (max-width: 640px) {
  .game-toolbar { padding: 0.5rem; }
  .toolbar-controls { width: 100%; }
  .toolbar-controls .btn { flex: 1 1 auto; padding-inline: 0.6rem; }
  .game-root { padding: 0.6rem; border-radius: 12px; }
}

/* Win banner */
.win-banner {
  position: absolute !important;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(10, 25, 18, 0.62);
  backdrop-filter: blur(2px);
  animation: fade-in 0.3s ease;
}

.win-card {
  background: var(--bg-elevated);
  color: var(--text);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 1.6rem 2.2rem;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  max-width: 90%;
}

.win-card h3 {
  font-family: var(--font-serif);
  font-weight: normal;
  font-size: 1.7rem;
  margin: 0 0 0.6rem;
  color: var(--primary);
}

.win-card p { margin: 0.2rem 0; color: var(--text-muted); }
.win-card .btn { margin-top: 1rem; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 20px);
  background: #1d2433;
  color: #f4f0e8;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  font-size: 0.95rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* Rules / help */
.game-content {
  max-width: 52rem;
  margin: 2rem 0;
  padding: 0.5rem 1.75rem 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.game-content h2 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.35rem;
  margin-top: 1.6rem;
}

.faq-list .faq-item { margin-bottom: 1rem; }
.faq-list dt { font-weight: 600; margin-bottom: 0.2rem; }
.faq-list dd { margin: 0; color: var(--text-muted); }

.related-games { margin-bottom: 3rem; }
.related-games h2 { font-family: var(--font-serif); font-weight: normal; }

.game-link-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.game-link-list a {
  display: inline-block;
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  text-decoration: none;
  color: var(--primary);
}

.game-link-list a:hover { border-color: var(--gold); }

/* ---------- ads ---------- */

.ad-slot {
  min-height: 90px;
  margin: 1rem auto;
  max-width: var(--max-width);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  display: none;
}

body.ads-on .ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.75rem 0;
  margin-top: 2rem;
  background: var(--bg-elevated);
}

.footer-tag { margin: 0 0 0.4rem; color: var(--text-muted); }
.footer-links { margin: 0; font-size: 0.95rem; }
.footer-links a { color: var(--primary); }

.pwa-hint {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90%, 22rem);
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  z-index: 50;
  display: none;
}

.pwa-hint.visible { display: block; }
.pwa-hint button { margin-left: 0.5rem; }
