/* ============================================================
   Romeo & Juliet Study Guide — Stylesheet
   /var/www/html/library/rj/css/style.css
   ============================================================ */

:root {
    --cream: #FAF7F2; --cream-dark: #F0EBE3; --parchment: #F5F0E8;
    --ink: #1a1a1a; --ink-light: #4a4a4a; --ink-lighter: #7a7a7a;
    /* accent vars are set inline by PHP for theme switching */
    --gold: #B8860B; --gold-light: #D4A843;
    --border: rgba(0,0,0,0.08); --border-strong: rgba(0,0,0,0.15);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Source Sans 3', 'Segoe UI', sans-serif;
    --radius: 6px; --transition: 0.2s ease;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-body); background: var(--cream); color: var(--ink); line-height: 1.65; -webkit-font-smoothing: antialiased; }

/* === TOPBAR === */
.topbar { position: sticky; top: 0; z-index: 100; background: var(--ink); color: white; display: flex; align-items: center; padding: 0 1.25rem; height: 52px; gap: 1rem; }
.topbar-brand { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap; opacity: 0.95; cursor: pointer; text-decoration: none; color: white; }
.topbar-brand:hover { opacity: 1; }
.topbar-search { flex: 1; max-width: 480px; position: relative; }
.topbar-search input { width: 100%; padding: 0.45rem 0.75rem 0.45rem 2.25rem; border: 1px solid rgba(255,255,255,0.15); border-radius: 20px; background: rgba(255,255,255,0.08); color: white; font-family: var(--font-body); font-size: 0.88rem; transition: var(--transition); outline: none; }
.topbar-search input::placeholder { color: rgba(255,255,255,0.45); }
.topbar-search input:focus { background: rgba(255,255,255,0.95); color: var(--ink); border-color: transparent; }
.topbar-search input:focus::placeholder { color: var(--ink-lighter); }
.topbar-search-icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); opacity: 0.45; pointer-events: none; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.topbar-btn { background: none; border: none; color: rgba(255,255,255,0.7); cursor: pointer; padding: 0.35rem; border-radius: 4px; display: flex; transition: var(--transition); text-decoration: none; }
.topbar-btn:hover { color: white; background: rgba(255,255,255,0.1); }
.menu-btn { display: none; }

/* === LAYOUT === */
.layout { display: flex; min-height: calc(100vh - 52px); }

/* === SIDEBAR === */
.sidebar { width: 170px; min-width: 170px; background: white; border-right: 1px solid var(--border); overflow-y: auto; padding: 1rem 0; transition: width 0.3s ease, min-width 0.3s ease; position: relative; flex-shrink: 0; }
.sidebar.collapsed { width: 0; min-width: 0; padding: 0; overflow: hidden; border-right: none; }
.sidebar-toggle { flex-shrink: 0; align-self: flex-start; position: sticky; top: 60px; z-index: 91; width: 22px; height: 44px; background: white; border: 1px solid var(--border); border-left: none; border-radius: 0 6px 6px 0; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s ease; box-shadow: 2px 0 6px rgba(0,0,0,0.04); margin-left: -1px; }
.sidebar-toggle:hover { background: var(--parchment); }
.sidebar-toggle svg { width: 12px; height: 12px; stroke: var(--ink-lighter); transition: transform 0.3s ease; }
.sidebar-toggle.flipped svg { transform: rotate(180deg); }
.sb-label { font-family: var(--font-display); font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-lighter); padding: 0 0.75rem; margin-bottom: 0.4rem; }
.sb-section { margin-bottom: 1.25rem; }
.sb-act { padding: 0.3rem 0.75rem; font-family: var(--font-display); font-weight: 600; font-size: 0.82rem; color: var(--accent); cursor: pointer; display: flex; align-items: center; gap: 0.35rem; transition: var(--transition); user-select: none; }
.sb-act:hover { background: var(--accent-faint); }
.sb-act .arrow { transition: transform 0.2s ease; display: inline-block; font-size: 0.7rem; }
.sb-act.open .arrow { transform: rotate(90deg); }
.sb-scenes { display: none; }
.sb-act.open + .sb-scenes { display: block; }
.sb-ch { display: block; padding: 0.25rem 0.75rem 0.25rem 1.6rem; font-size: 0.8rem; color: var(--ink-light); text-decoration: none; transition: var(--transition); border-left: 2px solid transparent; }
.sb-ch:hover { background: var(--parchment); color: var(--ink); }
.sb-ch.active { background: var(--accent-faint); color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.sb-divider { height: 1px; background: var(--border); margin: 1rem 1.25rem; }

/* === MAIN === */
.main { flex: 1; overflow-y: auto; padding: 2.5rem 3rem; max-width: 1100px; }

/* === HOME === */
.hero { text-align: center; padding: 3rem 0 2.5rem; border-bottom: 1px solid var(--border); margin-bottom: 2.5rem; }
.hero h1 { font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; color: var(--accent); line-height: 1.15; margin-bottom: 0.6rem; }
.hero .subtitle { font-family: var(--font-display); font-size: 1.3rem; font-style: italic; color: var(--ink-light); }
.hero .byline { margin-top: 1rem; font-size: 0.85rem; color: var(--ink-lighter); }
.section-label { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--ink); margin: 2rem 0 0.75rem; padding-bottom: 0.5rem; border-bottom: 2px solid var(--ink); }
.act-header { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; color: var(--accent); padding: 1rem 0 0.4rem; border-bottom: 1px solid var(--accent-glow); margin-top: 0.75rem; }
.toc-row { display: flex; align-items: center; padding: 0.65rem 0.75rem; cursor: pointer; border-radius: var(--radius); transition: var(--transition); gap: 0.75rem; text-decoration: none; color: var(--ink); }
.toc-row:hover { background: var(--accent-faint); }
.toc-num { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; color: var(--accent); min-width: 2.5rem; }
.toc-title { font-size: 0.95rem; }
.toc-lock { margin-left: auto; color: var(--ink-lighter); font-size: 0.8rem; display: flex; align-items: center; gap: 0.3rem; }
.toc-lock svg { width: 14px; height: 14px; }
.toc-row.locked { opacity: 0.65; }
.toc-row.locked:hover { opacity: 0.85; }
.toc-free-badge { margin-left: auto; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #2d8a4e; background: rgba(45,138,78,0.08); padding: 0.15rem 0.5rem; border-radius: 10px; }

/* === READER === */
.reader-header { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.breadcrumb { font-size: 0.82rem; color: var(--ink-lighter); margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .bc-links { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; font-size: 0.78rem; }
.breadcrumb .bc-links a { color: var(--ink-lighter); display: inline-flex; align-items: center; gap: 0.25rem; }
.breadcrumb .bc-links a:hover { color: var(--accent); }
.breadcrumb .bc-links svg { width: 12px; height: 12px; flex-shrink: 0; opacity: 0.6; }
.reader-title { font-family: var(--font-display); font-size: 2.2rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.reader-subtitle { font-family: var(--font-display); font-size: 1rem; font-style: italic; color: var(--accent); }
.reader-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; }

/* === TABS === */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.75rem; }
.tab { padding: 0.6rem 1.25rem; font-family: var(--font-body); font-size: 0.88rem; font-weight: 500; color: var(--ink-lighter); cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent; transition: var(--transition); }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-ai { position: relative; }
.ai-badge { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 0.15rem 0.45rem 0.15rem 0.3rem; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--gold)); color: white; margin-left: 0.4rem; vertical-align: middle; line-height: 1; }
.ai-badge svg { width: 10px; height: 10px; stroke: white; }

