/* Utilitarian, responsive analysis UI. No framework required. */
:root {
  --bg: #f5f3ef;
  --panel: #fefdfa;
  --panel-strong: #ffffff;
  --ink: #181716;
  --muted: #65615c;
  --line: #d9d4cb;
  --line-strong: #bfb8ac;
  --focus: #4b5b81;
  --focus-ring: color-mix(in srgb, var(--focus), transparent 70%);
  --chip: #e9e5dd;
  --table-head: #efebe4;
  --table-sticky: #faf8f5;
  --row-hover: rgb(255 255 255 / 55%);
  --shadow: 0 18px 45px rgb(25 23 20 / 9%);
  --danger: #c44;
  color-scheme: light;
}

/* Dark palette — warm charcoal so the cream/ink brand feel carries over.
   Applied via the [data-theme] attribute set by the inline head bootstrap. */
:root[data-theme="dark"] {
  --bg: #151412;
  --panel: #1f1d1a;
  --panel-strong: #282622;
  --ink: #f0ede7;
  --muted: #a49f97;
  --line: #383530;
  --line-strong: #4c4840;
  --focus: #9fb0d7;
  --focus-ring: color-mix(in srgb, var(--focus), transparent 55%);
  --chip: #302d28;
  --table-head: #2a2824;
  --table-sticky: #23211d;
  --row-hover: rgb(255 255 255 / 6%);
  --shadow: 0 18px 45px rgb(0 0 0 / 45%);
  --danger: #e06868;
  color-scheme: dark;
}

/* Smooth, non-jarring theme changes; honor reduced-motion preferences.
   The theme is set before first paint, so this only animates user switches. */
@media (prefers-reduced-motion: no-preference) {
  :root[data-theme] *,
  :root[data-theme] *::before,
  :root[data-theme] *::after {
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.2s ease;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a { color: var(--focus); text-underline-offset: 0.16em; }
a:hover { text-decoration-thickness: 0.14em; }

button,
input { font: inherit; }

button {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  padding: 0.48rem 0.72rem;
}

button:hover { border-color: var(--focus); }
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

#main-content {
  width: min(1560px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 2.5rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: end;
  padding: clamp(1rem, 3vw, 2.5rem) 0 1rem;
}

.eyebrow {
  margin: 0 0 0.35rem 0.25rem;
}

.eyebrow a {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  letter-spacing: 0.075em;
  text-transform: uppercase;
  text-decoration: none;
}

h1,
h2,
h3 { line-height: 1.1; margin: 0; }

h1 { font-size: clamp(2rem, 5vw, 4.7rem); letter-spacing: -0.06em; }
h2 { font-size: clamp(1.08rem, 2vw, 1.45rem); letter-spacing: -0.025em; }
h3 { font-size: 1rem; }

.lead {
  max-width: 72ch;
  color: var(--muted);
  font-size: clamp(1rem, 1.4vw, 1.15rem);
}

.lead p { margin: 0.65rem 0 0; }

.hero-card {
  min-width: 11rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.55rem;
  align-items: baseline;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric { font-size: 1.65rem; font-weight: 830; letter-spacing: -0.04em; }
.metric-label { color: var(--muted); }

.notice {
  padding: 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.9rem;
  background: var(--panel-strong);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.controls,
.results {
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  position: sticky;
  top: 1rem;
  padding: 1rem;
}

.app-shell.controls-collapsed {
  grid-template-columns: 1fr;
}

.app-shell.controls-collapsed .controls {
  display: none;
}

.control-block + .control-block {
  margin-top: 1.2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.control-heading {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.7rem;
}

.control-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
}

.checkbox-list {
  display: grid;
  gap: 0.35rem;
}

.check-row,
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.45rem 0.52rem;
  border: 1px solid transparent;
  border-radius: 0.7rem;
}

.check-row:hover,
.toggle-row:hover { border-color: var(--line); background: var(--row-hover); }

.check-row input,
.toggle-row input { margin-top: 0.18rem; accent-color: var(--focus); }

.check-title { display: block; font-weight: 680; }
.check-meta { display: block; color: var(--muted); font-size: 0.78rem; overflow-wrap: anywhere; }

.dimension-list {
  max-height: 25rem;
  overflow: auto;
  padding-right: 0.25rem;
}

.search-label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 680;
}

.search-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 0.8rem;
  background: var(--panel-strong);
  padding: 0.68rem 0.75rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.75rem 0;
}

.results {
  min-width: 0;
  padding: 1rem;
}

.results-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.results-toolbar-main {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.controls-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 0.8rem;
  background: var(--panel-strong);
  padding: 0.5rem 0.7rem;
  color: inherit;
  font: inherit;
  font-weight: 680;
  cursor: pointer;
}

.controls-toggle:hover {
  border-color: var(--focus);
  box-shadow: var(--shadow);
}

.controls-toggle svg { flex: none; }

.status-line {
  margin: 0;
  color: var(--muted);
  text-align: right;
  font-style: italic;
  font-size: 0.88rem;
}

h2#results-title {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.game-summary {
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  background: var(--panel-strong);
  padding: 0.85rem;
}

