:root {
    --bg: #0d0709;
    --surface: #1a1013;
    --border: #33191f;
    --text: #f3e9ec;
    --text-dim: #a58c93;
    --accent: #d6153f;
    --accent-rgb: 214, 21, 63;
    --accent-hover: #ff5c8a;
    --accent-hover-rgb: 255, 92, 138;
}

* {
    box-sizing: border-box;
}

/* ---------- Site-wide themed scrollbars ---------- */
/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--bg);
}

/* Chromium/WebKit - applies everywhere, including inside CodeMirror's own
   scrollbar divs (those are just normal overflow:scroll elements under the
   hood) and any overflow-x:auto table wrapper, modal, etc. */
*::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

*::-webkit-scrollbar-track {
    background: var(--bg);
}

*::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 8px;
    border: 3px solid var(--bg);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

*::-webkit-scrollbar-corner {
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
}

/* ---------- Header / Hero ---------- */

.site-header {
    position: relative;
    overflow: hidden;
    padding: 1.5rem 1.5rem 4rem;
    background: var(--bg);
}

#header-bg-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    /* Natural aspect ratio, not stretched/cropped to match the header's
       full (much taller) height like object-fit:cover was doing - spans
       the same full width the hex-rain canvas did, but sits as a shorter
       strip across the top instead of being blown up to fill the whole
       header vertically. */
    height: auto;
    display: block;
    z-index: 0;
    opacity: 0.5;
    mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
}

/* Darkens the video enough for the hero text on top of it to stay readable,
   same job the hex-rain canvas's own translucent fill used to do. */
.header-bg-overlay {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: rgba(13, 7, 9, 0.55);
    mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}

.nav, .hero {
    position: relative;
    z-index: 1;
}

.nav {
    max-width: 1000px;
    margin: 0 auto 3rem;
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.02em;
}

.hero {
    max-width: 640px;
    margin: 0 auto;
    text-align: center;
}

.hero h1, .hero .tagline, .hero-note {
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.hero h1 {
    font-size: clamp(1.75rem, 4vw, 2.75rem);
    line-height: 1.2;
    margin: 0 0 1rem;
}

.tagline {
    color: var(--text-dim);
    font-size: 1.1rem;
    line-height: 1.6;
    margin: 0 auto 2rem;
    max-width: 520px;
}

.hero-note {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-top: 0.9rem;
}

/* ---------- Buttons ---------- */

button {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
    background: var(--accent-hover);
}

.cta {
    padding: 0.85rem 2rem;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
}

.cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(var(--accent-hover-rgb), 0.35);
}

/* ---------- Main sections ---------- */

main {
    flex: 1;
    padding: 1rem 1.5rem 3rem;
}

/* ---------- App (upload / tabs / results) ---------- */

.app {
    max-width: 1000px;
    margin: 0 auto 4rem;
}

.mode-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.mode-tab-button {
    background: none;
    color: var(--text-dim);
    border-radius: 8px 8px 0 0;
    padding: 0.65rem 1.1rem;
    font-weight: 600;
}

.mode-tab-button:hover {
    background: var(--surface);
    color: var(--text);
}

.mode-tab-button.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.mode-panel {
    display: none;
}

.mode-panel.active {
    display: block;
}

.xml-result-area {
    text-align: center;
    padding: 1.5rem 0;
}

.xml-result-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.rttex-result-area {
    text-align: center;
    padding: 1.5rem 0;
}

.rttex-preview-wrap {
    display: inline-flex;
    max-width: 100%;
    max-height: 420px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    /* Checkerboard so transparency in the preview is actually visible,
       instead of just reading as plain background color. */
    background-image:
        linear-gradient(45deg, #2a1c20 25%, transparent 25%),
        linear-gradient(-45deg, #2a1c20 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a1c20 75%),
        linear-gradient(-45deg, transparent 75%, #2a1c20 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: var(--surface);
}

#rttex-preview-canvas {
    max-width: 100%;
    max-height: 380px;
    width: auto;
    height: auto;
    image-rendering: pixelated;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 14px;
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(var(--accent-rgb), 0.06);
}

.drop-zone-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0 0 0.4rem;
}

.drop-zone-sub {
    color: var(--text-dim);
    margin: 0;
}

.progress-area {
    text-align: center;
    padding: 2rem 0;
}

#progress-label {
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}

