/* ===========================
   PnPFinder — style.css
   Dark by default; optional light theme via data-theme="light"
   =========================== */

/* Theme variables: dark by default */
:root,
html[data-theme="dark"] {
  --bg: #0b0b0b;
  --bg-elev: #141414;
  --text: #eaeaea;
  --muted: #a7a7a7;
  --accent: #7ee787;   /* subtle green */
  --accent-2: #58a6ff; /* subtle blue */
  --card: #121212;
  --border: #2a2a2a;
  --focus: #ffd166;
  --shadow: 0 6px 24px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.25);
}

/* Light theme (only used if you explicitly set data-theme="light") */
html[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f5f7fb;
  --text: #1a1a1a;
  --muted: #4e5561;
  --accent: #0c8c52;
  --accent-2: #165dff;
  --card: #ffffff;
  --border: #e6e9ef;
  --focus: #b54708;
  --shadow: 0 8px 24px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.06);
}

/* Base */
* { box-sizing: border-box; }
html, body { height: 100%; }
html { color-scheme: dark light; }
body {
  background: var(--bg);
  color: var(--text);
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap { width: min(1200px, 92vw); margin: 0 auto; }

/* Header */
.site-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: end;
  padding: 1.25rem 0 0.5rem;
}
.brand h1 { margin: 0; font-size: 1.75rem; letter-spacing: .2px; }
.brand .brand-link { color: var(--text); text-decoration: none; }
.brand .brand-link:hover { text-decoration: underline; }
.brand .tagline { margin: .25rem 0 0; color: var(--muted); font-size: .95rem; }

/* Top navigation (Games / Tutorials / Resources) */
.top-nav {
  margin-top: .5rem;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.nav-link {
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: .45rem .75rem;
  border-radius: 999px;
}
.nav-link:hover { border-color: color-mix(in srgb, var(--accent-2) 40%, var(--border)); }
.nav-link.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-2) 30%, transparent);
}

.controls {
  display: grid;
  gap: .75rem;
  grid-auto-flow: column;
  align-items: center;
}

/* Search (with custom clear button) */
.search { position: relative; }
.search input {
  appearance: none;              /* hide inconsistent native clear buttons */
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .65rem 2.4rem .65rem .85rem; /* extra right padding for clear button */
  min-width: 280px;
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: inset 0 0 0 1px transparent;
}
.search input::placeholder { color: color-mix(in srgb, var(--muted) 85%, transparent); }
.search input:focus { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Clear button shown inside the search field */
.search .clear-btn {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: none;                /* toggled via JS */
}
.search .clear-btn:hover { color: var(--text); background: color-mix(in srgb, var(--bg) 60%, transparent); }
.search .clear-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* View + Theme toggles share styling */
.view-toggle .toggle, .theme .toggle {
  border: 1px solid var(--border);
  padding: .55rem .9rem;
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.view-toggle .toggle:hover, .theme .toggle:hover {
  border-color: color-mix(in srgb, var(--accent-2) 40%, var(--border));
}
.view-toggle .toggle.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-2) 30%, transparent);
}

/* Sort control */
.sort select {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: .55rem .6rem;
  border-radius: 10px;
}

/* Filters panel */
.filters {
  margin: 1rem 0 0.5rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .5rem 1rem 1rem;
  box-shadow: var(--shadow);
}
.filters summary {
  cursor: pointer;
  padding: .5rem 0;
  font-weight: 600;
}

