/* =============================================================
   MARKDOWN STUDIO — Obsidian Gold Edition
   ============================================================= */

/* --- Custom Properties --- */
:root {
    /* Dark theme (default) */
    --bg:              #0C0B0F;
    --surface:         #141318;
    --surface-raised:  #1D1C24;
    --surface-hover:   #242332;
    --border:          #28273200;
    --border-solid:    #282732;
    --border-bright:   #3C3B4A;
    --text-primary:    #EDE8E3;
    --text-secondary:  #9994A8;
    --text-muted:      #52506080;
    --text-muted-s:    #524F60;
    --accent:          #D4A843;
    --accent-dim:      rgba(212, 168, 67, 0.10);
    --accent-glow:     rgba(212, 168, 67, 0.22);
    --accent-bright:   #F0C060;
    --blue:            #7EB3D4;
    --success:         #7EB87A;
    --danger:          #D47E7E;
    --font-display:    'Cormorant', Georgia, serif;
    --font-ui:         'DM Sans', system-ui, sans-serif;
    --font-mono:       'JetBrains Mono', 'Fira Code', monospace;
    --font-prose:      'Lora', Georgia, serif;
    --radius:          6px;
    --radius-lg:       10px;
    --shadow:          0 2px 12px rgba(0, 0, 0, 0.45);
    --shadow-lg:       0 8px 40px rgba(0, 0, 0, 0.65);
    --transition:      0.18s ease;
    --header-h:        52px;
    --toolbar-h:       40px;
}

body.light-mode {
    --bg:              #F2EDE4;
    --surface:         #FDFAF5;
    --surface-raised:  #EDE7DB;
    --surface-hover:   #E4DDD0;
    --border:          rgba(180, 168, 148, 0);
    --border-solid:    #C8BEA8;
    --border-bright:   #B0A488;
    --text-primary:    #1A1710;
    --text-secondary:  #6B5E48;
    --text-muted:      rgba(130, 112, 88, 0.55);
    --text-muted-s:    #8A7058;
    --accent:          #9A6C0E;
    --accent-dim:      rgba(154, 108, 14, 0.10);
    --accent-glow:     rgba(154, 108, 14, 0.22);
    --accent-bright:   #7A540A;
    --blue:            #2E6B9A;
    --success:         #3A7838;
    --danger:          #9A3838;
    --shadow:          0 2px 12px rgba(0, 0, 0, 0.12);
    --shadow-lg:       0 8px 40px rgba(0, 0, 0, 0.18);
}

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

html { height: 100%; }

body {
    font-family: var(--font-ui);
    background-color: var(--bg);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.35s, color 0.35s;
}

/* Ambient background glow */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 70% 50% at 15% 8%,  rgba(212, 168, 67, 0.05) 0%, transparent 65%),
        radial-gradient(ellipse 50% 40% at 88% 92%,  rgba(126, 179, 212, 0.04) 0%, transparent 65%);
    pointer-events: none;
    z-index: 0;
}

body > * { position: relative; z-index: 1; }

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem 0 1.5rem;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border-solid);
    flex-shrink: 0;
    position: relative;
    animation: slideDown 0.4s ease both;
}

/* Gold accent line along the bottom of the header */
.app-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--accent) 30%,
        var(--accent-bright) 50%,
        var(--accent) 70%,
        transparent 100%);
    opacity: 0.45;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.brand-glyph {
    color: var(--accent);
    font-size: 1rem;
    line-height: 1;
    flex-shrink: 0;
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

#app-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    letter-spacing: 0.025em;
    max-width: 420px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color var(--transition);
}

/* --- View toggle --- */
.view-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--surface-raised);
    border: 1px solid var(--border-solid);
    border-radius: var(--radius);
    padding: 3px;
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 26px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.view-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.view-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
    box-shadow: 0 0 0 1px rgba(212, 168, 67, 0.25);
}

/* --- View mode classes on editor-container --- */
.editor-container.mode-editor #preview-panel,
.editor-container.mode-editor .resizer {
    display: none;
}

.editor-container.mode-preview #editor-panel,
.editor-container.mode-preview .resizer {
    display: none;
}

/* --- File controls (in header) --- */
.file-controls {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    flex-shrink: 0;
}

/* Hide the raw file input — triggered by the label */
#file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* --- Button system --- */
.btn {
    font-family: var(--font-ui);
    font-size: 0.775rem;
    font-weight: 500;
    letter-spacing: 0.025em;
    padding: 0.32rem 0.7rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--surface-raised);
    color: var(--text-primary);
    border-color: var(--border-solid);
}

