/* ========================================
   Garbaniphoro Grand Library - Main Theme
   Greek classical + dark aesthetic
   ======================================== */

/* --- Fonts loaded via <link> in each HTML file for non-blocking first paint --- */

/* --- Shared Properties (theme files provide color vars) --- */
:root {
  /* Typography */
  --font-heading: 'Cinzel', 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
  --font-body: 'EB Garamond', 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
  --font-serif: 'EB Garamond', 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
  --font-display: 'EB Garamond', 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
  /* Latin-first stack — use on names / short labels where the EN word should look refined.
     Keep CJK fallback so mixed strings stay coherent. */
  --font-latin: 'EB Garamond', 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
  --font-weight-heading: 600;
  --font-weight-body: 300;

  /* Modular type scale — 8 levels anchored at body 1rem.
     Reading region (micro→body) uses a tight ~1.07 ratio for fine
     differentiation between meta / small / secondary / body. Heading
     region (lead→h2) jumps 1.125 / 1.333 / 1.5 for clear hierarchy. */
  --fs-micro:     0.75rem;    /* 12px — badges, counts, version chips */
  --fs-meta:      0.8125rem;  /* 13px — kicker, speaker, version label */
  --fs-small:     0.875rem;   /* 14px — meta info, short intro */
  --fs-secondary: 0.9375rem;  /* 15px — bilingual mirror text */
  --fs-body:      1rem;       /* 16px — reading body anchor */
  --fs-lead:      1.125rem;   /* 18px — list titles, epigraph, intro */
  --fs-h3:        1.5rem;     /* 24px — section / card title */
  --fs-h2:        2.25rem;    /* 36px — page title */

  /* Sizing */
  --max-width: 1200px;
  --nav-height: 60px;

  /* Transitions */
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition: 250ms var(--ease);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  font-family: var(--font-body);
  font-weight: var(--font-weight-body);
  color: var(--text-primary);
  background: var(--bg-base);
  line-height: 1.7;
  min-height: 100vh;
}


a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover {
  color: var(--gold-bright);
}

::selection {
  background: var(--gold-glow);
  color: var(--text-primary);
}

/* --- Keyboard focus indicator (mouse clicks don't trigger this) --- */
:focus-visible {
  outline: 2px solid var(--gold-dim);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Programmatically-focused view containers (tabindex="-1") receive focus
   only to anchor screen readers / keyboard users into the new view after
   a route swap. The user already knows where they are, so suppress the
   visible focus ring on these wrappers without affecting real keyboard
   focus on interactive elements inside. */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}

/* Skip-to-content link — first focusable element on every page so
   keyboard / screen-reader users can jump past the nav into main.
   Hidden visually until focused; theme-aware via tokens. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.65rem 1.1rem;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-decoration: none;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: 2px;
}
.skip-link:focus,
.skip-link:focus-visible {
  left: 0.5rem;
  top: 0.5rem;
  outline: 2px solid var(--gold-dim);
  outline-offset: 2px;
}

/* --- Header & Navigation --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: transparent;
  backdrop-filter: none;
  border-bottom: 1px solid transparent;
  transition: background 0.3s ease, border-color 0.3s ease, backdrop-filter 0.3s ease;
}
.site-header.scrolled {
  background: rgba(236, 232, 224, 0.90);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  line-height: 1.25;
}
.site-logo:hover {
  color: var(--gold-bright);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 0.5rem 0.85rem;
  border-radius: 2px;
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
}
.nav-link:hover,
.nav-link:focus-visible {
  color: var(--text-primary);
  background: var(--gold-glow);
}
.nav-link.active {
  color: var(--gold);
}

.lang-toggle {
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-primary);
  background: transparent;
  border: none;
  padding: 0.35rem 0.4rem;
  cursor: pointer;
  letter-spacing: 0.08em;
  transition: all var(--transition);
  margin-left: 0.1rem;
}
.lang-toggle:hover {
  color: var(--gold);
}

/* --- Theme Switcher --- */
.theme-switcher {
  position: relative;
  margin-left: 0.5rem;
}
.theme-trigger {
  font-family: var(--font-heading);
  font-size: 0.58rem;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid rgba(0, 0, 0, 0.35);
  padding: 0.18rem 0.5rem 0.18rem 0.6rem;
  min-width: 3.8rem;
  border-radius: 5px;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  white-space: nowrap;
}
.theme-trigger::after {
  content: '▾';
  font-size: 0.6rem;
  opacity: 0.6;
}
.theme-trigger:hover {
  color: var(--gold);
  border-color: var(--border-accent);
}
.theme-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 3px;
  min-width: 100%;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.theme-switcher.open .theme-dropdown {
  display: block;
}
.theme-option {
  display: block;
  width: 100%;
  font-family: var(--font-heading);
  font-size: 0.65rem;
  color: var(--text-muted);
  background: transparent;
  border: none;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  transition: all var(--transition);
  white-space: nowrap;
}
.theme-option:hover {
  color: var(--gold);
  background: var(--gold-glow);
}
.theme-option.active {
  color: var(--gold);
}

