/* ============================================================
   ПОДНЕБЕСЬЕ WIKI — Style Sheet
   Medieval fantasy · Warm dark palette · Cormorant + Raleway
   ============================================================ */

/* ── DESIGN TOKENS ──────────────────────────────────────── */
:root {
  /* Type scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Fonts */
  --font-display: 'Cormorant Garamond', 'Georgia', serif;
  --font-body:    'Raleway', 'Helvetica Neue', sans-serif;
}

/* ── LIGHT MODE ─────────────────────────────────────────── */
:root, [data-theme="light"] {
  --color-bg:              #f4f0e8;
  --color-surface:         #f8f5ee;
  --color-surface-2:       #faf8f3;
  --color-surface-offset:  #ede8dd;
  --color-surface-accent:  #e8dfce;
  --color-divider:         #d8d0c0;
  --color-border:          #c8bfac;
  --color-text:            #2a2218;
  --color-text-muted:      #6b5f4e;
  --color-text-faint:      #a89880;
  --color-text-inverse:    #f8f5ee;
  --color-gold:            #9c6f1e;
  --color-gold-light:      #c4973a;
  --color-gold-glow:       rgba(196, 151, 58, 0.15);
  --color-crimson:         #8b2a2a;
  --color-forest:          #2a5c3a;
  --color-slate:           #2a3c5c;
  --color-tag-bg:          #e4ddd0;
  --color-tag-text:        #5a4a38;
  --color-tag-active-bg:   #c4973a;
  --color-tag-active-text: #2a2218;
  --shadow-sm:  0 1px 3px rgba(42, 34, 24, 0.08);
  --shadow-md:  0 4px 16px rgba(42, 34, 24, 0.10);
  --shadow-lg:  0 12px 40px rgba(42, 34, 24, 0.14);
  --shadow-glow: 0 0 20px rgba(196, 151, 58, 0.18);
  --ornament-opacity: 0.08;
}

/* ── DARK MODE ──────────────────────────────────────────── */
[data-theme="dark"],
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --color-bg:              #14110c;
  --color-surface:         #1a1610;
  --color-surface-2:       #201b14;
  --color-surface-offset:  #17140f;
  --color-surface-accent:  #2a2218;
  --color-divider:         #2e2820;
  --color-border:          #3d3428;
  --color-text:             #e8dfc8;
  --color-text-muted:      #9a8a70;
  --color-text-faint:      #5a5045;
  --color-text-inverse:    #14110c;
  --color-gold:            #c4973a;
  --color-gold-light:      #e0b85a;
  --color-gold-glow:       rgba(196, 151, 58, 0.2);
  --color-crimson:         #c44040;
  --color-forest:          #4a8c5c;
  --color-slate:           #4a6c9c;
  --color-tag-bg:          #2a2218;
  --color-tag-text:        #9a8a70;
  --color-tag-active-bg:   #c4973a;
  --color-tag-active-text: #14110c;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 24px rgba(196, 151, 58, 0.22);
  --ornament-opacity: 0.06;
}}

[data-theme="dark"] {
  --color-bg:              #14110c;
  --color-surface:         #1a1610;
  --color-surface-2:       #201b14;
  --color-surface-offset:  #17140f;
  --color-surface-accent:  #2a2218;
  --color-divider:         #2e2820;
  --color-border:          #3d3428;
  --color-text:             #e8dfc8;
  --color-text-muted:      #9a8a70;
  --color-text-faint:      #5a5045;
  --color-text-inverse:    #14110c;
  --color-gold:            #c4973a;
  --color-gold-light:      #e0b85a;
  --color-gold-glow:       rgba(196, 151, 58, 0.2);
  --color-crimson:         #c44040;
  --color-forest:          #4a8c5c;
  --color-slate:           #4a6c9c;
  --color-tag-bg:          #2a2218;
  --color-tag-text:        #9a8a70;
  --color-tag-active-bg:   #c4973a;
  --color-tag-active-text: #14110c;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 24px rgba(196, 151, 58, 0.22);
  --ornament-opacity: 0.06;
}