.btn-outline {
    background: transparent;
    color: var(--accent);
    border-color: rgba(212, 168, 67, 0.25);
}

.btn-outline:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn-icon-only {
    background: transparent;
    color: var(--text-muted-s);
    border-color: transparent;
    padding: 0.32rem 0.55rem;
    font-size: 1.1rem;
    line-height: 1;
}

.btn-icon-only:hover {
    color: var(--accent);
    background: var(--accent-dim);
}

.btn:active { transform: scale(0.95); }

.divider-v {
    display: inline-block;
    width: 1px;
    height: 1.4rem;
    background: var(--border-solid);
    margin: 0 0.3rem;
    flex-shrink: 0;
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 0 1.5rem;
    height: var(--toolbar-h);
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border-solid);
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    animation: slideDown 0.4s ease 0.06s both;
}

.toolbar::-webkit-scrollbar { display: none; }

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 1px;
}

.tool-btn {
    font-family: var(--font-ui);
    font-size: 0.73rem;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    min-width: 28px;
    text-align: center;
    white-space: nowrap;
    line-height: 1.5;
}

.tool-btn:hover {
    background: var(--accent-dim);
    color: var(--accent-bright);
    border-color: rgba(212, 168, 67, 0.18);
}

.tool-btn:active { transform: scale(0.94); }

.toolbar-separator {
    display: inline-block;
    width: 1px;
    height: 1.1rem;
    background: var(--border-bright);
    margin: 0 5px;
    flex-shrink: 0;
    opacity: 0.6;
}

/* Status indicator — right-aligned in toolbar */
.status-indicator {
    margin-left: auto;
    padding-left: 1rem;
    font-family: var(--font-ui);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.07em;
    color: var(--text-muted-s);
    white-space: nowrap;
    transition: color 0.3s, opacity 0.3s;
    flex-shrink: 0;
}

.status-indicator.unsaved { color: var(--accent); }
.status-indicator.saved   { color: var(--success); }

/* --- Editor container --- */
.editor-container {
    display: flex;
    flex: 1;
    min-height: 0;
    padding: 0.85rem 1.25rem;
    gap: 0;
    animation: slideDown 0.4s ease 0.12s both;
}

/* Panel wrapper — flex column: label + content */
.panel-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 100px;
    min-height: 0;
}

.panel-label {
    font-family: var(--font-ui);
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-muted-s);
    padding: 0 0.5rem 0.35rem;
}

/* --- Textarea (editor) --- */
#markdown-input {
    flex: 1;
    min-height: 0;
    resize: none;
    font-family: var(--font-mono);
    font-size: 0.86rem;
    line-height: 1.75;
    padding: 1.1rem 1.25rem;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-solid);
    border-radius: var(--radius-lg);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    caret-color: var(--accent);
}

#markdown-input:focus {
    border-color: var(--border-bright);
    box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow);
}

#markdown-input::placeholder {
    color: var(--text-muted-s);
    font-style: italic;
    font-size: 0.82rem;
}

#markdown-input.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow);
    background: rgba(212, 168, 67, 0.04);
}

/* --- Resizer --- */
.resizer {
    width: 22px;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0 8px;
}

.resizer-handle {
    width: 2px;
    height: 36px;
    background: var(--border-bright);
    border-radius: 2px;
    transition: all 0.2s ease;
}

.resizer:hover .resizer-handle,
.resizer.active .resizer-handle {
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
    height: 56px;
}

/* --- Preview output --- */
#rendered-output {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.1rem 1.5rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border-solid);
    border-radius: var(--radius-lg);
    font-family: var(--font-prose);
    font-size: 0.9375rem;
    line-height: 1.85;
    color: var(--text-primary);
    transition: background var(--transition), border-color var(--transition);
}

/* --- Custom scrollbars --- */
#rendered-output::-webkit-scrollbar,
#markdown-input::-webkit-scrollbar {
    width: 5px;
}

#rendered-output::-webkit-scrollbar-track,
#markdown-input::-webkit-scrollbar-track {
    background: transparent;
}

#rendered-output::-webkit-scrollbar-thumb,
#markdown-input::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 3px;
    transition: background 0.2s;
}

#rendered-output::-webkit-scrollbar-thumb:hover,
#markdown-input::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* ===== Markdown rendered content styles ===== */

#rendered-output h1,
#rendered-output h2,
#rendered-output h3,
#rendered-output h4,
#rendered-output h5,
#rendered-output h6 {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text-primary);
    margin: 1.6em 0 0.5em;
    line-height: 1.25;
    letter-spacing: 0.01em;
}