/* === CONTENT === */
.content { font-size: 1.08rem; line-height: 1.8; color: var(--ink); }
.content p { margin-bottom: 1.25rem; }
.content b { color: var(--accent); font-weight: 600; }
.summary-box { background: white; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; padding: 1.25rem 1.5rem; margin-bottom: 2rem; }
.summary-box h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; color: var(--accent); margin-bottom: 0.5rem; }
.summary-box p { font-size: 0.95rem; line-height: 1.7; color: var(--ink-light); }
.quote-box { background: var(--parchment); border-left: 3px solid var(--gold); padding: 1.25rem 1.5rem; border-radius: 0 var(--radius) var(--radius) 0; font-family: var(--font-display); font-size: 1.05rem; font-style: italic; line-height: 1.7; color: var(--ink-light); }

/* === SIDE-BY-SIDE TRANSLATION === */
.text-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.text-col { padding: 1.5rem; }
.text-col-original { background: var(--cream); border-right: 1px solid var(--border); }
.text-col-modern { background: var(--parchment); }
.text-col-header { font-family: var(--font-display); font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-lighter); margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.5rem; }
.text-col-header svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5; }
.speech-block { margin-bottom: 1rem; }
.speaker { font-weight: 700; color: var(--accent); text-transform: uppercase; font-size: 0.85rem; letter-spacing: 0.04em; margin-bottom: 0.15rem; }
.stage-direction { font-style: italic; color: var(--ink-lighter); font-size: 0.95rem; margin: 0.4rem 0; }
.speech-text { font-size: 1.05rem; line-height: 1.5; color: var(--ink); }
.speech-text[style*="pre-line"] { margin: 0; /* pre-line: collapse \r\n\r\n into tighter gaps */ }
.text-col-modern .speech-text { color: var(--ink-light); }