/* Filters grid: wrap neatly, never overflow the box */
.filters-grid {
  display: grid;
  gap: .75rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Filter item */
.select {
  display: grid;
  gap: .35rem;
  min-width: 0; /* allow shrinking inside grid */
}
.select label {
  font-size: .85rem;
  color: var(--muted);
  white-space: normal;
  word-wrap: anywhere;
}
.select select {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: .55rem .6rem;
  border-radius: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0; /* prevent overflow */
}

/* Buttons */
.filter-actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
}
button.primary, button.secondary, .btn.primary, .btn.secondary, .btn.danger {
  border-radius: 10px;
  padding: .65rem .9rem;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .05s ease, box-shadow .15s ease;
  text-decoration: none;
  display: inline-block;
}
button.primary, .btn.primary { background: var(--accent-2); color: white; border-color: transparent; }
button.secondary, .btn.secondary { background: var(--bg-elev); color: var(--text); }
.btn.danger { background: #f23064; color: white; border-color: transparent; }
button:hover, .btn:hover { box-shadow: 0 2px 10px rgba(0,0,0,.25); }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.btn.disabled { opacity: .6; pointer-events: none; }

/* Results meta */
.results-meta { margin: .75rem 0; color: var(--muted); font-size: .95rem; }

/* Cards grid */
.cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
}

