/* ============================================================================
 * chat-composer.css — Chat-mode composer (assets/js/chat-composer.js)
 *
 *   1. Chat-only bits stay hidden everywhere else
 *   2. Growth, stacking, Expand / Collapse
 *   3. Landing: anchored by the top edge (desktop), grows downward
 *   4. The "+" menu
 *   5. Tool chip
 *   6. Landing suggestions
 *   7. Sheets: Add from library
 *   8. Sketch pad
 *   9. Phones
 *
 * Everything that changes the composer is scoped to
 * html.app-chat body:not(.character-mode) so Work mode and character chats
 * keep their layout exactly.
 * ========================================================================== */

:root {
    --cc-ease: cubic-bezier(0.32, 0.72, 0, 1);
    --cc-blue: #62a8ff;
    --cc-hover: color-mix(in srgb, var(--text-color, #fff) 7%, transparent);
    --cc-press: color-mix(in srgb, var(--text-color, #fff) 11%, transparent);
}
body.light_mode {
    --cc-blue: #1a6fe0;
}

/* ── 1. Chat-only bits ────────────────────────────────────────────────────── */
.cc-tool-chip[hidden],
.cc-expand-btn[hidden],
.cc-suggest[hidden],
.cc-layer[hidden] { display: none !important; }

.cc-tool-chip,
.cc-expand-btn,
.cc-suggest { display: none; }

.plus-menu .pm-chat-only,
.plus-menu .pm-desc { display: none !important; }

html.app-chat body:not(.character-mode) .plus-menu .pm-chat-only { display: flex !important; }
html.app-chat body:not(.character-mode) .plus-menu .pm-desc { display: block !important; }
html.app-chat body:not(.character-mode) .plus-menu .pm-shortcut,
html.app-chat body:not(.character-mode) .plus-menu .pm-check { display: none !important; }

/* A camera row only makes sense on a device that has one in hand. */
@media (hover: hover) and (pointer: fine) {
    html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections #take-photo-button { display: none !important; }
}

.cc-mirror {
    position: absolute !important;
    top: -10000px !important;
    left: -10000px !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
    visibility: hidden !important;
    pointer-events: none !important;
    resize: none !important;
    border: 0 !important;
}

/* ── 2. Growth, stacking, Expand ──────────────────────────────────────────── */
html.app-chat body:not(.character-mode) .typing-area.cc-owned .typing-form .typing-input {
    transition: height 0.16s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--text-color, #fff) 22%, transparent) transparent;
    overscroll-behavior: contain;
}
html.app-chat body:not(.character-mode) .typing-area.cc-owned.cc-anim .typing-form .typing-input {
    transition: height 0.42s var(--cc-ease) !important;
}
html.app-chat body:not(.character-mode) .typing-area.cc-owned.cc-no-anim .typing-form .typing-input {
    transition: none !important;
}
html.app-chat body:not(.character-mode) .typing-area.cc-owned .typing-form .typing-input::-webkit-scrollbar { width: 8px; }
html.app-chat body:not(.character-mode) .typing-area.cc-owned .typing-form .typing-input::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--text-color, #fff) 20%, transparent);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* ui-manager.js writes an inline max-height (200px / 260px) on the wrapper
   whenever the attachment tray shows or hides; that clipped a tall composer.
   Chat mode sizes the textarea itself, so the card must never be capped. */
html.app-chat body:not(.character-mode) .typing-area.cc-owned .typing-form .input-wrapper {
    max-height: none !important;
}

/* Room for the Expand button beside the first lines. */
html.app-chat body:not(.character-mode) .typing-area.chat-expanded.cc-can-expand .typing-form .typing-input {
    padding-right: 42px !important;
}

html.app-chat body:not(.character-mode) .typing-area.cc-can-expand .typing-form .input-wrapper > .cc-expand-btn:not([hidden]) {
    grid-column: auto;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--subheading-color, #aaa);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.2s var(--cc-ease);
    animation: cc-pop-in 0.22s var(--cc-ease) both;
}
.cc-expand-btn .material-symbols-rounded { font-size: 18px; }
html.app-chat body:not(.character-mode) .cc-expand-btn:hover { background: var(--cc-hover); color: var(--text-color, #fff); }
html.app-chat body:not(.character-mode) .cc-expand-btn:active { transform: scale(0.92); }
html.app-chat body:not(.character-mode) .cc-expand-btn:focus-visible {
    outline: 2px solid var(--cc-blue);
    outline-offset: 1px;
}

@keyframes cc-pop-in {
    from { opacity: 0; transform: scale(0.7); }
    to { opacity: 1; transform: scale(1); }
}

/* ── 3. Landing: top-anchored, grows downward (desktop) ───────────────────── */
@media (min-width: 769px) {
    html.app-chat body.new-chat-view:not(.character-mode) .typing-area.cc-owned {
        top: calc(58dvh - 130px) !important;
        bottom: auto !important;
        transform: none !important;
    }
    html.app-chat body.new-chat-view:not(.character-mode) .typing-area.cc-owned.cc-full {
        top: 72px !important;
    }
    html.app-chat body.new-chat-view:not(.character-mode) .typing-area.cc-owned.cc-anim {
        transition: top 0.42s var(--cc-ease) !important;
    }
    html.app-chat body.new-chat-view:not(.character-mode) .chat-list .header {
        transition: opacity 0.25s ease;
    }
    html.app-chat body.new-chat-view:not(.character-mode):has(.typing-area.cc-full) .chat-list .header {
        opacity: 0;
        pointer-events: none;
    }
}
@media (min-width: 769px) and (max-width: 1000px) {
    html.app-chat body.new-chat-view:not(.character-mode) .typing-area.cc-owned:not(.cc-full) {
        top: calc(60dvh - 126px) !important;
    }
}

/* ── 4. The "+" menu ──────────────────────────────────────────────────────── */
/* The menu is placed against the whole composer (not the + button), so it can
   match the composer's width on phones and open downward on the landing. */
html.app-chat body:not(.character-mode) .typing-form .input-tools-left,
html.app-chat body:not(.character-mode) .typing-form #attach-file-button {
    position: static !important;
}
/* A transform / will-change:transform on the button would make IT the menu's
   containing block again (the menu then shrinks to the button's 36px). */
html.app-chat body:not(.character-mode) .typing-form #attach-file-button {
    transform: none !important;
    will-change: auto !important;
}

html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu {
    left: 0 !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(100% + 8px) !important;
    margin: 0 !important;
    width: min(360px, 100%);
    min-width: 0 !important;
    max-height: min(460px, calc(100dvh - 140px));
    overflow-y: auto;
    padding: 6px !important;
    gap: 1px !important;
    border-radius: 20px !important;
    background: var(--secondary-color, #2a2927) !important;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1)) !important;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38), 0 2px 8px rgba(0, 0, 0, 0.22) !important;
    transform-origin: bottom left;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px) scale(0.97);
    transition: opacity 0.16s ease, transform 0.26s var(--cc-ease), visibility 0s linear 0.26s !important;
    scrollbar-width: none;
    z-index: 1200;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu.show {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.16s ease, transform 0.26s var(--cc-ease), visibility 0s linear 0s !important;
}

@media (min-width: 769px) {
    html.app-chat body.new-chat-view:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu {
        top: calc(100% + 8px) !important;
        bottom: auto !important;
        transform-origin: top left;
        transform: translateY(-6px) scale(0.97);
    }
    html.app-chat body.new-chat-view:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu.show {
        transform: none;
    }
}

/* Expanded composer: no room outside it, so the menu opens inside the card,
   just above the action row. */
html.app-chat body:not(.character-mode) .typing-area.cc-full #attach-file-button .attach-file-selections.plus-menu,
html.app-chat body.new-chat-view:not(.character-mode) .typing-area.cc-full #attach-file-button .attach-file-selections.plus-menu {
    top: auto !important;
    bottom: 52px !important;
    left: 6px !important;
    transform-origin: bottom left;
}

html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item {
    gap: 12px !important;
    padding: 9px 12px !important;
    border-radius: 14px !important;
    min-width: 0;
    align-items: center;
    outline: none;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item:hover,
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item:focus-visible {
    background: var(--cc-hover) !important;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item:active {
    background: var(--cc-press) !important;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item p {
    flex: 0 0 auto !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: var(--text-color) !important;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item .pm-desc {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--subheading-color, #aaa);
    opacity: 1;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item .pm-ico {
    font-size: 20px !important;
    opacity: 0.92 !important;
    flex: 0 0 auto;
}
html.app-chat body:not(.character-mode) #menu-websearch-btn .pm-ico,
html.app-chat body:not(.character-mode) #menu-research-btn .pm-ico { color: var(--cc-blue) !important; }
html.app-chat body:not(.character-mode) .plus-menu .pm-ico-image {
    background: linear-gradient(135deg, #ff7a59 10%, #ffc83d 38%, #4ade80 62%, #38bdf8 88%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent !important;
}
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-sep {
    margin: 4px 10px !important;
}

/* Rows rise in, lightly staggered (indices set by chat-composer.js). */
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu.show .plus-menu-item,
html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu.show .plus-menu-sep {
    animation: cc-row-in 0.3s var(--cc-ease) both;
    animation-delay: calc(var(--i, 0) * 16ms);
}
@keyframes cc-row-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

/* ── 5. Tool chip ─────────────────────────────────────────────────────────── */
html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip:not([hidden]) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    max-width: 190px;
    margin: 0 0 0 2px;
    padding: 0 12px 0 8px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--cc-blue) !important;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    flex: 0 0 auto;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease;
}
html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip:hover,
html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip:focus-visible {
    background: color-mix(in srgb, var(--cc-blue) 14%, transparent);
    outline: none;
}
html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip .cc-chip-label,
html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip .material-symbols-rounded {
    color: var(--cc-blue) !important;
}
.cc-chip-ico-wrap { position: relative; width: 20px; height: 20px; flex: 0 0 20px; }
.cc-chip-ico-wrap .material-symbols-rounded {
    color: inherit !important;
    position: absolute;
    inset: 0;
    font-size: 20px !important;
    line-height: 20px;
    transition: opacity 0.15s ease, transform 0.22s var(--cc-ease);
}
.cc-chip-x { opacity: 0; transform: rotate(-60deg) scale(0.6); }
.cc-tool-chip:hover .cc-chip-ico,
.cc-tool-chip:focus-visible .cc-chip-ico { opacity: 0; transform: scale(0.6); }
.cc-tool-chip:hover .cc-chip-x,
.cc-tool-chip:focus-visible .cc-chip-x { opacity: 1; transform: none; }
.cc-chip-label { overflow: hidden; text-overflow: ellipsis; }

/* ── 6. Landing suggestions ───────────────────────────────────────────────── */
/* The composer (and the + menu inside it) always paints above the panel. */
html.app-chat body:not(.character-mode) .typing-area.cc-owned > .typing-form {
    position: relative;
    z-index: 3;
}
html.app-chat body:not(.character-mode) .cc-suggest:not([hidden]) {
    position: relative;
    z-index: 1;
    display: block;
    margin: 14px 2px 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--text-color, #fff) 20%, transparent) transparent;
}
.cc-sg-tabs { display: flex; gap: 6px; margin: 0 4px 10px; }
.cc-sg-tab {
    appearance: none;
    border: 0;
    padding: 7px 14px;
    border-radius: 999px;
    background: transparent;
    color: var(--subheading-color, #aaa);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.cc-sg-tab:hover { color: var(--text-color); }
.cc-sg-tab.is-active { background: var(--cc-press); color: var(--text-color); }

.cc-sg-list { display: flex; flex-direction: column; gap: 1px; }
.cc-sg-row {
    appearance: none;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-width: 0;
    padding: 11px 12px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--text-color);
    font: inherit;
    font-size: 14.5px;
    text-align: left;
    cursor: pointer;
    animation: cc-row-in 0.32s var(--cc-ease) both;
    animation-delay: calc(var(--i, 0) * 28ms);
    transition: background-color 0.15s ease;
}
.cc-sg-row:hover,
.cc-sg-row:focus-visible { background: var(--cc-hover); outline: none; }
.cc-sg-row:active { background: var(--cc-press); }
.cc-sg-row > .material-symbols-rounded { font-size: 20px; color: var(--subheading-color, #aaa); flex: 0 0 auto; }
.cc-sg-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cc-sg-rich .cc-sg-title { font-weight: 600; flex: 0 0 auto; max-width: 45%; }
.cc-sg-desc {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--subheading-color, #aaa);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cc-sg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 10px;
    padding: 2px;
}
.cc-sg-card {
    appearance: none;
    position: relative;
    aspect-ratio: 4 / 5;
    border: 0;
    border-radius: 18px;
    overflow: hidden;
    padding: 0;
    background: var(--card-bg, #333);
    color: var(--card-ink, #fff);
    cursor: pointer;
    font: inherit;
    animation: cc-card-in 0.36s var(--cc-ease) both;
    animation-delay: calc(var(--i, 0) * 24ms);
    transition: transform 0.22s var(--cc-ease), box-shadow 0.22s ease;
}
.cc-sg-card:hover,
.cc-sg-card:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.3);
    outline: none;
}
.cc-sg-card:focus-visible { box-shadow: 0 0 0 2px var(--cc-blue); }
.cc-sg-card:active { transform: scale(0.98); }
.cc-sg-emoji {
    position: absolute;
    inset: 0 0 18% 0;
    display: grid;
    place-items: center;
    font-size: 52px;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.25));
}
.cc-sg-card-label {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 28px 12px 11px;
    text-align: left;
    font-size: 13.5px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.58), transparent);
}
.cc-sg-upload {
    background: var(--highlight-background, #383531);
    box-shadow: inset 0 0 0 1px var(--border-color, rgba(255, 255, 255, 0.1));
}
.cc-sg-upload > .material-symbols-rounded {
    position: absolute;
    inset: 0 0 14% 0;
    display: grid;
    place-items: center;
    font-size: 34px;
    color: var(--subheading-color, #aaa);
}
.cc-sg-upload .cc-sg-card-label { background: none; color: var(--text-color); font-weight: 500; }
@keyframes cc-card-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

/* ── 7. Sheets (Add from library) ─────────────────────────────────────────── */
.cc-layer {
    position: fixed;
    inset: 0;
    z-index: 100300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.cc-scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    transition: opacity 0.22s ease;
}
.cc-layer.is-open .cc-scrim { opacity: 1; }

.cc-sheet {
    position: relative;
    width: min(680px, 100%);
    height: min(640px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    background: var(--secondary-color, #2a2927);
    color: var(--text-color);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    transition: opacity 0.2s ease, transform 0.3s var(--cc-ease);
    outline: none;
}
.cc-layer.is-open .cc-sheet { opacity: 1; transform: none; }

.cc-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px 8px 24px;
}
.cc-sheet-head h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }

.cc-icon-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.15s ease, opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.cc-icon-btn:hover { background: var(--cc-hover); }
.cc-icon-btn:active { background: var(--cc-press); }
.cc-icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.cc-icon-btn:focus-visible { outline: 2px solid var(--cc-blue); outline-offset: 1px; }
.cc-icon-btn .material-symbols-rounded { font-size: 22px; }

.cc-lib-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px 12px 24px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}
.cc-lib-search {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--subheading-color, #aaa);
}
.cc-lib-search .material-symbols-rounded { font-size: 20px; }
.cc-lib-search input {
    flex: 1;
    min-width: 0;
    height: 38px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text-color);
    font: inherit;
    font-size: 15px;
}
.cc-lib-search input::placeholder { color: var(--placeholder-color, #938d86); }
.cc-seg { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--cc-hover); }
.cc-seg button {
    appearance: none;
    width: 34px;
    height: 30px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--subheading-color, #aaa);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.cc-seg button .material-symbols-rounded { font-size: 19px; }
.cc-seg button[aria-pressed="true"] { background: var(--secondary-color, #2a2927); color: var(--text-color); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.cc-seg button:focus-visible { outline: 2px solid var(--cc-blue); }

.cc-lib-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 12px 16px;
    scrollbar-width: thin;
    outline: none;
}
.cc-lib-body[data-view="list"] { display: flex; flex-direction: column; gap: 1px; }
.cc-lib-body[data-view="grid"] {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 10px;
    align-content: start;
}
.cc-lib-item {
    appearance: none;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--text-color);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease;
}
.cc-lib-item:hover,
.cc-lib-item:focus-visible { background: var(--cc-hover); outline: none; }
.cc-lib-item:active { background: var(--cc-press); }
.cc-lib-thumb {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: var(--highlight-background, #383531);
    color: var(--subheading-color, #aaa);
}
/* The row is the click target; a bare <img> click would be claimed by the
   app's global image viewer. */
.cc-lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.cc-lib-thumb .material-symbols-rounded { font-size: 22px; }
.cc-lib-meta { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.cc-lib-name { font-size: 14.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-lib-date { font-size: 12.5px; color: var(--subheading-color, #aaa); }

.cc-lib-body[data-view="grid"] .cc-lib-item { flex-direction: column; align-items: stretch; gap: 8px; padding: 8px; }
.cc-lib-body[data-view="grid"] .cc-lib-thumb { width: 100%; height: auto; aspect-ratio: 1; flex: none; border-radius: 12px; }
.cc-lib-body[data-view="grid"] .cc-lib-thumb .material-symbols-rounded { font-size: 34px; }
.cc-lib-body[data-view="grid"] .cc-lib-name { font-size: 13px; }
.cc-lib-body[data-view="grid"] .cc-lib-date { font-size: 12px; }

.cc-lib-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 220px;
    grid-column: 1 / -1;
    color: var(--subheading-color, #aaa);
    font-size: 14px;
    text-align: center;
}
.cc-text-btn {
    appearance: none;
    border: 0;
    background: var(--cc-hover);
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 999px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}
.cc-spin {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid color-mix(in srgb, var(--text-color, #fff) 18%, transparent);
    border-top-color: var(--text-color, #fff);
    animation: cc-spin 0.8s linear infinite;
}
@keyframes cc-spin { to { transform: rotate(360deg); } }

/* ── 8. Sketch pad ────────────────────────────────────────────────────────── */
.cc-pad {
    position: relative;
    width: min(780px, 100%);
    height: min(780px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    background: var(--secondary-color, #2a2927);
    color: var(--text-color);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    border-radius: 28px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    transition: opacity 0.2s ease, transform 0.3s var(--cc-ease);
}
.cc-layer.is-open .cc-pad { opacity: 1; transform: none; }

.cc-pad-top {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px 6px;
}
.cc-pad-hist { display: flex; gap: 2px; }
.cc-pad-tools {
    position: relative;
    display: flex;
    gap: 2px;
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    background: color-mix(in srgb, var(--text-color, #fff) 4%, transparent);
}
.cc-pad-tools > button,
.cc-shape-pop > button {
    appearance: none;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-color);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.cc-pad-tools > button:hover,
.cc-shape-pop > button:hover { background: var(--cc-hover); }
.cc-pad-tools > button[aria-pressed="true"],
.cc-shape-pop > button[aria-checked="true"] { background: var(--cc-press); }
.cc-pad-tools > button:active { transform: scale(0.92); }
.cc-pad-tools > button:focus-visible,
.cc-shape-pop > button:focus-visible { outline: 2px solid var(--cc-blue); outline-offset: -2px; }
.cc-pad-tools .material-symbols-rounded,
.cc-shape-pop .material-symbols-rounded { font-size: 21px; }
.cc-shape-pop {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 2px;
    padding: 4px;
    border-radius: 999px;
    background: var(--secondary-color, #2a2927);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    animation: cc-row-in 0.2s var(--cc-ease) both;
}
.cc-shape-pop[hidden] { display: none; }

.cc-pad-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    background: var(--secondary-color, #2a2927);
    touch-action: none;
    overflow: hidden;
}
.cc-pad-stage canvas {
    position: absolute;
    inset: 0;
    touch-action: none;
    cursor: crosshair;
}
.cc-pad-stage[data-tool="select"] canvas { cursor: default; }
.cc-pad-stage[data-tool="text"] canvas { cursor: text; }
.cc-pad-stage[data-tool="eraser"] canvas { cursor: cell; }

.cc-pad-text {
    position: absolute;
    z-index: 2;
    min-width: 140px;
    min-height: 1.3em;
    margin: 0;
    padding: 0 2px;
    border: 1px dashed rgba(120, 170, 255, 0.85);
    border-radius: 4px;
    outline: none;
    resize: none;
    overflow: hidden;
    background: transparent;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-weight: 600;
    line-height: 1.25;
}

/* Brush size: a vertical tapered track, wide at the top (largest). */
.cc-size {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    display: flex;
    justify-content: center;
    width: 34px;
    height: 200px;
}
.cc-size input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    appearance: none;
    -webkit-appearance: none;
    width: 34px;
    height: 200px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}
.cc-size input[type="range"]::-webkit-slider-runnable-track {
    width: 26px;
    height: 100%;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--text-color, #fff) 40%, transparent), color-mix(in srgb, var(--text-color, #fff) 12%, transparent));
    clip-path: polygon(0 0, 100% 0, 56% 100%, 44% 100%);
    border-radius: 3px;
}
.cc-size input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    border: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    margin-left: 1px;
}
.cc-size input[type="range"]::-moz-range-track {
    width: 26px;
    height: 100%;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--text-color, #fff) 40%, transparent), color-mix(in srgb, var(--text-color, #fff) 12%, transparent));
    clip-path: polygon(0 0, 100% 0, 56% 100%, 44% 100%);
}
.cc-size input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    border: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.cc-pad-bottom {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 76px 16px;
}
.cc-swatches {
    display: flex;
    gap: 8px;
    padding: 5px;
    overflow-x: auto;
    scrollbar-width: none;
    max-width: 100%;
}
.cc-swatches::-webkit-scrollbar { display: none; }
.cc-swatch {
    appearance: none;
    position: relative;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--sw, #fff);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
    cursor: pointer;
    transition: transform 0.15s var(--cc-ease), box-shadow 0.15s ease;
}
.cc-swatch:hover { transform: scale(1.08); }
.cc-swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--secondary-color, #2a2927), 0 0 0 4px var(--cc-blue); }
.cc-swatch:focus-visible { outline: 2px solid var(--cc-blue); outline-offset: 2px; }
.cc-swatch-custom {
    background: conic-gradient(#ef4444, #f59e0b, #eab308, #22c55e, #06b6d4, #3b82f6, #8b5cf6, #ec4899, #ef4444);
    overflow: hidden;
}
.cc-swatch-custom input {
    position: absolute;
    inset: -6px;
    width: calc(100% + 12px);
    height: calc(100% + 12px);
    opacity: 0;
    cursor: pointer;
    border: 0;
    padding: 0;
}
.cc-done {
    appearance: none;
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: #2f7cf6;
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(47, 124, 246, 0.35);
    transition: transform 0.15s var(--cc-ease), filter 0.15s ease;
}
.cc-done:hover { filter: brightness(1.08); }
.cc-done:active { transform: translateY(-50%) scale(0.92); }
.cc-done:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.cc-done .material-symbols-rounded { font-size: 24px; }

/* ── 9. Phones ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* The composer stays docked on phones; suggestions sit above it. */
    html.app-chat body:not(.character-mode) .typing-area.cc-owned {
        display: flex;
        flex-direction: column;
    }
    /* Only the order changes; nothing inside may be squeezed by the flexbox. */
    html.app-chat body:not(.character-mode) .typing-area.cc-owned > * {
        flex-shrink: 0;
    }
    html.app-chat body:not(.character-mode) .typing-area.cc-owned > .cc-suggest:not([hidden]) {
        order: -1;
        margin: 0 0 10px;
        max-height: min(44dvh, 360px);
    }
    html.app-chat.cc-suggest-open body.new-chat-view:not(.character-mode) .chat-list .header {
        opacity: 0;
        transition: opacity 0.2s ease;
    }
    .cc-sg-grid {
        grid-auto-flow: column;
        grid-template-columns: none;
        grid-auto-columns: 124px;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        padding-bottom: 4px;
    }
    .cc-sg-grid::-webkit-scrollbar { display: none; }
    .cc-sg-card { scroll-snap-align: start; }
    .cc-sg-rich { flex-wrap: wrap; row-gap: 2px; }
    .cc-sg-rich .cc-sg-title { max-width: calc(100% - 40px); }
    .cc-sg-rich .cc-sg-desc { flex-basis: 100%; padding-left: 34px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}

@media (max-width: 640px) {
    html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu {
        width: auto;
        right: 0 !important;
        border-radius: 22px !important;
        padding: 8px !important;
    }
    html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu .plus-menu-item {
        padding: 12px 12px !important;
    }

    .cc-layer { padding: 0; align-items: flex-end; }
    .cc-sheet {
        width: 100%;
        height: min(88dvh, 720px);
        border-radius: 24px 24px 0 0;
        border-bottom: 0;
        transform: translateY(100%);
        transition: opacity 0.2s ease, transform 0.36s var(--cc-ease);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .cc-sheet::before {
        content: "";
        position: absolute;
        top: 7px;
        left: 50%;
        width: 36px;
        height: 4px;
        margin-left: -18px;
        border-radius: 4px;
        background: color-mix(in srgb, var(--text-color, #fff) 22%, transparent);
    }
    .cc-sheet-head { padding: 18px 10px 4px 20px; }
    .cc-lib-bar { padding: 4px 12px 10px 20px; }
    .cc-lib-search input { font-size: 16px; }
    .cc-lib-body { padding: 6px 8px calc(16px + env(safe-area-inset-bottom, 0px)); }
    .cc-lib-body[data-view="grid"] { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }

    .cc-layer.cc-sketch { align-items: stretch; }
    .cc-pad {
        width: 100%;
        height: 100dvh;
        border-radius: 0;
        border: 0;
        padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
    }
    .cc-pad-top { padding: 8px 8px 4px; }
    .cc-pad-tools > button { width: 36px; height: 36px; }
    .cc-pad-hist .cc-icon-btn { width: 36px; height: 36px; }
    .cc-size { left: 8px; height: 170px; }
    .cc-size input[type="range"] { height: 170px; }
    .cc-pad-bottom { justify-content: flex-start; padding: 10px 70px 12px 10px; }
    .cc-done { right: 12px; }
}

@media (max-width: 380px) {
    html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip .cc-chip-label { display: none; }
    html.app-chat body:not(.character-mode) .typing-form .cc-tool-chip:not([hidden]) { padding: 0 8px; }
    .cc-pad-tools > button { width: 32px; height: 32px; }
}

@media (hover: none) {
    .cc-sg-card:hover { transform: none; box-shadow: none; }
    .cc-sg-row:hover,
    .cc-lib-item:hover,
    .cc-icon-btn:hover { background: transparent; }
    .cc-sg-row:active,
    .cc-lib-item:active,
    .cc-icon-btn:active { background: var(--cc-press); }
    /* No hover on touch: the chip always shows its remove affordance. */
    .cc-tool-chip .cc-chip-x { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    html.app-chat body:not(.character-mode) .typing-area.cc-owned .typing-form .typing-input,
    html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu,
    .cc-sheet, .cc-pad, .cc-scrim, .cc-sg-card { transition: none !important; }
    .cc-sg-row, .cc-sg-card,
    html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu.show .plus-menu-item,
    html.app-chat body:not(.character-mode) #attach-file-button .attach-file-selections.plus-menu.show .plus-menu-sep { animation: none !important; }
}
