/* ==========================================================================
   CodeTestPad — Cozy French Villa Writing Studio
   Warm creams, parchment, espresso text, terracotta & slate accents
   ========================================================================== */

:root {
    /* Surfaces */
    --color-bg:           #ebe4d6;
    --color-surface:      #f7f2ea;
    --color-surface-soft: #faf7f2;
    --color-surface-raised: #fffdf9;
    --color-paper:        #f3ece0;

    /* Vellum (center column surround) */
    --color-vellum-base:    #e2d4b5;
    --color-vellum-light:   #efe6cf;
    --color-vellum-shadow:  #d2c099;
    --color-vellum-stain:   rgba(139, 105, 60, 0.14);

    /* Text */
    --color-text:         #3a2a1e;
    --color-text-muted:   #6f5e50;
    --color-text-faint:   #9a8878;

    /* Accents */
    --color-accent:       #b85c38;
    --color-accent-hover: #9e4a28;
    --color-accent-soft:  rgba(184, 92, 56, 0.12);
    --color-slate:        #5c728e;
    --color-slate-soft:   rgba(92, 114, 142, 0.14);

    /* Borders & shadows */
    --color-border:       #ddd2c0;
    --color-border-light: #e8dfd0;
    --shadow-soft:        0 2px 12px rgba(58, 42, 30, 0.06);
    --shadow-panel:       0 4px 24px rgba(58, 42, 30, 0.08);

    /* Typography */
    --font-serif: 'Lora', 'EB Garamond', Georgia, 'Times New Roman', serif;
    --font-sans:  'Source Sans 3', 'Segoe UI', system-ui, sans-serif;

    /* Layout */
    --sidebar-width: 280px;
    --lore-width:    300px;
    --header-height: 60px;
    --radius-sm:     8px;
    --radius-md:     14px;
    --radius-lg:     20px;

    /* Motion */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

/* --------------------------------------------------------------------------
   Buttons & form controls
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.45rem 0.9rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s var(--ease-out), border-color 0.2s, color 0.2s, box-shadow 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-accent);
    color: var(--color-surface-raised);
    box-shadow: var(--shadow-soft);
}
.btn-primary:hover { background: var(--color-accent-hover); }

.btn-secondary {
    background: var(--color-surface-raised);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-paper);
    border-color: var(--color-text-faint);
}

.btn-danger {
    background: transparent;
    color: #8b3a3a;
    border-color: rgba(139, 58, 58, 0.35);
}
.btn-danger:hover {
    background: rgba(139, 58, 58, 0.08);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--color-accent-soft);
    color: var(--color-text);
}

.btn-block { width: 100%; }
.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    border-radius: 6px;
}

.control-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.control-select {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    color: var(--color-text);
    min-width: 10rem;
}

.control-select:focus {
    outline: none;
    border-color: var(--color-slate);
    box-shadow: 0 0 0 3px var(--color-slate-soft);
}

/* --------------------------------------------------------------------------
   Studio shell
   -------------------------------------------------------------------------- */

.studio {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 10% 0%, rgba(184, 92, 56, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 100%, rgba(92, 114, 142, 0.07) 0%, transparent 45%),
        var(--color-bg);
}

.studio-header {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding: 0.65rem 1.25rem;
    background: var(--color-surface-soft);
    border-bottom: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-soft);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand {
    display: flex;
    flex-direction: column;
    min-width: 140px;
}

.brand-title {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: 0.01em;
}

.brand-subtitle {
    font-size: 0.72rem;
    color: var(--color-text-faint);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.save-status {
    font-size: 0.8rem;
    color: var(--color-text-faint);
    min-width: 5rem;
    text-align: right;
    transition: color 0.2s;
}
.save-status.is-saving { color: var(--color-slate); }
.save-status.is-saved  { color: #5a7a5a; }
.save-status.is-error  { color: #8b3a3a; }

.studio-body {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--lore-width);
    flex: 1;
    min-height: 0;
    gap: 0;
    height: calc(100vh - var(--header-height));
}

/* --------------------------------------------------------------------------
   Panels
   -------------------------------------------------------------------------- */

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem 0.65rem;
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-surface);
}

.panel-title {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

/* Sidebar */
.panel-sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-soft);
}

.tree-root {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.35rem 1rem;
}

