/*
 * Shared stylesheet for the Scriptorium Genre Manual.
 *
 * Loaded by both the index page (/scriptoriumGenres) and every single-genre
 * page (/scriptoriumGenres/:id). All visual rules live here — change the
 * editorial palette in :root, change layouts in their named sections, and
 * every genre page picks the change up automatically.
 *
 * Companion: /genres/manual.js owns rendering and behavior.
 */

:root {
  --paper:    #0B1020;
  --paper2:   #111733;
  --card:     #161D3A;
  --ink:      #E6EBFF;
  --ink2:     #C7D0EE;
  --ink3:     #8893BF;
  --rule:     #252C4E;
  --rule2:    #1E2545;
  --accent:   #F87171;
  --accent2:  #FB7185;
  --positive: #34D399;
  --warn:     #FBBF24;
  --cool:     #60A5FA;
  --cool2:    #22D3EE;
  --display:  'Fraunces', Georgia, serif;
  --body:     'IBM Plex Sans', system-ui, sans-serif;
  --mono:     'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--body); font-size: 14px; line-height: 1.6;
  background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,0.04) 1px, transparent 0);
  background-size: 18px 18px;
}
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--rule); }
a:hover { color: var(--accent2); border-bottom-color: var(--accent2); }
code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--card); border: 1px solid var(--rule2);
  border-radius: 3px; padding: 1px 5px;
}

/* ===== Masthead =========================================================== */

header.masthead {
  max-width: 1080px; margin: 0 auto;
  padding: 56px 32px 24px; border-bottom: 1px solid var(--rule);
}
.seal {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent);
  padding: 4px 10px; border: 1px solid var(--accent); border-radius: 2px;
}
.masthead h1 {
  font-family: var(--display); font-weight: 500;
  font-size: 44px; line-height: 1.05;
  margin: 18px 0 6px; letter-spacing: -0.01em;
}
.masthead .deck {
  font-family: var(--display); font-style: italic; font-weight: 400;
  font-size: 19px; color: var(--ink2); margin: 0 0 14px;
}
.masthead .meta {
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink3);
}
.crosslink {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 16px;
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink3); border-bottom: 1px solid var(--rule); padding-bottom: 1px;
}
.crosslink:hover { color: var(--accent); border-bottom-color: var(--accent); }
.crosslink + .crosslink { margin-inline-start: 14px; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 32px 80px; }

/* ===== Breadcrumb (single-genre pages) ==================================== */

nav.breadcrumb {
  margin: 18px 0 24px;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.06em; color: var(--ink3);
}
nav.breadcrumb a {
  color: var(--ink3); border-bottom: none;
}
nav.breadcrumb a:hover { color: var(--accent); }
nav.breadcrumb .sep { margin: 0 8px; color: var(--rule); }

/* ===== Category navigation (index page) =================================== */

nav.cat-nav-wrap {
  background: var(--card); border: 1px solid var(--rule2);
  border-radius: 4px; padding: 18px 22px; margin: 24px 0 32px;
}
nav.cat-nav-wrap h4 {
  font-family: var(--body); font-weight: 600; font-size: 13px;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink2);
  margin: 0 0 12px;
}
ul.cat-nav { list-style: none; padding: 0; margin: 0; columns: 2; column-gap: 28px; }
@media (max-width: 720px) { ul.cat-nav { columns: 1; } }
ul.cat-nav li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; break-inside: avoid;
}
ul.cat-nav a { border-bottom: none; color: var(--ink2); flex: 1; }
ul.cat-nav a:hover { color: var(--accent); }
ul.cat-nav .count {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink3);
  background: var(--paper2); border: 1px solid var(--rule2);
  padding: 1px 7px; border-radius: 2px;
  min-width: 28px; text-align: center;
}

/* ===== Category section (index page) ====================================== */

section.category { margin: 56px 0 0; }
.section-num {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px;
}
section.category h2 {
  font-family: var(--display); font-weight: 500;
  font-size: 30px; letter-spacing: -0.005em;
  margin: 0 0 12px; padding-bottom: 8px;
  border-bottom: 2px solid var(--ink);
}
.cat-summary { color: var(--ink3); margin: 0 0 20px; font-size: 13px; }

