/* ============================================================
   Keely Reader — Global Stylesheet
   public/styles/reader.css
   ============================================================ */

/* ------------------------------------------------------------
   Design tokens — override these to theme a Keely instance
   ------------------------------------------------------------ */
:root {
  /* Colors */
  --color-bg: #ffffff;
  --color-text: #1a1a1a;
  --color-link: #4a3f8f;
  --color-link-hover: #2d2660;
  --color-border: #cccccc;
  --color-header-bg: #1a1a2e;
  --color-header-text: #ffffff;
  --color-wiki-bg: #f5f5f5;
  --color-wiki-strip: #4a3f8f;

  /* Typography */
  --font-prose: Georgia, 'Times New Roman', serif;
  --font-ui: system-ui, -apple-system, sans-serif;
  --font-size-base: 1.1rem;
  --line-height-prose: 1.75;

  /* Layout */
  --header-height: 48px;
  --wiki-pane-width: 380px;
  --wiki-pane-collapsed-width: 12px;
  --prose-pane-padding: 2rem;
  --prose-max-width: 75ch;

  /* story blocks */
  --color-warning-bg: #fff8e1;
  --color-warning-border: #f0c040;
  --color-block-bg: #f5f5f5;
  --color-block-border: #cccccc;
  --color-credits-bg: #e8f0fe;
  --color-credits-border: #4a7fc1;
  --color-acknowledgments-bg: #e8f4fd;
  --color-acknowledgments-border: #5ba3c9;
}

/* ------------------------------------------------------------
   Reset & base
   ------------------------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-prose);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.site-layout {
  overflow: auto;
  height: auto;
}

/* ------------------------------------------------------------
   Site header
   ------------------------------------------------------------ */
#site-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--color-header-bg);
  color: var(--color-header-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  font-family: var(--font-ui);
  z-index: 10;
}

#site-header a {
  color: var(--color-header-text);
  text-decoration: none;
}

#site-header a:hover {
  text-decoration: underline;
}

#nav-toggle {
  background: transparent;
  border: 1px solid var(--color-header-text);
  color: var(--color-header-text);
  font-family: var(--font-ui);
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  border-radius: 3px;
}

#nav-toggle:hover {
  background: rgba(255,255,255,0.1);
}

#wiki-header-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--color-header-text);
  color: var(--color-header-text);
  font-family: var(--font-ui);
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  border-radius: 3px;
}

#wiki-header-btn:hover {
  background: rgba(255,255,255,0.1);
}

/* ------------------------------------------------------------
   Pane row
   ------------------------------------------------------------ */
#pane-row {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

/* ------------------------------------------------------------
   Prose pane
   ------------------------------------------------------------ */
#prose-pane {
  flex: 1;
  overflow-y: auto;
  padding: var(--prose-pane-padding);
}

#prose-pane > * {
  max-width: var(--prose-max-width);
  margin-left: auto;
  margin-right: auto;
}

#prose-pane a {
  color: var(--color-link);
}

#prose-pane a:hover {
  color: var(--color-link-hover);
}

/* ------------------------------------------------------------
   Projects Index page
   ------------------------------------------------------------ */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.project-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.project-card-cover {
  width: 100%;
  height: auto;
  display: block;
}

.project-card-cover-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--color-wiki-bg);
}

.project-card-meta {
  padding: 0.75rem;
}

.project-card-meta h2 {
  font-size: 1rem;
  margin: 0 0 0.25rem 0;
}

.project-card-tagline {
  font-size: 0.85rem;
  color: var(--color-text-muted, #666);
  margin: 0;
}

.project-card-tags {
  margin-top: 0.5rem;
}

.project-card-tags .meta-genre,
.project-card-tags .meta-rating {
  font-size: 0.5rem;
  padding: 0.2rem 0.5rem;
}

/* ------------------------------------------------------------
   Scene page
   ------------------------------------------------------------ */
.scene-meta {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  background: var(--color-wiki-bg);
  border-left: 4px solid var(--color-wiki-strip);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}

.scene-meta p {
  margin: 0.3rem 0;
  line-height: 1.4;
}

.scene-prose hr,
hr {
  margin-bottom: 1.5rem;
}

#prose-pane .scene-prose p {
  margin-bottom: 1.1em;
  line-height: 1.5;
}