/* ── BASE RESET ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--color-text);
  background-color: var(--color-bg);
  overflow-x: hidden;
}

img, svg { display: block; max-width: 100%; }
ul, ol { list-style: none; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input { font: inherit; color: inherit; }
h1, h2, h3, h4 { text-wrap: balance; }
p, li { text-wrap: pretty; }

::selection {
  background: var(--color-gold-glow);
  color: var(--color-text);
}
:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── HEADER ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  max-width: 1100px;
  margin: 0 auto;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-svg {
  color: var(--color-gold);
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.logo-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-gold);
  line-height: 1.1;
  letter-spacing: 0.02em;
}

.logo-sub {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.search-toggle-btn,
.theme-toggle {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: color var(--transition), background var(--transition);
}

.search-toggle-btn:hover,
.theme-toggle:hover {
  color: var(--color-text);
  background: var(--color-surface-accent);
}

/* ── SEARCH BAR ─────────────────────────────────────────── */
.search-bar-wrap {
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms cubic-bezier(0.16, 1, 0.3, 1);
  background: var(--color-surface-2);
  border-top: 0px solid var(--color-border);
}

.search-bar-wrap.open {
  max-height: 200px;
  border-top-width: 1px;
}

.search-inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  max-width: 1100px;
  margin: 0 auto;
}

.search-icon {
  color: var(--color-text-faint);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--text-base);
  color: var(--color-text);
}

.search-input::placeholder {
  color: var(--color-text-faint);
}

.search-clear {
  padding: var(--space-1);
  color: var(--color-text-faint);
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.search-clear:hover { color: var(--color-text); }

/* Tag Pills */
.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-5) var(--space-3);
  max-width: 1100px;
  margin: 0 auto;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
  user-select: none;
}

.tag-pill:hover {
  background: var(--color-surface-accent);
  transform: translateY(-1px);
}

.tag-pill.active {
  background: var(--color-tag-active-bg);
  color: var(--color-tag-active-text);
}

/* ── TAB NAV ────────────────────────────────────────────── */
.tab-nav {
  position: sticky;
  top: 57px;
  z-index: 90;
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-2);
  gap: var(--space-1);
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
  letter-spacing: 0.03em;
}

.tab-btn:hover {
  color: var(--color-text);
}

.tab-btn.active {
  color: var(--color-gold);
  border-bottom-color: var(--color-gold);
  font-weight: 600;
}

/* ── MAIN CONTENT ───────────────────────────────────────── */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-16);
}

.tab-section {
  display: none;
}
.tab-section.active {
  display: block;
  animation: fadeIn 220ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Section title */
.section-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-gold);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 48px;
  height: 2px;
  background: var(--color-gold);
  border-radius: 2px;
}

/* ── CHARACTER GROUPS ───────────────────────────────────── */
.char-group {
  margin-bottom: var(--space-10);
}

.group-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  margin-bottom: var(--space-4);
}

/* ── CARDS GRID ─────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}

/* ── CARD ───────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--card-accent, var(--color-gold));
  opacity: 0;
  transition: opacity var(--transition);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold);
}

.card:hover::before {
  opacity: 1;
}

.card-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-1);
  line-height: 1.2;
}

.card-role {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

.card-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── STUDENT CARDS (compact) ────────────────────────────── */
.students-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
}

.student-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}

.student-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-gold);
  opacity: 0;
  transition: opacity var(--transition);
}

.student-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: var(--color-gold);
}

.student-card:hover::before {
  opacity: 1;
}

.student-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.2;
  margin-bottom: 2px;
}

.student-role {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── CARD TAGS ──────────────────────────────────────────── */
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-3);
}

.card-tag {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.03em;
}

/* ── NATIONS ────────────────────────────────────────────── */
.nations-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-5);
}

.nation-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.nation-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold);
}

.nation-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.nation-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
}

.nation-analogue {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.nation-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
}

.nation-meta-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nation-meta-value {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.nation-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ── GODS ───────────────────────────────────────────────── */
.gods-group {
  margin-bottom: var(--space-10);
}

.gods-group-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-gold);
}

.gods-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.god-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.god-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold);
}

.god-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}

.god-role {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

.god-desc {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── HOLIDAYS ───────────────────────────────────────────── */
.holidays-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.holiday-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.holiday-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold);
}

.holiday-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.holiday-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
}

