/* ── Design tokens ──────────────────────────────────── */
:root {
    --bg-cream: #faf9f5;
    --bg-surface: #f2efe9;
    --bg-desk: #e8e4de;
    --accent: #c15f3c;
    --accent-hover: #a64e30;
    --text-dark: #1c1917;
    --text-muted: #6b6560;
    --code-surface: #f0ede6;
    --clawd-orange: #d77757;
    --scroll-thumb: #c4b8ae;
    --heading-font: 'DM Sans', sans-serif;
    --body-font: 'Lora', serif;
    --page-width: 215.9mm;
}

/* ── Reset ──────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
[hidden] {
    display: none !important;
}
html,
body {
    height: 100%;
}

body {
    display: grid;
    grid-template-rows: 56px 1fr;
    height: 100dvh;
    overflow: hidden;
    font-family: 'DM Sans', sans-serif;
    background: var(--bg-cream);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
}

/* ── Toolbar ────────────────────────────────────────── */
#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    gap: 12px;
    background: var(--bg-cream);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    user-select: none;
    flex-shrink: 0;
}
.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
#clawd-toolbar svg {
    display: block;
    cursor: default;
    transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1);
}
@media (hover: hover) and (pointer: fine) {
    #clawd-toolbar:hover svg {
        transform: translateY(-2px) rotate(-4deg);
    }
}
@media (prefers-reduced-motion: reduce) {
    #clawd-toolbar svg {
        transition: none;
    }
}
.app-name {
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}
.app-name-accent {
    color: var(--clawd-orange);
}
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* pill toggle */
.toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 20px;
    padding: 5px 12px;
    font-family: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    transition:
        background-color 150ms ease,
        color 150ms ease,
        border-color 150ms ease;
    min-height: 32px;
}
@media (hover: hover) and (pointer: fine) {
    .toggle-btn:hover {
        border-color: rgba(0, 0, 0, 0.15);
        color: var(--text-dark);
    }
}
.toggle-btn:active {
    transform: scale(0.97);
}
.toggle-btn.active {
    background: rgba(215, 119, 87, 0.1);
    border-color: rgba(215, 119, 87, 0.3);
    color: var(--text-dark);
}
.toggle-btn #clawd-btn-icon svg {
    display: block;
}
.toggle-label {
    line-height: 1;
}
.toggle-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--scroll-thumb);
    flex-shrink: 0;
    transition: background-color 150ms ease;
}
.toggle-btn.active .toggle-dot {
    background: var(--clawd-orange);
}
.download-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 6px 16px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    min-height: 32px;
    min-width: 44px;
    transition:
        background-color 150ms ease,
        opacity 150ms ease;
    white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
    .download-btn:hover:not(:disabled) {
        background: var(--accent-hover);
    }
}
.download-btn:active:not(:disabled) {
    transform: scale(0.97);
}
.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Main split layout ──────────────────────────────── */
main {
    display: grid;
    grid-template-columns: 1fr 6px 1fr;
    overflow: hidden;
    height: 100%;
}

/* ── Editor pane ────────────────────────────────────── */
#editor-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#editor {
    flex: 1;
    resize: none;
    background: var(--bg-cream);
    color: var(--text-dark);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.65;
    padding: 20px 24px;
    border: none;
    outline: none;
    overflow-y: auto;
    caret-color: var(--accent);
}
#editor::placeholder {
    color: var(--text-muted);
}
#editor::-webkit-scrollbar {
    width: 6px;
}
#editor::-webkit-scrollbar-track {
    background: var(--bg-cream);
}
#editor::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 3px;
}

/* ── Divider ───────────────────────────────────────── */
#resize-handle {
    background: rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

/* ── Preview pane ───────────────────────────────────── */
#preview-pane {
    overflow-y: auto;
    background: var(--bg-desk);
    padding: 24px 20px;
}
#preview-pane::-webkit-scrollbar {
    width: 6px;
}
#preview-pane::-webkit-scrollbar-track {
    background: var(--bg-desk);
}
#preview-pane::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 3px;
}

/* ── PDF paper — US Letter pages with visible gaps ────── */
#preview-content {
    position: relative;
    width: var(--page-width);
    min-width: var(--page-width);
    margin: 0 auto;
    padding: 48px 48px 6px;
    border-radius: 20px;
    overflow: hidden;
    min-height: 279.4mm;
    color: var(--text-dark);
    box-shadow:
        0 2px 16px rgba(0, 0, 0, 0.1),
        0 1px 4px rgba(0, 0, 0, 0.06);
    background: var(--bg-cream);
}

/* ── Decorative Clawds along page borders ───────────── */
.page-clawd {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}
/* document header — clawd + title side by side */
.doc-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 20px;
    margin-bottom: 0.8em;
}
.doc-header .top-clawd {
    align-self: center;
    line-height: 0;
}
.doc-header .header-text {
    align-self: center;
    font-family: 'JetBrains Mono', monospace;
}
/* override #md-output specificity for header elements */
#md-output .doc-header h1 {
    margin: 0;
    font-family: 'JetBrains Mono', monospace;
}
#md-output .doc-header p {
    margin: 0.15em 0 0;
    color: var(--text-muted);
    font-size: 10pt;
}
/* spacers push content past page breaks */
.page-spacer {
    pointer-events: none;
}
/* curved page separators between pages */
.page-sep {
    position: absolute;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--bg-desk);
    z-index: 4;
    pointer-events: none;
}
.page-sep::before,
.page-sep::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 12px;
    background: var(--bg-cream);
}
.page-sep::before {
    top: 0;
    border-radius: 0 0 14px 14px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
}
.page-sep::after {
    bottom: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -3px 8px rgba(0, 0, 0, 0.06);
}
/* page number bottom-right */
.page-num {
    position: absolute;
    right: 36px;
    font-family: var(--body-font);
    font-size: 9pt;
    color: var(--text-muted);
    z-index: 2;
    pointer-events: none;
    opacity: 0.5;
}
/* hide them when toggled off */
#preview-content.clawds-hidden .page-clawd,
#preview-content.clawds-hidden .doc-header .top-clawd {
    display: none;
}

