/* Leonardo Library -- Poems shelf. Phone-first, mirrors the Books/Quotes
   "qm-" design so the Library reads as one system. A poem is self-contained:
   the full text shows on the card. */

:root {
    --qm-ink:    #1d2330;
    --qm-muted:  #6b7280;
    --qm-line:   #e6e8ef;
    --qm-bg:     #f4f5f9;
    --qm-card:   #ffffff;
    --qm-accent: #5b4bd6;
    --qm-gold:   #f0a500;
    --qm-danger: #c2384a;
}

* { box-sizing: border-box; }

body {
    background: var(--qm-bg);
    color: var(--qm-ink);
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Fixed-viewport shell: pins .qm-top (Leonardo menu band + stats + filters);
   only .qm-body scrolls, so the chrome never scrolls off. Ref compensation.html. */
.qm-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---- top ---------------------------------------------------------------- */
.qm-top { background: #2f2a52; color: #fff; flex: 0 0 auto; }
.lw-nav { min-height: 6px; }

.qm-stats { display: flex; gap: 0; padding: 6px 8px; }
.qm-stat {
    flex: 1 1 0; min-width: 56px; text-align: center;
    padding: 3px 2px; border-right: 1px solid rgba(255,255,255,.16);
}
.qm-stat:last-child { border-right: none; }
.qm-stat .n { font-size: 16px; font-weight: 700; display: block; line-height: 1.1; }
.qm-stat .l { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; color: #cfc9f2; }

/* ---- action buttons ----------------------------------------------------- */
.qm-actions {
    display: flex; gap: 7px; padding: 9px 10px; flex-wrap: wrap;
    background: #fff; border-bottom: 1px solid var(--qm-line);
}
.qm-btn {
    font: inherit; font-size: 13px; font-weight: 600;
    border: 1px solid var(--qm-line); border-radius: 999px;
    background: #fff; color: var(--qm-ink);
    padding: 8px 13px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    transition: background .12s, border-color .12s, transform .05s;
    text-decoration: none;
}
.qm-btn:hover { background: #f3f1fd; border-color: #d7d0f7; }
.qm-btn:active { transform: scale(.97); }
.qm-btn.primary { background: var(--qm-accent); border-color: var(--qm-accent); color: #fff; }
.qm-btn.primary:hover { background: #4a3bc4; }
.qm-btn .ic { font-size: 15px; line-height: 1; }

/* ---- search + filter ---------------------------------------------------- */
.qm-searchbar {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; background: #fff; border-bottom: 1px solid var(--qm-line);
    cursor: pointer; font-size: 13px; font-weight: 600; color: var(--qm-ink);
}
.qm-searchbar .chev { margin-left: auto; transition: transform .15s; color: var(--qm-muted); }
.qm-searchbar.open .chev { transform: rotate(180deg); }
.qm-searchbar .activedot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--qm-accent); }
.qm-searchbar.filtered .activedot { display: inline-block; }

.qm-filters {
    display: none; flex-direction: column; gap: 10px;
    padding: 12px 10px; background: #fff; border-bottom: 1px solid var(--qm-line);
}
.qm-filters.open { display: flex; }
.qm-filters label { font-size: 11px; font-weight: 600; color: var(--qm-muted); margin-bottom: -4px; }
.qm-filters input, .qm-filters select {
    width: 100%; box-sizing: border-box;
    padding: 11px 12px; font: inherit; font-size: 15px;
    border: 1px solid var(--qm-line); border-radius: 10px; background: #fff; outline: none;
}
.qm-filters input:focus, .qm-filters select:focus { border-color: var(--qm-accent); box-shadow: 0 0 0 3px rgba(91,75,214,.15); }
.qm-filters .favrow { display: flex; align-items: center; gap: 8px; }
.qm-filters .favrow input { width: 20px; height: 20px; }
.qm-filters .favrow label { margin: 0; font-size: 14px; color: var(--qm-ink); }
.qm-filters .clearrow { display: flex; justify-content: flex-end; gap: 8px; }
.qm-filters .ps-select {
    width: 100%; box-sizing: border-box; padding: 11px 12px; font: inherit; font-size: 15px;
    border: 1px solid var(--qm-line); border-radius: 10px; background: #fff;
}

/* ---- group-by bar ------------------------------------------------------- */
.qm-groupbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; flex-wrap: wrap; }
.qm-groupbar .lbl { font-size: 12px; color: var(--qm-muted); }
.qm-seg { display: inline-flex; border: 1px solid var(--qm-line); border-radius: 999px; overflow: hidden; background: #fff; }
.qm-seg button { font: inherit; font-size: 12px; font-weight: 600; border: none; background: transparent; color: var(--qm-muted); padding: 6px 11px; cursor: pointer; }
.qm-seg button.on { background: var(--qm-accent); color: #fff; }

/* ---- body / groups / cards ---------------------------------------------- */
.qm-body { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 10px 90px; }

.qm-group { border: 1px solid var(--qm-line); border-radius: 12px; background: #fff; margin-bottom: 10px; overflow: hidden; }
.qm-group-h { display: flex; align-items: center; gap: 8px; padding: 12px 14px; cursor: pointer; user-select: none; background: #faf9ff; }
.qm-group-h .chev { transition: transform .15s; color: var(--qm-accent); font-size: 12px; }
.qm-group.open .qm-group-h .chev { transform: rotate(90deg); }
.qm-group-h .t { font-size: 14px; font-weight: 800; color: var(--qm-accent); }
.qm-group-h .c { margin-left: auto; font-size: 11px; color: var(--qm-muted); background: #efe9ff; padding: 1px 9px; border-radius: 999px; }
.qm-group-body { display: none; padding: 8px 10px 10px; }
.qm-group.open .qm-group-body { display: block; }

.qm-card {
    background: var(--qm-card);
    border: 1px solid var(--qm-line);
    border-left: 4px solid var(--qm-accent);
    border-radius: 10px;
    padding: 12px 14px 8px;
    margin: 0 0 9px;
    box-shadow: 0 1px 2px rgba(20,20,50,.04);
}
.qm-card:last-child { margin-bottom: 0; }

.qm-card .poem-title {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 17px; font-weight: 700; color: var(--qm-accent); margin-bottom: 2px;
    word-break: break-word;
}
.qm-card .poem-byline { font-size: 13px; color: #3a3f4b; margin-bottom: 8px; }
.qm-card .poem-byline .auth { font-weight: 700; }
.qm-card .poem-byline .auth::before { content: "\2014 "; color: var(--qm-muted); font-weight: 400; }
.qm-card .poem-byline .dot { color: var(--qm-line); margin: 0 6px; }
.qm-card .poem-byline .dt { color: var(--qm-muted); }

.qm-card .poem-text {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 15.5px; line-height: 1.55; color: #20242e;
    white-space: pre-wrap; word-break: break-word;
    max-height: 8.5em; overflow: hidden; position: relative;
    transition: max-height .2s ease;
}
.qm-card .poem-text.expanded { max-height: 4000px; }
.qm-card .poem-text.clipped::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.4em;
    background: linear-gradient(rgba(255,255,255,0), #fff);
}
.qm-card .poem-more {
    display: none; margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--qm-accent);
    background: none; border: none; cursor: pointer; padding: 4px 0;
}
.qm-card .poem-more.show { display: inline-block; }

.qm-card .poem-notes { font-size: 12px; color: var(--qm-muted); font-style: italic; margin-top: 8px; }

.qm-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.qm-meta .src { font-size: 11px; color: var(--qm-muted); font-style: italic; }
.qm-meta-right { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.qm-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; background: #efe9ff; color: var(--qm-accent); padding: 2px 8px; border-radius: 999px; }

.qm-cardactions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; padding-top: 6px; border-top: 1px dashed #eef0f6; }
.qm-icobtn {
    border: none; background: transparent; cursor: pointer;
    font-size: 19px; line-height: 1; padding: 8px 11px; border-radius: 8px; color: var(--qm-muted);
    min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
}
.qm-icobtn:hover { background: #f1eefc; }
.qm-icobtn.star.on { color: var(--qm-gold); }
.qm-icobtn.del:hover { background: #fdecef; color: var(--qm-danger); }

.qm-empty { text-align: center; color: var(--qm-muted); padding: 50px 20px; font-size: 14px; }
.qm-empty .big { font-size: 40px; display: block; margin-bottom: 8px; opacity: .5; }

/* ---- floating add ------------------------------------------------------- */
.qm-fab {
    position: fixed; right: 18px; bottom: 22px; z-index: 60;
    width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--qm-accent); color: #fff; font-size: 28px; line-height: 1;
    box-shadow: 0 6px 18px rgba(91,75,214,.45);
}
.qm-fab:active { transform: scale(.94); }

/* ---- modal -------------------------------------------------------------- */
.qm-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(20,18,40,.55); display: none; align-items: flex-end; justify-content: center; }
.qm-overlay.show { display: flex; }
.qm-modal { background: #fff; width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 16px 16px 22px; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
@media (min-width: 640px) { .qm-overlay { align-items: center; } .qm-modal { border-radius: 16px; } }
.qm-modal h2 { margin: 2px 0 12px; font-size: 17px; display: flex; align-items: center; gap: 8px; }

.qm-field { margin-top: 12px; }
.qm-field:first-of-type { margin-top: 4px; }
.qm-field label { display: block; font-size: 12px; font-weight: 600; color: var(--qm-muted); margin-bottom: 5px; }
.qm-field input[type=text], .qm-field select, .qm-field textarea {
    width: 100%; box-sizing: border-box;
    padding: 11px 12px; font: inherit; font-size: 15px;
    border: 1px solid var(--qm-line); border-radius: 10px; outline: none; background: #fff;
}
.qm-field textarea { resize: vertical; min-height: 120px; line-height: 1.5; font-family: Georgia, serif; }
.qm-field .ps-select {
    width: 100%; box-sizing: border-box; padding: 11px 12px; font: inherit; font-size: 15px;
    border: 1px solid var(--qm-line); border-radius: 10px; background: #fff;
}
.qm-field .ps-select:focus, .qm-field .ps-select.is-open { border-color: var(--qm-accent); box-shadow: 0 0 0 3px rgba(91,75,214,.15); }
.qm-field input:focus, .qm-field select:focus, .qm-field textarea:focus { border-color: var(--qm-accent); box-shadow: 0 0 0 3px rgba(91,75,214,.15); }
.qm-field .hint { font-size: 11px; color: var(--qm-muted); margin-top: 4px; }

/* PicassoVoice wraps text inputs in an inline-block .voice-mic-wrap span, which
   collapses width:100% to the intrinsic content width. Force the wrap to block
   in every Poems form/filter context so fields truly span the full row. */
.qm-field .voice-mic-wrap,
.qm-filters .voice-mic-wrap,
.qm-tagaddrow .voice-mic-wrap { display: block; width: 100%; }

.qm-dupwarn { display: none; margin-top: 10px; padding: 10px 12px; background: #fff5e0; border: 1px solid #f0d28a; border-radius: 10px; font-size: 13px; color: #8a5b00; }
.qm-dupwarn.show { display: block; }

.qm-modal-btns { display: flex; gap: 8px; margin-top: 16px; }
.qm-modal-btns .qm-btn { flex: 1; justify-content: center; padding: 11px; }

/* ---- read-only poem view ------------------------------------------------ */
.pv-scroll { padding: 4px 2px 2px; }
.pv-head { text-align: center; border-bottom: 1px solid var(--qm-line); padding-bottom: 14px; margin-bottom: 16px; }
.pv-title { font-size: 22px; font-weight: 800; color: var(--qm-accent); line-height: 1.25; word-break: break-word; }
.pv-fav { color: var(--qm-gold); font-size: 18px; }
.pv-byline { font-size: 14px; color: #3a3f4b; margin-top: 6px; }
.pv-byline .auth { font-weight: 700; }
.pv-byline .dot { color: var(--qm-line); margin: 0 6px; }
.pv-byline .dt { color: var(--qm-muted); }
.pv-rating { color: var(--qm-gold); font-size: 15px; letter-spacing: 2px; margin-top: 6px; }
.pv-text { font-family: Georgia, "Times New Roman", serif; font-size: 16.5px; line-height: 1.6; color: #20242e; white-space: pre-wrap; word-break: break-word; }
.pv-notes { font-size: 13px; color: var(--qm-muted); font-style: italic; margin-top: 14px; padding-top: 12px; border-top: 1px dashed #eef0f6; }
.pv-src { font-size: 12px; color: var(--qm-muted); font-style: italic; margin-top: 12px; }
.pv-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; }

/* spotlight (random) */
.qm-spotlight { text-align: center; padding: 8px 6px 4px; }
.qm-spotlight .sq { font-family: Georgia, serif; font-size: 18px; line-height: 1.55; color: #20242e; margin: 10px 0; white-space: pre-wrap; text-align: left; }
.qm-spotlight .sa { font-size: 15px; font-weight: 700; color: var(--qm-accent); }
.qm-spotlight .st { font-size: 12px; color: var(--qm-muted); margin-top: 4px; }

.qm-statusbar { background: #232733; color: #aeb4c2; padding: 5px 12px; font-size: 11px; }
/* Story 6820: Reader and Listen buttons */
.pr-btns { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.qm-cardactions .pr-btns { margin-left: 6px; }
.qm-readbtn { border: 1px solid #d8d4e6; background: #fff; border-radius: 7px; padding: 4px 9px; font-size: 12px; font-weight: 600; cursor: pointer; color: inherit; }
.pv-read { margin-top: 10px; }
