:root {
    --bg: #f6f4ef;
    --panel: #ffffff;
    --ink: #2c2a26;
    --muted: #8b867c;
    --line: #e6e2d8;
    --accent: #7a6ff0;
    --accent-soft: #edeafd;
    --danger: #c0564e;
    --phone-bg: #fdfcf9;
    --radius: 12px;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h1 {
    font-size: 16px;
    margin: 0;
    white-space: nowrap;
}

.topbar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.scheme-label { color: var(--muted); font-size: 13px; }

#scheme-select {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    max-width: 320px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.user-email { color: var(--muted); }

/* ---------- buttons ---------- */

.btn {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s;
}
.btn:hover { background: var(--accent-soft); }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: #665ce0; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fbeae8; }
.btn-ghost { border: none; background: transparent; color: var(--accent); }
.btn-ghost:hover { background: transparent; text-decoration: underline; }

/* ---------- layout ---------- */

.layout {
    display: grid;
    grid-template-columns: 260px 1fr 340px;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
    align-items: start;
}

.toc, .comments {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    position: sticky;
    top: 72px;
    max-height: calc(100vh - 92px);
    display: flex;
    flex-direction: column;
}

.toc h2, .comments h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 0 0 10px;
}

/* ---------- TOC ---------- */

.toc-list { overflow-y: auto; }

.toc-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin: 12px 0 4px;
    padding-left: 8px;
}
.toc-section:first-child { margin-top: 0; }

.toc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--ink);
    cursor: pointer;
}
.toc-item:hover { background: var(--accent-soft); }
.toc-item.active { background: var(--accent); color: #fff; }

.toc-badge {
    font-size: 11px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
    padding: 1px 7px;
    flex-shrink: 0;
}
.toc-item.active .toc-badge { background: rgba(255,255,255,0.25); color: #fff; }

/* ---------- phone column ---------- */

.phone-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.phone-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 375px;
    max-width: 100%;
}
.toolbar-gap { flex: 1; }
.nav-btn { font-size: 16px; padding: 4px 12px; }
.slide-pos { font-size: 13px; color: var(--muted); min-width: 52px; text-align: center; }
.edit-buttons { display: flex; gap: 6px; }

.phone {
    width: 375px;
    height: 730px;
    background: #1c1a18;
    border-radius: 44px;
    padding: 12px;
    box-shadow: 0 18px 50px rgba(40, 35, 25, 0.25);
    position: relative;
    flex-shrink: 0;
}

.phone-notch {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    width: 110px;
    height: 26px;
    background: #1c1a18;
    border-radius: 999px;
    z-index: 2;
}

.phone-screen {
    width: 100%;
    height: 100%;
    background: var(--phone-bg);
    border-radius: 34px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 56px 26px 28px;
}

/* slide content */

.s-progress { margin-bottom: 22px; }
.s-progress-track {
    height: 5px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
}
.s-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.3s;
}
.s-progress-label {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
    text-align: center;
}

.s-title {
    font-size: 26px;
    line-height: 1.22;
    font-weight: 700;
    margin: 0 0 12px;
    text-align: center;
}

.s-subtitle {
    font-size: 15.5px;
    font-style: italic;
    color: var(--muted);
    text-align: center;
    margin: 0 0 16px;
    line-height: 1.45;
}

.s-line {
    font-size: 15.5px;
    line-height: 1.5;
    text-align: center;
    margin: 0 0 14px;
}

.s-loader {
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    margin: 4px 0 20px;
}
.s-loader::after {
    content: '';
    display: block;
    height: 100%;
    width: 40%;
    background: var(--accent);
    border-radius: 999px;
    animation: loader-slide 1.6s ease-in-out infinite;
}
@keyframes loader-slide {
    0% { margin-left: -40%; }
    100% { margin-left: 100%; }
}

.s-options { display: flex; flex-direction: column; gap: 9px; margin: 6px 0 14px; }
.s-option {
    padding: 13px 16px;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    background: #fff;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.s-option:hover { border-color: var(--accent); }
.s-option.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
    font-weight: 600;
}