/* ── Markdown rendered output ───────────────────────── */
#md-output {
    position: relative;
    z-index: 2;
    font-family: var(--body-font);
    font-size: 10.5pt;
    line-height: 1.7;
    color: var(--text-dark);
}

/* headings */
#md-output h1,
#md-output h2,
#md-output h3,
#md-output h4,
#md-output h5,
#md-output h6 {
    font-family: var(--heading-font);
    color: var(--text-dark);
    margin: 1.4em 0 0.4em;
    line-height: 1.2;
    break-after: avoid;
}
#md-output h1 {
    font-size: 18pt;
    font-weight: 700;
}
#md-output h2 {
    font-size: 15pt;
    font-weight: 600;
    border-bottom: 1px solid var(--bg-surface);
    padding-bottom: 0.25em;
}
#md-output h3 {
    font-size: 13pt;
    font-weight: 600;
}
#md-output h4 {
    font-size: 11pt;
    font-weight: 600;
}
#md-output h5 {
    font-size: 10.5pt;
    font-weight: 600;
}
#md-output h6 {
    font-size: 10pt;
    font-weight: 600;
    color: var(--text-muted);
}

#md-output p {
    margin: 0 0 0.8em;
}
#md-output a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
#md-output a:hover {
    color: var(--accent-hover);
}

/* inline code */
#md-output code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9.5pt;
    background: var(--code-surface);
    color: var(--text-dark);
    padding: 0.15em 0.35em;
    border-radius: 3px;
}
/* code blocks */
#md-output pre {
    background: var(--code-surface);
    border-radius: 6px;
    padding: 0.8em 1em;
    overflow-x: auto;
    margin: 0.4em 0 1em;
    font-size: 9.5pt;
    line-height: 1.55;
}
#md-output pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    border-radius: 0;
}
/* blockquotes */
#md-output blockquote {
    border-left: 3px solid var(--clawd-orange);
    margin: 0.8em 0;
    padding: 0.3em 0 0.3em 1em;
    color: var(--text-muted);
    font-style: italic;
}
#md-output blockquote p {
    margin: 0;
}
/* lists */
#md-output ul,
#md-output ol {
    margin: 0 0 0.8em 1.4em;
    padding: 0;
}
#md-output li {
    margin-bottom: 0.2em;
}
#md-output li p {
    margin: 0;
}
/* tables */
#md-output table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.4em 0 1em;
    font-size: 10pt;
    background: #fff;
}
#md-output th {
    background: var(--bg-surface);
    font-weight: 600;
    text-align: left;
    font-family: var(--heading-font);
}
#md-output th,
#md-output td {
    border: 1px solid #d4cfc8;
    padding: 0.35em 0.6em;
}
#md-output tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.035);
}
/* hr */
#md-output hr {
    border: none;
    border-top: 1px solid #d0c4b6;
    margin: 1.4em 0;
}
#md-output img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}
#md-output del {
    color: var(--text-muted);
}
/* page break avoidance for PDF */
#md-output pre,
#md-output blockquote,
#md-output table,
#md-output img {
    break-inside: avoid;
}
/* hide spacers during PDF export */
#md-output.pdf-export .page-spacer {
    display: none;
}
/* hide top clawd in PDF when toggle is off */
#md-output.pdf-no-clawds .top-clawd {
    display: none;
}

/* ── highlight.js warm overrides ────────────────────── */
.hljs {
    background: var(--code-surface) !important;
    color: #3d2b1a !important;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-title {
    color: #a64e30;
    font-weight: 600;
}
.hljs-string,
.hljs-attr {
    color: #5c7a3e;
}
.hljs-number,
.hljs-literal,
.hljs-variable {
    color: #7a5c2e;
}
.hljs-comment,
.hljs-quote {
    color: #9a8e84;
    font-style: italic;
}
.hljs-built_in,
.hljs-name {
    color: #3a6e8c;
}
.hljs-meta {
    color: var(--text-muted);
}

/* ── Floating feedback button ──────────────────────── */
#feedback-fab {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 0;
    height: 44px;
    padding: 0 14px;
    background: var(--bg-cream);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 22px;
    box-shadow:
        0 2px 12px rgba(0, 0, 0, 0.1),
        0 1px 3px rgba(0, 0, 0, 0.06);
    text-decoration: none;
    color: var(--text-dark);
    cursor: pointer;
    overflow: hidden;
    transition:
        box-shadow 200ms ease,
        border-color 200ms ease;
}
#feedback-fab:hover {
    border-color: rgba(215, 119, 87, 0.3);
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.12),
        0 1px 4px rgba(0, 0, 0, 0.08);
}
#fab-clawd svg {
    display: block;
    flex-shrink: 0;
    margin-right: 0;
}

.fab-label {
    font-family: var(--heading-font);
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition:
        max-width 250ms ease,
        opacity 200ms ease,
        margin 250ms ease;
    margin-left: 0;
}
#feedback-fab:hover .fab-label {
    max-width: 80px;
    opacity: 1;
    margin-left: 6px;
}

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
    }
    #resize-handle,
    #preview-pane {
        display: none;
    }
    #preview-content {
        padding: 20px 16px;
    }
}