.holiday-nation {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 600;
  letter-spacing: 0.05em;
  white-space: nowrap;
  margin-left: var(--space-3);
}

.holiday-date {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-bottom: var(--space-3);
}

.holiday-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── PLOTLINES ──────────────────────────────────────────── */
.plot-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-5);
}

.plot-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}

.plot-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold);
}

.plot-accent-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.plot-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.plot-icon { font-size: 1.25rem; }

.plot-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
}

.plot-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: var(--space-3);
}

.plot-chars {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.plot-char-chip {
  display: inline-block;
  padding: 3px var(--space-2);
  background: var(--color-surface-accent);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.plot-char-chip:hover {
  background: var(--color-gold-glow);
  color: var(--color-gold);
  border-color: var(--color-gold);
}

/* ── GLOSSARY ───────────────────────────────────────────── */
.glossary-list {
  display: grid;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.glossary-item {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  align-items: baseline;
  transition: background var(--transition);
}

.glossary-item:last-child { border-bottom: none; }

.glossary-item:hover {
  background: var(--color-surface-offset);
}

.glossary-word {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-gold);
}

.glossary-def {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
}

.glossary-def-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

/* ── ACADEMY SECTIONS ───────────────────────────────────── */

/* Hero intro block */
.academy-hero {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-8);
  margin-bottom: var(--space-8);
  position: relative;
  overflow: hidden;
}

.academy-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-gold), var(--color-gold-light), var(--color-gold));
}

.academy-hero-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-gold);
  margin-bottom: var(--space-3);
}

.academy-hero-desc {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.65;
  margin-bottom: var(--space-6);
}

.academy-classes-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.academy-class-chip {
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.academy-class-chip-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}

.academy-class-chip-meta {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 500;
  letter-spacing: 0.04em;
}

/* Location grid */
.location-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.location-number {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-gold);
  opacity: 0.35;
  line-height: 1;
  margin-bottom: var(--space-2);
  letter-spacing: -0.02em;
}

/* Courses accordion */
.courses-accordion {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.accordion-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.accordion-header:hover {
  background: var(--color-surface-offset);
}

.accordion-title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
}

.accordion-count {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 600;
  margin-left: var(--space-3);
}

.accordion-arrow {
  color: var(--color-text-faint);
  transition: transform var(--transition);
  flex-shrink: 0;
}

.accordion-block.open .accordion-arrow {
  transform: rotate(180deg);
}

.accordion-body {
  display: none;
  padding: 0 var(--space-5) var(--space-4);
  border-top: 1px solid var(--color-divider);
}

.accordion-block.open .accordion-body {
  display: block;
}

.course-item {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-divider);
}

.course-item:last-child { border-bottom: none; }

.course-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}

.course-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-2);
}

.course-teacher {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 500;
}

.course-days {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.course-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* Schedule table */
.schedule-scroll-controls {
  margin-bottom: var(--space-2);
}
.schedule-scroll-controls[hidden] { display: none; }
.schedule-scroll-hint {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  padding-bottom: 3px;
}
.schedule-scroll-top {
  width: 100%;
  height: 17px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: auto;
  scrollbar-color: var(--color-gold) var(--color-surface-offset);
}
.schedule-scroll-top > div { height: 1px; }
.schedule-scroll-top::-webkit-scrollbar { height: 12px; }
.schedule-scroll-top::-webkit-scrollbar-track {
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
}
.schedule-scroll-top::-webkit-scrollbar-thumb {
  background: var(--color-gold);
  border-radius: var(--radius-full);
}
.schedule-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

.schedule-table,
.menu-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  min-width: 700px;
}

.schedule-table th,
.menu-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  background: var(--color-surface-offset);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-gold);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.schedule-table td,
.menu-table td {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-divider);
  vertical-align: top;
  line-height: 1.5;
}

.schedule-table tr:last-child td,
.menu-table tr:last-child td {
  border-bottom: none;
}

.schedule-table tbody tr:nth-child(even),
.menu-table tbody tr:nth-child(even) {
  background: var(--color-surface-offset);
}

