/* Canvas — base styles */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ── Canvas Rich Text Editor ─────────────────────────────────────────────── */

/* Default theme tokens (Cream). JS overrides these per-theme via inline style. */
.rte-wrap {
    --rte-bg:             #f9f7f2;
    --rte-text:           #1a1a1a;
    --rte-tbg:            #faf8f4;
    --rte-bdr:            #ded5c4;
    --rte-sep:            #ede5d4;
    --rte-btn-color:      #495057;
    --rte-btn-hover-bg:   #f0ebe0;
    --rte-btn-hover-bdr:  #d9d0c0;
    --rte-input-bg:       #fff;
    --rte-hint-color:     #c8c0b2;
    --rte-exit-bg:        rgba(255,255,255,0.7);
    --rte-exit-bdr:       #ddd;
    --rte-exit-color:     #aaa;

    border: 1px solid var(--rte-bdr);
    border-radius: 8px;
    overflow: hidden;
    background: var(--rte-bg);
    transition: background 0.25s, border-color 0.25s;
}
.rte-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    padding: 5px 8px;
    background: var(--rte-tbg);
    border-bottom: 1px solid var(--rte-sep);
    transition: background 0.25s, border-color 0.25s;
}
.rte-toolbar + .rte-toolbar {
    border-top: none;
    padding-top: 4px;
    padding-bottom: 4px;
}
.rte-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 26px;
    padding: 0 5px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--rte-btn-color);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    line-height: 1;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.rte-btn:hover      { background: var(--rte-btn-hover-bg); border-color: var(--rte-btn-hover-bdr); }