/* Translation Controls */
.translate-controls { background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.translate-controls-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.translate-controls-title { font-family: var(--font-display); font-size: 0.95rem; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 0.4rem; }
.translate-controls-title svg { width: 16px; height: 16px; stroke: var(--accent); }
.style-presets { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.style-btn { padding: 0.3rem 0.75rem; font-size: 0.8rem; font-family: var(--font-body); border: 1px solid var(--border-strong); border-radius: 20px; background: white; color: var(--ink-light); cursor: pointer; transition: var(--transition); }
.style-btn:hover { border-color: var(--accent); color: var(--accent); }
.style-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.level-slider-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.level-label { font-size: 0.78rem; color: var(--ink-lighter); min-width: 80px; }
.level-slider { flex: 1; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px; background: var(--border-strong); outline: none; }
.level-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; }
.level-value { font-size: 0.78rem; color: var(--accent); font-weight: 600; min-width: 90px; text-align: right; }
.custom-prompt-row { display: flex; gap: 0.5rem; }
.custom-prompt-input { flex: 1; padding: 0.45rem 0.75rem; font-size: 0.85rem; font-family: var(--font-body); border: 1px solid var(--border); border-radius: var(--radius); outline: none; color: var(--ink); }
.custom-prompt-input:focus { border-color: var(--accent); }
.custom-prompt-input::placeholder { color: var(--ink-lighter); font-size: 0.8rem; }
.custom-prompt-submit { padding: 0.45rem 1rem; font-size: 0.82rem; font-family: var(--font-body); background: var(--accent); color: white; border: none; border-radius: var(--radius); cursor: pointer; transition: var(--transition); white-space: nowrap; }
.custom-prompt-submit:hover { background: var(--accent-light); }
.custom-prompt-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.translate-loading { text-align: center; padding: 2rem; color: var(--ink-lighter); font-style: italic; }

/* Mobile text toggle */
.text-toggle { display: none; margin-bottom: 1rem; }
.text-toggle-btn { flex: 1; padding: 0.5rem; font-family: var(--font-body); font-size: 0.85rem; border: 1px solid var(--border-strong); background: white; color: var(--ink-light); cursor: pointer; transition: var(--transition); text-align: center; }
.text-toggle-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.text-toggle-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.text-toggle-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* === NAVIGATION === */
.chapter-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.nav-btn { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1.1rem; background: white; border: 1px solid var(--border-strong); border-radius: var(--radius); font-family: var(--font-body); font-size: 0.88rem; color: var(--ink); cursor: pointer; transition: var(--transition); text-decoration: none; }
.nav-btn:hover { background: var(--parchment); border-color: var(--accent); color: var(--accent); }

/* === TAGS === */
.devices { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.device-tag { font-size: 0.78rem; padding: 0.2rem 0.65rem; border-radius: 20px; background: var(--accent-faint); color: var(--accent); font-weight: 500; cursor: pointer; transition: var(--transition); text-decoration: none; }
.device-tag:hover { background: var(--accent-glow); }
.tag-pill { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.82rem; padding: 0.3rem 0.75rem; border-radius: 20px; cursor: pointer; transition: var(--transition); border: 1px solid transparent; }
.tag-pill .tag-count { font-size: 0.72rem; opacity: 0.6; background: rgba(0,0,0,0.06); padding: 0.1rem 0.35rem; border-radius: 10px; margin-left: 0.15rem; }
.tag-pill-themes { background: var(--accent-faint); color: var(--accent); }
.tag-pill-themes:hover { background: var(--accent-glow); border-color: var(--accent); }
.tag-pill-literary_devices { background: rgba(184,134,11,0.08); color: var(--gold); }
.tag-pill-literary_devices:hover { background: rgba(184,134,11,0.15); border-color: var(--gold); }
.tag-pill-characters { background: rgba(100,100,180,0.08); color: #555; }
.tag-pill-characters:hover { background: rgba(100,100,180,0.15); border-color: #888; }
.tag-pill-motifs { background: rgba(34,139,34,0.08); color: #2d7d2d; }
.tag-pill-motifs:hover { background: rgba(34,139,34,0.15); border-color: #2d7d2d; }

/* === TAG SEARCH PANEL === */
.tag-search-panel { display: none; margin-top: 1.5rem; background: white; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tag-search-panel.open { display: block; animation: calloutFadeIn 0.3s ease-out; }
.tag-search-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1.25rem; background: var(--parchment); border-bottom: 1px solid var(--border); }
.tag-search-panel-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }
.tag-search-ai-zone { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: linear-gradient(135deg, rgba(26,58,92,0.03), rgba(184,134,11,0.03)); }
.tag-search-ai-prompt { display: flex; align-items: center; gap: 0.75rem; }
.tag-search-ai-icon { flex-shrink: 0; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; background: var(--accent); border-radius: 50%; color: white; }
.tag-search-ai-text { flex: 1; }
.tag-search-ai-text .ai-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin-bottom: 0.15rem; display: flex; align-items: center; gap: 0.3rem; }
.tag-search-ai-text .ai-desc { font-size: 0.85rem; color: var(--ink-light); line-height: 1.4; }
.ai-analysis-btn { flex-shrink: 0; display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.55rem 1.15rem; background: var(--accent); color: white; border: none; border-radius: 20px; font-family: var(--font-body); font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: var(--transition); }
.ai-analysis-btn:hover { background: var(--accent-light); }
.ai-analysis-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-result { padding: 1rem 0 0; }
.ai-result-analysis { font-size: 0.93rem; line-height: 1.7; color: var(--ink); margin-bottom: 1rem; }
.ai-evidence { margin-bottom: 0.75rem; }
.ai-evidence-quote { font-family: var(--font-display); font-style: italic; font-size: 0.95rem; color: var(--ink-light); padding: 0.5rem 0.75rem; background: var(--parchment); border-left: 2px solid var(--gold); border-radius: 0 4px 4px 0; margin-bottom: 0.25rem; }
.ai-evidence-explanation { font-size: 0.85rem; color: var(--ink-lighter); padding-left: 0.75rem; }
.ai-connection { font-size: 0.88rem; color: var(--ink-light); font-style: italic; padding-top: 0.5rem; border-top: 1px solid var(--border); margin-top: 0.75rem; }
.tag-search-panel-body { padding: 0; overflow-y: auto; max-height: 400px; }
.tag-search-section { padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); }
.tag-search-section-title { font-family: var(--font-display); font-size: 0.82rem; font-weight: 600; color: var(--ink-lighter); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.5rem; }
.tag-search-ch-link { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0; font-size: 0.9rem; color: var(--ink); text-decoration: none; transition: var(--transition); }
.tag-search-ch-link:hover { color: var(--accent); }
.tag-search-ch-link .ch-badge { font-family: var(--font-display); font-weight: 600; color: var(--accent); min-width: 2rem; }
.tag-search-ch-link.current { font-weight: 600; color: var(--accent); }
.tag-search-snippet { padding: 0.5rem 0.75rem; margin: 0.35rem 0; background: var(--cream); border-radius: 4px; font-size: 0.85rem; line-height: 1.6; color: var(--ink-light); border-left: 2px solid var(--border); }
.tag-search-snippet mark { background: rgba(184,134,11,0.25); color: var(--ink); padding: 0.05em 0.15em; border-radius: 2px; }

/* === AI ASK BOX === */
.ai-ask-box { flex-shrink: 0; width: 300px; }
.ai-ask-collapsed { display: flex; align-items: center; gap: 0.5rem; padding: 0.55rem 1rem; cursor: pointer; background: white; border: 1px solid var(--border); border-radius: 24px; font-family: var(--font-body); font-size: 0.85rem; color: var(--ink-lighter); transition: var(--transition); box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.ai-ask-collapsed:hover { border-color: var(--accent); color: var(--accent); }
.ai-ask-collapsed svg { stroke: var(--accent); flex-shrink: 0; }
.ai-ask-expanded { display: none; background: white; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); overflow: hidden; }
.ai-ask-box.open .ai-ask-collapsed { display: none; }
.ai-ask-box.open .ai-ask-expanded { display: block; animation: calloutFadeIn 0.3s ease-out; }
.ai-ask-header { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.85rem; background: linear-gradient(135deg, var(--accent), var(--accent-light)); color: white; }
.ai-ask-label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.ai-ask-minimize { background: none; border: none; color: rgba(255,255,255,0.7); font-size: 1.2rem; cursor: pointer; padding: 0 0.3rem; line-height: 1; }
.ai-ask-minimize:hover { color: white; }
.ai-ask-hint { padding: 0.6rem 0.85rem 0.35rem; font-size: 0.78rem; color: var(--ink-lighter); line-height: 1.45; }
.ai-ask-input-row { display: flex; align-items: center; gap: 0; padding: 0.35rem 0.85rem 0.5rem; }
.ai-ask-input { flex: 1; padding: 0.5rem 0.7rem; font-family: var(--font-body); font-size: 0.85rem; border: 1px solid var(--border); border-right: none; border-radius: var(--radius) 0 0 var(--radius); outline: none; color: var(--ink); }
.ai-ask-input:focus { border-color: var(--accent); }
.ai-ask-input::placeholder { color: var(--ink-lighter); font-size: 0.8rem; }
.ai-ask-submit { padding: 0.5rem 0.7rem; background: var(--accent); color: white; border: 1px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; cursor: pointer; transition: var(--transition); display: flex; align-items: center; }
.ai-ask-submit:hover { background: var(--accent-light); }
.ai-ask-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-ask-suggestions { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0 0.85rem 0.65rem; }
.ai-ask-chip { padding: 0.25rem 0.6rem; font-size: 0.72rem; background: var(--parchment); border: 1px solid var(--border); border-radius: 12px; cursor: pointer; color: var(--ink-light); transition: var(--transition); white-space: nowrap; }
.ai-ask-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-faint); }
.ai-ask-result { max-height: 350px; overflow-y: auto; border-top: 1px solid var(--border); }
.ai-ask-result:empty { display: none; border-top: none; }
.ai-ask-answer { padding: 0.85rem; font-size: 0.88rem; line-height: 1.7; color: var(--ink); }
.ai-ask-answer p { margin: 0 0 0.6rem; }
.ai-ask-loading { padding: 1.25rem; text-align: center; color: var(--ink-lighter); font-size: 0.85rem; font-style: italic; }
.ai-ask-q { padding: 0.5rem 0.85rem; font-size: 0.8rem; background: var(--parchment); color: var(--ink-light); font-style: italic; border-bottom: 1px solid var(--border); }

/* === SEARCH MODAL === */
.search-overlay { display: none; position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5); justify-content: center; padding-top: 80px; }
.search-overlay.open { display: flex; }
.search-modal { background: white; width: 90%; max-width: 640px; border-radius: 12px; box-shadow: var(--shadow-lg); overflow: hidden; max-height: 70vh; display: flex; flex-direction: column; }
.search-modal-header { display: flex; align-items: center; padding: 1rem 1.25rem; gap: 0.75rem; border-bottom: 1px solid var(--border); }
.search-modal-header input { flex: 1; border: none; font-family: var(--font-body); font-size: 1.05rem; outline: none; color: var(--ink); background: transparent; }
.search-modal-header input::placeholder { color: var(--ink-lighter); }
.search-close { background: none; border: none; cursor: pointer; color: var(--ink-lighter); padding: 0.25rem; font-size: 1.3rem; border-radius: 4px; line-height: 1; }
.search-close:hover { background: var(--parchment); color: var(--ink); }
.search-results { overflow-y: auto; flex: 1; }
.search-result { padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: var(--transition); display: block; text-decoration: none; color: var(--ink); }
.search-result:hover { background: var(--accent-faint); }
.search-result-title { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; margin-bottom: 0.15rem; }
.search-result-context { font-size: 0.88rem; color: var(--ink-light); line-height: 1.5; }
.search-result-context mark { background: rgba(184,134,11,0.2); color: var(--ink); padding: 0.05em 0.15em; border-radius: 2px; }
.search-count { padding: 0.5rem 1.25rem; font-size: 0.82rem; color: var(--ink-lighter); border-bottom: 1px solid var(--border); background: var(--parchment); }
.search-empty { padding: 2.5rem 1.25rem; text-align: center; color: var(--ink-lighter); font-style: italic; font-family: var(--font-display); font-size: 1rem; }

