/* Game Mechanics Atlas — single stylesheet, no framework. */

:root {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --border: #e2e5ea;
  --text: #1c1f24;
  --muted: #5b616b;
  --accent: #3257d6;
  --accent-soft: #eaefff;
  --radius: 10px;
  --maxw: 860px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --border: #2a2e36;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --accent: #7d97ff;
    --accent-soft: #23283a;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout --------------------------------------------------------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.site-nav { margin-left: auto; }
.site-main { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Typography ----------------------------------------------------- */
h1 { font-size: 2rem; line-height: 1.2; margin: 0.2em 0 0.4em; }
h2 { font-size: 1.3rem; margin: 1.8rem 0 0.6rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 0.4rem; }
.lede { font-size: 1.1rem; color: var(--text); }
.muted, .colophon, .count { color: var(--muted); }

/* --- Breadcrumb ----------------------------------------------------- */
.breadcrumb { font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--muted); }
.breadcrumb .sep { padding: 0 0.4rem; opacity: 0.6; }

/* --- Mechanic page -------------------------------------------------- */
.relations { margin-top: 1.5rem; }
.relation-group { margin-bottom: 1rem; }
.relation-group h3 { margin-bottom: 0.3rem; }
.tag-list { display: flex; flex-wrap: wrap; gap: 0.5rem; list-style: none; padding: 0; margin: 0.3rem 0; }
.tag-list li a {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.92rem;
}
.map-link { margin-top: 2rem; font-weight: 600; }
.fact-strip {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem;
  list-style: none; padding: 0.6rem 0; margin: 1rem 0;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: 0.92rem; color: var(--muted);
}
.fact-strip strong { color: var(--text); font-weight: 600; }

/* --- Lists ---------------------------------------------------------- */
.mechanic-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.4rem 1.25rem;
}
.mechanic-list li a { display: block; padding: 0.35rem 0; }

/* --- Homepage ------------------------------------------------------- */
.hero { padding: 1rem 0 2rem; }
.tagline { font-size: 1.15rem; color: var(--muted); max-width: 40rem; }
.button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-weight: 600;
}
.button:hover { text-decoration: none; opacity: 0.92; }
.button-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
.button-ghost:hover { background: var(--accent-soft); opacity: 1; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.search { margin-top: 1.5rem; position: relative; max-width: 30rem; }
.search input {
  width: 100%;
  max-width: 30rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}
/* Homepage search dropdown — overlays the domain tree below it. Reuses the
   .search-results box style shared with the map; adds absolute positioning. */
.hero .search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.3rem);
  z-index: 6;
  max-height: 320px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.hero .search-results li { padding: 0; }
.hero .search-results a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.7rem;
  color: var(--text);
}
.hero .search-results a:hover { text-decoration: none; }
.hero .search-results li:hover { background: var(--accent-soft); }
.sr-cat { color: var(--muted); font-size: 0.82rem; flex: none; }
.search-status { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 0; }
.domain { margin: 2rem 0; }
.domain > h2 { border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.domain-categories {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.4rem 1.5rem;
}
.domain-categories a { font-weight: 600; }
.domain-categories .cat-count { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

/* --- Sponsor -------------------------------------------------------- */
.sponsor {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.sponsor .sponsor-label {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.7rem;
  color: var(--muted);
}
.sponsor-header { margin-left: 0; }
.sponsor-footer { margin-bottom: 1rem; max-width: 22rem; }
.sponsor img { height: 24px; width: auto; display: block; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  h1 { font-size: 1.6rem; }
  .site-nav { margin-left: 0; }
  .sponsor-header { width: 100%; }
}

/* --- Game reverse-index --------------------------------------------- */
.game-cat h2 { border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.game-list { margin-top: 1rem; }

/* --- Random roll ---------------------------------------------------- */
.roll-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
  margin: 1.5rem 0;
}
.roll-count {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
  margin: 0;
}
.roll-count legend { font-size: 0.8rem; color: var(--muted); padding: 0; }
.roll-count label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
.roll-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.roll-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
}
.roll-card-name { font-size: 1.15rem; margin: 0 0 0.2rem; }
.roll-card-cat {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.roll-card-desc { font-size: 0.95rem; margin: 0; }
.roll-status { color: var(--muted); }

/* --- Interactive map ------------------------------------------------ */
/* Fill the viewport with a flex column so the map always gets exactly the
   space left by the header, whatever height the header wraps to. */
.map-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.map-page .site-header { flex: 0 0 auto; max-width: none; }
.map-shell {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  overflow: hidden;
}
#cy { position: absolute; inset: 0; background: var(--bg); }

.map-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 250px;
  max-width: calc(100% - 24px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  z-index: 5;
  backdrop-filter: blur(6px);
  font-size: 0.9rem;
}
.control-block { margin-bottom: 0.6rem; }
.control-block summary { cursor: pointer; font-weight: 600; margin-bottom: 0.3rem; }
.control-block label { display: flex; align-items: center; gap: 0.4rem; padding: 0.1rem 0; }
.map-controls input[type="search"] {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex: none; }
.search-results {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.search-results li { padding: 0.4rem 0.6rem; cursor: pointer; }
.search-results li:hover { background: var(--accent-soft); }
.map-hint { color: var(--muted); font-size: 0.78rem; margin: 0.5rem 0 0; }
.control-note { color: var(--muted); font-size: 0.72rem; line-height: 1.4; margin: 0.4rem 0 0; }

.map-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 380px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.25rem;
  z-index: 6;
  backdrop-filter: blur(6px);
  line-height: 1.55;
}
.map-panel h2 { margin-top: 0.1rem; margin-bottom: 0.6rem; font-size: 1.3rem; padding-right: 1.5rem; }
.panel-desc { font-size: 0.95rem; }
.panel-meta { font-size: 0.92rem; margin: 0.35rem 0; }
.panel-relations { margin-top: 0.75rem; padding-top: 0.6rem; border-top: 1px solid var(--border); }
.panel-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.panel-key { color: var(--muted); }
.panel-rel, .panel-cats { font-size: 0.92rem; margin: 0.4rem 0; }
.panel-open { margin-top: 0.8rem; }
.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  z-index: 4;
}
.map-loading[hidden] { display: none; }

@media (max-width: 600px) {
  /* Controls: compact, sits top-left over the graph. */
  .map-controls { width: 168px; padding: 0.5rem; font-size: 0.82rem; }
  .map-controls input[type="search"] { font-size: 0.85rem; padding: 0.4rem 0.5rem; }
  .map-hint { display: none; }
  /* Detail panel becomes a bottom sheet so it doesn't cover the graph. */
  .map-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    max-height: 48%;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
  }
}