.scene-filter {
  margin-top: 0.75rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

.scene-filter select {
  margin-left: 0.5rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.scene-inline-image {
  max-width: 50%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
}

.scene-authors-note {
  background: var(--color-credits-bg);
  border-left: 4px solid var(--color-credits-border);
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}


/* ------------------------------------------------------------
   Wiki pane
   ------------------------------------------------------------ */
#wiki-pane {
  width: var(--wiki-pane-width);
  min-width: var(--wiki-pane-width);
  background: var(--color-wiki-bg);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 1.5rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
}

/* Collapsed state */
#wiki-pane.collapsed {
  width: var(--wiki-pane-collapsed-width);
  min-width: var(--wiki-pane-collapsed-width);
  padding: 0;
  overflow: hidden;
  background: var(--color-wiki-strip);
  cursor: pointer;
}

#wiki-pane.collapsed .wiki-pane-inner {
  display: none;
}

/* Toggle tab */
#wiki-toggle {
  position: relative;
  align-self: center;
  width: 16px;
  height: 48px;
  background: var(--color-wiki-strip);
  border: none;
  border-radius: 4px 0 0 4px;
  cursor: pointer;
  color: white;
  font-size: 0.6rem;
  z-index: 5;
  flex-shrink: 0;
}

/* ------------------------------------------------------------
   Wiki pane contents
   ------------------------------------------------------------ */
#wiki-pane a {
  color: var(--color-link);
}

#wiki-pane a:hover {
  color: var(--color-link-hover);
}

#wiki-nav-controls {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  font-family: var(--font-ui);
}

.wiki-pane-index-link {
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.wiki-pane-index-link a {
  color: var(--color-link);
  text-decoration: none;
}

.wiki-pane-index-link a:hover {
  text-decoration: underline;
}

.entity-tags ul {
  padding-left: 1.25rem;
}

#scene-info p {
  margin-bottom: 0.6rem;
}


/* ------------------------------------------------------------
   Story landing page
   ------------------------------------------------------------ */

.story-banner img {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: cover;
}

.story-landing {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-prose);
}

.story-back {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.story-back a {
  color: var(--color-link);
  text-decoration: none;
}

.story-back a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.story-block {
  border-left: 4px solid var(--color-block-border);
  background: var(--color-block-bg);
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

.story-block h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  color: var(--color-text);
}

.story-block--warnings {
  background: var(--color-warning-bg);
  border-left-color: var(--color-warning-border);
}

.story-landing h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.story-tagline {
  font-size: 1.2rem;
  color: #555;
  margin-bottom: 1.5rem;
}

.story-summary {
  line-height: var(--line-height-prose);
  margin-bottom: 1.5rem;
}

.story-author-note {
  color: #555;
  font-style: italic;
  line-height: var(--line-height-prose);
  margin-bottom: 1.5rem;
}

.story-start {
  display: inline-block;
  margin: 1.5rem 0;
  padding: 0.75rem 2rem;
  background: var(--color-header-bg);
  color: white;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 1.1rem;
  border-radius: 3px;
}

.story-start:hover {
  opacity: 0.85;
}

.story-block {
  margin-bottom: 1.5rem;
}

.story-block--credits {
  background: var(--color-credits-bg);
  border-left-color: var(--color-credits-border);
}

.story-block--acknowledgments {
  background: var(--color-acknowledgments-bg);
  border-left-color: var(--color-acknowledgments-border);
}


#entity-content .entity-portrait img {
  width: 40%;
  max-width: 150px;
  height: auto;
  float: right;
  margin: 0 0 1rem 1rem;
}

.entity-portrait img {
  max-width: 300px;
  width: 100%;
  height: auto;
}

.story-meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-ui);
}

