/* ========================
Root & transitions
======================== */
:root {
    --border-radius: 4px;
    --font-size: clamp(1rem, 2.5vw, 1.125rem);
    transition:
        background 0.5s ease,
        color 0.5s ease,
        --accent 0.5s ease,
        --btn-bg 0.5s ease,
        --btn-hover 0.5s ease;
}

/* ========================
Global reset
======================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    display: flex;
    height: 100vh;
    font-family: var(--font-family, sans-serif);
    background: var(--bg);
    color: var(--fg);
    transition: background-color 0.3s, color 0.3s;
}

hr {
    margin: 2rem 0;
}

/* ========================
Settings panel (transparent)
======================== */
#settings {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 1rem;
    padding: 1rem;
    z-index: 100;
    background: transparent !important;
    backdrop-filter: none !important;
}

/* ========================
Sidebar
======================== */
nav {
    width: 250px;
    min-width: 200px;
    background-color: var(--nav-bg);
    border-right: 1px solid var(--nav-border);
    padding: 1rem;
    overflow-y: auto;
    transition: transform 0.3s ease;
    position: relative;
    margin: 1rem;
    border-radius: var(--border-radius);
}
nav.collapsed {
    transform: translateX(calc(-100% - 2rem));
    position: absolute;
    z-index: 50;
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
}
nav h2 {
    font-size: 1.2em;
    margin: 1rem 0;
}
nav > div {
    margin-bottom: 2rem;
}

/* ========================
Chapter buttons
======================== */
nav button.chapter-btn, nav button.insert-chapter-btn {
    display: block;
    width: 100%;
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: none;
    border-radius: var(--border-radius);
    padding: 0.5em;
    text-align: left;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
nav button.chapter-btn:hover,
nav button.insert-chapter-btn:hover
{
    background: var(--btn-hover);
    transform: translateX(4px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
nav button.chapter-btn:active {
    transform: translateX(2px) scale(0.98);
}

nav button.insert-chapter-btn {
    width: 36px!important; 
    height: 36px!important;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================
Sidebar toggles
======================== */
#navCloseBtn,
#sidebarToggle {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, background-color 0.2s ease;
    z-index: 200;
}
#sidebarToggle {
    position: fixed;
    top: 10px;
    left: 10px;
    font-size: 1.2em;
}
#sidebarToggle.open {
    transform: rotate(90deg);
}
#navCloseBtn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 201;
}
#navCloseBtn i,
#sidebarToggle i {
    font-size: 1.25rem;
}
#navCloseBtn:hover,
#sidebarToggle:hover {
    background: var(--btn-hover);
}

/* ========================
Main content
======================== */
main {
    flex: 1;
    padding: 1rem;
    padding-top: 5rem;
    overflow-y: auto;
    scroll-behavior: smooth;
}
main::-webkit-scrollbar {
    width: 8px;
}
main::-webkit-scrollbar-thumb {
    background: var(--btn-bg);
    border-radius: var(--border-radius);
}
#content {
    max-width: 70ch;
    margin: auto;
    line-height: 1.6;
    font-size: var(--font-size);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}
#content.loaded {
    opacity: 1;
    transform: translateY(0);
}
#content p {
    margin-bottom: 1rem;
}