/* Card */
.card {
  list-style: none;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: .6rem;
  transition: transform .08s ease, box-shadow .15s ease, border-color .15s ease;
}
.card.is-clickable { cursor: pointer; }
.card.is-clickable:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent-2) 40%, var(--border)); }
.card h3 { margin: 0; font-size: 1.15rem; }
.card h3 a { color: var(--text); text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.card .subtitle { color: var(--muted); font-size: .95rem; }
.card .desc { color: var(--text); }
.card .meta { display: flex; flex-wrap: wrap; gap: .35rem .5rem; }
.badge {
  font-size: .8rem;
  border: 1px solid var(--border);
  padding: .2rem .5rem;
  border-radius: 999px;
  color: var(--muted);
}
.card .links { margin-top: .25rem; display: flex; gap: .5rem; }
.card .links a {
  text-decoration: none;
  border: 1px solid var(--border);
  padding: .35rem .6rem;
  border-radius: 8px;
  color: var(--accent);
}
.card .links a:hover { text-decoration: underline; }

/* Card thumbnail */
.card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.card .thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* ===== List view (image | content) ===== */
.list { display: block; }
.list .card {
  display: grid;
  grid-template-columns: 140px 1fr; /* image | content */
  gap: 1rem;
  align-items: start;
}
.list .card .thumb { aspect-ratio: 4 / 3; border-radius: 8px; }

/* Right-hand content stack */
.list .list-body { display: grid; gap: .4rem; }

/* Title + mechanism block */
.list .list-header { display: grid; gap: .15rem; }
.list .list-header h3 { margin: 0; font-size: 1rem; }
.list .list-header .subtitle { color: var(--muted); font-size: .95rem; }

/* Short description under header */
.list .desc { color: var(--text); opacity: .9; margin-top: .1rem; }

/* Badges under description */
.list .meta { margin-top: .1rem; }

/* Download/actions at the bottom */
.list .list-actions { margin-top: .25rem; }

/* Pager */
.pager {
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: center;
  margin: 1.25rem 0 2.25rem;
}
.page-btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: .5rem .75rem;
  border-radius: 8px;
  cursor: pointer;
}
.page-btn[disabled] { opacity: .5; cursor: not-allowed; }
.page-btn:hover:not([disabled]) { box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.page-numbers { display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; }
.page-numbers button {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: .45rem .7rem;
  border-radius: 8px;
  min-width: 2.2rem;
  cursor: pointer;
}
.page-numbers button:hover { box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.page-numbers button[aria-current="page"] {
  background: var(--accent-2);
  border-color: transparent;
  color: white;
}
.page-numbers span {
  color: var(--muted);
  padding: .25rem .4rem;
}

/* ===== Game Details page ===== */
.detail { display: grid; gap: 1.25rem; }

/* Image on top, meta underneath (centered block) */
.detail-hero { display: block; }
.detail-media {
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  gap: .75rem;
}

/* Wide 16:9 hero image */
.detail-thumb {
  width: 100%;
  max-width: 720px;
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.detail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-head h2 { margin: 0 0 .25rem; }
.byline { color: var(--muted); margin-bottom: .25rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .25rem; }

.detail-sections { display: grid; gap: 1rem; }
.detail-section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.detail-section h3 { margin: 0 0 .5rem; }
.lead { font-weight: 600; }

.facts { margin: 0; }
.facts.two-col {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: .5rem 1rem;
}
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; }

.detail-back { margin: .25rem 0 1rem; }

.empty-state {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  text-align: center;
}

/* Footer */
.site-footer {
  margin: 2rem 0 3rem;
  color: var(--muted);
  text-align: center;
}

/* Accessibility helpers */
.sr-only {
  position: absolute !important;
  height: 1px; width: 1px; overflow: hidden;
  clip: rect(1px,1px,1px,1px);
  white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
/* === Responsive header controls fix (wrap + no horizontal scroll) === */

/* Never allow horizontal scrolling caused by oversized controls */
html, body { overflow-x: hidden; }

/* Header layout: allow wrapping and sensible gaps */
.site-header .controls {
  display: flex;
  flex-wrap: wrap;              /* <-- the key fix */
  align-items: center;
  justify-content: flex-end;
  gap: .5rem .6rem;
  max-width: 100%;
}

/* Make the search input stretchy; other controls stay compact */
.site-header .controls :is(.search, .search-wrap) { 
  flex: 1 1 280px; 
  min-width: 0; 
}

.site-header .controls :is(input[type="search"], input[type="text"], .search-input) {
  width: 100%;
  min-width: 0;                 /* prevents overflow in narrow viewports */
}

/* Keep Sort dropdown compact but flexible */
.site-header .controls :is(.sort, .sort-wrap, select) {
  flex: 0 1 180px;
  min-width: 140px;
  max-width: 100%;
}

/* View toggle + theme toggle stay natural size */
.site-header .controls :is(.view-toggle, .theme, #themeToggle, .btn-toggle) {
  flex: 0 0 auto;
}

/* Tighten paddings on very small screens */
@media (max-width: 720px) {
  .site-header .wrap { padding-inline: 12px; }
  .site-header .controls { gap: .5rem; }
}

/* When it’s extremely narrow, make controls stack cleanly */
@media (max-width: 520px) {
  .site-header .controls {
    justify-content: stretch;   /* left-align when stacked */
  }
  .site-header .controls :is(.search, .search-wrap) {
    flex: 1 1 100%;
  }
  .site-header .controls :is(.sort, .sort-wrap, select) {
    flex: 1 1 50%;              /* put sort on its own line if needed */
    min-width: 0;
  }
}

/* Avoid oversized native dropdowns bursting the row */
.site-header .controls select {
  max-width: 100%;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* If your list/card toggle is a button group, let it wrap without breaking */
.site-header .controls .view-toggle {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .25rem;
}

/* Guard against any fixed/min widths from earlier styles */
.site-header .controls > * {
  max-width: 100%;
  min-width: 0;
}
/* ===== Modern polish layer (safe overrides) ===== */

/* 1) Refined tokens & elevation */
:root, html[data-theme="dark"] {
  --radius: 14px;
  --radius-sm: 10px;
  --ring: 0 0 0 2px color-mix(in srgb, var(--accent-2) 28%, transparent);
  --shadow-sm: 0 4px 12px rgba(0,0,0,.25);
  --shadow-md: 0 8px 24px rgba(0,0,0,.28), 0 2px 8px rgba(0,0,0,.18);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.35), 0 6px 16px rgba(0,0,0,.25);
  --elev-gloss: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,0));
}

/* Optional: slightly richer dark palette (keeps existing accents) */
html[data-theme="dark"] {
  --bg: #0d0f12;
  --bg-elev: #12151a;
  --card: #151922;
  --border: color-mix(in srgb, var(--text) 10%, transparent);
  --muted: #9ea7b3;
  --accent: #7de0a0;
  --accent-2: #78a6ff;
}

/* 2) Fluid type scale (subtle) */
:root {
  --step--1: clamp(.88rem, .86rem + .2vw, .95rem);
  --step-0: clamp(1rem, .95rem + .35vw, 1.05rem);
  --step-1: clamp(1.1rem, 1rem + .6vw, 1.25rem);
  --step-2: clamp(1.25rem, 1.1rem + 1vw, 1.5rem);
  --step-3: clamp(1.45rem, 1.2rem + 1.6vw, 1.9rem);
}
body { font-size: var(--step-0); letter-spacing: .1px; }
.brand h1 { font-size: var(--step-3); }
.card h3 { font-size: var(--step-1); }

/* 3) Cards: depth + gentle motion */
.card {
  border-radius: var(--radius);
  background: var(--card), var(--elev-gloss);
  box-shadow: var(--shadow-md);
}
.card.is-clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* 4) Buttons & inputs refinement */
button.primary, .btn.primary {
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
button.secondary, .btn.secondary {
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--bg-elev) 90%, white 10%),
    var(--bg-elev)
  );
}