.game-summary h3 { margin-bottom: 0.45rem; }
.game-summary p { margin: 0.55rem 0 0; color: var(--muted); }

.table-wrap {
  overflow: auto;
}

.analysis-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.75rem;
  table-layout: fixed;
}

.analysis-table th,
.analysis-table td {
  vertical-align: top;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.85rem 0.85rem 1.25rem;
}

.analysis-table th:last-child,
.analysis-table td:last-child {
  border-top-right-radius: 0.95rem;
  border-bottom-right-radius: 0.95rem;
}

.analysis-table th:first-child,
.analysis-table td:first-child {
  border-left: 1px solid var(--line);
  border-top-left-radius: 0.95rem;
  border-bottom-left-radius: 0.95rem;
}

.analysis-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--table-head);
  text-align: left;
  padding-bottom: 0.85rem;
}

.analysis-table thead th:not(.dimension-head) {
  font-size: 1.75rem;
}

.analysis-table tbody td { background: var(--panel-strong); }

.analysis-table .dimension-head,
.analysis-table .dimension-cell {
  width: 17rem;
  min-width: 17rem;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--table-head);
}

.analysis-table .dimension-head { z-index: 4; }

.dimension-title { display: block; font-weight: 800; }
.slug {
  display: inline-block;
  margin-top: 0.45rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.value p { margin: 0 0 0.75rem; }
.value p:last-child { margin-bottom: 0; }
.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.86rem;
}
.sources a {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  padding: 0.13rem 0.43rem;
  color: var(--muted);
  text-decoration: none;
}
.sources a:hover { border-color: var(--focus); }

.empty-state {
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

/* Shared site footer */
.site-footer {
  width: min(1560px, calc(100% - 2rem));
  margin: 2.5rem auto 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem 1.5rem;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
}

.footer-nav a {
  color: var(--ink);
  font-weight: 680;
  text-decoration: none;
}

.footer-nav a:hover { color: var(--focus); text-decoration: underline; }

.footer-note { margin: 0; color: var(--muted); font-size: 0.86rem; }

/* Theme switcher — segmented Light / Dark / System control in the footer. */
.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
}

.theme-switcher-label {
  padding: 0 0.35rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 760;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.theme-option {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  padding: 0.32rem 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 680;
}

.theme-option svg { flex: none; }

.theme-option:hover { border-color: var(--line); color: var(--ink); }

.theme-option[aria-pressed="true"] {
  background: var(--chip);
  border-color: var(--line-strong);
  color: var(--ink);
}

@media (max-width: 480px) {
  .theme-switcher-label { display: none; }
}

/* Compare button — styled link shown in the game hero, linking to the comparison widget */
.btn-compare {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel-strong);
  padding: 0.52rem 1rem;
  color: var(--focus);
  font-weight: 680;
  font-size: 0.9rem;
  text-decoration: none;
}