.tree-empty {
    padding: 1.5rem 1rem;
    color: var(--color-text-faint);
    font-size: 0.9rem;
    text-align: center;
}

.tree-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree-list-nested {
    margin-left: 0.65rem;
    padding-left: 0.55rem;
    border-left: 1px solid var(--color-border-light);
}

.tree-item {
    margin: 0.1rem 0;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.tree-row:hover { background: var(--color-accent-soft); }
.tree-row.is-active {
    background: var(--color-slate-soft);
}

.tree-toggle {
    flex-shrink: 0;
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-text-faint);
    cursor: pointer;
    font-size: 0.65rem;
    border-radius: 4px;
    line-height: 1;
}
.tree-toggle:hover { color: var(--color-text); }
.tree-toggle.is-leaf { visibility: hidden; }

.tree-link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.5rem 0.4rem 0;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
    min-width: 0;
}

.tree-link-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.type-icon {
    flex-shrink: 0;
    font-size: 0.7rem;
    width: 1.1rem;
    text-align: center;
    opacity: 0.65;
}

/* Editor */
.panel-editor {
    position: relative;
    background-color: var(--color-vellum-base);
    background-image:
        radial-gradient(ellipse 140px 100px at 12% 18%, var(--color-vellum-stain) 0%, transparent 100%),
        radial-gradient(ellipse 120px 90px at 88% 82%, rgba(120, 88, 48, 0.11) 0%, transparent 100%),
        radial-gradient(ellipse 90px 70px at 72% 12%, rgba(170, 135, 85, 0.09) 0%, transparent 100%),
        radial-gradient(ellipse 110px 80px at 28% 88%, rgba(150, 115, 70, 0.08) 0%, transparent 100%),
        repeating-linear-gradient(
            92deg,
            transparent 0,
            transparent 4px,
            rgba(110, 82, 48, 0.022) 4px,
            rgba(110, 82, 48, 0.022) 5px
        ),
        repeating-linear-gradient(
            88deg,
            transparent 0,
            transparent 11px,
            rgba(95, 72, 42, 0.014) 11px,
            rgba(95, 72, 42, 0.014) 12px
        ),
        linear-gradient(
            172deg,
            var(--color-vellum-light) 0%,
            #e8ddc4 22%,
            var(--color-vellum-base) 50%,
            #dccaa8 78%,
            var(--color-vellum-shadow) 100%
        );
    box-shadow: inset 0 0 80px rgba(92, 68, 40, 0.07);
}

.panel-editor::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 200px 200px;
    mix-blend-mode: multiply;
}

.panel-editor::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(
        ellipse at center,
        transparent 55%,
        rgba(92, 68, 40, 0.06) 100%
    );
}

.panel-editor > * {
    position: relative;
    z-index: 1;
}

.editor-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2rem;
}

.editor-empty-inner {
    max-width: 22rem;
    text-align: center;
    color: var(--color-text-muted);
}

.editor-empty-icon {
    font-size: 2.5rem;
    margin: 0 0 0.75rem;
    opacity: 0.45;
}

.editor-empty h2 {
    font-family: var(--font-serif);
    font-size: 1.35rem;
    font-weight: 500;
    color: var(--color-text);
    margin: 0 0 0.5rem;
}

.editor-empty p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
}

.editor-active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 1.25rem 1.75rem 1rem;
}

.editor-toolbar {
    margin-bottom: 0.75rem;
}

.editor-title {
    width: 100%;
    font-family: var(--font-serif);
    font-size: 1.65rem;
    font-weight: 500;
    color: var(--color-text);
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    padding: 0.25rem 0 0.5rem;
    margin-bottom: 0.35rem;
    transition: border-color 0.2s;
}

.editor-title:focus {
    outline: none;
    border-bottom-color: var(--color-border);
}

.editor-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}

.editor-actions {
    margin-left: auto;
    display: inline-flex;
    gap: 0.5rem;
}

.editor-actions .btn-ghost {
    background: rgba(58, 42, 30, 0.04);
}

.editor-actions .btn-ghost:hover {
    background: var(--color-accent-soft);
}

.share-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
    margin: 0 0.25rem;
    font-family: var(--font-sans);
    font-weight: 500;
}

.share-toggle input {
    cursor: pointer;
    margin: 0;
}

.type-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.meta-text {
    font-size: 0.78rem;
    color: var(--color-text-faint);
}