/* ========================
Prev/Next buttons
======================== */
.nav-buttons {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.nav-buttons button {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.nav-buttons button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.nav-buttons button:active {
    transform: translateY(0) scale(0.95);
}

/* ========================
Standard button styles
======================== */
button,
select {
    background-color: var(--btn-bg);
    color: var(--btn-fg);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.9em;
    padding: 0.6em 1em;
    transition: background-color 0.2s ease, transform 0.1s ease;
}
button:hover,
select:hover {
    background-color: var(--btn-hover);
}
button:active {
    transform: scale(0.97);
}

/* ========================
Ripple effect
======================== */
.ripple {
    position: absolute;        /* absolute within button */
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    width: 0;
    height: 0;
    transform: scale(0);
    pointer-events: none;
    animation: ripple 0.6s ease-out forwards;
}
@keyframes ripple {
to {
    transform: scale(4);
    opacity: 0;
}
}

/* ========================
Code & misc
======================== */
pre {
    background: var(--code-bg);
    padding: 1em;
    overflow-x: auto;
}
h1 {
    /* Control the size in a scalable way */
    font-size: 2rem;            /* ≈32px if root font-size is 16px */
    line-height: 1.25;          /* improve readability */

    /* Use logical properties for top/bottom margins */
    margin-block-start: 1.5rem; /* space above */
    margin-block-end:   1rem;   /* space below */

    /* Optional: tweak weight/family to match your theme */
    font-weight: 700;
}
h1, h2, h3, h4 {
    color: var(--accent);
    margin-bottom: 1rem;
}
a {
    color: var(--link);
}
code {
    font-family: var(--font-family, 'Courier New', monospace);
    background-color: var(--code-bg);
    color: var(--fg);
    padding: 0.2em 0.4em;
    border-radius: var(--border-radius);
}
body, nav, main, #content, h1, h2, h3, h4, p, li {
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ========================
Skeleton shimmer
======================== */
.skeleton {
    background: #e2e2e2;
    position: relative;
    overflow: hidden;
}
.skeleton::after {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
100% { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0 !important;
        scroll-behavior: auto !important;
    }
}

/* Edit‑mode textarea fills the content area and scrolls */
#editor {
    width: 100%;
    height: 70vh;           /* keep your desired fixed height */
    overflow-y: auto;       /* ← this makes the textarea scrollable */
    white-space: pre-wrap;  /* preserve word‑wrapping inside */
    font-family: var(--font-family, monospace);
    font-size:   var(--font-size);
    padding:     1rem;
    border:      1px solid var(--nav-border);
    border-radius: var(--border-radius);
    resize: vertical;       /* still allow the user to resize if you like */
}

.edit-btn {
    margin-left: 1rem;
}
/* make the CM container fill the article area */
#editor-wrapper {
    height: 70vh;
    margin-bottom: 1rem;
    border: 1px solid var(--nav-border);
    border-radius: var(--border-radius);
    overflow: hidden;
}
/* (optional) restyle Save/Cancel to match your button styles */
#editor-wrapper ~ button {
    margin-right: 0.5rem;
}

/* apply your CSS‑variable theme to the editor */
.CodeMirror {
    height: 70vh !important;
    background: var(--content-inner-bg) !important;
    color:      var(--fg)            !important;
    font-family: var(--font-family)  !important;
    font-size:   var(--font-size)    !important;
    border:      1px solid var(--nav-border) !important;
    border-radius: var(--border-radius)      !important;
}


/* make sure the scroll gutter is auto */
.CodeMirror-scroll {
    overflow: auto;
}

/* 1) Hook into CM’s “default” skin (the one you load via codemirror.min.css) */
.cm-s-default .CodeMirror {
    background:    var(--content-inner-bg);
    color:         var(--fg);
    font-family:   var(--font-family);
    font-size:     var(--font-size);
}

/* GUTTER (line‑numbers column) */
.CodeMirror-gutters {
    background:    var(--content-inner-bg) !important;
    border-right:  1px solid var(--nav-border) !important;
}

/* gutter filler (for when there's no content) */
.CodeMirror-gutter-filler,
.CodeMirror-scrollbar-filler {
    background: var(--content-inner-bg) !important;
}


/* 3) Cursor */
.cm-s-default .CodeMirror-cursor {
    border-left:   1px solid var(--accent);
}

/* 4) Selection */
.cm-s-default .CodeMirror-selected {
    background:    var(--btn-hover);
}

/* Tab buttons */
.tabs-bar {
    display: flex;
    border-bottom: 1px solid var(--nav-border);
    margin-bottom: 0.5rem;
}
.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 0.75em;
    cursor: pointer;
    font-size: 1em;
    color: var(--fg);
    transition: background 0.2s;
}
.tab-btn.active {
    background: var(--btn-bg);
    color: var(--btn-fg);
}
.tab-btn:not(.active):hover {
    background: var(--btn-hover);
}

/* Panels */
.tab-panel {
    height: calc(70vh - 2.5em); /* adjust to fit your Editor height */
    overflow-y: auto;
}
.hidden {
    display: none;
}

/* Save/Cancel row */
.edit-actions {
    margin-top: 0.5rem;
}
.edit-actions button {
    margin-right: 0.5rem;
}

/* Always show a high‑contrast cursor in CodeMirror */
.CodeMirror-cursor {
    border-left: 1px solid var(--accent) !important;
}

/* Optional: make it a little thicker on high‑DPI screens */
@media (min-resolution: 2dppx) {
    .CodeMirror-cursor {
        border-left-width: 2px !important;
    }
}