/* Keep the time column visible when swiping across the week. */
.schedule-table {
  border-collapse: separate;
  border-spacing: 0;
}
.schedule-table th:first-child,
.schedule-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 94px;
  background: var(--color-bg);
  box-shadow: 2px 0 0 var(--color-border);
}
.schedule-table thead th:first-child {
  z-index: 3;
  background: var(--color-surface-offset);
}
.schedule-table tbody tr:nth-child(even) td:first-child {
  background: var(--color-surface-offset);
}
.schedule-time {
  white-space: nowrap;
  color: var(--color-gold);
  font-weight: 600;
  font-size: var(--text-xs);
}

.schedule-day-col {
  min-width: 120px;
}

.meal-label {
  display: block;
  font-weight: 700;
  color: var(--color-text-faint);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-1);
}

.menu-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ── CLERGY CARDS ───────────────────────────────────────── */
.clergy-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-5);
}

.clergy-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}

.clergy-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--color-gold);
  opacity: 0;
  transition: opacity var(--transition);
}

.clergy-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-gold);
}

.clergy-card:hover::before {
  opacity: 1;
}

.clergy-nation {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 2px;
  line-height: 1.2;
}

.clergy-subtitle {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-4);
}

.clergy-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
  margin-bottom: var(--space-4);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.clergy-clothing {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-style: italic;
  margin-bottom: var(--space-4);
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  border-left: 2px solid var(--color-gold);
  line-height: 1.55;
}

.clergy-hierarchy {
  margin-bottom: var(--space-4);
}

.clergy-hierarchy-title,
.clergy-taboos-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
}

.clergy-hierarchy-list {
  counter-reset: hierarchy;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.clergy-hierarchy-list li {
  counter-increment: hierarchy;
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.45;
}

.clergy-hierarchy-list li::before {
  content: counter(hierarchy) '.';
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-gold);
  flex-shrink: 0;
  min-width: 16px;
  font-size: var(--text-xs);
}

.clergy-taboos-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-4);
}

.clergy-taboos-list li {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: 1.45;
}

.clergy-taboos-list li::before {
  content: '✕';
  color: var(--color-crimson);
  flex-shrink: 0;
  font-size: 0.65rem;
}

.clergy-initiation {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-style: italic;
  line-height: 1.55;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-divider);
}

.clergy-initiation-label {
  font-style: normal;
  font-weight: 700;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.65rem;
  display: block;
  margin-bottom: 3px;
}

/* ── SEARCH RESULTS ─────────────────────────────────────── */
.search-results {
  animation: fadeIn 200ms ease;
}

.search-results.hidden {
  display: none;
}

.results-grid {
  display: grid;
  gap: var(--space-3);
}

.result-type-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  padding: var(--space-3) 0 var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  margin-top: var(--space-4);
}

.result-type-label:first-child {
  margin-top: 0;
}

.result-empty {
  padding: var(--space-8);
  text-align: center;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
}

/* ── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(20, 17, 12, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-4);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-sheet {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-xl) var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  margin: var(--space-4) var(--space-4) 0 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--color-surface-accent);
  color: var(--color-text-muted);
  transition: color var(--transition), background var(--transition);
  z-index: 10;
}

.modal-close:hover {
  color: var(--color-text);
  background: var(--color-border);
}

.modal-body {
  padding: var(--space-6) var(--space-6) var(--space-8);
  clear: both;
}

.modal-type-badge {
  display: inline-block;
  padding: 3px var(--space-3);
  background: var(--color-gold-glow);
  border: 1px solid rgba(196, 151, 58, 0.3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: var(--space-3);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-2);
  line-height: 1.2;
}

.modal-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

.modal-section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
  margin-top: var(--space-4);
}

.modal-text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.65;
}

.modal-divider {
  height: 1px;
  background: var(--color-divider);
  margin: var(--space-5) 0;
}

.modal-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
}

.modal-meta-label {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}

.modal-meta-value {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.modal-relations {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.relation-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.relation-chip:hover {
  background: var(--color-gold-glow);
  border-color: var(--color-gold);
}

.relation-name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.relation-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex: 1;
}

.relation-arrow {
  color: var(--color-text-faint);
  flex-shrink: 0;
}

.modal-plot-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.plot-badge {
  display: inline-block;
  padding: 4px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}

.plot-badge:hover { opacity: 0.8; }

/* Clergy modal detail styles */
.clergy-modal-hierarchy,
.clergy-modal-taboos {
  margin: var(--space-3) 0;
}