/* Genre tiles inside category sections (index) */
.genre-tiles {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
a.genre-tile {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 16px;
  background: var(--paper2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: inherit;
  border-bottom: 1px solid var(--rule);
  transition: border-color 120ms ease, transform 120ms ease;
}
a.genre-tile:hover {
  border-color: var(--accent);
  color: inherit;
  transform: translateY(-1px);
}
a.genre-tile .tile-name {
  font-family: var(--display); font-size: 17px; font-weight: 500;
  color: var(--ink);
}
a.genre-tile .tile-meta {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink3);
  letter-spacing: 0.04em;
}

/* ===== Single-genre page header =========================================== */

.genre-header {
  margin: 16px 0 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule2);
}
.genre-header .category-tag {
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px; display: block;
}
.genre-header h1 {
  font-family: var(--display); font-weight: 500;
  font-size: 48px; letter-spacing: -0.015em; line-height: 1.05;
  color: var(--ink); margin: 0 0 12px;
}
.genre-header .pills {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px;
}

/* ===== Section headings within genre body ================================= */

.genre-body h2 {
  font-family: var(--body); font-weight: 600; font-size: 13px;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink2);
  margin: 36px 0 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--rule2);
}
.genre-body h2:first-child { margin-top: 0; }
.genre-body p { margin: 0 0 12px; color: var(--ink2); }
.framework { font-size: 12.5px; color: var(--ink3); margin-top: -4px !important; }
.framework .label {
  font-family: var(--mono); font-size: 10px; color: var(--accent);
  letter-spacing: 0.12em; text-transform: uppercase;
  margin-inline-end: 6px;
}

/* ===== Writing context grid =============================================== */

dl.context {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 18px; margin: 0 0 12px;
}
dl.context > div {
  display: flex; gap: 8px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px dashed var(--rule2);
}
dl.context dt {
  font-family: var(--mono); font-size: 10px; color: var(--ink3);
  letter-spacing: 0.12em; text-transform: uppercase;
  min-width: 64px;
}
dl.context dd { margin: 0; font-size: 13px; color: var(--ink); }

/* ===== "How to write one" steps =========================================== */

ol.how-to {
  counter-reset: step; list-style: none;
  padding-inline-start: 0; margin: 0 0 8px;
}
ol.how-to > li {
  counter-increment: step;
  position: relative;
  padding: 14px 18px 14px 52px;
  margin: 8px 0;
  background: var(--paper2);
  border: 1px solid var(--rule2);
  border-radius: 4px;
  color: var(--ink2);
}
ol.how-to > li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute; inset-inline-start: 16px; top: 14px;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; color: var(--accent);
}
ol.how-to li strong { color: var(--ink); }
ol.how-to q {
  font-style: italic; color: var(--ink2);
  quotes: "\201C" "\201D";
}

/* ===== Craft anchors ====================================================== */

ul.anchors { list-style: none; padding: 0; margin: 0 0 8px; }
ul.anchors > li {
  padding: 10px 0;
  border-bottom: 1px dashed var(--rule2);
  color: var(--ink2);
}
ul.anchors > li:last-child { border-bottom: none; }
.anchor-cat {
  font-family: var(--mono); font-size: 10px; color: var(--accent);
  letter-spacing: 0.12em; text-transform: uppercase;
  margin-inline-end: 8px;
}

/* ===== Rubric traits ====================================================== */

.rubric-intro { font-size: 12.5px; color: var(--ink3); }
.traits {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
article.trait {
  background: var(--paper2);
  border: 1px solid var(--rule2);
  border-radius: 4px;
  padding: 14px 16px;
}
article.trait > header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 6px;
}
article.trait h3 {
  margin: 0; font-family: var(--display); font-weight: 500;
  font-size: 16px; color: var(--ink);
}
article.trait .weight {
  font-family: var(--mono); font-size: 11px;
  color: var(--accent); font-weight: 500;
}
article.trait .trait-desc {
  font-size: 12.5px; color: var(--ink2); margin: 0 0 8px;
}
article.trait details.levels { margin-top: 8px; }
article.trait details.levels > summary {
  cursor: pointer; font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink3); padding: 4px 0;
  list-style: none;
}
article.trait details.levels > summary::-webkit-details-marker { display: none; }
article.trait details.levels > summary::before {
  content: '+'; color: var(--accent); margin-inline-end: 4px;
}
article.trait details.levels[open] > summary::before { content: '−'; }
article.trait details.levels > summary:hover { color: var(--accent); }
article.trait details.levels ul {
  list-style: none; padding: 0; margin: 8px 0 0;
  display: grid; gap: 6px;
}
article.trait details.levels li {
  display: grid; grid-template-columns: 130px 1fr; gap: 10px;
  font-size: 12px; color: var(--ink2);
  padding: 6px 0; border-top: 1px dashed var(--rule2);
}
.level-tag {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.06em; padding: 2px 6px;
  border-radius: 2px; height: fit-content; align-self: start;
}
.level-1 { color: var(--ink3);    background: rgba(136,147,191,0.08); }
.level-2 { color: var(--cool);    background: rgba(96,165,250,0.08); }
.level-3 { color: var(--warn);    background: rgba(251,191,36,0.08); }
.level-4 { color: var(--positive);background: rgba(52,211,153,0.08); }
.level-5 { color: var(--accent);  background: rgba(248,113,113,0.08); }
.level-text { color: var(--ink2); }

