/* World Modeler v1.0 */

:root {
    --bg: #1a1a2e;
    --bg-panel: #16213e;
    --bg-input: #0f3460;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #e94560;
    --accent2: #7451ab;
    --border: #2a2a4a;
    --node-hover: #1a3a5c;
    --success: #4ecca3;
    --font-mono: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Crimson / DDB character sheet theme */
    --crimson: #8b1a2b;
    --crimson-light: #c41e3a;
    --crimson-dark: #5c1018;
    --sheet-bg: #0d0d14;
    --sheet-panel: #141420;
    --sheet-border: #2a1520;
    --sheet-card-bg: #1a1a28;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    position: relative;
}

.header-left,
.header-right {
    min-width: 120px;
    flex-shrink: 0;
}

.header-left {
    position: relative;
}

.header-right {
    text-align: right;
}

header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent);
}

.story-title {
    font-family: 'Quintessential', cursive;
    font-size: 1.6rem;
    font-weight: 400;
    text-align: center;
    flex: 1;
    cursor: text;
}

.story-title:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 4px;
    text-decoration-color: var(--text-muted);
}

/* File menu */
.file-menu-trigger {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-size: 0.85rem;
    padding: 0.3rem 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-sans);
}

.file-menu-trigger:hover {
    background: var(--bg-input);
    border-color: var(--border);
}

.file-menu-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    min-width: 200px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 300;
    padding: 4px 0;
}

.file-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.45rem 0.9rem;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    font-family: var(--font-sans);
    text-align: left;
}

.file-menu-item:hover {
    background: var(--bg-input);
}

.file-menu-item kbd {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-sans);
}

.file-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Main layout: tree | divider | sidebar */
main {
    display: grid;
    grid-template-columns: 1fr 6px 1fr;
    grid-template-rows: 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--border);
    transition: grid-template-columns 0.25s ease;
}

main.sheet-mode {
    grid-template-columns: 1fr 6px 1fr;
}

.panel {
    background: var(--bg-panel);
    overflow-y: auto;
    padding: 1rem;
    min-height: 0;
}

/* Tree panel */
.panel-tree {
    overflow: auto;
    min-width: 250px;
    overflow-anchor: none;
}

/* Drag divider between tree and sidebar */
.panel-divider {
    background: var(--border);
    cursor: col-resize;
    transition: background 0.15s;
}

.panel-divider:hover,
.panel-divider.dragging {
    background: var(--accent);
}

/* Sidebar stacks vertically */
.panel-sidebar {
    overflow-y: auto;
}

.panel-header {
    margin-bottom: 0.75rem;
}

.panel-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* Tree */
.tree, .tree ul {
    list-style: none;
    padding-left: 1.2rem;
}

.tree > li { padding-left: 0; }

.tree li {
    position: relative;
}

.tree-node {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.tree-node:hover {
    background: var(--node-hover);
}

.node-icon {
    color: var(--accent);
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

.node-icon svg {
    width: 1em;
    height: 1em;
    fill: currentColor;
    vertical-align: middle;
}

.node-name {
    font-weight: 500;
}

.node-type {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
}

.node-attrs {
    font-size: 0.65rem;
    color: var(--accent2);
    font-family: var(--font-mono);
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-identity {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-style: italic;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Search */
.search-wrapper {
    position: relative;
    width: 100%;
}

#search-input {
    width: 100%;
    padding: 0.5rem 1.8rem 0.5rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
}

#search-input:focus {
    border-color: var(--accent);
}

.search-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.3rem;
    line-height: 1;
    display: flex;
    align-items: center;
}

.search-clear:hover {
    color: var(--text);
}

.search-results {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 4px;
}

.search-results ul { list-style: none; }

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    text-decoration: none;
    color: var(--text);
    border-radius: 3px;
    cursor: pointer;
}

.search-result-item:hover,
.search-result-item.search-active {
    background: var(--node-hover);
}

.search-result-parent {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: auto;
    white-space: nowrap;
}

/* Orphan node warning */
.orphan-warning {
    background: rgba(233, 69, 96, 0.1);
    border-left: 3px solid var(--accent);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.8rem;
    color: var(--accent);
    border-radius: 0 4px 4px 0;
}

/* Drop hint next to Narrative Input heading */
.upload-drop-hint {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-muted);
    font-family: var(--font-mono);
    text-transform: none;
    letter-spacing: normal;
    margin-left: 0.5rem;
}

/* Textarea file-drop active state */
.textarea-drop-active {
    border-color: var(--accent) !important;
    border-style: dashed !important;
    background: rgba(233, 69, 96, 0.08) !important;
}

/* Input panel */
.input-form {
    margin-bottom: 1rem;
}

.input-form textarea,
.input-form input[type="text"] {
    width: 100%;
    padding: 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    resize: vertical;
    outline: none;
}