.progress-track {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    transition: width 0.2s ease;
}

.error-area {
    background: rgba(var(--accent-rgb), 0.12);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    color: var(--text);
}

.unsaved-warning {
    background: rgba(var(--accent-rgb), 0.1);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem 1rem;
    margin-bottom: 1rem;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tabs-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding-bottom: 0.5rem;
}

.tabs-action-button {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.tabs-action-button:hover {
    background: var(--border);
}

#download-template-button {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

#download-template-button:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.tabs-action-danger {
    color: var(--accent-hover);
}

.tabs-action-danger:hover {
    background: rgba(var(--accent-rgb), 0.15);
    border-color: var(--accent);
}

.tab-button {
    background: none;
    color: var(--text-dim);
    border-radius: 8px 8px 0 0;
    padding: 0.65rem 1.1rem;
    font-weight: 600;
}

.tab-button:hover {
    background: var(--surface);
    color: var(--text);
}

.tab-button.active {
    background: var(--surface);
    color: var(--accent-hover);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.search-box {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 0.7rem 1rem;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.search-box:focus {
    outline: none;
    border-color: var(--accent);
}

.sort-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.sort-label {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.sort-button {
    background: var(--surface);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.sort-button:hover {
    background: var(--border);
    color: var(--text);
}

.sort-button.active {
    background: rgba(var(--accent-rgb), 0.18);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.sort-button .sort-arrow {
    margin-left: 0.3rem;
    display: inline-block;
}

.panel-note {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin: 0 0 1rem;
}

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

.item-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.85rem;
    overflow: hidden;
}

.item-card-icon {
    position: absolute;
    inset: 0 0 0 50%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 70% 70%;
    image-rendering: pixelated;
    z-index: 0;
    /* Fades toward the surface color on the left so text stays readable
       instead of butting up against the art with a hard edge. */
    -webkit-mask-image: linear-gradient(to right, transparent, black 35%);
    mask-image: linear-gradient(to right, transparent, black 35%);
}

.item-card-top, .item-card > .item-meta {
    position: relative;
    z-index: 1;
}

.item-card .item-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin: 0 0 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-card .item-meta {
    color: var(--text-dim);
    font-size: 0.78rem;
    margin: 0;
}

.item-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.item-edit-button {
    /* Solid background (not transparent) - item cards show the icon as a
       background image right behind this button, and a transparent button
       was nearly invisible against busy artwork. */
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    width: 1.8rem;
    height: 1.8rem;
    min-width: 0;
    padding: 0;
    line-height: 1;
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.item-edit-button:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ---------- Item row menu ---------- */

.item-menu {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.4rem;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    z-index: 50;
    display: flex;
    flex-direction: column;
    min-width: 140px;
}

.item-menu[hidden] {
    display: none;
}

.item-menu-option {
    background: none;
    color: var(--text);
    text-align: left;
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    font-size: 0.9rem;
    font-weight: 400;
}

.item-menu-option:hover:not(:disabled) {
    background: var(--border);
}

.item-menu-option:disabled {
    color: var(--text-dim);
    opacity: 0.5;
    cursor: default;
}

.item-menu-danger {
    color: var(--accent-hover);
}

/* ---------- Modals ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1.5rem;
    overflow-y: auto;
    z-index: 100;
}

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

.modal-panel {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.75rem;
    width: 100%;
    max-width: 540px;
}

.modal-panel h2 {
    margin: 0 0 0.25rem;
}

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

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
}

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

.field-label {
    display: block;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 1rem 0 0.35rem;
}

.field-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    font-size: 0.95rem;
}

.field-input:disabled {
    opacity: 0.6;
}

.field-checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    cursor: pointer;
}

textarea.field-input {
    resize: vertical;
    font-family: inherit;
}

.field-static {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin: 0;
    word-break: break-all;
}

.modal-section-button {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 600;
}

.modal-section-button:hover:not(:disabled) {
    background: var(--border);
}

.modal-section-button:disabled {
    color: var(--text-dim);
    cursor: default;
    opacity: 0.5;
}

.multiselect {
    position: relative;
}

.multiselect-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    font-size: 0.95rem;
    font-weight: 400;
    text-align: left;
}

.multiselect-toggle::after {
    content: "\25BE";
    color: var(--text-dim);
    margin-left: 0.5rem;
}

.multiselect-toggle:hover {
    background: var(--bg);
    border-color: var(--accent);
}

.multiselect-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem;
    z-index: 10;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    max-height: 260px;
    display: flex;
    flex-direction: column;
}

.multiselect-panel[hidden] {
    display: none;
}

.multiselect-search {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.multiselect-search:focus {
    outline: none;
    border-color: var(--accent);
}

.multiselect-options {
    overflow-y: auto;
}

.multiselect-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    padding: 0.45rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
}

.multiselect-options label:hover {
    background: var(--border);
}

.multiselect-options .multiselect-empty {
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 0.45rem 0.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.file-row {
    display: flex;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
}

.file-row .file-path {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-row .file-size {
    color: var(--text-dim);
    flex-shrink: 0;
    margin-left: 1rem;
}

/* ---------- Resources table ---------- */

.resource-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.resource-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.resource-table th {
    text-align: left;
    padding: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.resource-sort-header {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.7rem 0.9rem;
    width: 100%;
    text-align: left;
    min-width: 0;
}

.resource-sort-header:hover {
    background: none;
    color: var(--text);
}

.resource-sort-header.active {
    color: var(--accent-hover);
}

.resource-sort-header .sort-arrow {
    margin-left: 0.3rem;
}

/* Static (non-sortable) column header label - Scripts/Config tables reuse
   the resource table's look without opting into the sort-click listener
   that .resource-sort-header carries (which reads dataset.sortField). */
.th-label {
    display: inline-block;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.7rem 0.9rem;
}

.resource-table td {
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.resource-table tr:last-child td {
    border-bottom: none;
}

.resource-table tr:hover td {
    background: rgba(var(--accent-rgb), 0.05);
}

.resource-table .col-name {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resource-table .col-actions {
    text-align: right;
    width: 2.5rem;
}

/* ---------- Config tab: breadcrumb + folder browser ---------- */

.config-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.breadcrumb-segment {
    background: none;
    color: var(--text-dim);
    font-weight: 600;
    padding: 0.2rem 0.3rem;
    border-radius: 6px;
}

.breadcrumb-segment:hover:not(:disabled) {
    color: var(--text);
    background: var(--border);
}

.breadcrumb-segment.current {
    color: var(--text);
    cursor: default;
}

.breadcrumb-sep {
    color: var(--text-dim);
}

.config-folder-row {
    cursor: pointer;
}

.config-folder-row .col-name {
    font-weight: 600;
}

.config-folder-arrow {
    color: var(--text-dim);
}

.config-folder-row:hover .config-folder-arrow {
    color: var(--accent-hover);
}

/* ---------- View/Edit resource modals ---------- */

.view-resource-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
}

.view-resource-body img {
    max-width: 100%;
    max-height: 60vh;
    image-rendering: pixelated;
}

.editor-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    padding: 1rem 1.25rem;
}

.editor-fullscreen[hidden] {
    display: none;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
}

.editor-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.editor-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.editor-hint {
    color: var(--text-dim);
    font-size: 0.78rem;
}

.editor-header-actions .modal-close {
    position: static;
}

.editor-close-btn {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 600;
    padding: 0.6rem 1.1rem;
    width: auto;
}

.editor-close-btn:hover {
    background: var(--border);
}

.editor-body {
    position: relative;
    flex: 1;
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    min-height: 0;
}

/* CodeMirror mounts into #editor-body and needs to fill it completely. */
.editor-body .CodeMirror {
    flex: 1;
    height: 100%;
    font-family: "Courier New", monospace;
    font-size: 0.9rem;
}

/* Custom minimal theme (CodeMirror's "theme" mechanism is just a
   cm-s-<name> class) - only two accent colors as requested: tag names
   (and their brackets) in green, string/attribute values in blue.
   Everything else - attribute names, punctuation, the <?xml ?> prolog -
   stays the plain text color instead of CodeMirror's usual multi-color
   scheme. */
.cm-s-gothbuilds.CodeMirror {
    background: var(--bg);
    color: var(--text);
}

.cm-s-gothbuilds .CodeMirror-gutters {
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.cm-s-gothbuilds .CodeMirror-linenumber {
    color: var(--text-dim);
}

.cm-s-gothbuilds .cm-tag {
    color: #7ee787;
}

.cm-s-gothbuilds .cm-string {
    color: #79c0ff;
}

.cm-s-gothbuilds .cm-attribute {
    color: #79c0ff;
}

.cm-s-gothbuilds .cm-meta,
.cm-s-gothbuilds .cm-qualifier {
    color: var(--text);
}

/* Same two accent colors extended to Lua/JSON/CSS (Scripts and Config now
   open those modes too, not just XML) - keywords/property names in green
   alongside tag names, strings/numbers in blue alongside attribute values,
   comments dimmed since they're not code. */
.cm-s-gothbuilds .cm-keyword,
.cm-s-gothbuilds .cm-property,
.cm-s-gothbuilds .cm-def,
.cm-s-gothbuilds .cm-builtin,
.cm-s-gothbuilds .cm-atom {
    color: #7ee787;
}

.cm-s-gothbuilds .cm-number,
.cm-s-gothbuilds .cm-string-2 {
    color: #79c0ff;
}

.cm-s-gothbuilds .cm-comment {
    color: var(--text-dim);
    font-style: italic;
}

.cm-s-gothbuilds .cm-variable,
.cm-s-gothbuilds .cm-variable-2,
.cm-s-gothbuilds .cm-variable-3 {
    color: var(--text);
}

/* The angle brackets share class="cm-tag cm-bracket" with the tag name
   itself in CodeMirror's xml mode - the plain tag-name token only ever
   carries "cm-tag" alone, so this higher-specificity two-class selector
   (.cm-tag.cm-bracket beats plain .cm-tag regardless of source order) is
   what actually separates "<" / ">" / "</" / "/>" from the tag name text,
   letting them be styled differently even though both start as "cm-tag". */
.cm-s-gothbuilds .cm-tag.cm-bracket {
    color: var(--text-dim);
}

.cm-s-gothbuilds .CodeMirror-cursor {
    border-left: 1px solid var(--text);
}

.cm-s-gothbuilds .CodeMirror-selected,
.cm-s-gothbuilds .CodeMirror-focused .CodeMirror-selected {
    /* codemirror.min.css loads after this stylesheet, so its own
       .CodeMirror-focused .CodeMirror-selected rule (equal specificity)
       otherwise wins the cascade by load order alone - !important makes
       this win unconditionally instead of depending on link order. */
    background: rgba(var(--accent-rgb), 0.28) !important;
}

.cm-s-gothbuilds .CodeMirror-matchingbracket {
    color: var(--accent-hover) !important;
    text-decoration: underline;
}

/* Indent guides - CodeMirror 5 has no built-in indent-guide addon, so
   script.js's "renderLine" handler sets an inline background-image + size
   on each individual line, sized to exactly that line's own indent depth
   (not the whole editor width) - see getResourceEditor(). No CSS needed
   here since the gradient and its size are computed and applied per line. */

/* ---------- VS Code-style find/replace widget ---------- */
/* A custom-built widget (not CodeMirror's own dialog addon) so it can match
   a specific compact top-right box layout exactly, with match-case/whole-
   word/regex toggles and a live match counter. */

.cm-find-widget {
    position: absolute;
    top: 0.6rem;
    right: 1.5rem;
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    padding: 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.cm-find-widget[hidden] {
    display: none;
}

.cm-find-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.cm-find-row[hidden] {
    display: none;
}

.cm-find-chevron {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1rem;
    width: 1.4rem;
    height: 1.9rem;
    padding: 0;
    min-width: 0;
    flex-shrink: 0;
    transition: transform 0.1s ease;
}

.cm-find-chevron.expanded {
    transform: rotate(90deg);
}

.cm-find-chevron:hover {
    background: var(--border);
}

.cm-find-spacer {
    width: 1.4rem;
    flex-shrink: 0;
}

.cm-find-input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
    width: 170px;
}

.cm-find-input:focus {
    outline: none;
    border-color: var(--accent);
}

.cm-find-toggles {
    display: flex;
    gap: 2px;
}

.cm-find-toggle {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.72rem;
    font-weight: 700;
    width: 1.5rem;
    height: 1.9rem;
    padding: 0;
    min-width: 0;
}

.cm-find-toggle:hover {
    background: var(--bg);
    color: var(--text);
}

.cm-find-toggle.active {
    background: rgba(var(--accent-rgb), 0.3);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.cm-find-count {
    color: var(--text-dim);
    font-size: 0.75rem;
    white-space: nowrap;
    min-width: 4.5rem;
    text-align: center;
}

.cm-find-icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.95rem;
    width: 1.6rem;
    height: 1.9rem;
    padding: 0;
    min-width: 0;
    flex-shrink: 0;
}

.cm-find-icon-btn:hover:not(:disabled) {
    background: var(--border);
    color: var(--text);
}

.cm-find-icon-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* Highlighted match spans, applied via CodeMirror markText. */
.cm-find-match {
    background: rgba(var(--accent-rgb), 0.25);
    border-radius: 2px;
}

.cm-find-match-current {
    background: var(--accent);
    color: #fff !important;
    border-radius: 2px;
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.page-button {
    background: var(--surface);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.page-button:hover:not(:disabled):not(.active) {
    background: var(--border);
    color: var(--text);
}

.page-button.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.page-button:disabled {
    opacity: 0.35;
    cursor: default;
}

.page-ellipsis {
    color: var(--text-dim);
    padding: 0 0.25rem;
}

.page-jump {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: 0.5rem;
}

.page-jump-input {
    width: 4.5rem;
    height: 2.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 0 0.5rem;
    font-size: 0.85rem;
}

.page-jump-input:focus {
    outline: none;
    border-color: var(--accent);
}

.page-jump-button {
    height: 2.25rem;
    padding: 0 0.85rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
}

.section-title {
    text-align: center;
    font-size: 1.5rem;
    margin: 0 0 2rem;
}

.steps, .highlights {
    max-width: 1000px;
    margin: 0 auto 4rem;
}

.steps-grid, .highlights-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}

@media (max-width: 720px) {
    .steps-grid, .highlights-grid {
        grid-template-columns: 1fr;
    }
}

.step, .highlight-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.75rem;
}

.step h3, .highlight-card h3 {
    margin: 0.25rem 0 0.5rem;
    font-size: 1.1rem;
}

.step p, .highlight-card p {
    color: var(--text-dim);
    line-height: 1.5;
    margin: 0;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(var(--accent-rgb), 0.22);
    color: var(--accent-hover);
    font-weight: 700;
}

/* ---------- Footer ---------- */

footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-dim);
    font-size: 0.85rem;
}