.editor-content {
    flex: 1;
    width: 100%;
    min-height: 200px;
    resize: none;
    border: none;
    background: var(--color-surface-raised);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-panel);
    padding: 1.75rem 2rem;
    font-family: var(--font-serif);
    font-size: 1.125rem;
    line-height: 1.85;
    color: var(--color-text);
    transition: box-shadow 0.2s;
}

.editor-content:focus {
    outline: none;
    box-shadow: var(--shadow-panel), 0 0 0 2px var(--color-slate-soft);
}

.editor-content::placeholder {
    color: var(--color-text-faint);
    font-style: italic;
}

.editor-footer {
    padding: 0.5rem 0.25rem 0;
    text-align: right;
}

/* Lore panel */
.panel-lore {
    background: var(--color-surface);
    border-left: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-soft);
}

.lore-empty,
.lore-active {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.lore-empty {
    color: var(--color-text-faint);
    font-size: 0.9rem;
    line-height: 1.6;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
    color: var(--color-text-faint);
}

.breadcrumb span::after {
    content: ' › ';
    opacity: 0.5;
}
.breadcrumb span:last-child::after { content: ''; }
.breadcrumb span:last-child { color: var(--color-text-muted); }

.lore-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: 0.45rem;
}

.lore-content {
    width: 100%;
    min-height: 12rem;
    flex: 1;
    resize: vertical;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    padding: 0.85rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--color-text);
}

.lore-content:focus {
    outline: none;
    border-color: var(--color-slate);
    box-shadow: 0 0 0 3px var(--color-slate-soft);
}

.lore-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border-light);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(58, 42, 30, 0.25);
    z-index: 150;
}

/* --------------------------------------------------------------------------
   Auth pages
   -------------------------------------------------------------------------- */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(184, 92, 56, 0.08) 0%, transparent 55%),
        var(--color-bg);
}

.auth-card {
    width: 100%;
    max-width: 24rem;
    padding: 2rem 2rem 1.75rem;
    background: var(--color-surface-raised);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-panel);
    border: 1px solid var(--color-border-light);
}

.auth-title {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    font-weight: 600;
    margin: 0 0 0.35rem;
    text-align: center;
}

.auth-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin: 0 0 1.5rem;
    font-size: 0.95rem;
}

.auth-error {
    background: rgba(139, 58, 58, 0.08);
    color: #8b3a3a;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin: 0 0 1rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-top: 0.5rem;
}

.form-input {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-soft);
    color: var(--color-text);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-slate);
    box-shadow: 0 0 0 3px var(--color-slate-soft);
}

.auth-form .btn { margin-top: 1rem; }

.auth-footer {
    text-align: center;
    margin: 1.25rem 0 0;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.auth-footer a {
    color: var(--color-accent);
    text-decoration: none;
}
.auth-footer a:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   Responsive — narrow / mobile
   -------------------------------------------------------------------------- */

@media (max-width: 960px) {
    .studio-body {
        grid-template-columns: 1fr;
        position: relative;
    }

    .panel-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: min(var(--sidebar-width), 88vw);
        z-index: 200;
        transform: translateX(-105%);
        transition: transform 0.28s var(--ease-out);
    }

    .panel-sidebar.is-open {
        transform: translateX(0);
    }

    .panel-lore {
        position: fixed;
        top: var(--header-height);
        right: 0;
        bottom: 0;
        width: min(var(--lore-width), 88vw);
        z-index: 200;
        transform: translateX(105%);
        transition: transform 0.28s var(--ease-out);
    }

    .panel-lore.is-open {
        transform: translateX(0);
    }

    .sidebar-backdrop.is-visible {
        display: block;
    }

    .mobile-only { display: inline-flex; }

    .editor-active {
        padding: 1rem;
    }

    .editor-content {
        padding: 1.25rem 1.35rem;
        font-size: 1.05rem;
    }
}

@media (max-width: 600px) {
    .header-controls {
        order: 3;
        width: 100%;
    }

    .control-select {
        flex: 1;
    }

    .brand-subtitle { display: none; }
}

@media (max-width: 680px) {
    .editor-meta {
        flex-wrap: wrap;
        gap: 0.6rem;
    }
    .editor-actions {
        margin-left: 0;
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        border-top: 1px dashed var(--color-border-light);
        padding-top: 0.6rem;
        gap: 0.5rem;
    }
}