/* === PAYWALL === */
.paywall-overlay { position: relative; margin-top: -2rem; padding: 3rem 2rem 2.5rem; background: linear-gradient(to bottom, rgba(250,247,242,0), var(--cream) 40%); text-align: center; }
.paywall-card { max-width: 520px; margin: 0 auto; background: white; border: 1px solid var(--border); border-radius: 12px; padding: 2rem 2rem 1.5rem; box-shadow: 0 4px 24px rgba(0,0,0,0.08); }
.paywall-icon { margin-bottom: 1rem; }
.paywall-icon svg { width: 48px; height: 48px; stroke: var(--accent); stroke-width: 1.5; }
.paywall-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--ink); margin-bottom: 0.5rem; }
.paywall-desc { font-size: 0.93rem; color: var(--ink-light); line-height: 1.6; margin-bottom: 1.5rem; }
.paywall-price { font-family: var(--font-display); font-size: 2rem; font-weight: 700; color: var(--accent); margin-bottom: 0.25rem; }
.paywall-price-note { font-size: 0.82rem; color: var(--ink-lighter); margin-bottom: 1.25rem; }
.paywall-buy-btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.75rem 2rem; background: var(--accent); color: white; border: none; border-radius: 8px; font-family: var(--font-body); font-size: 1rem; font-weight: 600; cursor: pointer; transition: var(--transition); text-decoration: none; }
.paywall-buy-btn:hover { background: var(--accent-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.paywall-features { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: center; margin: 1.25rem 0 0; }
.paywall-feature { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--ink-light); }
.paywall-feature svg { width: 14px; height: 14px; stroke: #2d8a4e; flex-shrink: 0; }
.paywall-divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.25rem 0; color: var(--ink-lighter); font-size: 0.82rem; }
.paywall-divider::before, .paywall-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.paywall-code-form { display: flex; gap: 0.5rem; max-width: 320px; margin: 0 auto; }
.paywall-code-input { flex: 1; padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); font-family: var(--font-body); font-size: 0.9rem; text-align: center; letter-spacing: 0.1em; color: var(--ink); }
.paywall-code-input:focus { border-color: var(--accent); outline: none; }
.paywall-code-submit { padding: 0.55rem 1rem; background: var(--ink); color: white; border: none; border-radius: var(--radius); font-family: var(--font-body); font-size: 0.85rem; cursor: pointer; }
.paywall-alt { margin-top: 1rem; font-size: 0.82rem; color: var(--ink-lighter); }
.paywall-alt a { color: var(--ink-light); text-decoration: underline; }