.rte-btn.rte-active { background: var(--canvas-chrome-active, #6b7a4a); border-color: var(--canvas-chrome-active, #6b7a4a); color: #fff; }
.rte-btn.rte-active svg { stroke: #fff; }
.rte-heading {
    height: 26px;
    padding: 0 6px;
    border: 1px solid var(--rte-sep);
    border-radius: 4px;
    background: var(--rte-input-bg);
    color: var(--rte-btn-color);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: background 0.25s, color 0.25s, border-color 0.25s;
}
.rte-heading:focus { border-color: var(--canvas-chrome-active, #b0c27b); }
.rte-font {
    height: 26px;
    padding: 0 6px;
    border: 1px solid var(--rte-sep);
    border-radius: 4px;
    background: var(--rte-input-bg);
    color: var(--rte-btn-color);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    max-width: 160px;
    transition: background 0.25s, color 0.25s, border-color 0.25s;
}
.rte-font:focus { border-color: var(--canvas-chrome-active, #b0c27b); }
.rte-font option, .rte-font optgroup { font-size: 13px; }
.rte-size {
    height: 26px;
    padding: 0 5px;
    border: 1px solid var(--rte-sep);
    border-radius: 4px;
    background: var(--rte-input-bg);
    color: var(--rte-btn-color);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    width: 52px;
    text-align: center;
    transition: background 0.25s, color 0.25s, border-color 0.25s;
}
.rte-size:focus { border-color: var(--canvas-chrome-active, #b0c27b); }
.rte-sep {
    width: 1px;
    height: 18px;
    background: var(--rte-sep);
    margin: 0 3px;
    flex-shrink: 0;
    transition: background 0.25s;
}
.rte-body {
    padding: 1rem 1.2rem 2rem;
    font-family: Georgia, serif;
    font-size: 1.05rem;
    line-height: 1.85;
    color: var(--rte-text);
    background: var(--rte-bg);
    outline: none;
    overflow-y: auto;
    word-break: break-word;
    transition: background 0.25s, color 0.25s;
}
.rte-body:focus-visible { outline: none; }
.rte-body h1 { font-size: 1.75rem; font-weight: 700; margin: 0.9rem 0 0.45rem; line-height: 1.3; }
.rte-body h2 { font-size: 1.45rem; font-weight: 700; margin: 0.85rem 0 0.4rem;  line-height: 1.35; }
.rte-body h3 { font-size: 1.2rem;  font-weight: 700; margin: 0.75rem 0 0.35rem; line-height: 1.4; }
.rte-body h4 { font-size: 1.05rem; font-weight: 600; margin: 0.65rem 0 0.3rem;  }
.rte-body h5 { font-size: 0.95rem; font-weight: 600; margin: 0.55rem 0 0.25rem; }
.rte-body h6 { font-size: 0.85rem; font-weight: 600; margin: 0.5rem 0 0.2rem; color: var(--rte-muted, #6b7280); }
.rte-body p  { margin: 0 0 0.6rem; }
.rte-body ul { list-style: disc;    margin: 0.5rem 0; padding-left: 1.6rem; }
.rte-body ol { list-style: decimal; margin: 0.5rem 0; padding-left: 1.6rem; }
.rte-body li { margin-bottom: 0.25rem; }
.rte-body blockquote { border-left: 3px solid var(--rte-bdr); margin: 0.75rem 0; padding: 0.25rem 0.75rem; color: var(--rte-muted, #6b7280); }

/* ── Theme picker ────────────────────────────────────────────────────────────── */
.rte-theme-panel {
    position: fixed;
    z-index: 10200;
    display: none;         /* toggled to grid by JS */
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 10px;
    background: var(--canvas-card-bg, #fff);
    border: 1px solid var(--canvas-card-border, #e2e2e2);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.14), 0 2px 6px rgba(0,0,0,0.08);
}
.rte-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 52px;
    border-radius: 7px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
    gap: 3px;
    padding: 4px 2px 5px;
}
.rte-swatch:hover    { transform: scale(1.06); box-shadow: 0 3px 10px rgba(0,0,0,0.15); }
.rte-swatch.rte-swatch-active { border-color: var(--canvas-chrome-active, #6b7a4a); box-shadow: 0 0 0 1px var(--canvas-chrome-active, #6b7a4a); }
.rte-swatch span {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    pointer-events: none;
    opacity: 0.8;
}

/* ── Selection bubble toolbar ────────────────────────────────────────────────── */
.rte-bubble {
    position: fixed;
    z-index: 10100;
    display: none;
    align-items: center;
    gap: 1px;
    padding: 4px 6px;
    background: #1e2022;
    border-radius: 7px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.22), 0 1px 4px rgba(0,0,0,0.14);
    pointer-events: auto;
    user-select: none;
    --arrow-offset: 0px;
}
.rte-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: calc(50% + var(--arrow-offset));
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom: none;
    border-top-color: #1e2022;
    pointer-events: none;
}
.rte-bubble.rte-bubble-below::after {
    bottom: auto;
    top: -6px;
    border-top: none;
    border-bottom: 6px solid #1e2022;
}
.rte-bubble-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 24px;
    padding: 0 4px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #d8d5cf;
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    transition: background 0.1s, color 0.1s;
}
.rte-bubble-btn:hover      { background: rgba(255,255,255,0.12); color: #fff; }
.rte-bubble-btn.rte-active { background: rgba(255,255,255,0.2);  color: #fff; }
.rte-bubble-btn svg        { stroke: currentColor; }
.rte-bubble-sep {
    width: 1px;
    height: 14px;
    background: rgba(255,255,255,0.15);
    margin: 0 2px;
    flex-shrink: 0;
}
.rte-bubble-heading {
    height: 24px;
    padding: 0 5px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #d8d5cf;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    min-width: 32px;
}
.rte-bubble-heading:hover  { background: rgba(255,255,255,0.12); color: #fff; }
.rte-bubble-heading option { background: #1e2022; color: #e8e8e8; }
.rte-bubble-heading:focus  { background: rgba(255,255,255,0.12); }
.rte-bubble-font {
    height: 24px;
    padding: 0 5px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #d8d5cf;
    font-size: 11px;
    cursor: pointer;
    outline: none;
    min-width: 80px;
    max-width: 110px;
}
.rte-bubble-font:hover  { background: rgba(255,255,255,0.12); color: #fff; }
.rte-bubble-font option, .rte-bubble-font optgroup { background: #1e2022; color: #e8e8e8; }
.rte-bubble-font:focus  { background: rgba(255,255,255,0.12); }

/* ── Distraction-free writing mode ──────────────────────────────────────────── */

body.rte-df-page { overflow: hidden; }

.rte-wrap.rte-df {
    position: fixed;
    inset: 0;
    z-index: 9999;
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    background: var(--rte-bg);
    transition: background 0.25s;
}
.rte-wrap.rte-df .rte-toolbar { display: none; }

.rte-wrap.rte-df .rte-body {
    flex: 1;
    overflow-y: auto;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 5vh 2rem 6rem;
    font-size: 1.15rem;
    line-height: 1.95;
    min-height: unset;
    background: transparent;
    /* Hide scrollbar in DF mode — scrolling still works via wheel/keyboard/touch */
    scrollbar-width: none;
}
.rte-wrap.rte-df .rte-body::-webkit-scrollbar { width: 0; }

/* Exit button */
.rte-df-exit {
    display: none;
    position: fixed;
    top: 1rem;
    right: 1.25rem;
    z-index: 10001;
    width: 32px;
    height: 32px;
    border: 1px solid var(--rte-exit-bdr);
    border-radius: 6px;
    background: var(--rte-exit-bg);
    color: var(--rte-exit-color);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    opacity: 0.4;
    backdrop-filter: blur(4px);
    transition: opacity 0.2s, color 0.15s, background 0.15s;
}
.rte-wrap.rte-df .rte-df-exit { display: flex; }
.rte-df-exit:hover { opacity: 1; }

/* Keyboard shortcut hint */
.rte-df-hint {
    display: none;
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 0.7rem;
    color: var(--rte-hint-color);
    pointer-events: none;
    z-index: 10000;
    letter-spacing: 0.01em;
    transition: color 0.25s;
}
.rte-df-hint kbd {
    font-family: inherit;
    font-size: inherit;
    background: none;
    border: none;
    padding: 0;
}
.rte-wrap.rte-df .rte-df-hint { display: block; }

/* Line-clamp for older webkit */
.line-clamp-2 {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Prevent body scroll when a mobile sidebar drawer is open */
body.sidebar-open {
    overflow: hidden;
}

/* ── Theme-responsive page content ────────────────────────────────────────── */

/* Card and input backgrounds adapt to theme */
main {
    color: var(--canvas-text, #1a1a1a);
}

/* Dark themes: override white cards and cream borders in main content */
[data-canvas-theme="night"] main .bg-white,
[data-canvas-theme="slate"] main .bg-white,
[data-canvas-theme="forest"] main .bg-white {
    background-color: var(--canvas-card-bg) !important;
}
[data-canvas-theme="night"] main .border-cream-300,
[data-canvas-theme="slate"] main .border-cream-300,
[data-canvas-theme="forest"] main .border-cream-300 {
    border-color: var(--canvas-card-border) !important;
}
[data-canvas-theme="night"] main .text-gray-900,
[data-canvas-theme="slate"] main .text-gray-900,
[data-canvas-theme="forest"] main .text-gray-900 {
    color: var(--canvas-text) !important;
}
[data-canvas-theme="night"] main .text-gray-700,
[data-canvas-theme="slate"] main .text-gray-700,
[data-canvas-theme="forest"] main .text-gray-700 {
    color: var(--canvas-text) !important;
}
[data-canvas-theme="night"] main .text-gray-600,
[data-canvas-theme="slate"] main .text-gray-600,
[data-canvas-theme="forest"] main .text-gray-600 {
    color: var(--canvas-secondary-text) !important;
}
[data-canvas-theme="night"] main .text-gray-500,
[data-canvas-theme="slate"] main .text-gray-500,
[data-canvas-theme="forest"] main .text-gray-500 {
    color: var(--canvas-secondary-text) !important;
}
[data-canvas-theme="night"] main .text-gray-400,
[data-canvas-theme="slate"] main .text-gray-400,
[data-canvas-theme="forest"] main .text-gray-400 {
    color: var(--canvas-muted-text) !important;
}
[data-canvas-theme="night"] main input,
[data-canvas-theme="slate"] main input,
[data-canvas-theme="forest"] main input,
[data-canvas-theme="night"] main select,
[data-canvas-theme="slate"] main select,
[data-canvas-theme="forest"] main select,
[data-canvas-theme="night"] main textarea,
[data-canvas-theme="slate"] main textarea,
[data-canvas-theme="forest"] main textarea {
    background-color: var(--canvas-input-bg) !important;
    border-color: var(--canvas-card-border) !important;
    color: var(--canvas-text) !important;
}

/* Warm/tinted themes: use tinted surfaces */
[data-canvas-theme="sepia"] main .bg-white { background-color: var(--canvas-card-bg) !important; }
[data-canvas-theme="sepia"] main .border-cream-300 { border-color: var(--canvas-card-border) !important; }
[data-canvas-theme="dusk"]  main .bg-white { background-color: var(--canvas-card-bg) !important; }
[data-canvas-theme="dusk"]  main .border-cream-300 { border-color: var(--canvas-card-border) !important; }
[data-canvas-theme="rose"]  main .bg-white { background-color: var(--canvas-card-bg) !important; }
[data-canvas-theme="rose"]  main .border-cream-300 { border-color: var(--canvas-card-border) !important; }