.search input, .sort select, .select select {
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
  transition: box-shadow .2s ease, border-color .2s ease, background-color .2s ease;
}
.search input:focus, .sort select:focus, .select select:focus {
  outline: none;
  box-shadow: var(--ring);
}

/* 5) Links & badges polish */
.card .links a {
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  transition: transform .08s ease, box-shadow .15s ease, background-color .2s ease;
}
.card .links a:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.badge {
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elev) 85%, var(--accent-2) 15%);
  color: color-mix(in srgb, var(--text) 80%, white 20%);
  border: 1px solid color-mix(in srgb, var(--accent-2) 30%, var(--border));
}

/* 6) Header & nav subtle refinement */
.site-header { border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.top-nav .nav-link { border-radius: 999px; font-weight: 500; }

/* 7) Accessible focus ring (consistent) */
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* 8) List view & pager tweaks */
.list .card { border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.list .desc { opacity: .92; }
.page-numbers button[aria-current="page"] { box-shadow: var(--ring); }

/* 9) Empty state & detail sections */
.empty-state, .detail-section { border-radius: var(--radius); box-shadow: var(--shadow-md); }
.detail-thumb { border-radius: calc(var(--radius) + 2px); box-shadow: var(--shadow-md); }

/* 10) Respect reduced motion */
* { transition: background-color .2s ease, color .2s ease, border-color .2s ease; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.spot-hero { display:grid; grid-template-columns: 1fr; gap:1rem; margin:1rem 0 2rem; }
.spot-hero img { width:100%; aspect-ratio:16/9; object-fit:cover; border-radius:.75rem; }
.spot-hero .credit { font-size:.75rem; color:var(--muted,#666); margin-top:.25rem; }

.spot-list { display:grid; grid-template-columns:repeat(auto-fill,minmax(250px,1fr)); gap:1rem; }
.spot-card { border:1px solid var(--border,#e6e6e6); border-radius:.75rem; padding:.75rem; background:#fff; }
.spot-card h3 { margin:.25rem 0; font-size:1.05rem; }
.spot-card .meta { font-size:.9rem; color:var(--muted,#555); }

.spot-switch { margin:2rem 0; display:flex; gap:.5rem; flex-wrap:wrap; }
.spot-switch a { padding:.25rem .6rem; border:1px solid var(--border,#ddd); border-radius:.6rem; text-decoration:none; }
.spot-switch a.active { background:#000; color:#fff; border-color:#000; }

/* Accessible links in dark mode, excluding buttons */
:root[data-theme="dark"] a:not(.btn),
:root[data-theme="dark"] .spot-hero a:not(.btn),
:root[data-theme="dark"] .cards a:not(.btn) {
  color: #6bb3ff;
  text-decoration-color: rgba(107,179,255,.5);
}
:root[data-theme="dark"] a:not(.btn):hover,
:root[data-theme="dark"] .spot-hero a:not(.btn):hover,
:root[data-theme="dark"] .cards a:not(.btn):hover {
  color: #8cc7ff;
  text-decoration-color: rgba(140,199,255,.7);
}

