/* ═══════════════════════════════════════════════
   Story Studio — authoring side of the picture book
   ═══════════════════════════════════════════════ */

:root {
    --cream:        #FCEEDA;
    --card:         #FDF6EA;
    --coral:        #F4776A;
    --coral-dark:   #E4655A;
    --ink:          #4A4441;
    --ink-soft:     #7C736D;
    --muted:        #C4B4A0;
    --line:         #E7D9C4;
    --shadow:       rgba(160, 120, 80, 0.16);
    --warn-bg:      #FFF3DC;
    --warn-ink:     #8A6320;

    --font-title:   "Baloo 2", "Comic Sans MS", cursive;
    --font-body:    "Quicksand", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--cream);
    font-family: var(--font-body);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.studio {
    max-width: 1000px;
    margin: 0 auto;
    padding: 26px 22px 60px;
}

/* ─────────── Header ─────────── */
.studio-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}
.title-block h1 {
    margin: 0;
    font-family: var(--font-title);
    font-size: 34px;
    font-weight: 700;
}
.title-block p {
    margin: 4px 0 0;
    color: var(--ink-soft);
    font-size: 15px;
}

.ghost-btn {
    flex-shrink: 0;
    padding: 9px 16px;
    border-radius: 999px;
    border: 2px solid var(--line);
    background: transparent;
    color: var(--ink-soft);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.ghost-btn:hover { border-color: var(--muted); color: var(--ink); }

.studio-nav {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 10px;
}

/* ─────────── Panels ─────────── */
.panel {
    margin-bottom: 20px;
    padding: 22px 24px;
    border-radius: 18px;
    background: var(--card);
    box-shadow: 0 10px 30px -20px var(--shadow);
}
.panel h2 {
    margin: 0 0 4px;
    font-family: var(--font-title);
    font-size: 21px;
    font-weight: 600;
}
.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}
.panel-note {
    margin: 0 0 16px;
    color: var(--ink-soft);
    font-size: 13.5px;
    line-height: 1.6;
}
.counter {
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 600;
}

/* ─────────── Fields ─────────── */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
}

.field { display: block; }
.field > span {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
}
.field > span em {
    font-style: normal;
    font-weight: 500;
    opacity: 0.7;
}

input[type="text"], input:not([type]), textarea {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    resize: vertical;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--coral);
}
input[type="file"] {
    width: 100%;
    padding: 8px;
    border: 2px dashed var(--line);
    border-radius: 10px;
    background: #fff;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.warn {
    margin: 12px 0 0;
    padding: 10px 13px;
    border-radius: 10px;
    background: var(--warn-bg);
    color: var(--warn-ink);
    font-size: 13px;
    line-height: 1.55;
}

/* ─────────── Narrator ─────────── */
.narrator-row {
    display: flex;
    align-items: flex-start;
    gap: 22px;
}
.narrator-fields { flex: 1; min-width: 0; }

.avatar-preview {
    position: relative;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 148px;
    height: 148px;
    border-radius: 50%;
    overflow: hidden;
    background: #cfe6f5;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}
.avatar-preview img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    /* Same crop the server applies, so the preview is honest about what gets cut. */
    object-fit: cover;
    object-position: 50% 38%;
    display: none;
}
.avatar-preview.has-image img { display: block; }
.avatar-preview.has-image span { display: none; }

.avatar-source {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 12px;
    margin-top: 14px;
}
.avatar-source .or {
    margin: 0 0 11px;
    color: var(--muted);
    font-size: 13px;
}
.avatar-source.uploads-off #avatarUploadField { opacity: 0.45; pointer-events: none; }

/* ─────────── Pages ─────────── */
.pages { display: flex; flex-direction: column; gap: 14px; }

.page-card {
    display: flex;
    gap: 16px;
    padding: 14px;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.page-thumb {
    position: relative;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 132px;
    height: 132px;
    border-radius: 10px;
    background: var(--cream);
}
.page-thumb img {
    max-width: 100%;
    max-height: 100%;
    /* The player fits illustrations whole, so preview them the same way. */
    object-fit: contain;
    border-radius: 8px;
}
.page-body { flex: 1; min-width: 0; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.page-label {
    font-family: var(--font-title);
    font-size: 15px;
    font-weight: 600;
}
.page-tools { display: flex; gap: 4px; }
.page-tools button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 7px;
    background: var(--cream);
    color: var(--ink-soft);
    font: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}
.page-tools button:hover:not(:disabled) { background: var(--muted); color: #fff; }
.page-tools button:disabled { opacity: 0.35; cursor: default; }
.page-tools .remove:hover { background: var(--coral); color: #fff; }

.page-body textarea { font-size: 14.5px; line-height: 1.55; }
.page-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--ink-soft);
}
.page-meta.over { color: var(--coral-dark); font-weight: 600; }

.page-advanced { margin-top: 10px; }
.page-advanced summary {
    color: var(--ink-soft);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}
.page-advanced textarea { margin-top: 8px; font-size: 13px; }

.add-pages {
    display: block;
    margin-top: 16px;
    padding: 20px;
    border: 2px dashed var(--line);
    border-radius: 14px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.add-pages:hover, .add-pages.dragover {
    border-color: var(--coral);
    background: rgba(244, 119, 106, 0.05);
}
.add-pages input { display: none; }
.add-pages strong {
    display: block;
    font-family: var(--font-title);
    font-size: 16px;
}
.add-pages span {
    display: block;
    margin-top: 3px;
    color: var(--ink-soft);
    font-size: 13px;
}

.pages:empty + .add-pages { margin-top: 0; }

/* ─────────── Footer ─────────── */
.studio-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding: 4px 4px 0;
}
.status {
    margin: 0;
    flex: 1;
    font-size: 13.5px;
    color: var(--ink-soft);
}
.status.error { color: var(--coral-dark); font-weight: 600; }
.status.ok { color: #4E8A5B; font-weight: 600; }

.primary-btn {
    padding: 13px 26px;
    border: none;
    border-radius: 999px;
    background: var(--coral);
    color: #fff;
    font-family: var(--font-title);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 18px -10px var(--coral-dark);
}
.primary-btn:hover:not(:disabled) { background: var(--coral-dark); }
.primary-btn:disabled { background: var(--muted); box-shadow: none; cursor: progress; }

/* ─────────── Library ─────────── */
.library-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
    color: var(--ink-soft);
    font-size: 13.5px;
}
.library-card {
    display: flex;
    gap: 11px;
    align-items: center;
    padding: 10px;
    border: 2px solid var(--line);
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
}
.library-card:hover { border-color: var(--coral); }
.library-card img {
    width: 46px;
    height: 46px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--cream);
    flex-shrink: 0;
}
.library-card strong {
    display: block;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.3;
}

/* ─────────── Responsive ─────────── */
@media (max-width: 700px) {
    .studio { padding: 18px 14px 40px; }
    .narrator-row { flex-direction: column; align-items: center; }
    .narrator-fields { width: 100%; }
    .avatar-source { grid-template-columns: 1fr; }
    .avatar-source .or { margin: 0; text-align: center; }
    .page-card { flex-direction: column; }
    .page-thumb { width: 100%; height: 150px; }
    .studio-footer { flex-direction: column; align-items: stretch; }
}