.input-form textarea:focus,
.input-form input[type="text"]:focus {
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-secondary {
    background: var(--accent2);
    color: white;
}

.btn-success {
    background: var(--success);
    color: #111;
}

.btn-danger {
    background: #c0392b;
    color: white;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}

.btn-dark {
    background: var(--bg);
    color: #e0e0e0;
    border: 1px solid var(--text-muted);
}

/* HTMX indicator */
.htmx-indicator {
    display: none;
    font-size: 0.8rem;
    color: var(--accent);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline;
}

/* Results */
.result, .command-result {
    margin: 0.5rem 0;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 4px;
    border-left: 3px solid var(--success);
}

.result-summary {
    font-weight: 500;
    color: var(--success);
    font-size: 0.85rem;
}

.command-echo {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.command-output {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    white-space: pre-wrap;
    color: var(--text);
}

/* Description field edit/generate buttons */
.desc-actions {
    margin-top: 0.3rem;
    display: flex;
    gap: 0.4rem;
}

.btn-inline {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    transition: color 0.15s, border-color 0.15s;
}

.btn-inline:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Describe command save/replace */
.describe-actions {
    margin-top: 0.5rem;
}

.describe-saved {
    font-size: 0.8rem;
    color: var(--success);
    font-weight: 500;
}

.raw-response {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    white-space: pre-wrap;
    color: var(--text-muted);
    margin-top: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

details summary {
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Tree collapsible nodes */
.tree details {
    margin: 0;
}

.tree details > summary {
    list-style: none;
    margin: 0;
    font-size: inherit;
    color: inherit;
}

.tree details > summary::-webkit-details-marker {
    display: none;
}

.tree details > summary::before {
    content: "\25b6";
    display: inline-block;
    width: 1rem;
    height: 1rem;
    line-height: 1rem;
    text-align: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform 0.15s;
    vertical-align: middle;
}

.tree details[open] > summary::before {
    transform: rotate(90deg);
}

/* Leaf nodes: reserve same space as the arrow so siblings align */
.tree li > .tree-node {
    margin-left: 1rem;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

/* Detail panel */
.node-detail h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--accent);
}

.node-detail h4 {
    font-size: 0.85rem;
    margin-top: 1rem;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.node-detail dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 0.75rem;
    font-size: 1.2rem;
}

.node-detail dt {
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 15px;
}

.node-detail dd {
    color: var(--text);
}

.tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: var(--bg);
    border-radius: 3px;
    font-size: 0.8rem;
    text-decoration: none;
    color: var(--text);
    margin: 0.1rem;
}

.tag:hover { background: var(--node-hover); }

.breadcrumb-location { display: flex; flex-wrap: wrap; align-items: center; gap: 0.1rem; }
.breadcrumb-sep { color: var(--text-muted); font-size: 0.75rem; margin: 0 0.1rem; }

.attr-table {
    width: 100%;
    font-size: 0.8rem;
    border-collapse: collapse;
}

.attr-table td {
    padding: 0.2rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.attr-table td:first-child {
    font-weight: 600;
    color: var(--accent2);
    white-space: nowrap;
}

.attr-key, .attr-val {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.15s;
}

.attr-key:hover, .attr-val:hover {
    border-bottom-color: var(--text-muted);
}

.attr-actions {
    width: 1.5rem;
    text-align: center;
    padding: 0 !important;
}

.btn-attr-del {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.attr-table tr:hover .btn-attr-del {
    opacity: 1;
}

.btn-attr-del:hover {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.12);
}

.btn-attr-save {
    background: none;
    border: none;
    color: var(--success);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.1rem 0.3rem;
}

.btn-attr-save:hover {
    background: rgba(78, 204, 163, 0.15);
    border-radius: 3px;
}

.attr-add-row td {
    border-bottom: none !important;
    padding-top: 0.3rem !important;
}

.attr-add-editing td {
    padding: 0.15rem 0.3rem !important;
}

.attr-add-editing .editable-input {
    padding: 0.2rem 0.3rem;
    font-size: 0.8rem;
}

/* Relationships (grouped) */
.rel-groups {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 0.75rem;
    font-size: 0.85rem;
}

.rel-groups dt {
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    display: flex;
    align-items: flex-start;
    gap: 0.2rem;
}

.rel-groups dd {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    align-items: center;
}

.rel-predicate {
    background: var(--accent2);
    color: white;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 500;
}

.rel-arrow {
    color: var(--text-muted);
    margin: 0 0.2rem;
}

.rel-list a {
    color: var(--accent);
    text-decoration: none;
}

.rel-list a:hover { text-decoration: underline; }

/* History */
.history-section {
    margin-top: 1rem;
}

.history-table {
    width: 100%;
    font-size: 0.8rem;
    border-collapse: collapse;
}

.history-table th {
    text-align: left;
    padding: 0.4rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}

.history-table td {
    padding: 0.3rem 0.4rem;
    border-bottom: 1px solid var(--border);
}

.history-table a {
    color: var(--accent);
    text-decoration: none;
}

.event-type {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent2);
}

.event-time {
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.event-data {
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-list {
    list-style: none;
    font-size: 0.8rem;
}

.history-list li {
    padding: 0.15rem 0;
    display: flex;
    gap: 0.5rem;
}

.node-meta {
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
}

.muted {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* Links — use accent color throughout, no default blue */
.panel a, .node-detail a, .search-results a, .history-panel a {
    color: var(--accent);
    text-decoration: none;
}

.panel a:hover, .node-detail a:hover, .search-results a:hover, .history-panel a:hover {
    text-decoration: underline;
}

/* Ancestor identity annotations */
.ancestor-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* Tree node highlight (search reveal) */
.tree-node-highlight {
    background: var(--accent2);
    transition: background 0.3s ease-out;
}

/* Selected tree node (multi-select) */
li.node-selected > details > summary > .tree-node,
li.node-selected > .tree-node {
    background: rgba(233, 69, 96, 0.3);
    border-left: 2px solid var(--accent);
    padding-left: calc(0.5rem - 2px);
}

/* Move-mode cursor */
.tree-move-mode .tree-node {
    cursor: crosshair;
}

/* Selection panel */
.selection-panel h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.selection-list {
    list-style: none;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.selection-list li {
    padding: 0.2rem 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.selection-type-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.selection-type-row label {
    color: var(--text-muted);
    white-space: nowrap;
}

.selection-type-row select {
    max-width: 160px;
}

.selection-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Tree node context menu */
.context-menu {
    position: absolute;
    z-index: 1000;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0;
    min-width: 120px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 0.4rem 0.75rem;
    border: none;
    background: none;
    color: var(--text);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
}

.context-menu button:hover {
    background: var(--node-hover);
}

.context-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 0.25rem 0;
}

.context-menu-danger {
    color: var(--accent) !important;
}

.context-menu-danger:hover {
    background: rgba(233, 69, 96, 0.12) !important;
}

/* Undo toast */
.undo-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    border: 1px solid var(--success);
    color: var(--success);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Drag-and-drop tree reparenting */
.drag-source {
    opacity: 0.4;
    outline: 1px dashed var(--text-muted);
    outline-offset: 2px;
}

.drop-target {
    background: rgba(78, 204, 163, 0.15);
    outline: 2px solid var(--success);
    outline-offset: -1px;
    border-radius: 4px;
}

.drop-target-copy {
    background: rgba(116, 81, 171, 0.2);
    outline: 2px solid var(--accent2);
    outline-offset: -1px;
    border-radius: 4px;
}

/* -----------------------------------------------------------------------
   Bottom dock
   ----------------------------------------------------------------------- */

.bottom-dock {
    flex-shrink: 0;
}


.dock-grab-bar {
    height: 28px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.dock-grab-bar--active::after {
    display: none;
}

/* Visible notch handle */
.dock-grab-bar::after {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.15s;
}

.dock-grab-bar:hover::after {
    background: var(--accent);
}

/* Grab-bar activity indicator */
.dock-activity {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.dock-activity-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--accent2);
}

.dock-activity-icon.writing {
    animation: quillWrite 0.6s ease-in-out infinite;
}

@keyframes quillWrite {
    0%, 100% { transform: rotate(0deg) translateY(0); }
    25% { transform: rotate(-4deg) translateY(-1px); }
    75% { transform: rotate(4deg) translateY(1px); }
}

.dock-activity-text {
    color: var(--text-muted);
    font-weight: 500;
}

.dock-activity-text.flash-done {
    color: var(--success);
    animation: flashFadeOut 2s ease-out forwards;
}

@keyframes flashFadeOut {
    0% { opacity: 1; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

.dock-activity-bar {
    width: 80px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.dock-activity-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent2), var(--success));
    border-radius: 2px;
    transition: width 0.3s ease;
}

.dock-content {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    max-height: 40vh;
    overflow-y: auto;
}

.dock-open .dock-content {
    display: grid;
}

.dock-section-header {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}


/* Auto-save status indicator */
.autosave-row {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
}

.autosave-filename {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.autosave-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    user-select: none;
}

.autosave-toggle input[type="checkbox"] {
    accent-color: var(--success);
    cursor: pointer;
    margin: 0;
    width: 13px;
    height: 13px;
}

.autosave-toggle-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.autosave-status {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: right;
    min-height: 1em;
    white-space: nowrap;
}

.autosave-status.autosave-active {
    color: var(--success);
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* -----------------------------------------------------------------------
   File Upload
   ----------------------------------------------------------------------- */

.upload-section {
    margin-bottom: 0.5rem;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 6px;
    padding: 1rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover {
    border-color: var(--accent2);
}

.upload-zone-active {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.upload-browse-btn {
    cursor: pointer;
    display: inline-block;
}

.upload-formats {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    font-family: var(--font-mono);
}

/* Upload preview */
.upload-preview {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 4px;
    border-left: 3px solid var(--accent2);
}

.upload-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.upload-filename {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
}

.upload-size {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.upload-stats {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.upload-stats-sep {
    margin: 0 0.3rem;
}

.upload-chunk-details {
    margin-top: 0.5rem;
}

.upload-chunk-details summary {
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
}

.upload-chunk-list {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem;
    padding-left: 1.5rem;
    margin-top: 0.4rem;
}

.upload-chunk-list li {
    padding: 0.15rem 0;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.chunk-heading {
    color: var(--text);
}

.chunk-words {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    white-space: nowrap;
}

.chunk-result {
    color: var(--success);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* Upload progress */
.upload-progress {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 4px;
    border-left: 3px solid var(--success);
}

.progress-bar-track {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent2), var(--success));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.progress-text {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}

.progress-done {
    color: var(--success);
}

.progress-cancelled {
    color: var(--accent);
}

.progress-heading {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.progress-last-result {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 0.3rem;
}

.upload-results-log {
    margin-top: 0.75rem;
}

.upload-results-log summary {
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* Upload error */
.upload-error {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 4px;
    border-left: 3px solid var(--accent);
    color: var(--accent);
    font-size: 0.85rem;
}

.upload-success {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 4px;
    border-left: 3px solid var(--success);
    color: var(--text);
    font-size: 0.85rem;
}

.upload-success strong {
    color: var(--success);
}

.upload-entities {
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* -----------------------------------------------------------------------
   Inline editing
   ----------------------------------------------------------------------- */

.editable {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.15s;
}

.editable:hover {
    border-bottom-color: var(--text-muted);
}

.editable-multiline {
    white-space: pre-wrap;
}

.editable-placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.editable-input,
.editable-textarea,
.editable-select-input {
    width: 100%;
    padding: 0.1rem 0.2rem;
    margin: -0.1rem -0.2rem;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: 3px;
    color: var(--text);
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
    outline: none;
    box-sizing: border-box;
}

.editable-textarea {
    resize: vertical;
    min-height: 3rem;
}

.editable-select-input {
    cursor: pointer;
}

/* -----------------------------------------------------------------------
   Dialogue checklist
   ----------------------------------------------------------------------- */

.dialogue-list {
    list-style: none;
    font-size: 0.85rem;
}

.dialogue-line {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}

.dialogue-line br {
    width: 100%;
}

.dialogue-check {
    margin-top: 0.15rem;
    accent-color: var(--success);
    cursor: pointer;
    flex-shrink: 0;
}

.dialogue-context {
    font-weight: 600;
    color: var(--accent2);
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.dialogue-text {
    font-style: italic;
    color: var(--text);
    margin-top: 5px;
}

.dialogue-used .dialogue-text {
    color: var(--text-muted);
    text-decoration: line-through;
}

.btn-dialogue-del {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 0.2rem;
    margin-left: auto;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.dialogue-line:hover .btn-dialogue-del {
    opacity: 1;
}

.btn-dialogue-del:hover {
    color: var(--accent);
}

.dialogue-editable {
    cursor: pointer;
}

.dialogue-editable:hover {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

/* -----------------------------------------------------------------------
   Auto-merged notices
   ----------------------------------------------------------------------- */

.auto-merged-notice {
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.auto-merged-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--success, #2ea043);
    margin-bottom: 0.4rem;
}

.auto-merged-item {
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-left: 2px solid var(--success, #2ea043);
    margin-bottom: 0.2rem;
}

.auto-merged-item small {
    opacity: 0.7;
}

/* -----------------------------------------------------------------------
   Merge suggestions
   ----------------------------------------------------------------------- */

.merge-suggestions {
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.merge-suggestions-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.4rem;
}

.merge-suggestion {
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.5rem;
    border-left: 3px solid var(--accent2);
    background: rgba(116, 81, 171, 0.06);
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
}

.merge-pair {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
}

.merge-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.merge-side-name {
    font-weight: 600;
    color: var(--text);
}

.merge-side-type {
    color: var(--text-muted);
    font-weight: 400;
}

.merge-side-identity {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.3;
}

.merge-middle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0 0.4rem;
    flex-shrink: 0;
    color: var(--text-muted);
}

.merge-middle-actions {
    display: flex;
    gap: 0.3rem;
}

.merge-reason {
    color: var(--text-muted);
    font-style: italic;
}

.btn-merge {
    padding: 2px 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--text-muted);
    border-radius: 3px;
    cursor: pointer;
    background: var(--bg);
    color: #e0e0e0;
    transition: opacity 0.15s;
}

.btn-merge:hover {
    opacity: 0.85;
}

.btn-link {
    padding: 2px 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    background: #1a5c2a;
    color: #e8e8e8;
    transition: opacity 0.15s;
}

.btn-link:hover {
    opacity: 0.85;
}

.btn-dismiss {
    padding: 2px 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    background: #7a1a1a;
    color: #e8e8e8;
    transition: opacity 0.15s;
}

.btn-dismiss:hover {
    opacity: 0.85;
}

.btn-merge-accept {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    background: var(--success);
    color: var(--bg);
    transition: opacity 0.15s;
}

.btn-merge-accept:hover {
    opacity: 0.85;
}

.btn-merge-dismiss {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    background: transparent;
    color: var(--text-muted);
    transition: color 0.15s, border-color 0.15s;
}

.btn-merge-dismiss:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-merge-link {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    background: var(--accent2);
    color: white;
    transition: opacity 0.15s;
}

.btn-merge-link:hover {
    opacity: 0.85;
}

.merge-accepted {
    font-size: 0.8rem;
    color: var(--success);
    font-weight: 500;
}

.merge-dismissed {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.merge-entity-link {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.merge-entity-link:hover {
    text-decoration: underline;
}

/* Fade-out animation for resolved merge suggestions */
.merge-fade-out {
    animation: mergeFadeOut 1.5s ease forwards;
}

@keyframes mergeFadeOut {
    0%   { opacity: 1; max-height: 3rem; padding: 0.4rem 0.6rem; margin-bottom: 0.3rem; }
    50%  { opacity: 0; max-height: 3rem; padding: 0.4rem 0.6rem; margin-bottom: 0.3rem; }
    100% { opacity: 0; max-height: 0; padding: 0; margin-bottom: 0; overflow: hidden; }
}

/* -----------------------------------------------------------------------
   Compare panel (side-by-side entity comparison)
   ----------------------------------------------------------------------- */

.compare-panel {
    font-size: 0.85rem;
}

.compare-header h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.compare-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.compare-card {
    background: var(--bg);
    border-radius: 4px;
    padding: 0.6rem;
    border: 1px solid var(--border);
}

.compare-card-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.compare-name {
    color: var(--accent);
    font-size: 0.95rem;
}

.compare-identity {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.compare-field {
    margin-bottom: 0.4rem;
}

.compare-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.compare-attrs {
    font-size: 0.8rem;
}

.compare-attr-row {
    padding: 0.1rem 0;
}

.compare-attr-key {
    font-weight: 600;
    color: var(--accent2);
    margin-right: 0.3rem;
}

.compare-attr-key::after {
    content: ":";
}

.compare-rels {
    font-size: 0.8rem;
}

.compare-rel-row {
    padding: 0.1rem 0;
}

.compare-merge-bar {
    padding: 0.6rem;
    background: var(--bg);
    border-radius: 4px;
    border: 1px solid var(--border);
}

.compare-merge-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Scan results (displayed in detail panel) */
.scan-results h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.scan-results .scan-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.btn-merge-link-compare {
    background: var(--accent2);
    color: white;
}

/* -----------------------------------------------------------------------
   Similar Entities section in detail panel
   ----------------------------------------------------------------------- */

.similar-entities {
    list-style: none;
    padding: 0;
    margin: 0;
}

.similar-entity {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border);
}

.similar-entity:last-child { border-bottom: none; }

.similar-entity-actions { display: flex; gap: 0.25rem; }

.btn-similar-merge, .btn-similar-unlink {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
}

/* -----------------------------------------------------------------------
   Auto-action summaries
   ----------------------------------------------------------------------- */

.auto-actions-summary { margin-top: 0.5rem; }

.auto-action { margin: 0.2rem 0; font-size: 0.85rem; }

.auto-action-merged { color: var(--success, #4ecca3); }

.auto-action-linked { color: var(--accent2, #7451ab); }

/* -----------------------------------------------------------------------
   Detail header row (name + toggle)
   ----------------------------------------------------------------------- */

.detail-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.detail-header-row h3 {
    margin-bottom: 0;
}

/* -----------------------------------------------------------------------
   View toggle (Data / Sheet)
   ----------------------------------------------------------------------- */

.view-toggle {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.view-toggle-btn {
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.view-toggle-btn:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.view-toggle-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* -----------------------------------------------------------------------
   Character Sheet / Stats View — shared styles
   ----------------------------------------------------------------------- */

/* ── Top section: avatar + name + combat ── */
.sheet-top {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

/* Avatar zone */
.sheet-avatar-zone {
    width: 100px;
    height: 100px;
    flex-shrink: 0;
    border: 2px solid var(--crimson);
    border-radius: 6px;
    overflow: hidden;
    background: var(--sheet-panel);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s;
}

.sheet-avatar-zone:hover {
    border-color: var(--crimson-light);
}

.sheet-avatar-zone.avatar-drop-active {
    border-color: var(--crimson-light);
    border-style: dashed;
    background: rgba(139, 26, 43, 0.15);
}

.sheet-avatar-zone img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sheet-avatar-placeholder {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.65rem;
    line-height: 1.3;
}

.sheet-avatar-placeholder svg {
    display: block;
    margin: 0 auto 0.2rem;
    width: 24px;
    height: 24px;
    fill: var(--text-muted);
}

/* Top-right info area */
.sheet-top-info {
    flex: 1;
    min-width: 0;
}

/* Header row: name + toggle */
.sheet-top-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.sheet-top-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.sheet-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
    margin-bottom: 0.4rem;
}

.sheet-class {
    font-weight: 600;
    color: var(--crimson-light);
}

.sheet-sep {
    color: var(--sheet-border);
    margin: 0 0.2rem;
}

.sheet-identity {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-bottom: 0.4rem;
}

/* Combat stat blocks */
.sheet-combat-blocks {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.sheet-stat-box {
    flex: 1 1 0;
    min-width: 50px;
    text-align: center;
    padding: 0.35rem 0.25rem;
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    border-top: 2px solid var(--crimson);
    border-radius: 4px;
}

.sheet-stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    line-height: 1.2;
}

.sheet-stat-label {
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* ── Body: two-column layout ── */
.sheet-body {
    display: grid;
    grid-template-columns: 190px 1fr;
    gap: 0.75rem;
    min-height: 0;
}

/* Left column: abilities, saves, skills, senses */
.sheet-col-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Ability score vertical stack */
.sheet-ability-stack {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.sheet-ability-card-v {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.5rem;
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    border-left: 3px solid var(--crimson);
    border-radius: 0 4px 4px 0;
}

.sheet-ability-card-v .sheet-ability-name {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--crimson-light);
    width: 2.2rem;
    flex-shrink: 0;
}

.sheet-ability-card-v .sheet-ability-mod {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    min-width: 2rem;
    text-align: center;
}

.sheet-ability-card-v .sheet-ability-score {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-left: auto;
}

.sheet-ability-card-v.sheet-ability-empty .sheet-ability-mod,
.sheet-ability-card-v.sheet-ability-empty .sheet-ability-score {
    color: var(--sheet-border);
}

/* Left column sections (saves, skills, senses) */
.sheet-left-section {
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    border-radius: 4px;
    padding: 0.4rem 0.5rem;
}

.sheet-left-section h4 {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--crimson-light);
    margin: 0 0 0.3rem 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--sheet-border);
}

/* Right column: tabbed content */
.sheet-col-right {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Tab bar */
.sheet-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--sheet-border);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.sheet-tab {
    padding: 0.35rem 0.7rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

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

.sheet-tab.active {
    color: var(--crimson-light);
    border-bottom-color: var(--crimson-light);
}

/* Tab content panels */
.sheet-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.sheet-tab-content.active {
    display: block;
}

/* Generic sheet section (used inside tabs) */
.sheet-section {
    margin-bottom: 0.6rem;
}

.sheet-section h4 {
    font-size: 0.7rem;
    margin-top: 0;
    margin-bottom: 0.3rem;
    color: var(--crimson-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--sheet-border);
    padding-bottom: 0.15rem;
}

.sheet-text {
    font-size: 1.2rem;
    color: #e0e0e082;
    line-height: 1.4;
    margin-bottom: 0.3rem;
}

.sheet-text strong {
    color: white !important;
}

/* Markdown-rendered content (descriptions) */
.markdown-content p { margin: 0 0 0.4em; }
.markdown-content p:last-child { margin-bottom: 0; }
.markdown-content ul,
.markdown-content ol { margin: 0.3em 0; padding-left: 1.4em; }
.markdown-content li { margin-bottom: 0.15em; }
.markdown-content blockquote {
    border-left: 3px solid var(--accent2);
    padding: 0.2em 0.6em;
    margin: 0.4em 0;
    color: var(--text-muted);
    font-style: italic;
}
.markdown-content code {
    background: rgba(255,255,255,0.08);
    padding: 0.1em 0.3em;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}
.markdown-content pre {
    background: rgba(0,0,0,0.3);
    padding: 0.5em;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.4em 0;
}
.markdown-content pre code {
    background: none;
    padding: 0;
}
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin: 0.5em 0 0.2em;
    color: var(--text);
}
.markdown-content h1 { font-size: 1.2em; }
.markdown-content h2 { font-size: 1.1em; }
.markdown-content h3 { font-size: 1.0em; }
.markdown-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.5em 0;
}
.markdown-content a {
    color: var(--accent);
    text-decoration: underline;
}

/* Tag lists (skills, saves, spells, features) */
.sheet-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.sheet-tag {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    border-radius: 3px;
    font-size: 0.72rem;
    color: var(--text);
}

.sheet-tag-spell {
    border-color: var(--crimson);
    color: var(--crimson-light);
    background: rgba(139, 26, 43, 0.1);
}

/* Equipment list */
.sheet-equipment-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sheet-equipment-list li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid var(--sheet-border);
    font-size: 0.8rem;
}

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

.sheet-equip-icon {
    font-size: 0.85rem;
    width: 1.2rem;
    text-align: center;
    flex-shrink: 0;
}

.sheet-equip-rel {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-style: italic;
    margin-left: auto;
}

/* Spellcasting */
.sheet-spell-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}

.sheet-spell-stat {
    color: var(--text-muted);
}

.sheet-spell-stat strong {
    color: var(--text);
}

.sheet-spell-group {
    margin-bottom: 0.4rem;
}

.sheet-spell-level {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--crimson-light);
    display: block;
    margin-bottom: 0.2rem;
}

.sheet-spell-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.sheet-slot {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    border-radius: 3px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Personality traits grid */
.sheet-traits-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
}

.sheet-trait-card {
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    border-radius: 4px;
    padding: 0.4rem;
}

.sheet-trait-card-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--crimson-light);
    margin-bottom: 0.2rem;
}

.sheet-trait-card-text {
    font-size: 0.75rem;
    color: var(--text);
    line-height: 1.3;
}

/* Features trait groups */
.sheet-trait-group {
    margin-bottom: 0.4rem;
}

.sheet-trait-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.2rem;
}

/* Location breadcrumb in sheet */
.sheet-location {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
    margin-bottom: 0.1rem;
}

.sheet-location .tag {
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
    font-size: 13px;
}

.sheet-location .tag:hover {
    border-color: var(--crimson);
    color: var(--crimson-light);
}

.sheet-location .breadcrumb-sep {
    color: var(--text-muted);
    font-size: 12px;
}

/* ── Editable description textarea ── */
.sheet-editable-text {
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s;
    font-size: 1.2rem;
}

.sheet-editable-text:hover {
    background: rgba(139, 26, 43, 0.08);
}

.sheet-text-placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.sheet-edit-textarea {
    width: 100%;
    min-height: 60px;
    padding: 0.4rem;
    font-size: 0.8rem;
    font-family: inherit;
    color: var(--text);
    background: var(--sheet-card-bg);
    border: 1px solid var(--crimson);
    border-radius: 3px;
    resize: vertical;
    line-height: 1.4;
    outline: none;
}

.sheet-edit-textarea:focus {
    border-color: var(--crimson-light);
    box-shadow: 0 0 0 1px var(--crimson-light);
}

/* ── Editable dialogue lines ── */
.sheet-editable-inline {
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.15s;
}

.sheet-editable-inline:hover {
    background: rgba(139, 26, 43, 0.08);
}

/* ── Relationship tag with remove button ── */
.rel-tag-wrap {
    display: inline-flex;
    align-items: center;
    position: relative;
}

.rel-remove-btn {
    display: none;
    position: absolute;
    top: -5px;
    right: -5px;
    width: 14px;
    height: 14px;
    padding: 0;
    border: 1px solid var(--sheet-border);
    border-radius: 50%;
    background: var(--sheet-card-bg);
    color: var(--crimson-light);
    font-size: 10px;
    line-height: 12px;
    text-align: center;
    cursor: pointer;
    z-index: 1;
    transition: background 0.15s, color 0.15s;
}

.rel-tag-wrap:hover .rel-remove-btn {
    display: block;
}

.rel-remove-btn:hover {
    background: var(--crimson);
    color: #fff;
    border-color: var(--crimson);
}

/* -----------------------------------------------------------------------
   Sheet V2 — D&D Beyond-style layout
   ----------------------------------------------------------------------- */

/* Root container — override .node-detail defaults */
.node-detail.sheet-v2 {
    background: var(--sheet-bg);
    background-image: url('/static/images/interface/Stone%20Wall%20and%20Sconces%202.png');
    background-size: 100% auto;
    background-position: top center;
    background-repeat: no-repeat;
    color: var(--text);
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    padding: 0.75rem;
    border-radius: 6px;
    min-height: 100%;
}

.node-detail.sheet-v2 > .sv2-header,
.node-detail.sheet-v2 > .sv2-stat-bar {
    background: rgba(0, 0, 0, 0.55);
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.4rem;
    transition: background 0.2s ease;
}

.node-detail.sheet-v2 > .sv2-header:hover,
.node-detail.sheet-v2 > .sv2-stat-bar:hover {
    background: rgba(0, 0, 0, 0.75);
}

/* Row containers are transparent — individual .sv2-panel children handle their own hover */
.node-detail.sheet-v2 > .sv2-row2,
.node-detail.sheet-v2 > .sv2-row3,
.node-detail.sheet-v2 > .sv2-tabs-area {
    padding: 0.5rem;
    margin-bottom: 0.4rem;
}

/* Override .node-detail h3 / h4 inside sheet-v2 */
.node-detail.sheet-v2 h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0 0;
}

.node-detail.sheet-v2 h4 {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--crimson-light);
    margin: 0 0 0.3rem 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--sheet-border);
}

/* Override .node-detail dl grid inside sheet-v2 */
.node-detail.sheet-v2 dl {
    display: block;
}

/* ── Header ── */
.node-detail.sheet-v2 .sv2-header {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 0.6rem;
}

.sheet-v2 .sv2-header-info {
    flex: 1;
    min-width: 0;
}

.sheet-v2 .sv2-header-top {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

/* ── Row 1: Full-width stat bar ── */
.node-detail.sheet-v2 .sv2-stat-bar {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0.3rem;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
}

.sheet-v2 .sv2-stat-cell {
    flex: 0 0 auto;
    min-width: 52px;
    max-width: 90px;
    text-align: center;
    padding: 0.3rem 0.35rem;
    background: #0000007a;
    border: 1px solid var(--sheet-border);
    border-radius: 4px;
    transition: background 0.2s ease;
}

.sheet-v2 .sv2-stat-cell:hover {
    background: rgba(0, 0, 0, 0.65);
}

.sheet-v2 .sv2-stat-ability {
    border-top: 2px solid var(--crimson);
}

.sheet-v2 .sv2-stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    line-height: 1.2;
}

.sheet-v2 .sv2-stat-label {
    font-size: 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.sheet-v2 .sv2-stat-sub {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.sheet-v2 .sv2-stat-hp .sv2-stat-value {
    color: var(--success);
}

.sheet-v2 .sv2-stat-divider {
    width: 2px;
    align-self: stretch;
    background: var(--text-muted);
    margin: 0.2rem 0.25rem;
    flex-shrink: 0;
    opacity: 0.4;
    border-radius: 1px;
}

/* ── Row 2: Saves | Skills | Combat ── */
.node-detail.sheet-v2 .sv2-row2 {
    display: grid;
    grid-template-columns: 3fr 3fr 3fr;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.sheet-v2 .sv2-panel {
    background: #0000007a;
    border: 1px solid var(--sheet-border);
    border-radius: 4px;
    padding: 0.4rem 0.5rem;
    transition: background 0.2s ease;
}

.sheet-v2 .sv2-panel:hover {
    background: rgba(0, 0, 0, 0.65);
}

/* Saves 2-column grid */
.sheet-v2 .sv2-saves-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 0.5rem;
}

/* Save table */
.sheet-v2 .sv2-save-table {
    width: 100%;
    border-collapse: collapse;
}

.sheet-v2 .sv2-save-table tr {
    border-bottom: 1px solid rgba(42, 21, 32, 0.4);
}

.sheet-v2 .sv2-save-table tr:last-child {
    border-bottom: none;
}

.sheet-v2 .sv2-save-table td {
    padding: 0.15rem 0.1rem;
    font-size: 0.75rem;
}

.sheet-v2 .sv2-prof-dot {
    width: 16px;
    text-align: center;
}

.sheet-v2 .sv2-dot-filled {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    vertical-align: middle;
}

.sheet-v2 .sv2-dot-empty {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid var(--text-muted);
    background: transparent;
    vertical-align: middle;
}

.sheet-v2 .sv2-save-mod {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text);
    text-align: right;
    padding-right: 0.3rem;
    width: 28px;
}

.sheet-v2 .sv2-save-name {
    color: var(--text-muted);
}

.sheet-v2 .sv2-prof .sv2-save-mod,
.sheet-v2 .sv2-prof .sv2-skill-mod {
    color: var(--crimson-light);
}

.sheet-v2 .sv2-prof .sv2-save-name,
.sheet-v2 .sv2-prof .sv2-skill-name {
    color: var(--text);
    font-weight: 500;
}

/* Skills table */
.sheet-v2 .sv2-skill-table {
    width: 100%;
    border-collapse: collapse;
}

.sheet-v2 .sv2-skill-table tr {
    border-bottom: 1px solid rgba(42, 21, 32, 0.4);
}

.sheet-v2 .sv2-skill-table tr:last-child {
    border-bottom: none;
}

.sheet-v2 .sv2-skill-table td {
    padding: 0.12rem 0.1rem;
    font-size: 0.72rem;
}

.sheet-v2 .sv2-skill-mod {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text);
    text-align: right;
    padding-right: 0.3rem;
    width: 28px;
}

.sheet-v2 .sv2-skill-name {
    color: var(--text-muted);
}

.sheet-v2 .sv2-skill-ability {
    color: var(--text-muted);
    font-size: 0.6rem;
    opacity: 0.7;
    text-align: right;
    padding-left: 0.2rem;
}

/* Combat panel */
.sheet-v2 .sv2-combat-panel {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.sheet-v2 .sv2-combat-box {
    text-align: center;
    padding: 0.35rem;
    background: var(--sheet-bg);
    border: 1px solid var(--sheet-border);
    border-radius: 4px;
}

.sheet-v2 .sv2-combat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    line-height: 1.1;
}

.sheet-v2 .sv2-combat-label {
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.sheet-v2 .sv2-combat-section {
    padding: 0.25rem 0.4rem;
    border-radius: 3px;
    transition: background 0.2s ease;
}

.sheet-v2 .sv2-combat-section:hover {
    background: rgba(0, 0, 0, 0.3);
}

.sheet-v2 .sv2-combat-section-label {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--crimson-light);
    margin-bottom: 0.1rem;
}

.sheet-v2 .sv2-combat-section-text {
    font-size: 0.75rem;
    color: var(--text);
    line-height: 1.3;
}

/* ── Row 3: Sidebar + Tabs ── */
.node-detail.sheet-v2 .sv2-row3 {
    display: grid;
    grid-template-columns: 1fr 3fr;
    gap: 0.5rem;
}

.sheet-v2 .sv2-sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sheet-v2 .sv2-sidebar-section p {
    font-size: 0.75rem;
    line-height: 1.3;
}

.sheet-v2 .sv2-prof-group {
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    line-height: 1.3;
}

.sheet-v2 .sv2-prof-label {
    font-weight: 600;
    color: var(--crimson-light);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sheet-v2 .sv2-prof-value {
    color: var(--text);
}

/* ── Tabs (Sheet V2) ── */
.sheet-v2 .sv2-tabs-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #0000007a;
    border: 1px solid var(--sheet-border);
    border-radius: 4px;
    transition: background 0.2s ease;
}

.sheet-v2 .sv2-tabs-area:hover {
    background: rgba(0, 0, 0, 0.65);
}

.sheet-v2 .sv2-tab-bar {
    display: flex;
    flex-direction: row;
    gap: 0;
    border-bottom: 2px solid var(--sheet-border);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.sheet-v2 .sv2-tab {
    padding: 0.3rem 0.6rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.sheet-v2 .sv2-tab:hover {
    color: var(--text);
}

.sheet-v2 .sv2-tab.active {
    color: var(--crimson-light);
    border-bottom-color: var(--crimson-light);
}

.sheet-v2 .sv2-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.sheet-v2 .sv2-tab-content.active {
    display: block;
}

/* Reuse sheet-ddb styles inside sheet-v2 */
.sheet-v2 .rel-groups {
    display: block;
    font-size: 0.8rem;
}
.sheet-v2 .rel-groups dt { color: var(--text-muted); }
.sheet-v2 .rel-predicate { background: var(--crimson); }
.sheet-v2 .tag {
    background: var(--sheet-card-bg);
    border: 1px solid var(--sheet-border);
}

.sheet-v2 .sheet-location { margin-bottom: 0.1rem; }
.sheet-v2 .sheet-location .tag { font-size: 13px; }
.sheet-v2 .sheet-location .tag:hover {
    border-color: var(--crimson);
    color: var(--crimson-light);
}

.sheet-v2 .history-list {
    list-style: none;
    padding: 0;
    font-size: 0.8rem;
}

.sheet-v2 .history-list li {
    padding: 0.15rem 0;
    border-bottom: 1px solid rgba(42, 21, 32, 0.3);
}

/* ── Header location breadcrumb (all sheets) ── */
.sheet-header-location {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.7rem;
    font-weight: 400;
    margin-left: 0.5rem;
    vertical-align: middle;
    opacity: 0.8;
}
.sheet-header-location .tag {
    font-size: 0.65rem;
    padding: 0.1rem 0.35rem;
}
.sheet-header-location .breadcrumb-sep {
    font-size: 0.6rem;
}

/* ── Editable attribute values (stat cells, combat values) ── */
/* Stat value coloring: positive=green, negative=red, zero/empty=gray */
.sheet-v2 .stat-positive { color: var(--success) !important; }
.sheet-v2 .stat-negative { color: var(--crimson-light) !important; }
.sheet-v2 .stat-zero { color: var(--text-muted) !important; }

.editable-attr {
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: border-color 0.15s;
}
.editable-attr:hover {
    border-bottom-color: var(--crimson-light);
}
.editable-attr .editable-input {
    width: 100%;
    text-align: center;
    font-size: inherit;
    font-weight: inherit;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--crimson);
    border-radius: 3px;
    padding: 0.1rem 0.2rem;
}

/* User bar in header */
.user-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 0.75rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--border);
}
.user-bar .user-name {
    font-size: 0.8rem;
    color: var(--text-muted);
}