/* === THEME SWITCHER === */
.theme-switcher { display: flex; gap: 0.35rem; align-items: center; }
.theme-dot { width: 18px; height: 18px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: var(--transition); }
.theme-dot:hover { transform: scale(1.15); }
.theme-dot.active { border-color: white; box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }
.theme-dot-classic { background: #1a3a5c; }
.theme-dot-crimson { background: #8B1A1A; }
.theme-dot-emerald { background: #1a5c3a; }
.theme-dot-royal { background: #4a1a6b; }

/* Settings panel (dropdown below topbar, fixed positioning) */
.settings-panel { display: none; position: fixed; top: 52px; right: 0.75rem; z-index: 110; background: white; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 1rem 1.25rem; width: 280px; animation: calloutFadeIn 0.2s ease-out; }
.settings-panel.open { display: block; }
.settings-section { margin-bottom: 1rem; }
.settings-section:last-child { margin-bottom: 0; }
.settings-label { font-family: var(--font-display); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-lighter); margin-bottom: 0.5rem; }
.settings-row { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.settings-chip { padding: 0.25rem 0.6rem; font-size: 0.78rem; border: 1px solid var(--border-strong); border-radius: 14px; background: white; color: var(--ink-light); cursor: pointer; transition: var(--transition); }
.settings-chip:hover { border-color: var(--accent); color: var(--accent); }
.settings-chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.settings-size-row { display: flex; align-items: center; gap: 0.5rem; }
.settings-size-row button { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border-strong); background: white; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--ink-light); transition: var(--transition); font-family: var(--font-display); }
.settings-size-row button:hover { border-color: var(--accent); color: var(--accent); }
.settings-size-row span { flex: 1; text-align: center; font-size: 0.82rem; color: var(--ink); font-weight: 500; }
.settings-divider { height: 1px; background: var(--border); margin: 0.75rem 0; }

/* Theme dots inside settings panel — need solid visibility on white bg */
.settings-panel .theme-dot { width: 24px; height: 24px; border: 2px solid rgba(0,0,0,0.1); }
.settings-panel .theme-dot:hover { border-color: rgba(0,0,0,0.3); transform: scale(1.15); }
.settings-panel .theme-dot.active { border-color: var(--ink); box-shadow: 0 0 0 2px rgba(0,0,0,0.15); }

/* Font theme classes applied to body */
body.font-serif { --font-body: 'Cormorant Garamond', Georgia, serif; }
body.font-sans { --font-body: 'Source Sans 3', 'Segoe UI', sans-serif; }
body.font-modern { --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif; --font-display: system-ui, -apple-system, 'Segoe UI', sans-serif; }
body.font-mono { --font-body: 'Courier New', Courier, monospace; --font-display: Georgia, serif; }
body.font-dyslexic { --font-body: 'Comic Sans MS', 'OpenDyslexic', cursive, sans-serif; letter-spacing: 0.03em; word-spacing: 0.1em; }

/* ====== EASY READ MODE ====== */
body.easy-read .speech-text,
body.easy-read .content,
body.easy-read .ai-ask-answer,
body.easy-read .summary-box p,
body.easy-read .ai-result-analysis {
    letter-spacing: 0.12em;
    word-spacing: 0.16em;
    line-height: 1.9;
    text-align: left;
}

/* Cap line width for readability (~65 chars) */
body.easy-read .text-col {
    max-width: 65ch;
}

/* Override italics → bold (research: italic worsens crowding) */
body.easy-read .speech-text em,
body.easy-read .speech-text i,
body.easy-read .content em,
body.easy-read .content i {
    font-style: normal;
    font-weight: 700;
}

/* Ensure font remains sans-serif (don't force specific font) */
body.easy-read {
    --font-body: 'Source Sans 3', 'Segoe UI', Verdana, sans-serif;
}

/* Larger minimum font size when Easy Read is on */
body.easy-read .speech-text,
body.easy-read .content {
    font-size: max(1.1rem, 16px);
}

/* Size class overrides for Easy Read (ensure minimum) */
body.easy-read.size-sm .speech-text,
body.easy-read.size-sm .content { font-size: max(1.05rem, 16px); }
body.easy-read.size-md .speech-text,
body.easy-read.size-md .content { font-size: max(1.15rem, 16px); }
body.easy-read.size-lg .speech-text,
body.easy-read.size-lg .content { font-size: max(1.28rem, 17px); line-height: 1.95; }
body.easy-read.size-xl .speech-text,
body.easy-read.size-xl .content { font-size: max(1.42rem, 18px); line-height: 2.0; }

/* Easy Read background themes */
body.easy-read.er-cream { --cream: #FAF7F2; --parchment: #F5F0E8; --er-content-bg: #FAF7F2; color: #1a1a1a; }
body.easy-read.er-green { --cream: #E8F0E8; --parchment: #DEE8DE; --er-content-bg: #E8F0E8; color: #3B2F1E; }
body.easy-read.er-blue  { --cream: #E8EEF5; --parchment: #DEE4EE; --er-content-bg: #E8EEF5; color: #1a1a2a; }
body.easy-read.er-sand  { --cream: #F5EDE0; --parchment: #EBE3D6; --er-content-bg: #F5EDE0; color: #2C2417; }

/* Apply background to all content containers */
body.easy-read .main,
body.easy-read .sidebar { background: var(--er-content-bg, var(--cream)); }

body.easy-read .text-col-modern { background: var(--parchment); }

body.easy-read .summary-box,
body.easy-read .translate-controls,
body.easy-read .nav-btn,
body.easy-read .sidebar-toggle { background: var(--er-content-bg, white); }

body.easy-read .analysis-section,
body.easy-read .content { background: transparent; }

/* Fade overlay for locked analysis — match the Easy Read bg */
body.easy-read .analysis-fade::after { background: linear-gradient(to bottom, rgba(250,247,242,0), var(--cream)); }

/* Text size classes */
body.size-sm .speech-text, body.size-sm .content { font-size: 0.95rem; }
body.size-md .speech-text, body.size-md .content { font-size: 1.08rem; }
body.size-lg .speech-text, body.size-lg .content { font-size: 1.22rem; line-height: 1.75; }
body.size-xl .speech-text, body.size-xl .content { font-size: 1.38rem; line-height: 1.8; }

/* === SIDEBAR RESIZE HANDLE === */
.sidebar-resize-handle {
    position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
    cursor: col-resize; z-index: 92; background: transparent;
    transition: background 0.2s ease;
}
.sidebar-resize-handle::after {
    content: ''; position: absolute; top: 50%; right: 1px; transform: translateY(-50%);
    width: 3px; height: 40px; border-radius: 3px;
    background: var(--border-strong); opacity: 0; transition: opacity 0.2s ease;
}
.sidebar-resize-handle:hover::after,
.sidebar.resizing .sidebar-resize-handle::after { opacity: 1; background: var(--accent, #1a3a5c); }
.sidebar.resizing { transition: none; user-select: none; }
.sidebar.collapsed .sidebar-resize-handle { display: none; }

/* === TAG DEEP LINK HIGHLIGHT === */
.tag-highlight {
    background: rgba(184, 134, 11, 0.35); color: var(--ink); padding: 0.1em 0.2em;
    border-radius: 3px; animation: highlightPulse 1.5s ease-in-out 2;
}
.tag-highlight.fading { transition: background 1s ease-out, padding 1s ease-out; background: transparent; padding: 0; }
.highlight-pulse {
    box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.3); animation: highlightPulse 1.5s ease-in-out 2;
}
.highlight-pulse.fading { transition: box-shadow 1s ease-out; box-shadow: none; }
@keyframes highlightPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(184, 134, 11, 0); }
    50% { box-shadow: 0 0 0 6px rgba(184, 134, 11, 0.25); }
}

/* === ANIMATIONS === */
@keyframes calloutFadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* === CHARACTER MAP — Sidebar Button === */
.sb-charmap-btn {
    display: flex; align-items: center; gap: 0.45rem; width: 100%;
    padding: 0.5rem 0.75rem; font-family: var(--font-body); font-size: 0.82rem;
    font-weight: 500; color: var(--accent); background: var(--accent-faint);
    border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
    transition: var(--transition);
}
.sb-charmap-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.sb-charmap-btn svg { flex-shrink: 0; }

/* === CHARACTER MAP — Overlay + Modal === */
.charmap-overlay {
    display: none; position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.5); justify-content: center; align-items: flex-start;
    padding-top: 60px;
}
.charmap-overlay.open { display: flex; }
.charmap-modal {
    background: white; width: 92%; max-width: 860px; border-radius: 12px;
    box-shadow: var(--shadow-lg); overflow: hidden; max-height: 85vh;
    display: flex; flex-direction: column;
}
.charmap-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.85rem 1.25rem; background: var(--parchment);
    border-bottom: 1px solid var(--border);
}
.charmap-header-title {
    font-family: var(--font-display); font-size: 1.15rem; font-weight: 700;
    color: var(--ink); display: flex; align-items: center; gap: 0.5rem;
}
.charmap-header-title svg { stroke: var(--accent); }
.charmap-close {
    background: none; border: none; font-size: 1.5rem; color: var(--ink-lighter);
    cursor: pointer; padding: 0 0.3rem; line-height: 1; border-radius: 4px;
}
.charmap-close:hover { background: var(--cream); color: var(--ink); }

/* Tab toggle */
.charmap-tabs {
    display: flex; background: var(--cream-dark); border-radius: 20px;
    padding: 3px; gap: 2px;
}
.charmap-tab {
    padding: 0.35rem 0.9rem; font-family: var(--font-body); font-size: 0.78rem;
    font-weight: 500; color: var(--ink-lighter); background: transparent;
    border: none; border-radius: 18px; cursor: pointer; transition: var(--transition);
    white-space: nowrap;
}
.charmap-tab:hover { color: var(--ink); }
.charmap-tab.active {
    background: white; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.charmap-body { overflow-y: auto; flex: 1; padding: 1.25rem; }

/* Diagram body */
.charmap-diagram-body {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 1.25rem; overflow-y: auto;
}
.charmap-svg { width: 100%; height: auto; max-height: 70vh; }
.charmap-node circle { transition: stroke-width 0.2s ease, filter 0.2s ease; }
.charmap-node:hover circle { stroke-width: 3; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2)); }

/* Legend */
.charmap-legend {
    display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center;
    padding: 0.75rem 0 0.25rem; margin-top: 0.5rem;
    border-top: 1px solid var(--border);
}
.charmap-legend-item {
    display: flex; align-items: center; gap: 0.3rem;
    font-size: 0.75rem; color: var(--ink-lighter);
}
.charmap-legend-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.charmap-loading {
    text-align: center; padding: 3rem 1rem; color: var(--ink-lighter);
    font-style: italic; font-family: var(--font-display); font-size: 1rem;
}

/* Section headings */
.charmap-section-label {
    font-family: var(--font-display); font-size: 0.78rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-lighter);
    margin: 1.5rem 0 0.6rem; padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
}
.charmap-section-label:first-child { margin-top: 0; }

/* Card grid */
.charmap-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}

