/* ============================================================
   Writer - CouldIWriteABook.com
   Main Stylesheet
   Matches Story Idea Generator color scheme
   ============================================================ */

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

html { overflow-y: scroll; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background-color: #eef0f2;
    color: #2c3e50;
    min-height: 100vh;
}

body.night-mode {
    background-color: #1a1d23;
    color: #d0d4dc;
}

/* --- Page Wrapper ----------------------------------------- */
.page-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 40px 20px;
}

/* --- Card ------------------------------------------------- */
.card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 1024px;
    overflow: hidden;
}

.night-mode .card {
    background: #23272f;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* Keep all pages the same consistent width */
.card.card-wide {
    max-width: 1024px;
}

/* --- Card Header (nav bar) -------------------------------- */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid #e8eaed;
}

.night-mode .card-header {
    border-bottom-color: #383d47;
}

.card-header .nav-left {
    display: flex;
    align-items: center;
    gap: 18px;
}

.card-header .home-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #3d9bd4;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
}

.card-header .home-link:hover { color: #2a7db5; }

.card-header .nav-link {
    color: #3d9bd4;
    text-decoration: none;
    font-size: 1.05rem;
    font-weight: 500;
}

.card-header .nav-link:hover { color: #2a7db5; }

.card-header .nav-link.active {
    color: #2c3e50;
    font-weight: 600;
}

.night-mode .card-header .nav-link.active { color: #d0d4dc; }

/* --- Night Mode Toggle ------------------------------------ */
.night-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #888;
    cursor: pointer;
}

.night-mode .night-toggle { color: #b0b8c4; }

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background-color: #ccc;
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-slider:before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

input:checked + .toggle-slider { background-color: #3d9bd4; }
input:checked + .toggle-slider:before { transform: translateX(20px); }

/* --- Card Body -------------------------------------------- */
.card-body {
    padding: 40px 32px;
}

/* --- Page Title ------------------------------------------- */
.page-title {
    font-size: 2.25rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 6px;
}

.night-mode .page-title { color: #e8eaed; }

.page-subtitle {
    font-size: 1.4rem;
    color: #555;
    margin-bottom: 32px;
}

.night-mode .page-subtitle { color: #b0b8c4; }

/* --- Primary Button --------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
}

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

.btn-primary {
    background-color: #3d9bd4;
    color: #ffffff;
    width: 80%;
    padding: 16px;
    font-size: 1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.btn-primary:hover { background-color: #2a7db5; }

.btn-secondary {
    background-color: #f0f2f5;
    color: #2c3e50;
}

.btn-secondary:hover { background-color: #e2e5e9; }

.btn-danger {
    background-color: #e74c3c;
    color: #ffffff;
}

.btn-danger:hover { background-color: #c0392b; }

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.night-mode .btn-secondary {
    background-color: #383d47;
    color: #d0d4dc;
}

/* --- Book List (Home) ------------------------------------- */
.book-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 28px;
}

.book-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border: 1px solid #e8eaed;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.book-item:hover {
    border-color: #3d9bd4;
    box-shadow: 0 2px 8px rgba(61,155,212,0.15);
}

.book-item.active {
    border-color: #3d9bd4;
    background-color: #f0f8ff;
}

.night-mode .book-item {
    border-color: #383d47;
}

.night-mode .book-item.active {
    background-color: #1e2a35;
    border-color: #3d9bd4;
}

.book-item-title {
    font-weight: 600;
    font-size: 1rem;
    color: #2c3e50;
}

.night-mode .book-item-title { color: #e8eaed; }

.book-item-meta {
    font-size: 0.82rem;
    color: #95a5a6;
    margin-top: 2px;
}

.book-item-actions {
    display: flex;
    gap: 8px;
}

/* --- Tree (Outline) --------------------------------------- */
.tree {
    list-style: none;
    padding: 0;
}

.tree ul {
    list-style: none;
    padding-left: 20px;
    border-left: 3px solid #3d9bd4;
    margin-left: 16px;
}

.night-mode .tree ul { border-left-color: #383d47; }

.tree-node {
    margin: 4px 0;
}

.tree-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    transition: background 0.15s;
}

.tree-row:hover { background-color: #f5f7fa; }
.night-mode .tree-row:hover { background-color: #2a2f3a; }

.tree-row.selected {
    background-color: #e8f4fd;
    border-left: 3px solid #3d9bd4;
}

.night-mode .tree-row.selected { background-color: #1e2a35; }

.tree-move-btns {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.tree-move-btns button {
    background: none;
    border: none;
    cursor: pointer;
    color: #b0b8c1;
    font-size: 0.65rem;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.tree-move-btns button:hover {
    color: #3d9bd4;
    background: #e8f4fd;
}

.tree-title {
    flex: 1;
    font-size: 1.0rem;
    color: #2c3e50;
    cursor: pointer;
}

.night-mode .tree-title { color: #d0d4dc; }

.tree-title:hover { color: #3d9bd4; }

.tree-action-btns {
    display: flex;
    gap: 4px;
    opacity: 1;
}

.tree-action-btns button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.0rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.tree-action-btns .btn-add    { color: #27ae60; }
.tree-action-btns .btn-edit   { color: #3d9bd4; }
.tree-action-btns .btn-delete { color: #e74c3c; }

.tree-action-btns button:hover { background: #f0f2f5; }
.night-mode .tree-action-btns button:hover { background: #383d47; }

/* --- Write Area ------------------------------------------- */
.write-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 24px;
    min-height: 600px;
}

.write-sidebar {
    border-right: 1px solid #e8eaed;
    padding-right: 20px;
}

.night-mode .write-sidebar { border-right-color: #383d47; }

.write-editor {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.scene-title-input {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 10px 14px;
    border: 1px solid #e8eaed;
    border-radius: 6px;
    color: #2c3e50;
    background: #fafbfc;
    width: 100%;
}

.night-mode .scene-title-input {
    background: #1e2228;
    border-color: #383d47;
    color: #d0d4dc;
}

.scene-content-area {
    flex: 1;
    min-height: 480px;
    padding: 16px;
    border: 1px solid #e8eaed;
    border-radius: 6px;
    font-size: 1.1rem;
    line-height: 1.7;
    color: #2c3e50;
    background: #fafbfc;
    resize: vertical;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    width: 100%;
}

.night-mode .scene-content-area {
    background: #1e2228;
    border-color: #383d47;
    color: #d0d4dc;
}

.save-status {
    font-size: 0.8rem;
    color: #95a5a6;
    text-align: right;
}

/* --- Modals ----------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: #ffffff;
    border-radius: 10px;
    padding: 28px 32px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    animation: modal-in 0.2s ease;
}

.night-mode .modal {
    background: #23272f;
    color: #d0d4dc;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.modal h3 {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: #2c3e50;
}

.night-mode .modal h3 { color: #e8eaed; }

.modal-body { margin-bottom: 24px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* --- Form Fields ------------------------------------------ */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.night-mode .form-group label { color: #a0a8b4; }

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #dde1e7;
    border-radius: 6px;
    font-size: 0.92rem;
    color: #2c3e50;
    background: #fafbfc;
    transition: border-color 0.2s;
}

.form-group textarea { min-height: 100px; resize: vertical; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3d9bd4;
}

.night-mode .form-group input,
.night-mode .form-group select,
.night-mode .form-group textarea {
    background: #1e2228;
    border-color: #383d47;
    color: #d0d4dc;
}

/* --- Characters & Locations ------------------------------- */
.codex-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.codex-card {
    border: 1px solid #e8eaed;
    border-radius: 8px;
    padding: 16px 18px;
    transition: border-color 0.2s;
}

.codex-card:hover { border-color: #3d9bd4; }

.night-mode .codex-card { border-color: #383d47; }

.codex-card-name {
    font-weight: 700;
    font-size: 1rem;
    color: #2c3e50;
    margin-bottom: 4px;
}

.night-mode .codex-card-name { color: #e8eaed; }

.codex-card-role {
    font-size: 0.78rem;
    font-weight: 600;
    color: #3d9bd4;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.codex-card-desc {
    font-size: 0.85rem;
    color: #7f8c8d;
    line-height: 1.5;
}

.codex-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* --- Compile Button --------------------------------------- */
.compile-bar {
    display: flex;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid #e8eaed;
}

.night-mode .compile-bar { border-top-color: #383d47; }

/* --- Utility --------------------------------------------- */
.text-muted  { color: #95a5a6; font-size: 0.85rem; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.text-center { text-align: center; }
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: #7f8c8d;
}
.empty-state p { font-size: 1.2rem; margin-bottom: 16px; }

/* --- Book Nav Bar ----------------------------------------- */
.book-nav {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: #f5f7fa;
    border-bottom: 1px solid #e8eaed;
    flex-wrap: wrap;
    justify-content: space-between;
}

.night-mode .book-nav {
    background: #1e2228;
    border-bottom-color: #383d47;
}

.book-nav-title {
    font-weight: 700;
    font-size: 1.55rem;
    color: #2c3e50;
    white-space: nowrap;
}

.night-mode .book-nav-title { color: #e8eaed; }

.book-nav-links {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.book-nav .nav-link {
    color: #3d9bd4;
    text-decoration: none;
    font-size: 1.05rem;
    font-weight: 500;
}

.book-nav .nav-link:hover { color: #2a7db5; }

.book-nav .nav-link.active {
    color: #2c3e50;
    font-weight: 600;
}

.night-mode .book-nav .nav-link.active { color: #d0d4dc; }

/* --- Wizard Night Mode ------------------------------------ */
.night-mode .wizard-question h1 { color: #e8eaed; }
.night-mode .wizard-question p.inst { color: #a0a8b4; }
.night-mode .option-label {
    background: #2a2f3a;
    border-color: #383d47;
    color: #d0d4dc;
}
.night-mode .option-label:hover {
    background: #32384a;
    border-color: #3d9bd4;
    color: #e8eaed;
}
.night-mode .option-item input:checked + .option-label {
    background: #1e2a35;
    border-color: #3d9bd4;
    color: #e8eaed;
}
.night-mode .wizard-intro h1 { color: #e8eaed; }
.night-mode .wizard-intro p  { color: #a0a8b4; }
.night-mode .wizard-finish h1 { color: #e8eaed; }
.night-mode .wizard-finish p  { color: #a0a8b4; }
.night-mode .custom-choice-input {
    background: #2a2f3a;
    border-color: #383d47;
    color: #d0d4dc;
}

/* --- Help Tip — opens left -------------------------------- */
.help-tip.tip-left .tip-text {
    left: auto;
    right: 26px;
}
.help-tip.tip-left .tip-text::before {
    left: auto;
    right: -6px;
    border-width: 6px 0 6px 6px;
    border-color: transparent transparent transparent #2c3e50;
}