#rendered-output h1 {
    font-size: 2rem;
    font-style: italic;
    padding-bottom: 0.45em;
    border-bottom: 1px solid var(--border-solid);
    position: relative;
}

#rendered-output h1::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 60px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

#rendered-output h2 {
    font-size: 1.55rem;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-solid);
}

#rendered-output h3 {
    font-size: 1.22rem;
    color: var(--accent-bright);
}

#rendered-output h4 { font-size: 1.05rem; }

#rendered-output h5 {
    font-size: 0.85rem;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
}

#rendered-output h6 {
    font-size: 0.82rem;
    font-family: var(--font-ui);
    color: var(--text-secondary);
}

#rendered-output p { margin: 0.75em 0; }

#rendered-output a {
    color: var(--blue);
    text-decoration: none;
    border-bottom: 1px solid rgba(126, 179, 212, 0.3);
    transition: color var(--transition), border-color var(--transition);
}

#rendered-output a:hover {
    color: var(--accent);
    border-color: var(--accent);
}

#rendered-output strong {
    font-weight: 600;
    color: var(--text-primary);
}

#rendered-output em { font-style: italic; }

#rendered-output ul,
#rendered-output ol {
    padding-left: 1.75em;
    margin: 0.75em 0;
}

#rendered-output li { margin: 0.3em 0; }

#rendered-output li input[type="checkbox"] {
    accent-color: var(--accent);
    margin-right: 0.5em;
    transform: translateY(1px);
}

#rendered-output blockquote {
    margin: 1.2em 0;
    padding: 0.8em 1.25em;
    border-left: 3px solid var(--accent);
    background: var(--accent-dim);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
    font-style: italic;
}

#rendered-output blockquote p { margin: 0; }

#rendered-output code {
    font-family: var(--font-mono);
    font-size: 0.83em;
    background: var(--surface-raised);
    border: 1px solid var(--border-solid);
    padding: 0.15em 0.42em;
    border-radius: 4px;
    color: var(--accent-bright);
}

#rendered-output pre {
    background: var(--surface-raised);
    border: 1px solid var(--border-solid);
    border-radius: var(--radius-lg);
    padding: 1.1em 1.3em;
    overflow-x: auto;
    margin: 1.1em 0;
}

#rendered-output pre code {
    background: transparent;
    border: none;
    padding: 0;
    font-size: 0.84rem;
    color: var(--text-primary);
    line-height: 1.7;
}

#rendered-output pre::-webkit-scrollbar { height: 4px; }
#rendered-output pre::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 2px;
}

#rendered-output table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.1em 0;
    font-size: 0.88em;
    font-family: var(--font-ui);
}

#rendered-output th {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0.6em 0.9em;
    border-bottom: 2px solid var(--accent);
    text-align: left;
}

#rendered-output td {
    padding: 0.55em 0.9em;
    border-bottom: 1px solid var(--border-solid);
    vertical-align: top;
}

#rendered-output tr:hover td {
    background: var(--accent-dim);
}

#rendered-output hr {
    border: none;
    border-top: 1px solid var(--border-solid);
    margin: 2.2em 0;
    position: relative;
}

#rendered-output hr::before {
    content: '◈';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--accent);
    font-size: 0.7rem;
    background: var(--surface);
    padding: 0 0.6em;
    opacity: 0.8;
}

#rendered-output img {
    max-width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border-solid);
    display: block;
    margin: 0.75em 0;
}

/* First heading at top has less margin */
#rendered-output > h1:first-child,
#rendered-output > h2:first-child,
#rendered-output > h3:first-child {
    margin-top: 0;
}

/* --- Footer --- */
.app-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: 38px;
    padding: 0 1.1rem;
    background: var(--surface);
    border-top: 1px solid var(--border-solid);
    font-family: var(--font-ui);
}

.footer-tagline {
    font-size: 0.74rem;
    color: var(--text-muted-s);
    font-style: italic;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.footer-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.55rem;
    border-radius: var(--radius);
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition), background var(--transition);
}

.footer-link svg { flex: 0 0 auto; opacity: 0.85; }

.footer-link:hover {
    color: var(--accent-bright);
    background: var(--accent-dim);
}

.footer-bmc {
    color: var(--accent);
}

.footer-bmc:hover {
    color: var(--accent-bright);
}

/* Hide labels on narrow viewports, keep icons */
@media (max-width: 640px) {
    .footer-tagline { display: none; }
    .footer-link span { display: none; }
    .footer-link { padding: 0.3rem 0.45rem; }
}

/* --- Animations --- */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