/* Individual card */
.charmap-card {
    background: white; border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; transition: var(--transition);
}
.charmap-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.charmap-card-top {
    padding: 0.75rem 0.85rem; cursor: pointer; display: flex;
    flex-direction: column; gap: 0.3rem;
}
.charmap-card-row {
    display: flex; justify-content: space-between; align-items: center;
}
.charmap-card-name {
    font-family: var(--font-display); font-size: 1.05rem; font-weight: 700;
    color: var(--ink);
}
.charmap-card-count {
    font-size: 0.72rem; color: var(--ink-lighter); white-space: nowrap;
}
.charmap-scene-badges { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.charmap-scene-badge {
    font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: 10px;
    background: var(--accent-faint); color: var(--accent); font-weight: 500;
}

/* Expanded profile area */
.charmap-profile {
    display: none; padding: 0.85rem; border-top: 1px solid var(--border);
    background: var(--cream); animation: calloutFadeIn 0.25s ease-out;
}
.charmap-card.expanded .charmap-profile { display: block; }
.charmap-profile-loading {
    text-align: center; padding: 1rem; color: var(--ink-lighter);
    font-size: 0.85rem; font-style: italic;
}
.charmap-profile-field { margin-bottom: 0.6rem; }
.charmap-profile-label {
    font-family: var(--font-display); font-size: 0.72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-lighter);
    margin-bottom: 0.15rem;
}
.charmap-profile-value {
    font-size: 0.88rem; line-height: 1.55; color: var(--ink);
}