.btn-compare:hover {
  border-color: var(--focus);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.btn-compare:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Per-game detail page */
.game-detail {
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.dimension-entries { margin: 0; display: grid; gap: 1rem; }

.dimension-entry {
  display: grid;
  grid-template-columns: minmax(14rem, 18rem) minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  overflow: hidden;
  background: var(--panel-strong);
}

.dimension-entry dt {
  padding: 0.85rem 0.85rem 1.1rem;
  background: var(--table-head);
  border-right: 1px solid var(--line);
}

.dimension-entry dd { margin: 0; padding: 0.85rem 0.85rem 1.1rem; }

/* Games listing */
.games-index {
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.games-index .search-input { max-width: 32rem; }

.game-cards {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: 0.75rem;
}

.game-card { margin: 0; }

.game-card a {
  display: block;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  background: var(--panel-strong);
  padding: 0.9rem;
  color: inherit;
  text-decoration: none;
}

.game-card a:hover { border-color: var(--focus); box-shadow: var(--shadow); }

.game-card-title { display: block; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; }
.game-card-summary { display: block; margin-top: 0.4rem; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 980px) {
  .hero,
  .app-shell { grid-template-columns: 1fr; }
  .controls { position: static; }
  .dimension-entry { grid-template-columns: 1fr; }
  .dimension-entry dt { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 720px) {
  #main-content { width: min(100% - 1rem, 1560px); }
  .hero-card { width: 100%; }
  .results-toolbar { display: block; }
  .status-line { margin-top: 0.4rem; }
  h2#results-title { margin: 0;  font-size: 1.25rem; }
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .analysis-table,
  .analysis-table thead,
  .analysis-table tbody,
  .analysis-table tr,
  .analysis-table th,
  .analysis-table td { display: block; width: 100%; min-width: 0; }
  .analysis-table thead { display: none; }
  .analysis-table tr {
    margin-bottom: 0.85rem;
    border: 1px solid var(--line);
    border-radius: 0.95rem;
    overflow: hidden;
    background: var(--panel-strong);
  }
  .analysis-table th,
  .analysis-table td { border-right: 0; border-radius: 0; }
  .analysis-table tbody tr > :first-child { border-top: 0; border-left: 0; }
  .analysis-table tbody tr > :last-child { border-bottom: 0; }
  .analysis-table .dimension-cell {
    position: static;
    background: var(--table-head);
  }
  .analysis-table td::before {
    content: attr(data-game);
    display: block;
    margin-bottom: 0.45rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
}

/* --- Game picker --- */
.selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 1.5rem;
  margin-bottom: 0.75rem;
}

.game-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--chip);
  padding: 0.25rem 0.45rem 0.25rem 0.6rem;
  font-size: 0.84rem;
}

.game-chip.loading { opacity: 0.65; }
.game-chip.failed { border-color: #c05; }

.game-chip-name { font-weight: 680; }

.game-chip-remove,
.game-chip-retry {
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.25rem;
  font-size: 0.85rem;
  line-height: 1;
}

.game-chip-remove:hover { color: var(--ink); }
.game-chip-retry { color: #c05; font-size: 0.75rem; }
.game-chip-remove:disabled { cursor: default; opacity: 0.35; }

.game-picker { position: relative; }

.game-results {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 10;
  border: 1px solid var(--line-strong);
  border-radius: 0.9rem;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  max-height: 22rem;
  overflow-y: auto;
  padding: 0.35rem;
}

.game-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.7rem;
  cursor: pointer;
}

.game-result-item:hover,
.game-result-item:focus-within { background: var(--row-hover); }

.game-result-item.is-selected {
  background: color-mix(in srgb, var(--focus), transparent 90%);
  cursor: pointer;
}

.game-result-item.is-selected:hover,
.game-result-item.is-selected:focus-within {
  background: color-mix(in srgb, var(--focus), transparent 83%);
}

.game-result-item.is-selected:has(.btn-game-selected:disabled) {
  cursor: default;
}

.game-result-item.is-selected:has(.btn-game-selected:disabled):hover,
.game-result-item.is-selected:has(.btn-game-selected:disabled):focus-within {
  background: color-mix(in srgb, var(--focus), transparent 90%);
}

.game-result-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.game-result-title { font-weight: 700; font-size: 0.95rem; line-height: 1.2; }
.game-result-desc {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.game-result-empty {
  margin: 0;
  padding: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.btn-game-add {
  flex: none;
  border: 1.5px solid var(--focus);
  border-radius: 999px;
  background: var(--focus);
  color: var(--panel-strong);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.25;
  min-width: 4.5rem;
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
}

.btn-game-add:hover {
  background: color-mix(in srgb, var(--focus), var(--ink) 18%);
  border-color: color-mix(in srgb, var(--focus), var(--ink) 18%);
}

.btn-game-add:disabled {
  opacity: 0.35;
  cursor: default;
  background: transparent;
  border-color: var(--line-strong);
  color: var(--muted);
}

.btn-game-selected {
  flex: none;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 500;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.25;
  min-width: 4.5rem;
  text-align: center;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.btn-game-selected:hover:not(:disabled),
.btn-game-selected:focus-visible:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger), transparent 92%);
}

.btn-game-selected:disabled {
  cursor: default;
  color: var(--muted);
  border-color: var(--line);
  background: transparent;
}

/* Loading skeleton */
.skeleton {
  height: 3.5rem;
  border-radius: 0.5rem;
  background: linear-gradient(90deg, var(--line) 25%, var(--panel) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% center; }
  100% { background-position: -200% center; }
}

.loading-state {
  padding: 2rem;
  color: var(--muted);
  text-align: center;
}

.retry-inline {
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.retry-inline:hover { border-color: var(--focus); color: var(--ink); }

/* Dimension title — a link in the analysis table that navigates to the dimension page */
a.dimension-title {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-color: transparent;
}

a.dimension-title:hover {
  color: var(--focus);
  text-decoration-color: var(--focus);
}

/* Dimension page — game picker block above the game list */
.dim-picker-block {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

/* Brief game summary shown beneath the game title in the dimension page list */
.dim-game-summary {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 400;
}

/* Dimension page */
.dimension-entries .dimension-entry dt a {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}
.dimension-entries .dimension-entry dt a:hover { color: var(--focus); }

/* Keyboard-focused result item (arrow key navigation) */
.game-result-item.is-focused {
  background: var(--row-hover);
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* Mobile close button — hidden on desktop, shown as fixed overlay button on mobile */
.picker-close { display: none; }

/* Hidden on desktop; the media query below overrides this to show chips inside
   the full-screen overlay on narrow viewports. Must come before the media query
   so the media query rule (same specificity, later in source) can win. */
.picker-mobile-chips { display: none; }

/* Full-screen game picker on narrow viewports */
@media (max-width: 720px) {
  .game-results {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: none;
    z-index: 100;
    border-radius: 0;
    padding: 1rem;
    padding-top: 3rem;
  }

  .game-result-item {
    padding: 0.85rem 0.7rem;
  }

  .picker-close:not([hidden]) {
    display: block;
    position: fixed;
    top: 0.6rem;
    right: 1rem;
    z-index: 101;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ink);
    cursor: pointer;
    padding: 0.35rem 0.5rem;
  }

  /* Show selected-game chips at the top of the full-screen overlay on mobile */
  .picker-mobile-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
  }
}