.clergy-modal-hierarchy ol {
  counter-reset: mh;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.clergy-modal-hierarchy ol li {
  counter-increment: mh;
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.clergy-modal-hierarchy ol li::before {
  content: counter(mh) '.';
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-gold);
  flex-shrink: 0;
  min-width: 20px;
}

.clergy-modal-taboos ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.clergy-modal-taboos ul li {
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.clergy-modal-taboos ul li::before {
  content: '✕';
  color: var(--color-crimson);
  flex-shrink: 0;
  font-size: 0.75rem;
  margin-top: 2px;
}

/* ── ACADEMY CLASSES in Персонажи ───────────────────────── */
.academy-class-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  position: relative;
  overflow: hidden;
}

.academy-class-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--color-gold);
}

.academy-class-header {
  margin-bottom: var(--space-4);
}

.academy-class-name {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 2px;
}

.academy-class-teacher {
  font-size: var(--text-xs);
  color: var(--color-gold);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.academy-class-count {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-left: var(--space-3);
}

.student-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.student-tag {
  display: inline-block;
  padding: 2px var(--space-2);
  background: var(--color-surface-accent);
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 600px) {
  .main-content {
    padding: var(--space-4) var(--space-3) var(--space-12);
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .students-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .nations-list {
    grid-template-columns: 1fr;
  }

  .clergy-list {
    grid-template-columns: 1fr;
  }

  .glossary-item {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .nation-meta {
    grid-template-columns: 1fr;
  }

  .academy-hero {
    padding: var(--space-4) var(--space-5);
  }

  .modal-body {
    padding: var(--space-4) var(--space-4) var(--space-6);
  }

  .schedule-table,
  .menu-table {
    min-width: 560px;
  }

  .modal-meta-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 400px) {
  .tab-btn {
    padding: var(--space-3) var(--space-3);
    font-size: 0.75rem;
  }
}

/* ── MAP SECTION ────────────────────────────────────────── */
.map-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-gold);
  border-radius: var(--radius-md);
}

.map-frame-wrap {
  position: relative;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

#map-iframe {
  display: block;
  width: 100%;
  height: 70vh;
  min-height: 400px;
  border: none;
  background: var(--color-surface-2);
}

@media (min-width: 640px) {
  #map-iframe {
    height: 78vh;
  }
}

.map-open-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  position: absolute;
  bottom: var(--space-4);
  right: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  color: var(--color-gold);
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: background var(--transition), border-color var(--transition);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.map-open-link:hover {
  background: var(--color-surface-accent);
  border-color: var(--color-gold);
}

/* ── CHARACTER PORTRAITS ────────────────────────────────── */
.card-portrait {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: top center;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  display: block;
}

.modal-portrait {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: top center;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
  display: block;
  margin-left: auto;
  margin-right: auto;
}

/* ── EDITOR ─────────────────────────────────────────────── */
.editor-toggle-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-faint);
  transition: color var(--transition), background var(--transition);
}
.editor-toggle-btn:hover {
  color: var(--color-gold);
  background: var(--color-surface-accent);
}

/* Login panel */
#editor-login-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.editor-login-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.editor-login-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-gold);
  margin-bottom: var(--space-2);
}
.editor-login-desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}
.editor-pw-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  color: var(--color-text);
  margin-bottom: var(--space-4);
  outline: none;
  transition: border-color var(--transition);
}
.editor-pw-input:focus { border-color: var(--color-gold); }
.editor-login-actions { display: flex; gap: var(--space-3); }
.editor-login-error {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-crimson);
  min-height: 1.2em;
}

/* Buttons */
.editor-btn {
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition), background var(--transition);
}
.editor-btn-primary {
  background: var(--color-gold);
  color: var(--color-text-inverse);
  border: none;
}
.editor-btn-primary:hover { opacity: 0.88; }
.editor-btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.editor-btn-ghost:hover {
  color: var(--color-text);
  background: var(--color-surface-accent);
}