.story-status {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

.story-status span {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.meta-genre {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: #2d6a4f;
  color: white;
  font-size: 0.85rem;
  border-radius: 3px;
  font-weight: 600;
}

.meta-subgenre {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: #d8f3dc;
  border: 1px solid #95d5b2;
  color: #1b4332;
  font-size: 0.85rem;
  border-radius: 3px;
}

.meta-rating {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--color-wiki-strip);
  color: white;
  font-size: 0.85rem;
  border-radius: 3px;
  font-weight: 600;
}

/* ------------------------------------------------------------
   Project landing page
   ------------------------------------------------------------ */

.project-banner img {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: cover;
}

.project-cover img {
  max-width: 300px;
  width: 100%;
  height: auto;
}

.project-landing {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-prose);
}

.project-tagline {
  font-size: 1.2rem;
  color: #555;
  margin-bottom: 1.5rem;
}

.project-summary {
  line-height: var(--line-height-prose);
  margin-bottom: 1.5rem;
}

.project-author {
  font-size: 0.9rem;
  color: #777;
  margin-bottom: 1.5rem;
}

.project-author a {
  color: var(--color-link);
}

.project-author a:hover {
  color: var(--color-link-hover);
}

.project-author-note {
  color: #555;
  font-style: italic;
  line-height: var(--line-height-prose);
  margin-bottom: 1.5rem;
}

.project-stories {
  margin-top: 2rem;
}

.project-stories h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  font-family: var(--font-ui);
}

.project-stories a {
  color: var(--color-link);
}

.project-stories a:hover {
  color: var(--color-link-hover);
}

/* ------------------------------------------------------------
   Publisher landing page
   ------------------------------------------------------------ */

.publisher-landing {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-prose);
}

.publisher-landing h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.publisher-tagline {
  font-size: 1.2rem;
  color: #555;
  margin-bottom: 1.5rem;
}

.publisher-blurb {
  line-height: var(--line-height-prose);
  margin-bottom: 2rem;
}

.publisher-nav {
  display: flex;
  gap: 1.5rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.publisher-nav-card {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 160px;
  padding: 1.5rem 2rem;
  background: var(--color-wiki-bg);
  border: 2px solid var(--color-border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--color-text);
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.publisher-nav-card:hover {
  border-color: var(--color-link);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  color: var(--color-link);
}

/* ------------------------------------------------------------
   About page
   ------------------------------------------------------------ */

.about-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-prose);
}

.about-page h1 {
  font-size: 2.5rem;
  margin-bottom: 2rem;
}

.about-author {
  margin-bottom: 3rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--color-border);
}

.about-author:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.about-author h2 {
  font-size: 1.75rem;
  margin-bottom: 1rem;
}

.about-portrait {
  float: right;
  margin: 0 0 1.5rem 2rem;
}

.about-portrait img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

.about-bio {
  line-height: var(--line-height-prose);
  margin-bottom: 1.5rem;
}

.about-bio p {
  margin-bottom: 1em;
}

.about-links {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  clear: both;
}

.about-links li {
  display: inline-block;
  margin-right: 0.75rem;
  margin-top: 0.5rem;
}

.about-links a {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--color-link);
  border-radius: 3px;
  color: var(--color-link);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.about-links a:hover {
  background: var(--color-link);
  color: white;
}

/* ------------------------------------------------------------
   Wiki index page
   ------------------------------------------------------------ */

.wiki-index {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-ui);
}

.wiki-index h1 {
  font-size: 2rem;
  margin-bottom: 2rem;
  font-family: var(--font-prose);
}

.wiki-index-section {
  margin-bottom: 2rem;
}

.wiki-index-section h2 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--color-border);
}

.wiki-index-section h2 a {
  color: var(--color-text);
  text-decoration: none;
}

.wiki-index-section h2 a:hover {
  color: var(--color-link);
}

.wiki-index-list {
  list-style: none;
  padding: 0;
}

.wiki-index-list li {
  padding: 0.25rem 0;
}

.wiki-index-list a {
  color: var(--color-link);
  text-decoration: none;
}

.wiki-index-list a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