/* Trait chips */
.charmap-traits { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.2rem; }
.charmap-trait-chip {
    font-size: 0.75rem; padding: 0.15rem 0.55rem; border-radius: 12px;
    background: rgba(184,134,11,0.1); color: var(--gold); font-weight: 500;
}

/* Relationships */
.charmap-rel-list { list-style: none; padding: 0; margin: 0.2rem 0 0; }
.charmap-rel-list li {
    font-size: 0.85rem; line-height: 1.5; color: var(--ink-light);
    padding: 0.15rem 0;
}
.charmap-rel-name { color: var(--accent); font-weight: 600; }

/* Ask box inside card */
.charmap-ask-box {
    margin-top: 0.75rem; padding-top: 0.65rem;
    border-top: 1px solid var(--border);
}
.charmap-ask-row { display: flex; gap: 0; }
.charmap-ask-input {
    flex: 1; padding: 0.45rem 0.65rem; font-family: var(--font-body);
    font-size: 0.82rem; border: 1px solid var(--border); border-right: none;
    border-radius: var(--radius) 0 0 var(--radius); outline: none; color: var(--ink);
}
.charmap-ask-input:focus { border-color: var(--accent); }
.charmap-ask-input::placeholder { color: var(--ink-lighter); font-size: 0.78rem; }
.charmap-ask-btn {
    padding: 0.45rem 0.65rem; background: var(--accent); color: white;
    border: 1px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0;
    cursor: pointer; transition: var(--transition); display: flex; align-items: center;
}
.charmap-ask-btn:hover { background: var(--accent-light); }
.charmap-ask-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.charmap-ask-result {
    margin-top: 0.5rem; font-size: 0.88rem; line-height: 1.65; color: var(--ink);
}
.charmap-ask-result:empty { display: none; }
.charmap-ask-result p { margin: 0 0 0.5rem; }

/* FAQ container inside card */
.charmap-faq-container:empty { display: none; }
.charmap-faq-container {
    margin-bottom: 0.5rem; padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.charmap-faq-label {
    font-family: var(--font-display); font-size: 0.68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold);
    margin-bottom: 0.35rem;
}
.charmap-faq-item {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.3rem 0.5rem; margin: 0.2rem 0; border-radius: 4px;
    cursor: pointer; transition: var(--transition); font-size: 0.82rem;
    color: var(--ink-light);
}
.charmap-faq-item:hover { background: var(--accent-faint); color: var(--accent); }
.charmap-faq-question { flex: 1; }
.charmap-faq-count {
    font-size: 0.68rem; font-weight: 600; padding: 0.1rem 0.4rem;
    border-radius: 10px; background: rgba(0,0,0,0.06); color: var(--ink-lighter);
    white-space: nowrap;
}
.charmap-faq-featured {
    font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; padding: 0.1rem 0.4rem; border-radius: 10px;
    background: rgba(184,134,11,0.12); color: var(--gold); white-space: nowrap;
}