.s-input {
    width: 100%;
    padding: 13px 16px;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    font-size: 15px;
    margin: 6px 0 10px;
    background: #fff;
}
.s-input:focus { outline: none; border-color: var(--accent); }

.s-cards { display: flex; flex-direction: column; gap: 9px; margin: 6px 0 14px; }
.s-card {
    padding: 13px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.s-card-title { font-size: 15px; font-weight: 600; }
.s-card-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.s-rating {
    font-size: 24px;
    text-align: center;
    color: #e8a13c;
    margin: 6px 0 14px;
    font-weight: 600;
}

.s-quote {
    border-left: 3px solid var(--accent);
    padding: 4px 0 4px 14px;
    margin: 0 0 12px;
    font-size: 14.5px;
    font-style: italic;
    color: #55524b;
    line-height: 1.5;
}

.s-reward {
    align-self: center;
    background: linear-gradient(135deg, #f7d774, #eeb64c);
    color: #5c4508;
    font-weight: 700;
    font-size: 17px;
    padding: 10px 22px;
    border-radius: 999px;
    margin: 8px 0 12px;
    box-shadow: 0 4px 14px rgba(238, 182, 76, 0.4);
}

.s-caption {
    font-size: 13.5px;
    color: var(--muted);
    text-align: center;
    margin: 4px 0 10px;
    line-height: 1.45;
}

.s-spacer { flex: 1; min-height: 18px; }

.s-cta {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 16px;
    background: var(--accent);
    color: #fff;
    font-size: 16.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.12s;
}
.s-cta:hover { background: #665ce0; }

.s-skip {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 14px;
    text-decoration: underline;
    cursor: pointer;
    margin-top: 12px;
    align-self: center;
}

.s-legal {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    margin-top: 12px;
    line-height: 1.4;
}

.slide-note {
    width: 375px;
    max-width: 100%;
    background: #fdf6e3;
    border: 1px solid #efe2b8;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    color: #7a6a3a;
    line-height: 1.45;
}
.slide-note::before { content: '💡 '; }

/* ---------- comments ---------- */

.comments-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    min-height: 60px;
}

.comment {
    background: var(--bg);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
    position: relative;
}

.comment-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.comment-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}

.comment-email {
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.comment-time { font-size: 11px; color: var(--muted); margin-left: auto; flex-shrink: 0; }

.comment-text { line-height: 1.45; white-space: pre-wrap; word-break: break-word; }

.comment-delete {
    position: absolute;
    bottom: 6px;
    right: 8px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
}
.comment:hover .comment-delete { opacity: 1; }
.comment-delete:hover { color: var(--danger); }

.comment-form { display: flex; flex-direction: column; gap: 8px; }

.comment-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13.5px;
    font-family: inherit;
    resize: vertical;
}
.comment-form textarea:focus { outline: none; border-color: var(--accent); }

.empty-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 0; }

/* ---------- modals ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(40, 35, 25, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal {
    background: var(--panel);
    border-radius: 16px;
    padding: 26px;
    width: 380px;
    max-width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 16px; font-size: 14px; }

.modal-wide {
    width: 720px;
    max-height: 90vh;
    overflow-y: auto;
}

#email-form { display: flex; gap: 8px; }
#email-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 14px;
}

/* ---------- editor form ---------- */

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

.editor-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12.5px;
    color: var(--muted);
    flex: 1;
}

.editor-form input,
.editor-form textarea {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
}
.editor-form input:focus, .editor-form textarea:focus { outline: none; border-color: var(--accent); }

.field-row { display: flex; gap: 12px; }

.checkbox-label {
    flex-direction: row !important;
    align-items: center;
    font-size: 14px !important;
    color: var(--ink) !important;
}

.editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
    .layout { grid-template-columns: 220px 1fr; }
    .comments { grid-column: 1 / -1; position: static; max-height: none; }
}

@media (max-width: 760px) {
    .layout { grid-template-columns: 1fr; }
    .toc { position: static; max-height: 240px; }
    .phone { width: 340px; height: 660px; }
    .phone-toolbar, .slide-note { width: 340px; }
    .topbar { flex-wrap: wrap; }
}