/* --- Theme Ribbons (right-edge bookmarks, all pages except home) --- */
.ribbon-rail {
  position: fixed;
  top: 30vh;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 50;
  pointer-events: none;
}
/* faint vertical spine, anchors the rail without shouting */
.ribbon-rail::before {
  content: '';
  position: absolute;
  top: -10px;
  bottom: -10px;
  right: 0;
  width: 1px;
  background: currentColor;
  color: var(--text-muted, rgba(0,0,0,0.18));
  opacity: 0.22;
  pointer-events: none;
}

.ribbon {
  pointer-events: auto;
  position: relative;
  width: 84px;
  height: 18px;
  cursor: pointer;
  border: none;
  padding: 0 7px 0 14px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  font-family: var(--font-heading, 'Cinzel', serif);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  clip-path: polygon(8px 0, 100% 0, 100% 100%, 8px 100%, 0 50%);
  transition: width 0.5s cubic-bezier(0.22, 0.61, 0.36, 1),
              opacity 0.32s ease,
              filter 0.32s ease;
  opacity: 0.62;
  box-shadow:
    inset 0 0 0 1.2px var(--gilt, #c8a474),
    inset 0 0 0 2.2px rgba(0,0,0,0.18),
    -3px 2px 8px rgba(0,0,0,0.05);
}
.ribbon.active { width: 110px; }
.ribbon:hover { width: 110px; opacity: 0.92; }

/* paper grain — faint and warm, no harsh noise */
.ribbon::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='80' height='80'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.25 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.14;
  mix-blend-mode: multiply;
  pointer-events: none;
  clip-path: inherit;
}

/* thin top hairline — like a ribbon's folded edge catching light */
.ribbon::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 2px;
  top: 2px;
  height: 1px;
  background: rgba(255,255,255,0.10);
  pointer-events: none;
}

/* === Dusty, theme-tuned palette + per-theme gilt accent color === */
.ribbon[data-theme="light"] {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06) 0%, rgba(0,0,0,0.04) 100%),
    #8e5b4d;
  color: #f0e3cc;
  --gilt: #d4a86c;
}
.ribbon[data-theme="sepia"] {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05) 0%, rgba(0,0,0,0.06) 100%),
    #7d806f;
  color: #ebe0c4;
  --gilt: #c8a474;
}
.ribbon[data-theme="dark"] {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04) 0%, rgba(0,0,0,0.08) 100%),
    #2c2622;
  color: #c8a472;
  --gilt: #a8845a;
}

/* active state — gilt frame deepens, palmette ornament appears */
.ribbon.active {
  opacity: 1;
  box-shadow:
    inset 0 0 0 1.2px var(--gilt),
    inset 0 0 0 2.4px rgba(0,0,0,0.22),
    -4px 2px 10px rgba(0,0,0,0.12);
}

.ribbon:focus-visible {
  outline: none;
  opacity: 1;
  filter: brightness(1.06);
}