/* Raw text fallback */
.charmap-profile-raw { font-size: 0.88rem; line-height: 1.65; color: var(--ink); }
.charmap-profile-raw p { margin: 0 0 0.5rem; }

/* === CHARACTER MAP — Overview / Faction Board === */
.charmap-overview-body {
    overflow-y: auto; flex: 1; padding: 1.25rem;
}
.charmap-faction-board {
    display: flex; flex-direction: column; gap: 1.25rem;
}
.charmap-faction-columns {
    display: grid; grid-template-columns: 1fr auto 1fr; gap: 1.25rem;
}
.charmap-faction-col {
    display: flex; flex-direction: column; gap: 0.35rem;
    border-radius: var(--radius); padding: 0.75rem;
    background: var(--cream);
}
.charmap-faction-col-header {
    font-family: var(--font-display); font-size: 0.72rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.12em;
    padding-bottom: 0.4rem; margin-bottom: 0.25rem;
    border-bottom: 2px solid; opacity: 0.85;
}
.charmap-center-col {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-width: 170px;
}
.charmap-center-pair {
    display: flex; flex-direction: column; align-items: center; gap: 0;
}
.charmap-heart-connector {
    display: flex; align-items: center; justify-content: center;
    padding: 0.25rem 0;
    animation: heartPulse 2s ease-in-out infinite;
}
@keyframes heartPulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.15); opacity: 1; }
}

/* Character tiles */
.charmap-tile {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.45rem 0.5rem; border-radius: var(--radius);
    cursor: pointer; transition: var(--transition);
}
.charmap-tile:hover {
    background: rgba(0,0,0,0.04);
}
.charmap-tile-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white; font-family: var(--font-display); font-weight: 700;
    font-size: 0.85rem; flex-shrink: 0;
}
.charmap-tile-info {
    display: flex; flex-direction: column; min-width: 0;
}
.charmap-tile-name {
    font-family: var(--font-display); font-weight: 600; font-size: 0.9rem;
    color: var(--ink); line-height: 1.2;
}
.charmap-tile-role {
    font-size: 0.75rem; color: var(--ink-lighter); line-height: 1.3;
    display: flex; align-items: center; gap: 0.3rem;
}
.charmap-tile-icon {
    display: inline-flex; align-items: center; flex-shrink: 0;
}
.charmap-tile.minor .charmap-tile-avatar {
    width: 28px; height: 28px; font-size: 0.7rem;
}
.charmap-tile.minor {
    padding: 0.3rem 0.5rem;
}
.charmap-tile.minor .charmap-tile-name {
    font-size: 0.82rem;
}
.charmap-tile-divider {
    height: 1px; background: var(--border); margin: 0.25rem 0;
}

/* Neutral / Royalty row */
.charmap-neutral-row {
    padding: 0.75rem; border-radius: var(--radius);
    background: var(--cream);
    border-top: 1px solid var(--border);
}
.charmap-neutral-tiles {
    display: flex; flex-wrap: wrap; gap: 0.25rem;
}

/* === MOBILE === */
@media (max-width: 768px) {
    .menu-btn { display: flex !important; }
    .sidebar { position: fixed; top: 52px; left: 0; bottom: 0; z-index: 90; transform: translateX(-100%); box-shadow: var(--shadow-lg); transition: transform 0.3s ease; width: 240px; min-width: 240px; }
    .sidebar.open { transform: translateX(0); }
    .sidebar.collapsed { width: 240px; min-width: 240px; transform: translateX(-100%); }
    .sidebar-toggle { display: none !important; }
    .sidebar-resize-handle { display: none !important; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; top: 52px; background: rgba(0,0,0,0.3); z-index: 89; }
    .sidebar.open ~ .sidebar-overlay { display: block; }
    .main { padding: 1.5rem 1.25rem; }
    .hero h1 { font-size: 1.9rem; }
    .reader-title { font-size: 1.6rem; }
    .reader-header-row { flex-direction: column; gap: 0.75rem; }
    .ai-ask-box { width: 100%; }
    .text-columns { grid-template-columns: 1fr; }
    .text-col-original { border-right: none; border-bottom: 1px solid var(--border); }
    .text-toggle { display: flex; }
    .text-col.mobile-hidden { display: none; }
    /* Character Map mobile */
    .charmap-overlay { padding-top: 0; align-items: stretch; }
    .charmap-modal { width: 100%; max-width: 100%; max-height: 100vh; border-radius: 0; }
    .charmap-grid { grid-template-columns: 1fr; }
    .charmap-header { flex-wrap: wrap; gap: 0.5rem; }
    .charmap-tabs { order: 3; width: 100%; justify-content: center; }
    .charmap-diagram-body { padding: 0.75rem; }
    .charmap-legend { gap: 0.5rem; }
    /* Faction board mobile */
    .charmap-faction-columns { grid-template-columns: 1fr; gap: 0.75rem; }
    .charmap-center-col { min-width: 0; }
    .charmap-center-pair { flex-direction: row; gap: 0.5rem; align-items: center; flex-wrap: wrap; justify-content: center; }
    .charmap-heart-connector { padding: 0 0.25rem; }
    .charmap-neutral-tiles { flex-direction: column; }
}