/* ===== Pills ============================================================== */

.pill {
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.06em; padding: 3px 8px;
  border-radius: 2px; border: 1px solid;
  display: inline-flex; align-items: center;
}
.pill-human    { color: var(--positive); border-color: var(--positive); background: rgba(52,211,153,0.06); }
.pill-auto     { color: var(--ink3);     border-color: var(--rule);     background: var(--paper2); }
.pill-unknown  { color: var(--ink3);     border-color: var(--rule);     background: var(--paper2); }
.pill-neutral  { color: var(--ink2);     border-color: var(--rule);     background: var(--card); }

/* ===== Future-feature placeholders ======================================== */

.future-section {
  margin: 28px 0;
  padding: 18px 22px;
  background: var(--card);
  border: 1px dashed var(--rule);
  border-radius: 4px;
  color: var(--ink3);
  font-size: 13px;
}
.future-section h3 {
  font-family: var(--display); font-weight: 500;
  font-size: 16px; color: var(--ink2); margin: 0 0 6px;
}

/* ===== Misc =============================================================== */

.muted { color: var(--ink3); font-style: italic; }

footer {
  max-width: 1080px; margin: 0 auto;
  padding: 24px 32px 60px; border-top: 1px solid var(--rule);
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.06em; color: var(--ink3);
  text-align: center;
}
footer a { color: var(--ink3); }

/* RTL — most of the layout is logical-property-driven, but make sure the
   columns rule and the dotted background still behave. */
[dir="rtl"] ul.cat-nav { direction: rtl; }

/* ===== Genre popup (modal + iframe) ======================================
 * The index page intercepts tile clicks and opens a modal whose iframe
 * loads /scriptoriumGenres/{slug}?embed=1. The embed flag tells the
 * iframed page to hide its own masthead/footer (.genre-embed below) so
 * the modal frame doesn't show two mastheads stacked.
 * ========================================================================= */

.genre-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  animation: gmFadeIn 180ms ease;
}
.genre-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  cursor: pointer;
}
.genre-modal-card {
  position: relative;
  background: var(--paper);
  width: min(1120px, calc(100vw - 32px));
  height: min(880px, calc(100vh - 32px));
  border-radius: 6px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  display: flex; flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--rule);
  animation: gmCardIn 220ms ease;
}
.genre-modal-header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule2);
  background: var(--card);
  flex-shrink: 0;
}
.genre-modal-title {
  font-family: var(--display); font-weight: 500;
  font-size: 17px; color: var(--ink); flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.genre-modal-cat {
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent);
  margin-inline-end: 4px;
}
.genre-modal-open {
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink3);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
  text-decoration: none;
  white-space: nowrap;
}
.genre-modal-open:hover { color: var(--accent); border-bottom-color: var(--accent); }
.genre-modal-close {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 2px;
  width: 30px; height: 30px;
  font-size: 18px; line-height: 1;
  color: var(--ink2);
  cursor: pointer;
  padding: 0;
  font-family: var(--body);
  display: inline-flex; align-items: center; justify-content: center;
}
.genre-modal-close:hover {
  background: var(--accent); color: var(--paper);
  border-color: var(--accent);
}
.genre-modal-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: var(--paper);
  display: block;
}
@keyframes gmFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes gmCardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* On phones, take the full screen — modal is the page. */
@media (max-width: 720px) {
  .genre-modal-card {
    width: 100vw; height: 100vh;
    border-radius: 0; border: none;
  }
}

/* When this page is loaded *as* an iframe (embed mode), hide the chrome
   that would duplicate the modal's own header — masthead and footer. */
body.genre-embed header.masthead,
body.genre-embed footer { display: none; }
body.genre-embed main { padding-top: 16px; padding-bottom: 32px; }
body.genre-embed nav.breadcrumb { margin-top: 0; }