/* Active ornament — gilt rule + anthemion palmette only appear on active ribbon */
.rib-text { flex: 0 0 auto; }
.rib-rule {
  display: none;
  flex: 1 1 auto;
  height: 1px;
  min-width: 4px;
  background: linear-gradient(90deg, transparent 0%, var(--gilt) 30%, var(--gilt) 70%, transparent 100%);
  opacity: 0.85;
}
.rib-orn {
  display: none;
  flex: 0 0 auto;
  color: var(--gilt);
  line-height: 0;
  filter:
    drop-shadow(0 0 1px rgba(0,0,0,0.55))
    drop-shadow(0 0 2px var(--gilt-glow, rgba(212,168,108,0.45)));
}
.rib-orn svg {
  stroke-width: 1.35;
  fill: currentColor;
}
.rib-orn svg g {
  stroke-width: 1.35 !important;
}
.ribbon[data-theme="light"] { --gilt-glow: rgba(212,168,108,0.50); }
.ribbon[data-theme="sepia"] { --gilt-glow: rgba(200,164,116,0.45); }
.ribbon[data-theme="dark"]  { --gilt-glow: rgba(200,160,100,0.55); }
.ribbon.active .rib-rule,
.ribbon.active .rib-orn { display: block; }

.ribbon .tip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  background: rgba(20,15,10,0.92);
  color: #f4ecd6;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
  font-size: 11px;
  letter-spacing: 0.18em;
  padding: 7px 12px;
  font-weight: 300;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  border: 1px solid rgba(200,164,114,0.32);
}
.ribbon .tip strong {
  display: block;
  font-family: var(--font-heading, 'Cinzel', serif);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.28em;
  margin-bottom: 2px;
  color: #c8a474;
}
.ribbon:hover .tip { opacity: 1; }

@media (max-width: 640px) {
  .ribbon {
    width: 64px;
    height: 20px;
    font-size: 9px;
    letter-spacing: 0.14em;
    padding: 0 10px 0 16px;
    clip-path: polygon(6px 0, 100% 0, 100% 100%, 6px 100%, 0 50%);
  }
  .ribbon.active, .ribbon:hover { width: 116px; }
}

/* --- Main Content --- */
.main-content {
  position: relative;
  z-index: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  min-height: calc(100vh - var(--nav-height) - 80px);
}

/* --- Page Titles --- */
.page-title {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.06em;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.page-subtitle {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 2rem;
}

/* Decorative divider */
.divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--border-medium) 20%,
    var(--border-accent) 50%,
    var(--border-medium) 80%,
    transparent 100%
  );
  margin: 2rem 0;
}

/* --- Footer --- */
.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--border-subtle);
  padding: 1.5rem;
  text-align: center;
}

.site-footer p {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: var(--max-width);
  margin: 0 auto;
  line-height: 1.6;
}
/* "A fan-made archive for Castrum Kremnos." — set in Noto Serif SC for a
   classical Chinese-serif feel. Excludes painting credit and contact line. */
.site-footer > p:not(.painting-credit-footer):not(.site-footer-contact) {
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', SimSun, Georgia, serif;
}

.site-footer-contact {
  position: absolute !important;
  right: 0.75rem;
  bottom: 0.5rem;
  max-width: none !important;
  margin: 0 !important;
  font-family: 'EB Garamond', 'Cormorant Garamond', Georgia, serif;
  font-style: italic;
  font-weight: 300;
  font-size: 0.7rem !important;
  letter-spacing: -0.005em;
  text-align: right !important;
  opacity: 0.75;
}

.site-footer-contact a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
  transition: opacity 0.2s ease;
}

.site-footer-contact a:hover {
  opacity: 0.7;
}

/* --- Utility --- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

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

mark {
  background: rgba(138, 109, 46, 0.25);
  color: var(--text-primary);
  padding: 0.05em 0.15em;
  border-radius: 2px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 1rem;
  }

  .main-nav {
    gap: 0;
  }

  .nav-link {
    font-size: 0.7rem;
    padding: 0.4rem 0.5rem;
    letter-spacing: 0.05em;
  }

  .site-logo {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
  }

  .main-content {
    padding: 1.5rem 1rem;
  }

  .page-title {
    font-size: 1.6rem;
  }
}

@media (max-width: 480px) {
  .nav-link {
    font-size: 0.65rem;
    padding: 0.35rem 0.35rem;
  }

  .lang-toggle {
    margin-left: 0.35rem;
    padding: 0.25rem 0.5rem;
  }
}