/* ------------------------------------------------------------
   Wiki pages
   ------------------------------------------------------------ */

.entity-prose {
  line-height: var(--line-height-prose);
}

.entity-prose p {
  margin-bottom: 1em;
}

.entity-prose ul,
.entity-prose ol {
  padding-left: 1.5rem;
  margin-bottom: 1em;
}

.entity-prose li {
  margin-bottom: 0.25em;
}

.entity-prose h2,
.entity-prose h3,
.entity-prose h4 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

/* ------------------------------------------------------------
   Tags index page
   ------------------------------------------------------------ */
.tags-index {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-ui);
}

.tags-index h1 {
  font-size: 2rem;
  margin-bottom: 2rem;
  font-family: var(--font-prose);
}

.tags-list {
  list-style: none;
  padding: 0;
}

.tags-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
}

.tags-list li:last-child {
  border-bottom: none;
}

.tags-list a {
  color: var(--color-link);
  text-decoration: none;
  font-size: 1.05rem;
}

.tags-list a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

/* ------------------------------------------------------------
   Individual tag page
   ------------------------------------------------------------ */
.tag-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-ui);
}

.tag-page h1 {
  font-size: 2rem;
  margin-bottom: 2rem;
  font-family: var(--font-prose);
}

.tag-section {
  margin-bottom: 2rem;
}

.tag-section h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  margin-bottom: 0.75rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--color-border);
}

.tag-section ul {
  list-style: none;
  padding: 0;
}

.tag-section li {
  padding: 0.3rem 0;
}

.tag-section a {
  color: var(--color-link);
  text-decoration: none;
}

.tag-section a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

/* ------------------------------------------------------------
   Projects index page
   ------------------------------------------------------------ */

.projects-index {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
  font-family: var(--font-ui);
}

.projects-index h1 {
  font-size: 2rem;
  margin-bottom: 2rem;
  font-family: var(--font-prose);
}

.projects-list {
  list-style: none;
  padding: 0;
}

.projects-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.projects-list a {
  color: var(--color-link);
  text-decoration: none;
  font-size: 1.1rem;
}

.projects-list a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.projects-tagline {
  color: #555;
  font-size: 0.95rem;
}

/* Entity index pages */
.entity-index {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.entity-index h1 {
  margin-bottom: 1.5rem;
}

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.entity-card {
  display: block;
  padding: 1rem;
  border: 1px solid var(--color-border, #ddd);
  border-radius: 4px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.entity-card:hover {
  border-color: var(--color-link);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.entity-card-name {
  font-weight: 600;
  color: var(--color-link);
}

.entity-card-sub {
  font-size: 0.85rem;
  color: var(--color-text-muted, #666);
  margin-top: 0.25rem;
}

/* Entity pages */
.entity-page {
  max-width: 700px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.entity-meta {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--color-surface, #f9f9f9);
  border-radius: 4px;
  border: 1px solid var(--color-border, #ddd);
}

.entity-meta p {
  margin: 0.4rem 0;
}

.entity-prose {
  margin: 1.5rem 0;
}

.entity-appearances {
  margin: 1.5rem 0;
}

.entity-appearances h2 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.entity-appearances ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.entity-appearances li {
  margin: 0.3rem 0;
}

/* ------------------------------------------------------------
   Mobile drawer (max 768px)
   ------------------------------------------------------------ */

/* Hide the header wiki button on desktop */

#wiki-header-btn {
  display: none;
}

@media (max-width: 768px) {
  /* Hide the collapse tab - replaced by header button on mobile */
  #wiki-toggle {
    display: none;
  }

  #wiki-header-btn {
    display: inline-block;
  }

  /* Wiki pane becomes a fixed overlay drawer */
  #wiki-pane {
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: 85vw;
    max-width: var(--wiki-pane-width);
    height: calc(100vh - var(--header-height));
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 100;
    min-width: unset;
  }

  /* Open state */
  #wiki-pane.drawer-open {
    transform: translateX(0);
  }

  /* Backdrop */
  #wiki-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
  }

  #wiki-backdrop.active {
    display: block;
  }
}