/* Editor status bar */
#editor-bar {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-gold);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-5);
  box-shadow: var(--shadow-glow);
  z-index: 300;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  white-space: nowrap;
}
.editor-bar-icon { font-size: 1rem; }
.editor-bar-text { color: var(--color-gold); font-weight: 600; }
.editor-bar-exit { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }

/* Pencil button on cards */
.edit-pencil-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 28px;
  height: 28px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--transition), background var(--transition);
  z-index: 10;
}
.edit-pencil-btn:hover {
  opacity: 1;
  background: var(--color-gold);
}

/* Editor modal */
.editor-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.editor-modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.editor-modal-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-gold);
  margin-bottom: var(--space-5);
}
.editor-field { margin-bottom: var(--space-4); }
.editor-field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  margin-bottom: var(--space-2);
}
.editor-field-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  color: var(--color-text);
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.55;
}
.editor-field-input:focus { border-color: var(--color-gold); }
.editor-modal-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.editor-save-icon { margin-right: 2px; }
.editor-save-status {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  min-height: 1.4em;
  border-radius: var(--radius-sm);
  padding: 0 2px;
}
.editor-save-status.saving { color: var(--color-text-muted); }
.editor-save-status.success { color: var(--color-forest); font-weight: 600; }
.editor-save-status.error   { color: var(--color-crimson); }

/* ── LOCATION PHOTO GALLERY ─────────────────────────────────── */
.place-gallery-open {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  text-align: left;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-offset);
  color: var(--color-text);
  cursor: pointer;
}
.place-gallery-open img {
  width: min(42%, 170px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.place-gallery-open span { font-weight: 600; font-size: var(--text-sm); }
.academy-album-button { margin-top: var(--space-5); max-width: 520px; }
.place-gallery-open:hover,
.place-gallery-open:focus-visible { border-color: var(--color-gold); }

/* Uncropped map shown inside a location article. */
.place-map-preview {
  width: 100%;
  display: block;
  text-align: center;
  color: var(--color-text);
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: zoom-in;
}
.place-map-preview img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
}
.place-map-preview span {
  display: block;
  font-weight: 600;
  font-size: var(--text-sm);
  margin-top: var(--space-2);
}
.place-map-preview:hover,
.place-map-preview:focus-visible { border-color: var(--color-gold); }

.gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 350;
  background: rgba(10, 9, 8, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.gallery-overlay[hidden] { display: none; }
.gallery-sheet {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: min(100%, 1080px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.gallery-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
}
.gallery-close {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  color: var(--color-text);
  cursor: pointer;
}
.gallery-stage {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 4px;
  min-height: 0;
  padding: 0 var(--space-2);
}
.gallery-stage img {
  width: 100%;
  height: auto;
  max-height: min(66dvh, 720px);
  min-height: 0;
  object-fit: contain;
}
.gallery-nav {
  height: 50px;
  border-radius: var(--radius-md);
  background: var(--color-surface-offset);
  color: var(--color-text);
  font-size: 2.4rem;
  cursor: pointer;
}
.gallery-nav:hover,
.gallery-nav:focus-visible,
.gallery-close:hover,
.gallery-close:focus-visible { background: var(--color-gold-glow); }
.gallery-caption {
  font-size: var(--text-sm);
  text-align: center;
  padding: var(--space-2) var(--space-4);
  color: var(--color-text-muted);
}
.gallery-thumbnails {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-3);
  max-height: 104px;
  overflow-x: auto;
}
.gallery-thumb {
  width: 88px;
  height: 66px;
  flex: 0 0 auto;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  background: var(--color-surface-offset);
}
.gallery-thumb.is-active { border-color: var(--color-gold); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 600px) {
  .gallery-overlay { padding: 0; }
  .gallery-sheet { height: 100%; max-height: 100dvh; border-radius: 0; }
  .gallery-stage { flex: 1 1 auto; grid-template-columns: 34px minmax(0, 1fr) 34px; padding: 0 2px; }
  .gallery-stage img { max-height: 100%; }
  .gallery-nav { font-size: 1.8rem; height: 44px; }
  .gallery-thumb { width: 64px; height: 52px; }
  .gallery-toolbar { padding-top: max(var(--space-2), env(safe-area-inset-top)); }
  .gallery-thumbnails { padding-bottom: max(var(--space-3), env(safe-area-inset-bottom)); }
}
