.chat-column {
    position: relative;
    min-height: 0;
}

.conversation-loader {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  color: var(--text-2);
  font-size: .9rem;
}

.conversation-loader[hidden] {
  display: none;
}

.conversation-error {
    margin: auto;
    padding: 1rem;
    text-align: center;
    color: var(--text-2);
}

.conversation-error button,
.practice-test-open {
    padding: .4rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .8rem;
}

.conversation-error button:hover,
.practice-test-open:hover {
    border-color: var(--accent);
}

.message-search-target > .body {
    outline: 2px solid var(--accent);
    outline-offset: 5px;
    border-radius: 8px;
}

.chat-start-content .assistant-guest-note {
    margin: 0 0 .9rem;
    font-size: .8rem;
}

.assistant-guest-note a { color: var(--text); font-weight: 650; }

.assistant-access-note {
    margin: 0 0 .5rem;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-2);
    font-size: .8rem;
}

.conversation-loader-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: conversation-spin .8s linear infinite;
}

@keyframes conversation-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .conversation-loader-spinner {
    animation-duration: 2s;
  }
}

.chat-start {
    position: absolute;
    inset: 0;
  isolation: isolate;
    display: flex;
    align-items: center;
  justify-content: center;
    padding: 24px;
    padding-bottom: 120px;
    overflow-y: auto;
    z-index: 1;
    pointer-events: none;
}

  .chat-equation-layer {
    position: absolute;
    inset: 3% 3% 13%;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .chat-floating-equation {
    position: absolute;
    display: block;
    color: color-mix(in srgb, var(--accent) 62%, var(--muted));
    opacity: .36;
    font-size: .95rem;
    animation: chat-equation-drift 11s ease-in-out infinite alternate;
  }

  :root[data-theme="light"] .chat-floating-equation {
    color: color-mix(in srgb, var(--accent) 72%, var(--muted));
    opacity: .44;
  }

  .chat-floating-equation .katex {
    color: inherit;
  }

  @keyframes chat-equation-drift {
    to { transform: translate3d(var(--drift-x), var(--drift-y), 0) rotate(var(--drift-rotation)); }
  }

.chat-start-content {
    position: relative;
    z-index: 1;
    width: min(680px, 100%);
    margin: auto;
    text-align: center;
    pointer-events: auto;
}

.chat-start-logo img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.chat-start h1 {
    margin: 16px 0 8px;
    font-size: clamp(1.5rem, 3vw, 2.1rem);
}

.chat-start p {
    margin: 0 0 24px;
    color: var(--muted);
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.quick-actions button {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    min-height: 64px;
    padding: 14px;
    text-align: left;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: border-color .2s, background .2s, transform .2s;
}

.quick-actions button:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.quick-actions button:active {
    transform: scale(.98);
}

.quick-actions strong {
    font-size: .9rem;
    font-weight: 600;
}

@media (max-width: 640px) {
    /* Phones: the empty state lives in the column's own flow instead of
       floating over it, so it can never land on top of the composer. While
       no message is rendered it takes all the free space above the composer;
       the list gets that space back the moment a .msg exists — the exact
       condition syncChatStart uses to show / hide the hero. */
    .chat-start {
      position: relative;
        flex: 1 1 auto;
        min-height: 0;
        padding: 16px 14px 8px;
        align-items: center;
        pointer-events: auto;
    }

    .scroll:not(:has(.msg)) {
        flex: 0 0 0;
    }

    .chat-start-logo img {
        width: 40px;
        height: 40px;
    }

    .chat-floating-equation {
      font-size: .75rem;
      opacity: .24;
    }

    :root[data-theme="light"] .chat-floating-equation {
      opacity: .32;
    }

    .chat-start h1 {
        margin: 12px 0 6px;
        font-size: 1.3rem;
    }

    .chat-start p {
        margin: 0 0 16px;
        font-size: .9rem;
    }

    .quick-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .quick-actions button {
        min-height: 54px;
    }
}

@media (prefers-reduced-motion: reduce) {
  .chat-floating-equation {
    animation: none;
  }
}

/* Landscape / short phones — the hero is what does not fit, not the chips. */
@media (max-width: 640px) and (max-height: 560px) {
    .chat-start-logo {
        display: none;
    }

    .chat-start h1 {
        margin: 0 0 4px;
        font-size: 1.15rem;
    }

    .chat-start p {
        display: none;
    }
}
    .composer.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -3px;
}
  :root {
    --font:var(--assistant-font);
    --mono:var(--assistant-mono);
    --accent:var(--assistant-accent);
    --accent-ink:var(--assistant-accent-ink);
    --accent-weak:var(--assistant-accent-weak);
    --bg:var(--assistant-bg);
    --surface:var(--assistant-surface);
    --surface-2:var(--assistant-surface-2);
    --surface-3:var(--assistant-surface-3);
    --border:var(--assistant-border);
    --border-soft:var(--assistant-border-soft);
    --text:var(--assistant-text);
    --text-2:var(--assistant-text-2);
    --muted:var(--assistant-muted);
    --ring:var(--assistant-ring);
    --shadow:var(--assistant-shadow);
    --grain:var(--assistant-grain);
  }
  :root:not([data-theme="light"]) .chat-page{--bg:#000000}
  *{box-sizing:border-box;margin:0;padding:0}


  /* subtle atmospheric background */
  .chat-page::before{
    content:"";position:fixed;inset:0;pointer-events:none;z-index:0;
    background:
      radial-gradient(60rem 40rem at 15% -10%, var(--accent-weak), transparent 60%),
      radial-gradient(50rem 40rem at 100% 110%, color-mix(in srgb,var(--accent) 8%,transparent), transparent 55%);
    opacity:.9;
  }
  :root:not([data-theme="light"]) .chat-page::before{background:none}
  button{font-family:inherit;cursor:pointer;border:0;background:none;color:inherit}
  :focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:8px}
  ::-webkit-scrollbar{width:10px;height:10px}
  ::-webkit-scrollbar-thumb{background:var(--surface-3);border-radius:20px;border:3px solid transparent;background-clip:padding-box}
  ::-webkit-scrollbar-thumb:hover{background:var(--border)}

  /* ---------- shell ---------- */
  .app{
    position:relative;
    z-index:1;
    display:grid;
    grid-template-columns:288px minmax(0,1fr);
    height:100%;
    min-height:0;
    transition:grid-template-columns 220ms ease;
  }
  .app[hidden]{display:none!important}
  .page-loader{position:absolute;inset:0;z-index:10;display:grid;place-content:center;justify-items:center;gap:14px;
    background:var(--bg);color:var(--text-2);font-size:.9rem}
  .page-loader[hidden]{display:none}
  .app.collapsed{grid-template-columns:0 1fr}
  .app.collapsed .chat-sidebar{border-right-color:transparent}
  .scrim{position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:55;opacity:0;pointer-events:none;transition:.2s}

  /* ---------- sidebar ---------- */
  .chat-sidebar{
    --accent:#fb923c;
    --accent-weak:color-mix(in srgb,#fb923c 14%,transparent);
    --ring:color-mix(in srgb,#fb923c 38%,transparent);
    background:color-mix(in srgb,var(--surface) 96%,var(--bg));
    border-right:1px solid var(--border-soft);
    display:flex;flex-direction:column;min-width:0;min-height:0;overflow:hidden;
  }
  .brand{box-sizing:border-box;display:flex;align-items:center;gap:.65rem;height:var(--assistant-header-height);flex:0 0 var(--assistant-header-height);padding:0 var(--assistant-header-padding);border-bottom:1px solid var(--border-soft);
    font-size:.96rem;font-weight:650;letter-spacing:0}
  .brand .logo{width:28px;height:28px;border-radius:8px;object-fit:contain;flex:none}
  .brand small{margin-inline-start:auto;font:500 10px/1 var(--mono);color:var(--muted);letter-spacing:.04em;
    border:1px solid var(--border-soft);padding:.3em .55em;border-radius:999px}
  .newchat{min-height:36px;margin:.45rem .85rem .1rem;display:flex;align-items:center;justify-content:center;gap:.55rem;padding:.4rem .7rem;
    border:1px solid var(--border-soft);border-radius:10px;font-weight:600;font-size:.87rem;
    background:var(--surface-2);color:var(--accent);transition:background .15s,border-color .15s,transform .15s}
  .newchat:hover{border-color:var(--border);background:var(--surface-3)}
  .newchat:active{transform:scale(.985)}
  .newchat svg{width:16px;height:16px;color:var(--accent)}
  .side-label{padding:.65rem .95rem .35rem;font-size:.66rem;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--muted)}
  .thread-search-wrap{position:relative;padding:.45rem .7rem}
  .thread-search-wrap input{width:100%;height:34px;padding:0 .7rem 0 2.1rem;border:1px solid var(--border-soft);border-radius:10px;background:var(--surface-2);color:var(--text);font:inherit;font-size:.82rem;outline:none;transition:padding .16s ease,border-color .16s,box-shadow .16s}
  .thread-search-icon{position:absolute;z-index:1;top:calc(50% - 7px);left:1.35rem;width:16px;height:16px;color:var(--muted);pointer-events:none;transition:opacity .14s ease,transform .14s ease}
  .thread-search-wrap:focus-within input{padding-left:.7rem}
  .thread-search-wrap:focus-within .thread-search-icon{opacity:0;transform:scale(.85)}
  .thread-search-wrap input:focus{border-color:var(--accent);box-shadow:0 0 0 2px var(--ring)}
  .sidebar-history-scroll{flex:1;min-height:0;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain}
  .threads{flex:0 0 auto;min-height:0;overflow-x:hidden;overflow-y:visible;padding:0 .55rem .8rem;display:flex;flex-direction:column;gap:2px}
  .threads[hidden]{display:none}
  .thread-list{display:grid;grid-template-columns:minmax(0,1fr);gap:2px}
  .older-threads{margin-top:.45rem;padding-top:.35rem;border-top:1px solid var(--border-soft)}
  .older-threads > summary{display:flex;align-items:center;justify-content:space-between;min-height:34px;
    padding:0 .55rem;border-radius:7px;color:var(--text-2);font-size:.78rem;font-weight:650;list-style:none;cursor:pointer}
  .older-threads > summary::-webkit-details-marker{display:none}
  .older-threads > summary:hover,.older-threads > summary:focus-visible{background:var(--surface-2);color:var(--text)}
  .older-threads > summary svg{width:15px;height:15px}
  .older-threads[open] > summary svg{transform:rotate(180deg)}
  .older-threads-status[hidden],.older-threads-retry[hidden]{display:none}
  .older-threads-retry{width:100%;min-height:32px;border-radius:7px;background:var(--accent-weak);color:var(--accent);font-size:.78rem;font-weight:650}
  .thread-date-label{flex:none;padding:.75rem .55rem .3rem;font-size:.65rem;font-weight:700;letter-spacing:.07em;text-transform:uppercase;color:var(--muted)}
  .thread{display:flex;align-items:center;gap:.6rem;min-height:35px;padding:.4rem .55rem .4rem 1.35rem;border-radius:8px;color:var(--text-2);
    font-size:.84rem;line-height:1.35;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;transition:background .12s,color .12s;border:1px solid transparent}
  .thread:hover{background:transparent;color:var(--text)}
  .thread.active{background:transparent;color:var(--text);border-color:transparent}
  /* one row = the chat button + its conversation actions */
  .thread-row{position:relative;display:flex;align-items:center;gap:.1rem;border:1px solid transparent;border-radius:8px;transition:background .12s,border-color .12s}
  .thread-row::before{content:"";position:absolute;top:50%;left:.7rem;width:5px;height:5px;border-radius:50%;background:var(--border);transform:translateY(-50%)}
  .thread-row:hover{background:var(--surface-2)}
  .thread-row:has(.thread.active){background:var(--accent-weak);border-color:color-mix(in srgb,var(--accent) 16%,var(--border-soft))}
  .thread-row:has(.thread.active)::before{background:var(--accent)}
  .thread-row:has(.thread.active) .thread{color:var(--accent);font-weight:600}
  .thread-row .thread{flex:1;min-width:0}
  .thread-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .thread-row.is-renaming{gap:0;padding:4px;background:var(--surface-2);border-color:color-mix(in srgb,var(--accent) 28%,var(--border))}
  .thread-row.is-renaming::before{display:none}
  .thread-row.is-renaming > :is(.thread,.thread-menu){display:none}
  .thread-rename-form{display:grid;grid-template-columns:minmax(0,1fr);align-items:center;gap:6px;width:100%;min-width:0}
  .thread-rename-input{width:100%;min-width:0;height:32px;padding:0 8px;border:1px solid var(--border);border-radius:6px;background:var(--bg);color:var(--text);font:inherit;font-size:.8rem}
  .thread-rename-input:focus{border-color:var(--accent);outline:2px solid var(--ring);outline-offset:1px}
  .thread-rename-input[aria-invalid="true"]{border-color:#e5484d}
  .thread-rename-controls{display:flex;justify-content:flex-end;gap:5px}
  .thread-rename-controls button{min-height:29px;padding:0 .65rem;border:1px solid transparent;border-radius:7px;font:inherit;font-size:.75rem;font-weight:650;transition:background .12s,color .12s,border-color .12s}
  .thread-rename-save{background:var(--accent);color:var(--accent-ink)}
  .thread-rename-save:hover{background:color-mix(in srgb,var(--accent) 82%,white)}
  .thread-rename-cancel{border-color:var(--border)!important;background:var(--surface);color:var(--text-2)}
  .thread-rename-cancel:hover{background:var(--surface-3);color:var(--text)}
  .thread-rename-controls button:disabled{opacity:.55;cursor:wait}
  .thread-rename-error{grid-column:1/-1;color:#e5484d;font-size:.68rem;line-height:1.3}
  .search-result-row{align-items:stretch}
  .search-result-row::before{display:none}
  .search-result-button{padding-inline-start:.65rem;flex-direction:column;align-items:flex-start;gap:.22rem;min-height:54px;white-space:normal;text-align:start}
  .search-result-excerpt{display:-webkit-box;overflow:hidden;color:var(--muted);font-size:.76rem;line-height:1.35;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2}
  .search-result-excerpt mark{background:color-mix(in srgb,var(--accent) 28%,transparent);color:var(--text)}
  .thread-menu{position:relative;flex:none}
  .thread-menu>summary{list-style:none;cursor:pointer}
  .thread-menu>summary::-webkit-details-marker{display:none}
  .thread-menu-trigger{width:30px;height:30px;margin-inline-end:3px;display:grid;place-items:center;border-radius:7px;color:var(--muted);
    opacity:0;transition:background .14s,color .14s,opacity .14s}
  .thread-menu-trigger svg{width:16px;height:16px}
  .thread-row:hover .thread-menu-trigger,.thread-row:has(.thread.active) .thread-menu-trigger,.thread-menu[open] .thread-menu-trigger,.thread-menu-trigger:focus-visible{opacity:1}
  .thread-menu-trigger:hover,.thread-menu[open] .thread-menu-trigger{background:var(--surface-3);color:var(--text)}
  .thread-menu-panel{
    position:fixed;z-index:1200;top:0;left:0;min-width:122px;display:none;gap:5px;
    padding:4px;border:1px solid var(--border);border-radius:10px;
    background:var(--surface);box-shadow:0 8px 24px rgb(0 0 0 / .2);
  }
  .thread-menu[open] .thread-menu-panel{display:grid}
  .thread-action{
    display:grid;grid-template-columns:16px 1fr;align-items:center;column-gap:8px;
    width:100%;min-height:30px;padding:4px 8px;border:0;border-radius:6px;
    background:transparent;color:var(--text);font:inherit;font-size:.78rem;font-weight:550;
    line-height:1.2;text-align:start;white-space:nowrap;cursor:pointer;
  }
  .thread-action svg{display:block;width:16px;height:16px}
  .thread-action + .thread-action{position:relative}
  .thread-action + .thread-action::before{
    content:"";position:absolute;inset:-3px 8px auto;height:1px;background:var(--border-soft);pointer-events:none;
  }
  .thread-action:hover,.thread-action:focus-visible{background:var(--surface-2)}
  .thread-action:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
  .thread-action.danger{color:var(--thread-danger)}
  .thread-action.danger:hover,.thread-action.danger:focus-visible{background:color-mix(in srgb,var(--thread-danger) 11%,transparent)}
  .chat-page{--thread-danger:#bb2935}
  html[data-theme="dark"] .chat-page{--thread-danger:#ff9098}
  @media(any-pointer:coarse){
    .thread-menu-trigger{opacity:1}
    .thread-action{min-height:36px}
    .thread-search-wrap input,.thread-rename-input{font-size:16px}
  }
  .threads-empty{display:flex;flex-direction:column;align-items:center;gap:.45rem;padding:.7rem;font-size:.78rem;line-height:1.45;color:var(--muted);text-align:center;overflow-wrap:anywhere}
  .threads-empty a{color:var(--accent);font-size:.78rem;font-weight:600;text-decoration:none}
  .threads-empty a:hover{text-decoration:underline;text-underline-offset:3px}
  .side-foot{border-top:1px solid var(--border-soft);padding:.7rem .75rem;display:flex;align-items:center;gap:.6rem}
  .avatar{width:30px;height:30px;border-radius:9px;flex:none;display:grid;place-items:center;font-weight:600;font-size:.8rem;
    background:var(--surface-3);color:var(--text)}
  .side-foot .who{min-width:0;line-height:1.25}
  .side-foot .who b{font-weight:600;font-size:.86rem;display:block}
  .side-foot .who span{font-size:.75rem;color:var(--muted)}
  .icon-btn{width:34px;height:34px;border-radius:9px;display:grid;place-items:center;color:var(--text-2);transition:.14s;flex:none}
  .main-sidebar-btn{display:none}
  .icon-btn:hover{background:var(--surface-2);color:var(--text)}
  /* a tool whose plan allowance is used up (e.g. images) */
  .icon-btn:disabled,.icon-btn.spent{opacity:.4;cursor:not-allowed}
  .icon-btn:disabled:hover{background:none;color:var(--text-2)}
  .icon-btn svg{width:17px;height:17px}
  .side-foot .icon-btn{margin-left:auto}

  /* ---------- main ---------- */
  .main{
    display:flex;
    flex-direction:column;
    min-width:0;
    min-height:0;
    height:100%;
    container:assistant-main / inline-size;
  }
  .chat-page{
    --assistant-header-height:44px;
    --assistant-header-control:30px;
    --assistant-header-padding:10px;
    --assistant-frame-border:var(--border-soft);
  }
  :root[data-theme="light"] .chat-page {
    --assistant-frame-border:color-mix(in srgb,var(--text-2) 12%,var(--bg));
  }
  .topbar,.book-head,.test-head,.calc-head{
    box-sizing:border-box;display:flex;align-items:center;gap:.3rem;
    height:var(--assistant-header-height);flex:0 0 var(--assistant-header-height);
    padding:0 var(--assistant-header-padding);border-bottom:1px solid var(--border-soft);
    background:var(--bg);
  }
  :is(.topbar,.book-head,.test-head,.calc-head) .icon-btn,
  .header-chat .thread-menu-trigger{
    width:var(--assistant-header-control);height:var(--assistant-header-control);border-radius:7px;
  }
  .workspace-switch,.workspace-toolbar{display:none}
  .topbar:has(.header-chat :is(.thread-menu[open],.thread-rename-form)){position:relative}
  .header-chat{display:flex;align-items:center;gap:.2rem;min-width:0;max-width:14rem;position:relative}
  .header-chat[hidden]{display:none}
  .header-chat-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text);font-size:.82rem;font-weight:600}
  .header-chat .thread-menu-trigger{opacity:1;margin:0}
  .header-chat :is(.thread-menu-panel,.thread-rename-form){position:absolute;inset:calc(100% + 4px) 0 auto auto}
  .header-chat .thread-rename-form{
    width:min(15rem,calc(100vw - 5rem));padding:.45rem;z-index:1200;
    background:var(--surface);border:1px solid var(--border);border-radius:9px;
    box-shadow:0 8px 20px rgba(0,0,0,.18);
  }
  .assistant-tools-slot{display:flex;align-items:center;flex:none}
  .assistant-tools{display:flex;align-items:center;gap:2px;padding:2px;flex:none;border:1px solid var(--border-soft);border-radius:9px;background:var(--surface-2)}
  .assistant-tools > :is(.icon-btn,.book-toggle){display:flex;align-items:center;justify-content:center;gap:.32rem;width:auto;min-height:26px;height:26px;
    padding:0 .45rem;border:0;border-radius:6px;background:transparent;font-size:.76rem;font-weight:650;white-space:nowrap}
  .assistant-tools > button svg{width:15px;height:15px}
  .assistant-tools > button:hover{background:var(--surface-3);color:var(--text)}
  .assistant-tools > button[aria-expanded="true"]{background:var(--surface);color:var(--accent);box-shadow:0 1px 3px rgb(0 0 0 / .13)}
  .assistant-tools > button:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
  @container assistant-main (max-width:900px) {
    .assistant-tools > [data-calc-toggle]{min-width:26px}
    .assistant-tools > [data-calc-toggle] span{display:none}
  }
  /* visible on desktop too: it now collapses the chat sidebar to a rail */
  .menu-btn{display:grid}
  .assistant-new-chat-row{display:flex;align-items:center;min-height:42px;padding:.3rem 1.1rem;border-bottom:1px solid var(--border-soft)}
  .assistant-chat-controls{display:inline-flex;align-items:center;gap:3px;padding:3px;border:1px solid color-mix(in srgb,var(--accent) 28%,var(--border));border-radius:15px;background:var(--surface)}
  .assistant-chat-controls .menu-btn{width:28px;height:28px;border-radius:10px}
  .assistant-new-chat{display:inline-flex;align-items:center;gap:.3rem;min-height:26px;padding:0 .4rem;border:0;border-radius:10px;background:transparent;color:var(--text-2);font-size:.72rem;font-weight:550;transition:background .14s,color .14s}
  .assistant-new-chat:hover{background:var(--accent-weak);color:var(--text)}
  .assistant-new-chat svg{width:12px;height:12px;color:var(--accent)}
  /* model picker */
  .picker{position:relative}
  .picker>button{display:flex;align-items:center;gap:.5rem;padding:.5rem .7rem;border-radius:10px;font-weight:500;
    font-size:.9rem;border:1px solid transparent;transition:.14s}
  .picker>button:hover{background:var(--surface-2)}
  .picker .dot{width:7px;height:7px;border-radius:50%;background:var(--accent);box-shadow:0 0 0 3px var(--accent-weak)}
  .picker .chev{width:15px;height:15px;color:var(--muted);transition:.2s}
  .picker.open .chev{transform:rotate(180deg)}
  .header-status{display:flex;align-items:center;gap:.55rem;min-width:0}
  .header-model{display:flex;align-items:center;gap:.4rem;flex:none;padding:.35rem .55rem;border:1px solid var(--border-soft);border-radius:8px;
    color:var(--text-2);font-size:.76rem;font-weight:600;line-height:1}
  .header-model .dot{width:7px;height:7px;border-radius:50%;background:var(--accent);box-shadow:0 0 0 3px var(--accent-weak)}
  .sidebar-credit-count{display:flex;flex:none;align-items:center;gap:8px;width:100%;min-height:44px;margin-bottom:6px;padding:3px 8px;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--sidebar-text);font:500 13px var(--font);text-align:start;cursor:pointer}
  .sidebar-credit-count[hidden]{display:none}
  .sidebar-credit-count:hover,.sidebar-credit-count[aria-expanded="true"]{border-color:var(--sidebar-border);background:var(--sidebar-hover);color:var(--sidebar-text-hover)}
  .sidebar-credit-count:focus-visible{outline:2px solid var(--sidebar-accent);outline-offset:-2px}
  .credit-usage-ring{display:block;flex:none;width:36px;height:36px}
  .credit-usage-track,.credit-usage-progress{fill:none;stroke-width:3}
  .credit-usage-track{stroke:var(--sidebar-border)}
  .credit-usage-progress{stroke:var(--sidebar-accent);transform:rotate(-90deg);transform-origin:18px 18px;transition:stroke-dashoffset .25s ease}
  .sidebar-credit-count.out .credit-usage-progress{stroke:#e26a53}
  #count-value{fill:currentColor;font:700 8px/1 var(--mono)}
  @media(min-width:821px){
    body.sidebar-collapsed .sidebar-credit-count{justify-content:center;padding-inline:0}
    body.sidebar-collapsed .sidebar-credit-label{display:none}
  }
  .credit-usage-popover{box-sizing:border-box;position:fixed;z-index:1200;width:min(330px,calc(100vw - 24px));max-width:calc(100vw - 24px);max-height:calc(100dvh - 24px);overflow:auto;padding:.85rem;border:1px solid var(--border);border-radius:10px;background:var(--surface);box-shadow:var(--shadow);color:var(--text);animation:solve-menu-in .14s ease-out}
  .credit-usage-popover[hidden]{display:none}
  .credit-usage-header{display:flex;align-items:center;justify-content:space-between;gap:.75rem;padding-bottom:.65rem;border-bottom:1px solid var(--border)}
  .credit-usage-popover h2{margin:0;font-size:.83rem;font-weight:600}
  .credit-usage-popover h2 span{color:var(--muted);font-weight:400}
  .credit-usage-upgrade{flex:none;padding:.38rem .7rem;border:1px solid color-mix(in srgb,var(--accent) 45%,var(--border));border-radius:7px;background:var(--accent);color:var(--accent-ink);font-size:.75rem;font-weight:650;text-decoration:none;transition:background .15s ease,border-color .15s ease}
  .credit-usage-upgrade:hover{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 86%,var(--text));color:var(--accent-ink)}
  .credit-usage-meter{padding:.65rem 0 .7rem;border-bottom:1px solid var(--border)}
  .credit-usage-meter-heading{display:flex;justify-content:space-between;align-items:baseline;gap:.75rem;margin-bottom:.3rem}
  .credit-usage-meter-heading strong,.credit-usage-extra-heading strong{font-size:.79rem;font-weight:600}
  .credit-usage-meter-heading span,.credit-usage-extra-heading span{color:var(--muted);font-size:.67rem;text-align:right}
  .credit-usage-percent{display:flex;align-items:baseline;gap:.25rem;margin-bottom:.45rem;color:var(--muted);font-size:.72rem}
  .credit-usage-percent strong{color:var(--text);font-size:1.12rem;font-weight:700}
  .credit-usage-extra-track{height:5px;overflow:hidden;border-radius:999px;background:var(--surface-3)}
  .credit-usage-extra-track>span{display:block;width:0;height:100%;border-radius:inherit;background:var(--accent);transition:width .25s ease}
  .credit-usage-meter-foot{display:flex;justify-content:space-between;gap:.75rem;margin-top:.38rem;color:var(--muted);font-size:.68rem}
  .credit-usage-extra{border-bottom:1px solid var(--border)}
  .credit-usage-extra-meter{padding:.65rem 0;border-bottom:1px solid var(--border)}
  .credit-usage-extra-meter:last-child{border-bottom:0}
  .credit-usage-extra-heading{display:flex;justify-content:space-between;align-items:baseline;gap:.75rem;margin-bottom:.4rem}
  .credit-usage-extra-summary{display:flex;justify-content:space-between;gap:.75rem;margin-top:.35rem;color:var(--muted);font-size:.68rem}
  .credit-usage-billing{display:flex;justify-content:space-between;align-items:center;margin-top:.35rem;padding-top:.65rem;border-top:1px solid var(--border);color:var(--accent);font-size:.76rem;font-weight:600;text-decoration:none}
  .credit-usage-billing:hover{text-decoration:underline}
  .menu{position:absolute;top:calc(100% + 6px);left:0;min-width:230px;background:var(--surface);border:1px solid var(--border);
    border-radius:13px;box-shadow:var(--shadow);padding:.4rem;z-index:30;opacity:0;transform:translateY(-6px) scale(.98);
    pointer-events:none;transition:.16s}
  .picker.open .menu{opacity:1;transform:none;pointer-events:auto}
  .menu .opt{display:flex;align-items:flex-start;gap:.6rem;padding:.55rem .6rem;border-radius:9px;font-size:.88rem;transition:.12s;width:100%;text-align:left}
  .menu .opt:hover{background:var(--surface-2)}
  .menu .opt small{display:block;color:var(--muted);font-size:.76rem;font-weight:400}
  .menu .opt .check{margin-left:auto;color:var(--accent);opacity:0}
  .menu .opt.sel .check{opacity:1}
  .menu .opt svg{width:16px;height:16px}
  .grow{flex:1}
  /* ---------- messages ---------- */
  .scroll{
    flex:1;
    min-height:0;
    overflow-y:auto;
  }
  .stream{position:relative;max-width:760px;margin:0 auto;padding:2rem 1.4rem 1rem;display:flex;flex-direction:column}
  .stream > .msg + .msg{margin-block-start:2rem}
  .msg{display:flex;gap:.9rem;animation:rise .45s cubic-bezier(.2,.7,.3,1) both}
  .msg.me{direction:ltr}
  .msg.ai{direction:ltr}
  @keyframes rise{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
  .msg .ava{width:30px;height:30px;border-radius:9px;flex:none;display:grid;place-items:center}
  .msg.me .ava{border-radius:50%;background:var(--surface-3);color:var(--text);font-weight:600;font-size:.8rem}
  .msg.me .ava .user-ava-image{width:100%;height:100%;object-fit:cover;border-radius:50%}
  .msg .body{min-width:0;flex:1}
  .prose{color:var(--text-2)}
  .prose bdi[dir="ltr"]{direction:ltr;unicode-bidi:isolate}
  .prose p{margin:.2rem 0 .7rem}
  .prose p:last-child{margin-bottom:0}
  .prose strong{color:var(--text);font-weight:600}
  .prose a{color:var(--accent);text-underline-offset:3px}
  .prose ul{margin:.3rem 0 .8rem;padding-left:1.1rem;display:flex;flex-direction:column;gap:.25rem}
  .prose li::marker{color:var(--accent)}
  .prose code:not(pre code){font-family:var(--mono);font-size:.85em;background:var(--surface-2);
    border:1px solid var(--border-soft);padding:.1em .4em;border-radius:6px;color:var(--text)}
  /* ---------- rendered Markdown (live during streaming) ---------- */
  .prose h1,.prose h2,.prose h3,.prose h4,.prose h5,.prose h6{
    color:var(--text);font-weight:600;line-height:1.3;margin:1.05rem 0 .5rem;letter-spacing:-.01em}
  .prose h1{font-size:1.35rem}
  .prose h2{font-size:1.18rem}
  .prose h3{font-size:1.05rem}
  .prose h4,.prose h5,.prose h6{font-size:.96rem}
  .prose h1:first-child,.prose h2:first-child,.prose h3:first-child{margin-top:.1rem}
  .prose ol{margin:.3rem 0 .8rem;padding-left:1.35rem;display:flex;flex-direction:column;gap:.25rem}
  .prose li{margin:0}
  .prose li::marker{color:var(--accent)}
  .prose blockquote{margin:.5rem 0 .8rem;padding:.35rem .9rem;border-left:3px solid var(--accent);
    background:var(--surface-2);border-radius:0 8px 8px 0;color:var(--muted)}
  .prose blockquote p:last-child{margin-bottom:0}
  .prose hr{border:0;border-top:1px solid var(--border-soft);margin:1rem 0}
  .prose del{opacity:.65}
  .prose .table-wrap{margin:.5rem 0 .9rem;overflow-x:auto;border:1px solid var(--border-soft);border-radius:10px}
  .prose table{border-collapse:collapse;width:100%;font-size:.88rem}
  .prose th,.prose td{padding:.45rem .7rem;text-align:left;border-bottom:1px solid var(--border-soft)}
  .prose thead th{background:var(--surface-2);color:var(--text);font-weight:600;white-space:nowrap}
  .prose tbody tr:last-child td{border-bottom:0}
  .prose .code-block{margin:.5rem 0 .9rem;padding:.8rem 1rem;overflow-x:auto;font-family:var(--mono);
    font-size:12.5px;line-height:1.7;background:var(--surface);border:1px solid var(--border);border-radius:12px}
  .prose .code-block code{font-family:inherit;background:none;border:0;padding:0;color:var(--text-2);white-space:pre}
  /* KaTeX sizing inside chat bubbles */
  :is(.prose, .bubble) .katex{font-size:1.03em;direction:ltr;unicode-bidi:isolate}
  :is(.prose, .bubble) .katex-display{margin:.7rem 0;overflow-x:auto;overflow-y:hidden;padding:2px 0}
  :is(.prose, .bubble) .math-inline{direction:ltr;unicode-bidi:isolate;white-space:nowrap}
  :is(.prose, .bubble) .math-display{display:block;max-width:100%;overflow-x:auto;direction:ltr;unicode-bidi:isolate;text-align:left}
  :is(.prose, .bubble) .math-display .katex-display{width:max-content;min-width:100%;margin:.55rem 0;text-align:left}
  .prose .cmath{margin:.7rem 0}
  .prose .cmath .katex-display{margin:0}
  :is(.prose, .bubble) .math-equation-box{position:relative;display:inline-flex;align-items:center;max-width:100%;margin:.1rem .12rem;padding:.12rem .28rem;
    border:1px solid var(--border-soft);border-radius:6px;background:var(--surface-2);direction:ltr;unicode-bidi:isolate;vertical-align:middle}
  :is(.prose, .bubble) .math-equation-box.math-equation-display{display:block;width:fit-content;margin:.8rem 0 .5rem;padding:.35rem .55rem}
  :is(.prose, .bubble) .math-equation-box>.math-display,:is(.prose, .bubble) .math-equation-box>.cmath{max-width:100%;margin:0}
  :is(.prose, .bubble) .math-equation-actions{position:absolute;z-index:8;top:-.28rem;right:.25rem;display:flex;gap:.2rem;padding:.2rem;
    border:1px solid var(--border-soft);border-radius:7px;background:var(--surface);box-shadow:var(--shadow);
    opacity:0;visibility:hidden;pointer-events:none;transform:translateY(-100%);transition:opacity .12s ease}
  :is(.prose, .bubble) .math-equation-actions::after{content:"";position:absolute;top:100%;right:0;left:0;height:.4rem}
  :is(.prose, .bubble) .math-equation-box:focus-within .math-equation-actions,
  :is(.prose, .bubble) .math-equation-box.is-actions-open .math-equation-actions{opacity:1;visibility:visible;pointer-events:auto}
  :is(.prose, .bubble) .math-equation-copy{min-height:28px;padding:.3rem .5rem;border:0;border-radius:5px;background:transparent;color:var(--text-2);
    font-family:inherit;font-size:.7rem;font-weight:600;line-height:1.1;white-space:nowrap;cursor:pointer}
  :is(.prose, .bubble) .math-equation-copy:hover,:is(.prose, .bubble) .math-equation-copy:focus-visible{outline:none;background:var(--surface-3);color:var(--text)}
  :is(.prose, .bubble) .math-equation-copy.is-copied{color:var(--accent)}
  .prose .jsxgraph-figure{
    width:min(100%,640px);
    height:320px;
    margin:.8rem 0 1rem;
    overflow:hidden;
    border:1px solid var(--border);
    border-radius:8px;
    background:var(--surface);
  }
  .prose .jsxgraph-figure .JXGtext{
    font-family:var(--font)!important;
    font-size:11px!important;
    fill:var(--text-2)!important;
  }
  .prose .jsxgraph-figure.jsxgraph-error{
    display:flex;
    align-items:center;
    justify-content:center;
    padding:1rem;
    color:var(--muted);
    font-size:.9rem;
  }
  .prose .jsxgraph-figure.jsxgraph-loading{
    display:grid;
    place-items:center;
    color:var(--muted);
    font-size:.9rem;
  }
  @media(max-width:640px){
    .prose .jsxgraph-figure{height:250px}
  }
  /* user bubble — the bubble is its own scroll box, so a formula wider than
     the bubble scrolls inside it instead of running over the edge. */
  .msg.me .body{display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-end;gap:.35rem}
  .msg.me .bubble{background:var(--surface-2);border:1px solid var(--border-soft);padding:.7rem 1rem;border-radius:14px 14px 4px 14px;
    max-width:80%;min-width:0;overflow-wrap:anywhere;overflow-x:auto;overflow-y:hidden}
  .message-actions{display:flex;align-items:center;gap:3px}
  .message-actions:empty{display:none}
  .message-actions button,.act{width:30px;height:30px;display:grid;place-items:center;border-radius:7px;color:var(--muted);transition:background-color .14s,color .14s}
  .message-actions button:hover,.act:hover{background:var(--surface-2);color:var(--text)}
  .message-actions button:focus-visible,.act:focus-visible,.response-cost-trigger:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
  .message-actions svg,.act svg{width:15px;height:15px}
  .message-regenerate:disabled{opacity:.4;cursor:default}
  .chat-page[dir="rtl"] .msg.me .bubble{direction:rtl;text-align:right}

  @media(max-width:640px){
    .stream{padding-left:.5rem;padding-right:.5rem}
    .msg.ai{gap:0}
    .msg.ai .body{width:auto;min-width:0;flex:1}
  }

  /* code block */
  .code{margin:.5rem 0 .2rem;border:1px solid var(--border);border-radius:12px;overflow:hidden;background:var(--surface);box-shadow:var(--shadow)}
  .code .head{display:flex;align-items:center;gap:.5rem;padding:.45rem .75rem;background:var(--surface-2);border-bottom:1px solid var(--border-soft);
    font:500 11px/1 var(--mono);color:var(--muted)}
  .code .head .lang{color:var(--text-2)}
  .code .head .dots{display:flex;gap:5px}
  .code .head .dots i{width:9px;height:9px;border-radius:50%;background:var(--surface-3)}
  .code .copy{margin-left:auto;display:flex;align-items:center;gap:.35rem;font:500 11px/1 var(--mono);color:var(--muted);
    padding:.3em .5em;border-radius:6px;transition:.12s}
  .code .copy:hover{background:var(--surface-3);color:var(--text)}
  .code .copy svg{width:13px;height:13px}
  .code pre{margin:0;padding:.85rem 1rem;overflow-x:auto;font-family:var(--mono);font-size:12.5px;line-height:1.7;color:var(--text-2)}
  .code pre code{white-space:pre}
  .code .hljs-comment,.code .hljs-quote{color:var(--muted)}
  .code .hljs-keyword,.code .hljs-selector-tag,.code .hljs-literal,.code .hljs-built_in{color:var(--accent)}
  .code .hljs-string,.code .hljs-attr,.code .hljs-template-tag{color:#4d9259}
  .code .hljs-number,.code .hljs-symbol,.code .hljs-variable{color:#4d82b9}
  .code .kw{color:var(--accent)}
  .code .st{color:#7fd88f}.code .fn{color:#6fb7ff}.code .cm{color:var(--muted)}
  :root[data-theme="light"] .code .st{color:#128a3a}
  :root[data-theme="light"] .code .fn{color:#1f6feb}

  /* message actions */
  .actions{--response-action-size:28px;display:flex;align-items:center;flex-wrap:wrap;gap:2px;margin-top:.35rem}
  .actions .act{flex:none;width:var(--response-action-size);height:var(--response-action-size);border-radius:6px}
  .actions .act svg{stroke-width:1.6}
  @media(hover:none),(pointer:coarse){
    .actions{--response-action-size:36px}
  }
  .answer-copy svg[hidden],.message-copy svg[hidden]{display:none}
  .actions .answer-copy[data-copied="true"],.actions .response-feedback-button[aria-pressed="true"]{color:var(--text);background:var(--surface-2)}
  .message-copy[data-copied="true"]{color:var(--accent);background:var(--accent-weak)}
  @media (hover: hover) and (pointer: fine) {
    .msg:not(:hover):not(:has(:focus-visible,[data-copied="true"])) .message-actions {
      opacity: 0;
      pointer-events: none;
    }
  }
  .response-cost{position:relative;margin-inline-start:3px;font-size:.72rem;color:var(--muted);white-space:nowrap}
  .response-cost-trigger{display:flex;align-items:center;gap:5px;min-height:var(--response-action-size);padding:0 6px;
    border-radius:6px;font-variant-numeric:tabular-nums;list-style:none;cursor:pointer}
  .response-cost-trigger::-webkit-details-marker{display:none}
  .response-cost-trigger::after{content:"";width:4px;height:4px;margin-top:-2px;border:solid currentColor;border-width:0 1px 1px 0;transform:rotate(45deg)}
  .response-cost-trigger:hover,.response-cost details[open]>.response-cost-trigger{background:var(--surface-2);color:var(--text)}
  .response-cost details[open]>.response-cost-trigger::after{margin-top:2px;transform:rotate(225deg)}
  .response-cost-panel{display:none;position:absolute;bottom:100%;inset-inline-end:0;z-index:20;min-width:max-content;
    padding:4px;border:1px solid var(--border);border-radius:9px;background:var(--surface);box-shadow:var(--shadow)}
  .response-cost:has(details[open]) .response-cost-panel,.response-cost-panel:focus-within{display:block}
  @media (hover:hover){
    .response-cost:hover .response-cost-panel{display:block}
  }
  .response-cost-panel a{display:block;padding:.4rem .55rem;border-radius:5px;color:var(--text);text-decoration:none}
  .response-cost-breakdown{margin:0 0 .2rem;padding:.3rem .55rem;border-bottom:1px solid var(--border-soft)}
  .response-cost-breakdown>div{display:flex;justify-content:space-between;gap:.75rem}
  .response-cost-breakdown dt,.response-cost-breakdown dd{margin:0;font-weight:400}
  .response-cost-panel a:hover,.response-cost-panel a:focus-visible{background:var(--surface-2);color:var(--text)}
  .response-feedback-status{order:1;color:var(--muted);font-size:.7rem}
  .response-feedback-status:empty{display:none}

  .feedback-dialog:not([open]){display:none}
  .feedback-dialog[open]{display:flex}
  .feedback-dialog{
    position:fixed;inset:max(12px,env(safe-area-inset-top)) 12px max(12px,var(--chat-bottom,0px),env(safe-area-inset-bottom)) 12px;
    width:min(520px,calc(100% - 24px));height:fit-content;max-height:calc(100% - max(12px,env(safe-area-inset-top)) - max(12px,var(--chat-bottom,0px),env(safe-area-inset-bottom)));
    margin:auto;padding:0;border:1px solid var(--border);border-radius:16px;overflow:hidden;
    background:var(--surface);color:var(--text);box-shadow:var(--shadow)
  }
  .feedback-dialog::backdrop{background:rgb(12 15 20 / .52)}
  .feedback-form{display:flex;flex-direction:column;min-height:0;width:100%}
  .feedback-header,.feedback-footer{display:flex;flex:none;align-items:center;padding:10px 15px;background:var(--surface-2)}
  .feedback-header{justify-content:space-between;border-bottom:1px solid var(--border-soft)}
  .feedback-header h2{margin:0;font-size:1rem;font-weight:650}
  .feedback-body{min-height:0;overflow:auto;overscroll-behavior:contain;padding:14px 15px}
  .feedback-reasons{margin:0;padding:0;border:0}
  .feedback-reasons[hidden],.feedback-error[hidden]{display:none}
  .feedback-reasons legend{float:none;width:auto;margin:0 0 8px;font-size:.83rem;font-weight:650}
  .feedback-options{display:flex;flex-wrap:wrap;gap:6px}
  .feedback-options label{position:relative;display:inline-flex;max-width:100%;cursor:pointer}
  .feedback-options input{position:absolute;width:1px;height:1px;opacity:0}
  .feedback-options span{display:flex;align-items:center;min-height:34px;padding:4px 9px;border:1px solid var(--border-soft);
    border-radius:8px;background:var(--surface-2);color:var(--text-2);font-size:.8rem}
  .feedback-options label:hover span{border-color:var(--accent)}
  .feedback-options input:checked+span{border-color:var(--accent);background:var(--accent-weak);color:var(--text)}
  .feedback-options input:focus-visible+span{outline:2px solid var(--accent);outline-offset:1px}
  .feedback-comment{display:grid;gap:5px;margin-top:13px;color:var(--text);font-size:.8rem;font-weight:600}
  .feedback-comment textarea{width:100%;min-height:68px;max-height:160px;padding:8px 10px;border:1px solid var(--border);border-radius:9px;
    background:var(--surface-2);color:var(--text);font:400 16px/1.45 var(--font);resize:vertical}
  .feedback-comment textarea:focus{outline:2px solid var(--accent);outline-offset:-1px}
  .feedback-help,.feedback-error{margin:.55rem 0 0;color:var(--muted);font-size:.76rem;line-height:1.4}
  .feedback-error{color:var(--thread-danger)}
  .feedback-footer{justify-content:flex-end;border-top:1px solid var(--border-soft)}
  .feedback-submit{min-height:34px;padding:5px 13px;border-radius:8px;font-size:.8rem;font-weight:650}
  .feedback-submit:disabled{opacity:.55;cursor:wait}
  .stream-error{display:flex;align-items:center;gap:.55rem;margin:.15rem 0;color:#ff8e7a;font-size:.9rem}
  .stream-error .retry{padding:.35rem .55rem;border:1px solid currentColor;border-radius:7px;font:500 11px/1 var(--mono)}
  .stream-error .retry:hover{background:color-mix(in srgb,currentColor 12%,transparent)}
  /* out-of-quota card (server sends it with the 429) */
  .limit-card{border:1px solid var(--border-soft);border-radius:14px;background:var(--surface-2);padding:.9rem 1rem;max-width:540px}
  .limit-head{display:flex;align-items:center;gap:.5rem;margin-bottom:.45rem;color:var(--text)}
  .limit-badge{font:600 10px/1 var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--accent);
    background:var(--accent-weak);padding:.3em .5em;border-radius:5px;flex:none}
  .limit-wait{margin:.2rem 0 .3rem;color:var(--text-2);font-size:.9rem}
  .limit-wait b{color:var(--text)}
  .limit-card-credits{padding:1rem 1.1rem}
  .limit-credit-title{margin:.65rem 0 .2rem;color:var(--text);font-size:1rem;font-weight:650}
  .limit-reset{margin:.35rem 0 0;color:var(--text-2);font-size:.9rem}
  .limit-actions{display:flex;align-items:center;gap:1rem;flex-wrap:wrap;margin-top:.7rem}
  .limit-report{color:var(--muted);font-size:.82rem;text-underline-offset:3px}
  .limit-report:hover,.limit-report:focus-visible{color:var(--text)}
  .limit-label{font:600 10.5px/1 var(--mono);letter-spacing:.09em;text-transform:uppercase;color:var(--muted);margin:.75rem 0 .4rem}
  .limit-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:.3rem}
  .limit-list li{display:flex;align-items:center;justify-content:space-between;gap:.8rem;padding:.35rem .6rem;
    border-radius:9px;background:var(--surface);font-size:.86rem;color:var(--text-2)}
  .limit-list li b{font:500 12px/1 var(--mono);color:var(--text)}
  .limit-list li.out{color:#ff8e7a}
  .limit-list li.out b{color:#ff8e7a}
  .limit-upgrade{margin:.8rem 0 0;font-size:.86rem;color:var(--muted)}
  .limit-cta{display:inline-flex;align-items:center;margin-top:.7rem;padding:.5rem .9rem;border-radius:10px;
    background:var(--accent);color:var(--accent-ink);font-weight:600;font-size:.88rem;text-decoration:none;transition:.14s}
  .limit-cta:hover{filter:brightness(1.08)}
  .act.done{color:var(--accent)}

  .chat-quiz-heading{display:flex;align-items:center;justify-content:space-between;gap:.6rem;margin-bottom:.65rem}
  .chat-quiz-heading .chat-quiz-title{margin:0}
  .chat-quiz-copy{display:inline-flex;align-items:center;gap:.3rem;flex:none;padding:.32rem .48rem;border:1px solid var(--border-soft);border-radius:6px;background:transparent;color:var(--muted);font:inherit;font-size:.72rem;cursor:pointer}
  .chat-quiz-copy:hover,.chat-quiz-copy:focus-visible{background:var(--surface-2);color:var(--text)}
  .chat-quiz-copy svg{width:14px;height:14px}
  .chat-quiz-copy[data-copied="true"]{color:var(--accent)}
  .test-copy{display:inline-flex;align-items:center;justify-content:center;gap:.35rem;min-height:var(--assistant-header-control);padding:0 .45rem;border:1px solid var(--border-soft);border-radius:6px;background:transparent;color:var(--text-2);font:inherit;font-size:.76rem;cursor:pointer}
  .test-copy:hover,.test-copy:focus-visible{background:var(--surface-2);color:var(--text)}
  .test-copy:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
  .test-copy svg{width:15px;height:15px}
  .test-copy:disabled{opacity:.45;cursor:default}
  .test-copy[data-copied="true"]{color:var(--accent)}

  .assistant-progress{
    color:var(--text-2);
    font-size:.8rem;
    line-height:1.4;
    overflow-wrap:anywhere;
  }
  .assistant-progress-toggle{
    display:flex;
    align-items:center;
    gap:.45rem;
    max-width:100%;
    min-height:1.65rem;
    padding:0;
    border:0;
    background:none;
    color:inherit;
    text-align:start;
    font:inherit;
    cursor:pointer;
  }
  .assistant-progress-toggle:hover{color:var(--text)}
  .assistant-progress-toggle:focus-visible{outline:1px solid currentColor;outline-offset:-1px}
  .assistant-progress-icon{
    flex:0 0 1rem;
    text-align:center;
    line-height:1;
    color:var(--muted);
  }
  .assistant-progress-icon::before{content:"✓"}
  .assistant-progress[data-state="running"] > .assistant-progress-toggle .assistant-progress-icon::before{
    content:"";
    display:inline-block;
    box-sizing:border-box;
    width:.7rem;
    height:.7rem;
    border:1px solid currentColor;
    border-inline-end-color:transparent;
    border-radius:50%;
    color:var(--accent);
    animation:assistant-progress-spin 1s linear infinite;
  }
  .assistant-progress-step[aria-current] .assistant-progress-icon::before{content:"●";color:var(--accent);font-size:.65rem}
  .assistant-progress:is([data-state="stopped"],[data-state="failed"]) > .assistant-progress-toggle .assistant-progress-icon::before,
  .assistant-progress:is([data-state="stopped"],[data-state="failed"]) .assistant-progress-step:last-child .assistant-progress-icon::before{content:"–"}
  .assistant-progress-chevron{
    flex:none;
    width:.34rem;
    height:.34rem;
    border-inline-end:1px solid currentColor;
    border-block-end:1px solid currentColor;
    transform:rotate(45deg);
    transition:transform 180ms ease;
    margin-inline:.1rem .25rem;
  }
  .assistant-progress[dir="rtl"] .assistant-progress-chevron{transform:rotate(-45deg)}
  .assistant-progress-step .assistant-progress-chevron{transform:rotate(-45deg)}
  .assistant-progress[dir="rtl"] .assistant-progress-step .assistant-progress-chevron{transform:rotate(45deg)}
  .assistant-progress .assistant-progress-toggle[aria-expanded="true"] .assistant-progress-chevron{transform:rotate(225deg)}
  .assistant-progress[dir="rtl"] .assistant-progress-toggle[aria-expanded="true"] .assistant-progress-chevron{transform:rotate(135deg)}
  .assistant-progress .assistant-progress-step .assistant-progress-toggle[aria-expanded="true"] .assistant-progress-chevron{transform:rotate(45deg)}
  .assistant-progress[dir="rtl"] .assistant-progress-step .assistant-progress-toggle[aria-expanded="true"] .assistant-progress-chevron{transform:rotate(-45deg)}
  .assistant-progress-panel{
    display:grid;
    grid-template-rows:0fr;
    visibility:hidden;
    transition:grid-template-rows 180ms ease,visibility 180ms;
  }
  .assistant-progress-toggle[aria-expanded="true"] + .assistant-progress-panel{
    grid-template-rows:1fr;
    visibility:visible;
  }
  .assistant-progress-panel-content{min-height:0;overflow:clip}
  .assistant-progress .assistant-progress-list{
    list-style:none;
    margin:0;
    padding:0;
    padding-inline-start:.5rem;
  }
  .assistant-progress-step{
    position:relative;
    padding-inline-start:.45rem;
  }
  .assistant-progress-step::before{
    content:"";
    position:absolute;
    inset-block:0;
    inset-inline-start:0;
    border-inline-start:1px solid var(--border);
  }
  .assistant-progress-step:last-child::before{inset-block-end:auto;height:.83rem}
  .assistant-progress-step::after{
    content:"";
    position:absolute;
    inset-block-start:.83rem;
    inset-inline-start:0;
    width:.45rem;
    border-block-start:1px solid var(--border);
    pointer-events:none;
  }
  .assistant-progress-detail{
    margin-inline-start:1.45rem;
    padding-block-end:.25rem;
    font-size:.76rem;
  }
  @keyframes assistant-progress-spin{to{transform:rotate(1turn)}}
  @supports (background-clip:text){
    @media(prefers-reduced-motion:no-preference) and (forced-colors:none){
      .assistant-progress[data-state="running"] > .assistant-progress-toggle .assistant-progress-label{
        background:linear-gradient(90deg,var(--text-2) 40%,var(--text) 50%,var(--text-2) 60%) 100% 0 / 250% 100% no-repeat;
        background-clip:text;
        color:transparent;
        animation:assistant-progress-shimmer 2.4s linear infinite;
      }
      .assistant-progress[dir="rtl"] > .assistant-progress-toggle .assistant-progress-label{animation-direction:reverse}
    }
  }
  @keyframes assistant-progress-shimmer{to{background-position:0 0}}
  @media(prefers-reduced-motion:reduce){
    .assistant-progress .assistant-progress-icon::before{animation:none!important}
    .assistant-progress-chevron,.assistant-progress-panel{transition:none}
  }
  .direct-steps-toggle{display:inline-flex;align-items:center;gap:6px;min-height:30px;margin:0 0 .35rem;padding:3px 8px;
    border:1px solid var(--border-soft);border-radius:8px;background:var(--surface-2);color:var(--text-2);
    font:600 .8rem/1.3 var(--font);text-align:start;transition:background-color .15s,border-color .15s,color .15s}
  .direct-steps-toggle svg{width:15px;height:15px;color:var(--accent)}
  .direct-steps-toggle[aria-expanded="true"]{background:var(--accent-weak);border-color:color-mix(in srgb,var(--accent) 35%,var(--border))}
  .direct-steps-toggle::after{content:"";width:.42rem;height:.42rem;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;
    transform:rotate(45deg) translateY(-.1rem);transition:transform .15s}
  .direct-steps-toggle[aria-expanded="true"]::after{transform:rotate(225deg) translateY(-.1rem)}
  .direct-steps-toggle:hover{border-color:color-mix(in srgb,var(--accent) 55%,var(--border));background:var(--accent-weak);color:var(--text)}
  .direct-steps-toggle:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
  .direct-steps[hidden],.direct-steps-toggle[hidden]{display:none}
  .direct-steps{margin:.25rem 0 .8rem;padding-inline-start:.75rem;border-inline-start:2px solid var(--border);overflow-x:auto;color:var(--muted)}
  .direct-final{color:var(--text)}
  .caret{display:inline-block;width:8px;height:1.05em;background:var(--accent);border-radius:1px;vertical-align:text-bottom;
    margin-left:2px;animation:caret .9s steps(1) infinite}
  .prose.is-streaming>:last-child::after{content:"";display:inline-block;width:2px;height:1em;margin-left:.2em;
    vertical-align:-.15em;background:var(--accent);animation:caret .9s steps(1) infinite}
  @keyframes caret{50%{opacity:0}}
  .prose .stream-word{display:inline-block;animation:stream-word-in .2s ease-out both;animation-delay:var(--stream-word-delay,0ms)}
  @keyframes stream-word-in{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}
  @media(prefers-reduced-motion:reduce){.prose .stream-word{animation:none}}

  /* ---------- composer ---------- */
  .composer-wrap{padding:.5rem 1.4rem 1.3rem;background:linear-gradient(to top,var(--bg) 55%,transparent);
    flex:0 0 auto;min-height:0}
  .composer{position:relative;isolation:isolate;max-width:760px;margin:0 auto;background:var(--surface);border:1px solid var(--border);border-radius:16px;
    box-shadow:var(--shadow);transition:border-color .15s}
  /* The composer — and the LaTeX keypad that opens inside it — paint on top of
     the empty state, so the suggestion chips sit *behind* the input and the
     keypad instead of floating over them. */
  .composer-wrap{position:relative;z-index:2}
  .composer:focus-within{border-color:color-mix(in srgb,var(--accent) 60%,var(--border))}
    .composer.is-live-flash,.composer.is-live-flash:focus-within {
      border-color: var(--accent);
      box-shadow: var(--shadow),0 0 18px color-mix(in srgb,var(--accent) 30%,transparent);
    }
    .composer.is-live-flash::before {
      position: absolute;
      z-index: 2;
      inset: 0;
      padding: 1.5px;
      border-radius: inherit;
      background: conic-gradient(from var(--book-live-angle), transparent 0deg,
        color-mix(in srgb,var(--accent) 75%,#111) 52deg,
        color-mix(in srgb,var(--accent) 68%,#fff) 78deg,
        var(--accent) 102deg, transparent 150deg 360deg);
      content: "";
      pointer-events: none;
      -webkit-mask: linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
      -webkit-mask-composite: xor;
      mask: linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
      mask-composite: exclude;
      animation: book-live-orbit 2.8s linear infinite;
    }
  .composer-editor-wrap{position:relative;--editor-block-padding:.62rem;--editor-inline-padding:.85rem;--editor-font-size:.96rem}
  .composer-input-editor,.composer-placeholder{box-sizing:border-box;color:var(--text);font-family:inherit;font-size:var(--editor-font-size);line-height:1.5}
  .composer-input-editor{width:100%;min-height:44px;max-height:200px;padding:var(--editor-block-padding) var(--editor-inline-padding) .3rem;
    overflow:auto;overflow-wrap:anywhere;white-space:pre-wrap;outline:none;scrollbar-width:thin}
  .composer-placeholder{display:none;position:absolute;inset-block-start:var(--editor-block-padding);inset-inline:var(--editor-inline-padding);
    color:var(--muted);pointer-events:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .composer-editor-wrap[data-empty] .composer-placeholder{display:block}
  .composer-token-error{margin:0;padding:0 1.05rem .45rem;color:#ff8e7a;font-size:.78rem;line-height:1.4}
  :root[data-theme="light"] .composer-token-error{color:#b42318}
  .composer-equation-token{display:inline-flex;max-width:100%;align-items:center;gap:.2rem;vertical-align:middle;margin:0 .12rem;padding:.1rem .22rem;
    border:1px solid var(--border);border-radius:6px;background:var(--surface-2);color:var(--text);white-space:nowrap}
  .composer-equation-render{max-width:min(100%,32rem);overflow-x:auto}
  .composer-equation-remove{display:grid;flex:none;width:20px;height:20px;place-items:center;border:0;border-radius:4px;background:transparent;color:var(--muted);cursor:pointer;font-size:1rem;line-height:1}
  .composer-equation-remove:hover,.composer-equation-remove:focus-visible{outline:none;background:var(--surface-3);color:var(--text)}
  .composer-context{display:flex;flex-wrap:wrap;gap:.35rem;padding:.55rem .8rem 0}
  .composer-context[hidden]{display:none}
  .composer-context-item{display:inline-flex;align-items:center;gap:.45rem;max-width:100%;min-height:28px;padding:.2rem .35rem .2rem .6rem;
    border:1px solid var(--border);border-radius:7px;background:var(--surface-2);color:var(--text-2);font-size:.74rem;line-height:1.2}
  .composer-context-item span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  .composer-context-item button{display:grid;flex:none;width:20px;height:20px;place-items:center;border-radius:5px;color:var(--muted);font-size:1rem;line-height:1}
  .composer-context-item button:hover{background:var(--surface-3);color:var(--text)}

  .composer-menu-cost{margin-inline-start:auto;color:var(--muted);font-size:.68rem;font-weight:600;white-space:nowrap}
  .credit-estimate{position:relative;flex:none}
  .credit-estimate>summary{list-style:none}
  .credit-estimate>summary::-webkit-details-marker{display:none}
  .credit-estimate-toggle{display:flex;align-items:center;justify-content:center;gap:5px;min-width:28px;min-height:32px;
    padding:0 5px;border-radius:7px;color:var(--text-2);font-size:.78rem;line-height:1;cursor:pointer;white-space:nowrap}
  .credit-estimate-toggle strong{font-weight:600;font-variant-numeric:tabular-nums}
  .credit-estimate-toggle::after{content:"";width:5px;height:5px;margin-top:-2px;border:solid currentColor;
    border-width:0 1px 1px 0;transform:rotate(45deg)}
  .credit-estimate[open]>.credit-estimate-toggle::after{margin-top:2px;transform:rotate(225deg)}
  .credit-estimate-toggle:hover,.credit-estimate[open]>.credit-estimate-toggle{background:var(--surface-2);color:var(--text)}
  .credit-estimate-toggle:focus-visible{outline:2px solid currentColor;outline-offset:1px}
  .credit-estimate-popover{position:absolute;z-index:50;right:0;bottom:calc(100% + 8px);box-sizing:border-box;
    width:min(14rem,calc(100vw - 5rem));width:min(14rem,calc(100cqi - 5rem));padding:.75rem;
    border:1px solid var(--border);border-radius:9px;background:var(--surface);box-shadow:var(--shadow);color:var(--text-2);
    font-size:.8rem;line-height:1.4}
  .credit-estimate-heading{margin:0 0 .4rem;color:var(--text);font-size:inherit;font-weight:600}
  .credit-estimate-popover dl{margin:0}
  .credit-estimate-popover dl>div{display:flex;align-items:baseline;justify-content:space-between;gap:.75rem;padding-block:.2rem;
    overflow-wrap:anywhere}
  .credit-estimate-popover dl>div[hidden]{display:none}
  .credit-estimate-popover dd{flex:none;max-inline-size:70%;margin:0;color:var(--text);font-variant-numeric:tabular-nums;text-align:end}
  .credit-estimate-popover .credit-estimate-total{margin-top:.4rem;padding-block:.5rem 0;
    border-block-start:1px solid var(--border);color:var(--text);font-weight:600}

  .c-tools{display:flex;align-items:center;gap:.35rem;padding:.4rem .55rem .55rem;min-width:0}
  .composer-actions,.composer-settings,.composer-submit{display:flex;align-items:center;gap:.3rem;min-width:0}
  .composer-actions,.composer-submit{flex:none}
  .composer-settings{flex:1 1 auto;justify-content:flex-end}
  .composer-actions{gap:.4rem}
  .c-tools .icon-btn{width:32px;height:32px}
  .c-tools .icon-btn svg{width:16px;height:16px}
  .c-tools .icon-btn.on{background:var(--accent-weak);color:var(--accent);border-color:color-mix(in srgb,var(--accent) 45%,transparent)}
  .composer-menu{position:relative;flex:none}
  .composer-menu>summary{display:grid;place-items:center;list-style:none;cursor:pointer}
  .composer-menu>summary::-webkit-details-marker{display:none}
  .composer-menu-trigger svg{transition:transform .16s ease}
  .composer-menu[open] .composer-menu-trigger{background:var(--accent-weak);color:var(--accent)}
  .composer-menu[open] .composer-menu-trigger svg{transform:rotate(45deg)}
  .composer-menu-panel{position:absolute;z-index:40;inset-inline-start:0;bottom:calc(100% + 9px);width:min(240px,calc(100vw - 2rem));
    display:none;gap:2px;max-height:min(60vh,360px);overflow-y:auto;padding:6px;border:1px solid var(--border);border-radius:11px;background:var(--surface);box-shadow:var(--shadow);
    animation:solve-menu-in .14s ease-out}
  .composer-menu[open]>.composer-menu-panel{display:grid}
  .composer-menu-action{box-sizing:border-box;display:flex;width:100%;min-width:0;max-width:100%;height:40px;min-height:40px;max-height:40px;align-items:center;gap:.65rem;overflow:hidden;padding:.45rem .55rem;border:0;border-radius:7px;
    background:transparent;color:var(--text-2);font:inherit;font-size:.8rem;font-weight:550;text-align:start;white-space:nowrap;text-overflow:ellipsis;cursor:pointer}
  .composer-menu-action svg{width:17px;height:17px;flex:none}
  .composer-menu-action>span{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis}
  .composer-menu-action .composer-menu-cost{flex:none}
  .composer-menu-action:hover,.composer-menu-action:focus-visible{outline:none;background:var(--surface-2);color:var(--text)}
  .composer-menu-action.on{background:var(--accent-weak);color:var(--accent)}
  .composer-menu-action:disabled{opacity:.6;cursor:wait}
  .composer-menu-action.test-mode-toggle,.composer-menu-action.book-select-toggle{height:40px;min-height:40px;max-height:40px;padding:.45rem .55rem;border:0;border-radius:7px;white-space:nowrap}
  .composer-menu-action.test-mode-toggle:hover,.composer-menu-action.test-mode-toggle.on,
  .composer-menu-action.book-select-toggle:hover,.composer-menu-action.book-select-toggle[aria-expanded="true"]{border:0;background:var(--surface-2);color:var(--text)}
  .composer-menu-action.test-mode-toggle.on{background:var(--accent-weak);color:var(--accent)}
  .composer-menu-action.test-mode-toggle:disabled{opacity:.6;cursor:wait}

  /* ---------- fixed answer mode ---------- */
  .mode{position:relative}
  .mode-fixed{display:flex;align-items:center;gap:.35rem;height:32px;padding:0 .55rem;
    color:var(--text-2);font-size:.82rem;font-weight:500;white-space:nowrap}
  .mode-fixed .mode-emoji{font-size:.9rem;line-height:1}
  .test-mode-toggle{height:32px;padding:0 .65rem;border:1px solid var(--border-soft);border-radius:8px;
    background:var(--surface-2);color:var(--text-2);font:inherit;font-size:.75rem;font-weight:600;white-space:nowrap;cursor:pointer}
  .test-mode-toggle:hover,.test-mode-toggle.on{border-color:var(--accent);background:var(--accent-weak);color:var(--accent)}
  .test-mode-toggle:disabled{opacity:.6;cursor:wait}
  .book-select-toggle{height:32px;padding:0 .65rem;border:1px solid var(--border-soft);border-radius:8px;
    background:var(--surface-2);color:var(--text-2);font:inherit;font-size:.75rem;font-weight:600;white-space:nowrap;cursor:pointer}
  .book-select-toggle:hover,.book-select-toggle[aria-expanded="true"]{border-color:var(--accent);background:var(--accent-weak);color:var(--accent)}
  .book-select-dialog[open]{position:fixed;inset:0;display:grid;place-items:center;width:100%;height:100%;max-width:none;max-height:none;box-sizing:border-box;margin:0;padding:1rem;border:0;color:var(--text);background:transparent}
  .book-select-dialog::backdrop{background:rgb(0 0 0 / .48)}
  .book-select-panel{width:min(720px,100%);max-height:min(80vh,680px);overflow:auto;padding:1rem;border:1px solid var(--border);
    border-radius:12px;background:var(--surface);box-shadow:var(--shadow)}
  .book-select-head{display:flex;align-items:center;justify-content:space-between;gap:1rem;margin-bottom:1rem}
  .book-select-head h2{margin:0;color:var(--text);font-size:1.1rem}
  .book-select-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:.75rem}
  .book-select-grid[hidden]{display:none}
  .book-select-grid .book-card{width:100%;height:100%}
  .book-select-grid .book-card[aria-pressed="true"]{outline:2px solid var(--accent);outline-offset:2px}
  .book-select-empty{margin:.5rem 0;color:var(--muted)}
  .book-select-head .book-library-back{margin-inline-end:.25rem}
  .book-select-head .book-library-back[hidden]{display:none}
  .test-count-control select{height:32px;max-width:120px;padding:0 .45rem;border:1px solid var(--border-soft);
    border-radius:8px;background:var(--surface-2);color:var(--text-2);font:inherit;font-size:.72rem}
  .test-count-control[hidden]{display:none}
  .subscription-source-control select{height:32px;max-width:190px;padding:0 .45rem;border:1px solid var(--border-soft);
    border-radius:8px;background:var(--surface-2);color:var(--text-2);font:inherit;font-size:.72rem}
  .subscription-source-control[hidden]{display:none}
  .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}

  /* ---------- solve mode (normal / direct / step_by_step / hint) ---------- */
  .solve{position:relative;flex:0 0 auto}
  .solve-trigger{display:flex;align-items:center;gap:.4rem;height:32px;padding:0 .6rem;
    border:1px solid var(--border-soft);border-radius:9px;background:var(--surface-2);
    color:var(--text-2);font-size:.78rem;font-weight:600;white-space:nowrap;cursor:pointer}
  .solve-trigger:hover,.solve-trigger[aria-expanded="true"]{background:var(--surface-3);color:var(--text)}
  .solve-trigger svg{width:14px;height:14px;transition:transform .16s ease}
  .solve-trigger[aria-expanded="true"] > svg{transform:rotate(180deg)}
  .solve-menu{position:absolute;z-index:30;inset-inline-start:0;bottom:calc(100% + 8px);width:min(250px,calc(100vw - 2rem));
    padding:5px;border:1px solid var(--border);border-radius:11px;background:var(--surface);
    box-shadow:var(--shadow);animation:solve-menu-in .14s ease-out}
  .solve-menu[hidden]{display:none}
  .solve-floating .solve-menu{position:fixed;z-index:1201;inset-inline-start:auto;bottom:auto;
    max-height:min(60dvh,280px);overflow-y:auto;overscroll-behavior:contain}
  @keyframes solve-menu-in{from{opacity:0;transform:translateY(5px)}to{opacity:1;transform:translateY(0)}}
  .solve-btn{display:flex;width:100%;align-items:center;justify-content:space-between;gap:.75rem;
    padding:.55rem .65rem;border-radius:7px;color:var(--text);text-align:start;cursor:pointer}
  .solve-btn:hover,.solve-btn:focus-visible{background:var(--surface-2);outline:none}
  .solve-btn.on{color:var(--accent);background:var(--accent-weak)}
  .solve-btn:disabled{align-items:flex-start;flex-direction:column;gap:.2rem;opacity:.58;cursor:not-allowed;
    box-shadow:inset 0 0 0 1px var(--border-soft),0 1px 4px rgb(0 0 0 / .14)}
  .solve-btn:disabled:hover,.solve-btn:disabled:focus-visible{background:transparent}
  .solve-btn span{font-size:.82rem;font-weight:600;white-space:nowrap}
  .solve-btn small{color:var(--muted);font-size:.7rem;text-align:end}
  .solve-btn .solve-unavailable{color:var(--text-2);font-weight:600;text-align:start}
  .chat-column{container-type:inline-size;container-name:chat-column}
  @container chat-column (max-width:620px){
    .c-tools{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:.3rem .4rem}
    .composer-actions{grid-column:1;grid-row:1}
    .composer-settings{grid-column:2;grid-row:1;justify-content:flex-start;flex-wrap:nowrap;overflow-x:auto;overscroll-behavior-inline:contain;scrollbar-width:none;padding-bottom:0}
    .composer-submit{grid-column:3;grid-row:1}
    .composer-settings .solve{order:-1}
    .composer-settings::-webkit-scrollbar{display:none}
    .mode-fixed{display:none}
    .subscription-source-control select,.solve-trigger{height:34px}
  }
  @container chat-column (max-width:420px){
    .test-count-control select,.subscription-source-control select{max-width:130px}
    .solve-trigger{gap:.2rem;padding-inline:.45rem}
  }
  @container chat-column (max-width:460px){
    .composer-settings:has(.subscription-source-control:not([hidden])){display:contents}
    .composer-settings:has(.subscription-source-control:not([hidden])) .solve{grid-column:2;grid-row:1;justify-self:start}
    .subscription-source-control{grid-column:1 / -1;grid-row:2;min-width:0}
    .subscription-source-control select{width:100%;max-width:none}
  }
  @media(max-width:640px){
    .solve-menu{max-height:min(60dvh,280px);overflow-y:auto;overscroll-behavior:contain}
  }
  @media (prefers-reduced-motion:reduce){.solve-menu,.composer-menu-panel,.solve-trigger svg,.composer-menu-trigger svg{animation:none;transition:none}}

  /* ---------- MathLive keyboard ---------- */
  .math-kb {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 760px;
    max-height: min(420px, calc(100dvh - var(--chat-top, 0px) - var(--chat-bottom, 0px) - 8.5rem));
    margin: .5rem auto 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  .math-kb[hidden] { display: none; }

  .math-kb-field {
    flex: none;
    min-width: 0;
    min-height: 44px;
    padding: .45rem .7rem;
    border: 0;
    border-bottom: 1px solid var(--border-soft);
    border-radius: 0;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1rem;
    --caret-color: var(--accent);
    --selection-background-color: var(--accent-weak);
  }
  .math-kb-field:focus-within {
    outline: none;
    border-bottom-color: var(--accent);
  }
  .math-kb-field::part(virtual-keyboard-toggle) { display: none; }

  .math-kb-keys {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    --keyboard-background: var(--surface);
    --keyboard-accent-color: var(--accent);
    --keyboard-horizontal-rule: 1px solid var(--border);
    --keyboard-toolbar-text: var(--text-2);
    --keyboard-toolbar-text-active: var(--text);
    --keyboard-toolbar-background-hover: var(--surface-3);
    --keyboard-toolbar-background-selected: var(--surface-2);
    --keycap-height: clamp(26px, 7dvh, 52px);
    --keycap-background: var(--surface-2);
    --keycap-background-hover: var(--surface-3);
    --keycap-border: var(--border);
    --keycap-border-bottom: var(--border);
    --keycap-text: var(--text);
    --keycap-text-active: var(--accent-ink);
    --keycap-text-pressed: var(--accent-ink);
    --keycap-secondary-background: var(--surface-3);
    --keycap-secondary-background-hover: var(--surface-2);
    --keycap-secondary-border: var(--border);
    --keycap-secondary-border-bottom: var(--border);
    --keycap-secondary-text: var(--text-2);
    --keycap-primary-background-hover: var(--accent);
    --keycap-primary-text: var(--accent-ink);
    --variant-panel-background: var(--surface);
  }

  /* Let the embedded keyboard take up its own space in the composer. */
  .math-kb-keys > .ML__keyboard { height: auto; }
  .math-kb-keys > .ML__keyboard.is-visible > .MLK__backdrop {
    position: static;
    height: auto;
    transform: none;
  }
  .math-kb-keys .MLK__plate {
    position: static;
    width: 100%;
  }
  .math-kb-keys .MLK__rows > .MLK__row > :is(.shift, .action) {
    align-items: center;
    justify-content: center;
    padding: 2px 4px;
  }
  .math-kb-keys .MLK__row > div > :is(.svg-glyph, .svg-glyph-lg) { margin: 0; }

  /* Compound formulas need more room than single-character key labels. */
  .math-kb-keys .MLK__keycap > .ML__latex:has(.ML__large-op) {
    font-size: min(1em, 2.6cqw, max(8px, 3dvh));
  }
  .math-kb-keys .MLK__keycap > .ML__latex:has(.ML__stretchy) {
    font-size: min(1em, max(10px, 3.35dvh));
  }
  .math-kb-keys .MLK__shift:has(.ML__stretchy) { top: 10px; }

  @media (max-height: 420px) {
    .math-kb-keys {
      --keycap-font-size: 16px;
      --keycap-glyph-size: 16px;
      --keycap-glyph-size-lg: 20px;
    }
  }

  .math-kb-footer {
    display: flex;
    flex: none;
    align-items: center;
    gap: .35rem;
    padding: .25rem .5rem;
    border-top: 1px solid var(--border-soft);
    background: var(--surface-2);
  }
  .math-kb-latex {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font: .72rem/1.4 var(--mono);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .math-kb-footer .icon-btn { flex: none; }
  .math-kb-footer .math-kb-insert { color: var(--accent); }

  .count{margin-left:auto;font:400 11px/1 var(--mono);color:var(--muted);padding-right:.4rem}
  .count.out{color:#ff8e7a}
  .send{width:34px;height:34px;border-radius:10px;display:grid;place-items:center;background:var(--accent);color:var(--accent-ink);
    transition:.15s;flex:none}
  .send:disabled{background:var(--surface-3);color:var(--muted);cursor:not-allowed}
  .send:not(:disabled):hover{filter:brightness(1.08);transform:translateY(-1px)}
  .send svg{width:16px;height:16px;color:#fff}
  .send.stop{background:var(--surface-3);color:var(--text)}
  .hint{max-width:760px;margin:.55rem auto 0;text-align:center;font-size:11.5px;color:var(--muted)}
  .hint kbd{font-family:var(--mono);background:var(--surface-2);border:1px solid var(--border-soft);border-bottom-width:2px;
    padding:.05em .4em;border-radius:5px;font-size:.9em}

  /* ---------- empty state ---------- */
  .suggest{display:grid;grid-template-columns:1fr 1fr;gap:.6rem;max-width:760px;margin:.4rem auto 0}
  .chip[hidden]{display:none!important}
  .chip{text-align:left;padding:.8rem .95rem;border:1px solid var(--border-soft);border-radius:12px;background:var(--surface);
    -webkit-tap-highlight-color:transparent;
    transition:.14s}
  .chip:hover{border-color:var(--accent);background:var(--surface-2);transform:translateY(-2px)}
  .chip b{display:block;font-weight:500;font-size:.9rem;margin-bottom:.15rem}
  .chip span{font-size:.8rem;color:var(--muted)}

  /* ---------- empty state on phones ------------------------------------
     One chip per row, comfortable to tap, and every row the same height so
     the list reads as a list instead of ragged blocks. */
  @media(max-width:640px){
    .suggest{grid-template-columns:1fr;gap:.5rem;margin-top:.2rem;align-content:start}
    .chip{display:flex;flex-direction:column;justify-content:center;min-height:58px;padding:.7rem .85rem;
      border-radius:14px}
    .chip b{font-size:.95rem;line-height:1.25;margin-bottom:.2rem}
    .chip span{font-size:.8rem;line-height:1.35}
    .chip:hover{transform:none;background:var(--surface)}
    .chip:active{background:var(--surface-2);border-color:var(--accent);transform:scale(.99)}
  }

  @media (min-width: 641px) {
    #camera-btn { display: none !important; }
  }

@media (max-width: 820px), (max-width: 1400px) and (any-pointer: coarse) {

    .chat-page {
        margin-left: 0;
    }

    .chat-page .app,
    .chat-page .app.collapsed {
        grid-template-columns: 1fr;
    }

    /* The chat drawer lives in the content area, NOT over the site header:
       it starts where .chat-page starts and runs to the bottom of the screen.
       That way the drawer keeps its full height (brand header included) and
       the site header keeps its full height too — neither covers the other. */
    .chat-page .chat-sidebar {
        position: fixed;
        top: var(--header-height, 0px);
        left: 0;
        right: auto;
        bottom: 0;

        width: 264px;
        height: auto;

        /* #app sets z-index:1, which creates a stacking context. This value is
           therefore resolved inside that context — it must only beat .main. */
        z-index: 1090;

        transform: translateX(-100%);
        transition: transform 0.2s;
    }

    .chat-page .app.nav-open .chat-sidebar {
        transform: none;
        box-shadow: var(--shadow);
    }

    .chat-page .menu-btn {
        display: grid;
    }

    /* Scrim matches the drawer: below the site header so the header stays
       fully visible and usable while the history is open. */
    .chat-page .scrim {
        position: fixed;
        top: var(--header-height, 0px);
        left: var(--chat-left, 0px);
        right: 0;
        bottom: 0;

        z-index: 1080;

        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 220ms ease;
    }

    .chat-page .app.nav-open .scrim {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 820px) {
    .chat-page .main-sidebar-btn {
      display: grid;
    }

    /* Phones: the composer must always stay visible above the URL bar /
       on-screen keyboard. Give it a real (non-zero) share of the flex
       column, respect the home-indicator inset, and let the math keyboard
       scroll internally instead of pushing the composer off screen. */
    .chat-page .composer-wrap {
        flex: 0 0 auto;
        padding: .35rem .55rem .45rem;
    }

    .chat-page .composer-editor-wrap {
      --editor-inline-padding: .7rem;
      --editor-block-padding: .5rem;
    }

    .chat-page .composer-input-editor {
      min-height: 40px;
      max-height: clamp(52px, calc((100dvh - var(--chat-bottom, 0px)) * .22), 128px);
    }

    .chat-page .c-tools {
      gap: .3rem .4rem;
    } 

    .chat-page .math-kb:not([hidden]) {
      position: fixed;
      inset-inline: 0;
      bottom: var(--chat-bottom, 0px);
      z-index: 1200;
      max-height: min(520px, calc(100dvh - var(--chat-top, 0px) - var(--chat-bottom, 0px)));
      margin: 0 auto;
      padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
      padding-bottom: env(safe-area-inset-bottom, 0px);
      border-radius: 12px 12px 0 0;
    }

    .chat-page .app.math-kb-active { z-index: 1200; }
}
  /* reasoning ("thinking") collapsible */
  .thinking{border:1px solid var(--border-soft);border-radius:11px;background:var(--surface-2);margin:0 0 .8rem;overflow:hidden}
  .th-head{display:flex;align-items:center;gap:.5rem;padding:.55rem .8rem;cursor:pointer;font-size:.85rem;color:var(--muted);user-select:none}
  .th-head:hover{color:var(--text-2)}
  .th-head .spark{width:14px;height:14px;color:var(--accent);flex:none}
  .th-head .chev2{width:14px;height:14px;margin-left:auto;transition:.2s}
  .thinking.open .th-head .chev2{transform:rotate(90deg)}
  .th-body{display:none;padding:0 .8rem .7rem 2rem;font-size:.85rem;color:var(--muted);line-height:1.55}
  .thinking.open .th-body{display:block;padding-top:.1rem}

  /* tool / agent-step chips */
  .tools{display:flex;flex-direction:column;gap:.4rem;margin:0 0 .85rem}
  .tool{border:1px solid var(--border-soft);border-radius:10px;background:var(--surface-2);overflow:hidden}
  .t-head{display:flex;align-items:center;gap:.55rem;padding:.5rem .75rem;cursor:pointer;font-size:.85rem;user-select:none;color:var(--text-2)}
  .t-head .ti{width:15px;height:15px;color:var(--accent);flex:none}
  .t-head b{font-family:var(--mono);font-weight:500;font-size:.82rem}
  .t-head .status{margin-left:auto;font:500 11px/1 var(--mono);color:var(--accent);display:flex;align-items:center;gap:.3rem}
  .t-head .status svg{width:13px;height:13px}
  .t-body{display:none;padding:0 .75rem .6rem 2.05rem;font-family:var(--mono);font-size:11.5px;color:var(--muted)}
  .tool.open .t-body{display:block}

  /* inline citations + source cards */
  .cite{display:inline-flex;align-items:center;justify-content:center;min-width:15px;height:15px;padding:0 3px;margin:0 1px;
    font:600 9px/1 var(--mono);color:var(--accent);background:var(--accent-weak);border-radius:4px;vertical-align:super;text-decoration:none}
  .cite:hover{background:var(--accent);color:var(--accent-ink)}
  .sources-label{font:600 10.5px/1 var(--mono);letter-spacing:.09em;text-transform:uppercase;color:var(--muted);margin:.9rem 0 .5rem}
  .sources{display:grid;grid-template-columns:1fr 1fr;gap:.5rem}
  @media(max-width:640px){.sources{grid-template-columns:1fr}}
  .src-card{display:flex;gap:.6rem;align-items:center;padding:.55rem .7rem;border:1px solid var(--border-soft);border-radius:10px;background:var(--surface);transition:.12s}
  .src-card:hover{border-color:var(--accent);background:var(--surface-2)}
  .src-card .n{width:18px;height:18px;flex:none;border-radius:5px;background:var(--accent-weak);color:var(--accent);display:grid;place-items:center;font:600 10px/1 var(--mono)}
  .src-card .s-body{min-width:0}
  .src-card .s-title{font-size:.82rem;font-weight:500;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .src-card .s-url{font:400 11px/1.3 var(--mono);color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

  /* attachments (image thumbnails sitting above the composer textarea) */
  .attachs{display:flex;flex-wrap:wrap;gap:.5rem;padding:.7rem .8rem .1rem}
  .attachs[hidden]{display:none}
  /* The paperclip drives this input. Park it off-screen instead of leaving it
     display:none, which is the form some mobile browsers refuse to open. */
  .composer input[type="file"][hidden]{display:block;position:absolute;left:-9999px;width:1px;height:1px;opacity:0}
  .attach-chip{position:relative;width:76px;height:76px;flex:none;border-radius:11px;overflow:hidden;
    border:1px solid var(--border-soft);background:var(--surface-2)}
  .attach-chip img{width:100%;height:100%;object-fit:cover;display:block;cursor:zoom-in}
  .attach-chip .rm{position:absolute;top:3px;right:3px;width:20px;height:20px;border-radius:50%;display:grid;place-items:center;
    background:rgba(10,11,14,.72);color:#fff;font:600 11px/1 var(--mono);transition:.12s}
  .attach-chip .rm:hover{background:#e5484d}
  .composer.drag-over{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 10%,var(--surface))}

  /* images inside a sent message bubble */
  .msg.me .bubble .message-images{display:flex;flex-wrap:wrap;gap:.4rem;margin-top:.5rem}
  .msg.me .bubble .message-images.notext{margin-top:0}
  .msg.me .bubble .message-images img{width:132px;height:132px;object-fit:cover;display:block;cursor:zoom-in;
    border-radius:10px;border:1px solid var(--border-soft);background:var(--surface-3)}
  .msg.me .bubble .message-images.one img{width:180px;height:180px}

  /* LaTeX typed with the math keyboard renders inside the user bubble too. */
  .msg.me .bubble .katex{font-size:1.02em}
  .msg.me .bubble .katex-display{margin:.4rem 0;max-width:100%;overflow-x:auto;overflow-y:hidden}
  .msg.me .bubble p{margin:0}
  .msg.me .bubble p+p{margin-top:.5rem}

  @media (max-width:520px){
    .attach-chip{width:64px;height:64px}
    .msg.me .bubble{max-width:88%}
    .msg.me .bubble .message-images img{width:104px;height:104px}
    .msg.me .bubble .message-images.one img{width:150px;height:150px}
  }

  /* full-size image viewer, opened from an attachment thumbnail */
  .img-viewer{position:fixed;inset:0;z-index:120;display:flex;align-items:center;justify-content:center;
    padding:1.5rem;background:rgba(6,7,10,.85);animation:imgv-in .16s ease}
  .img-viewer[hidden]{display:none}
  .img-viewer img{max-width:min(92vw,1100px);max-height:86vh;object-fit:contain;border-radius:14px;
    box-shadow:0 30px 80px -20px rgba(0,0,0,.85)}
  .img-viewer .close{position:absolute;top:1rem;right:1rem;width:38px;height:38px;border-radius:50%;display:grid;place-items:center;
    background:var(--surface);border:1px solid var(--border);color:var(--text);transition:.12s}
  .img-viewer .close:hover{background:var(--surface-3)}
  .img-viewer .close svg{width:18px;height:18px}
  @keyframes imgv-in{from{opacity:0}to{opacity:1}}
  .msg-img{width:150px;height:98px;border-radius:10px;display:grid;place-items:center;color:var(--muted);font-size:.7rem;
    border:1px solid var(--border-soft);background:linear-gradient(135deg,var(--surface-3),var(--accent-weak))}

  /* error + retry state */
  .errbox{display:flex;align-items:center;gap:.7rem;padding:.7rem .85rem;border:1px solid var(--warn);background:var(--warn-soft);border-radius:11px}
  .errbox>svg{width:18px;height:18px;color:var(--warn);flex:none}
  .errbox .e-txt{font-size:.86rem;color:var(--text-2)}
  .errbox .e-txt b{color:var(--warn);font-weight:600}
  .retry{margin-left:auto;display:flex;align-items:center;gap:.4rem;padding:.42rem .8rem;border:1px solid var(--warn);border-radius:8px;
    color:var(--warn);font-weight:500;font-size:.84rem;background:transparent;transition:.12s;flex:none}
  .retry:hover{background:var(--warn);color:#fff}
  .retry svg{width:14px;height:14px}

  @media(prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
  
.chat-page {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;

    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -.005em;
}

.app {
    position: relative;
    z-index: 1;

    display: grid;
    grid-template-columns: 288px minmax(0, 1fr);

    width: 100%;
    height: 100%;
    min-height: 0;
}


.main {
    display: flex;
    flex-direction: column;

    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}




.scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-column {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  container-type: inline-size;
  container-name: chat-column;
}

.workspace {
    display: flex;
    flex-direction: row;
  direction: ltr;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    transition: width 220ms ease;
}

@media (min-width: 821px) {
  .chat-page .main > .topbar,
  .chat-page .chat-sidebar .brand {
    border-block-color: transparent;
  }

  /* Anchor the outline to the shell so opening chat history cannot move its corner. */
  .chat-page .app::after {
    content: "";
    position: absolute;
    inset: calc(var(--assistant-header-height) - 1px) 0 0;
    z-index: 1;
    pointer-events: none;
    border-top: 1px solid var(--assistant-frame-border);
    border-left: 1px solid var(--assistant-frame-border);
    border-top-left-radius: 14px;
  }

  .chat-page .app:not(.nav-open) > .chat-sidebar {
    border-right-color: transparent;
  }

  body.layout-fixed:has(.chat-page) #site-sidebar {
    border-right-color: transparent;
    box-shadow: none;
  }

  .chat-page .app.nav-open::after {
    z-index: 1091;
  }

  .chat-page .compact-workspace .workspace-toolbar > :is(.book-head,.test-head) {
    border-top-color: transparent;
  }

  .main:not(.compact-workspace):has(.book-pane.open, .test-pane.open) {
    --open-tool-pane-width: min(50%, 700px);
  }

  .main:not(.compact-workspace):has(.book-pane.open, .test-pane.open) > :is(.topbar,.workspace) {
    width: calc(100% - var(--open-tool-pane-width));
    margin-left: 0;
    margin-right: auto;
  }

  .main:not(.compact-workspace):has(.book-pane.open, .test-pane.open) > .workspace {
    overflow: visible;
  }

  .main:not(.compact-workspace) :is(.book-pane,.test-pane).open {
    position: absolute;
    inset: 0 0 0 auto;
    z-index: 2;
    width: var(--open-tool-pane-width);
    max-width: none;
    border-left-color: var(--border-soft);
    flex: 0 0 var(--open-tool-pane-width);
    transition: width 220ms ease, border-color 220ms ease;
  }

  .main:not(.compact-workspace) .workspace:not(.fill-book,.fill-test) :is(.book-head,.test-head) {
    border-bottom-color: var(--assistant-frame-border);
  }

  .main:has(.workspace.fill-book) > .topbar,
  .main:has(.workspace.fill-test) > .topbar,
  .main:has(.workspace.fill-book) > .workspace,
  .main:has(.workspace.fill-test) > .workspace {
    width: 100%;
    margin-inline: 0;
  }
}

  .book-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: var(--assistant-header-control);
    padding: 0 .55rem;
    border: 1px solid var(--border-soft);
    border-radius: 9px;
    color: var(--text-2);
    font-size: .78rem;
    white-space: nowrap;
    transition: background .14s, color .14s, border-color .14s;
  }
  .book-toggle:hover,.book-toggle.on {
    background: var(--accent-weak);
    border-color: color-mix(in srgb,var(--accent) 45%,var(--border));
    color: var(--accent);
  }
  .book-toggle svg { width: 17px; height: 17px; flex: none; }

  .book-pane {
    container: book-pane / inline-size;
    position: relative;
    display: flex;
    flex: 0 0 0;
    flex-direction: column;
    width: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--surface);
    border-left: 1px solid transparent;
    transition: flex-basis 220ms ease, border-color 220ms ease;
  }
  .book-pane.open {
    flex-basis: min(50%, 700px);
    border-left-color: var(--border-soft);
  }
  @property --book-live-angle {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
  }
  .book-pane.is-live-flash {
    border-left-color: var(--accent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--accent) 75%,#111),
      0 0 20px color-mix(in srgb,var(--accent) 30%,transparent);
  }
  .book-pane.is-live-flash::before {
    position: absolute;
    z-index: 4;
    inset: 0;
    padding: 1.5px;
    background: conic-gradient(from var(--book-live-angle), transparent 0deg,
      color-mix(in srgb,var(--accent) 75%,#111) 52deg,
      color-mix(in srgb,var(--accent) 68%,#fff) 78deg,
      var(--accent) 102deg, transparent 150deg 360deg);
    content: "";
    pointer-events: none;
    -webkit-mask: linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
    mask-composite: exclude;
    animation: book-live-orbit 2.8s linear infinite;
  }
  @keyframes book-live-orbit { to { --book-live-angle: 360deg; } }
  @media (prefers-reduced-motion: reduce) {
    .book-pane.is-live-flash::before { animation-duration: 8s; }
  }
  .book-live-status {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    margin: .45rem .65rem;
    padding: .45rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: .75rem;
    line-height: 1.4;
  }
  .book-live-status[hidden] { display: none; }
  .book-live-status > span { flex: 1 1 auto; min-width: 0; }
  .book-live-status-close {
    display: grid;
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    place-items: center;
    margin: -.2rem -.25rem 0 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
  }
  .book-live-status-close:hover { background: color-mix(in srgb,var(--accent) 14%,transparent); color: var(--accent); }
  .book-live-status-close svg { width: 16px; height: 16px; }
  .book-head { min-width: 0; color: var(--text); font-size: .84rem; }
  .book-head > b { flex: none; }
  .book-head:has(.book-back[hidden]) .book-filename,
  .book-head:has(.book-back:not([hidden])) > b,
  .book-page-label { display: none; }
  .book-head-controls {
    display: flex;
    min-width: 0;
  }
  .book-head-controls[hidden], .book-toolbar[hidden] { display: none; }
  .book-back[hidden] { display: none; }
  .book-toolbar { display: flex; align-items: center; gap: .35rem; min-width: 0; }
  .book-toolbar-group { display: flex; align-items: center; gap: .2rem; }
  .pane-head-actions { display: flex; align-items: center; gap: 2px; flex: none; margin-inline-start: auto; }
  .pane-head-actions .icon-btn[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); }
  .book-head .pane-head-actions .icon-btn { margin: 0; }
  .book-back svg { width: 15px; height: 15px; }
  .book-head:dir(rtl) .book-back svg { transform: scaleX(-1); }
  .book-filename {
    flex: 1 1 5rem;
    min-width: 0;
    margin-left: .25rem;
    overflow: hidden;
    color: var(--muted);
    font-size: .76rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .book-library-label {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: .72rem;
  }
  .book-library-select {
    width: min(30%, 190px);
    min-width: 90px;
    height: 30px;
    flex: 0 1 auto;
    padding: 0 .4rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .75rem;
    text-overflow: ellipsis;
  }
  .book-file-button {
    flex: 0 0 auto;
    padding: .32rem .55rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-2);
    cursor: pointer;
    font-size: .76rem;
    line-height: 1.3;
  }
  .book-file-button:hover { border-color: var(--accent); color: var(--text); }
  .book-file-input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .book-head [data-book-close] { margin: 0; }
  .book-control {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border: 1px solid var(--border-soft);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 1rem;
    line-height: 1;
  }
  .book-control:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
  .book-control:disabled { opacity: .4; cursor: not-allowed; }
  .book-control.book-live-toggle {
    display: inline-flex;
    width: auto;
    min-width: 84px;
    height: var(--assistant-header-control);
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: 0 .45rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 650;
  }
  .book-live-toggle[aria-checked="true"] {
    border-color: color-mix(in srgb,var(--accent) 70%,#111);
    background: color-mix(in srgb,var(--accent) 14%,var(--surface));
    color: var(--accent);
  }
  .book-live-track {
    display: inline-flex;
    width: 28px;
    height: 16px;
    flex: 0 0 28px;
    align-items: center;
    padding: 2px;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    background: var(--surface-3);
    transition: background .18s,border-color .18s;
  }
  .book-live-track > span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
    transition: transform .18s,background .18s;
  }
  .book-live-toggle[aria-checked="true"] .book-live-track {
    border-color: var(--accent);
    background: color-mix(in srgb,var(--accent) 28%,var(--surface));
  }
  .book-live-toggle[aria-checked="true"] .book-live-track > span {
    transform: translateX(12px);
    background: var(--accent);
  }
  .book-head:dir(rtl) .book-live-toggle[aria-checked="true"] .book-live-track > span { transform: translateX(-12px); }
  .book-page-label,.book-page-total,.book-zoom { color: var(--muted); font-size: .76rem; white-space: nowrap; }
  .book-page-number {
    width: 48px;
    height: 30px;
    border: 1px solid var(--border-soft);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    text-align: center;
    font: inherit;
    font-size: .78rem;
  }
  .book-page-number:disabled { opacity: .55; }
  .book-toolbar-spacer { flex: 1 1 auto; }
  .book-zoom { min-width: 38px; text-align: center; }
  .book-control.book-fit { width: auto; padding: 0 .45rem; font-size: .74rem; }
  .book-page-area {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 8px;
    background: var(--bg);
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .book-page-area canvas {
    display: block;
    flex: 0 0 auto;
    max-width: none;
    height: auto;
    align-self: flex-start;
    margin: 0;
    background: white;
    box-shadow: 0 2px 12px rgba(0,0,0,.28);
    cursor: grab;
    touch-action: none;
    user-select: none;
  }
  .book-page-area canvas.is-panning {
    cursor: grabbing;
  }
  .book-status:not([hidden]) ~ .book-canvas-stack {
    visibility: hidden;
  }
  .book-status {
    position: absolute;
    top: 50%;
    left: 50%;
    width: max-content;
    max-width: calc(100% - 32px);
    transform: translate(-50%,-50%);
    color: var(--muted);
    font-size: .88rem;
    text-align: center;
  }
  .book-status.is-loading { display: flex; align-items: center; justify-content: center; gap: .65rem; }
  .book-status.is-loading::before { content: ""; width: 16px; height: 16px; flex: 0 0 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: book-upload-spin .8s linear infinite; }
  .book-status[hidden] { display: none; }
  .book-upload-progress { position: absolute; top: calc(50% + 26px); left: 50%; display: flex; width: min(320px, calc(100% - 48px)); align-items: center; gap: .6rem; transform: translateX(-50%); }
  .book-upload-progress[hidden] { display: none; }
  .book-upload-progress-track { height: 6px; flex: 1 1 auto; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
  .book-upload-progress-track > span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .12s linear; }
  .book-upload-progress-value { min-width: 3ch; color: var(--text-2); font-size: .75rem; font-variant-numeric: tabular-nums; text-align: end; }

  .book-library {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 1.1rem;
    background: var(--bg);
  }
  .book-library[hidden],.book-viewer[hidden] { display: none; }
  .book-library-view[hidden] { display: none; }
  .book-library-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
  .book-library-heading h2 { margin: 0; color: var(--text); font-size: 1.05rem; font-weight: 650; }
  .book-library-heading p { margin: .15rem 0 0; color: var(--muted); font-size: .78rem; }
  .book-library-status { display: flex; align-items: flex-start; gap: .65rem; margin: 0 0 .85rem; padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text-2); font-size: .84rem; line-height: 1.45; }
  .book-library-status[hidden] { display: none; }
  .book-library-status.is-loading::before { content: ""; width: 15px; height: 15px; flex: 0 0 15px; margin-top: .08rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: book-upload-spin .8s linear infinite; }
  @keyframes book-upload-spin { to { transform: rotate(360deg); } }
  .book-upload { display: inline-flex; align-items: center; gap: .4rem; min-height: 34px; flex: 0 0 auto; padding: 0 .65rem;
    border: 1px solid var(--border); border-radius: 7px; color: var(--text-2); cursor: pointer; font-size: .76rem; }
  .book-upload:hover { border-color: var(--accent); color: var(--text); }
  .book-upload svg { width: 16px; height: 16px; }
  .book-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(132px,1fr)); gap: .85rem; }
  .book-folder-card,.book-add-card {
    display: grid;
    width: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 3 / 4;
    align-content: center;
    justify-items: center;
    gap: .6rem;
    padding: 1rem;
    border-radius: 8px;
    font: inherit;
    text-align: center;
    cursor: pointer;
  }
  .book-folder-card { border: 1px solid var(--border-soft); background: var(--surface); color: var(--text-2); }
  .book-folder-card:hover { border-color: var(--accent); background: var(--surface-2); color: var(--text); }
  .book-folder-card svg { width: 48px; height: 48px; color: var(--accent); }
  .book-folder-card span,.book-add-card > span:last-child { font-size: .82rem; font-weight: 600; }
  .book-folder-card small { max-width: 100%; overflow: hidden; color: var(--muted); font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
  .book-add-card {
    border: 2px dotted var(--border);
    background: transparent;
    color: var(--text-2);
    transition: border-color .15s,background .15s,color .15s;
  }
  .book-add-card:hover { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); }
  .book-add-icon { display: grid; width: 48px; height: 48px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 2rem; font-weight: 300; line-height: 1; }
  .book-library-back { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border: 1px solid var(--border-soft); border-radius: 6px; background: var(--surface); color: var(--text-2); font-size: 1.3rem; cursor: pointer; }
  .book-library-back:hover { border-color: var(--accent); color: var(--accent); }
  .book-org-title { flex: 1 1 auto; }
  .book-org-join { display: grid; min-height: 160px; place-items: center; }
  .book-org-join a { padding: .7rem 1rem; border: 1px solid var(--border); border-radius: 7px; color: var(--accent); font-size: .86rem; text-decoration: none; }
  .book-org-join a:hover { border-color: var(--accent); background: var(--accent-weak); }
  .book-card-shell { position: relative; min-width: 0; }
  .book-card { display: flex; min-width: 0; flex-direction: column; gap: .45rem; padding: .5rem; border: 1px solid var(--border-soft);
    width: 100%; border-radius: 8px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; transition: border-color .14s,background .14s,transform .14s; }
  .book-card:hover,.book-card[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-2); }
  .book-card:hover { transform: translateY(-2px); }
  .book-card-cover { position: relative; display: grid; width: 100%; aspect-ratio: 3 / 4; place-items: center; overflow: hidden; border-radius: 5px; background: var(--surface-3); }
  .book-card-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .book-cover-placeholder { display: grid; width: 48%; aspect-ratio: 1; place-items: center; color: var(--muted); }
  .book-cover-placeholder svg { width: 100%; height: 100%; }
  .book-cover-placeholder:not(:has(svg)) { font-size: .8rem; font-weight: 700; }
  .book-delete { position: absolute; top: .7rem; right: .7rem; display: grid; width: 28px; height: 28px; place-items: center;
    border: 1px solid rgba(255,255,255,.22); border-radius: 5px; background: rgba(10,11,14,.78); color: #fff; cursor: pointer; }
  .book-delete:hover { background: #9c2d2d; }
  .book-delete:disabled { opacity: .55; cursor: wait; }
  .book-delete svg { width: 15px; height: 15px; }
  .book-card-type { position: absolute; right: 6px; bottom: 6px; padding: .1rem .3rem; border-radius: 3px; background: rgba(10,11,14,.76); color: #fff; font: 600 9px/1.4 var(--mono); }
  .book-card-name { display: -webkit-box; min-height: 2.5em; overflow: hidden; color: var(--text-2); font-size: .77rem; line-height: 1.3; overflow-wrap: anywhere; line-clamp: 2; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .book-library-empty { grid-column: 1 / -1; margin: .5rem 0; color: var(--muted); font-size: .84rem; }
  .book-viewer { display: flex; flex: 1 1 auto; min-width: 0; min-height: 0; flex-direction: column; }
  .book-canvas-stack { position: relative; width: max-content; flex: 0 0 auto; margin: 0; }
  .book-canvas-stack #book-canvas { position: relative; z-index: 0; }
  @media (max-width: 720px) {
    .book-library { padding: .75rem; }
    .book-grid { grid-template-columns: repeat(auto-fill,minmax(105px,1fr)); gap: .55rem; }
    .book-back { margin-left: 0; }
    .book-head .icon-btn { margin-left: 0; }
  }

  .test-pane {
    display: flex;
    flex: 0 0 0;
    flex-direction: column;
    width: 0;
    min-width: 0;
    overflow: hidden;
    background: var(--surface);
    border-left: 1px solid transparent;
    transition: flex-basis 220ms ease, border-color 220ms ease;
  }
  .test-pane.open {
    flex-basis: min(50%, 700px);
    border-left-color: var(--border-soft);
  }

  .book-pane:not(.open),
  .test-pane:not(.open) {
    display: none;
  }

  .test-head { color: var(--text); }
  .test-head h2 { min-width: 0; margin: 0; margin-inline-end: auto; color: var(--text); font-size: .84rem; font-weight: 650; }
  .test-head > button { flex-shrink: 0; }
  .test-head > [hidden] { display: none; }
  .test-subtitle { color: var(--muted); font-size: .72rem; }
  .test-new { min-height:var(--assistant-header-control);padding:0 .55rem;border:1px solid var(--border);border-radius:7px;
    background:var(--surface);color:var(--text);font:inherit;font-size:.75rem;font-weight:600;cursor:pointer }
  .test-new:hover { background:var(--surface-3) }
  .test-body { flex: 1 1 auto; min-width: 0; min-height: 0; overflow: auto; padding: 1rem; }
  .test-history { border-bottom:1px solid var(--border-soft) }
  .test-history summary { padding:.5rem .15rem;color:var(--text-2);font-size:.82rem;font-weight:650;cursor:pointer }
  .test-history summary:focus-visible { outline:2px solid var(--accent);outline-offset:-2px;border-radius:6px }
  .test-history-list { display:grid;gap:.35rem;max-height:180px;overflow:auto;margin-bottom:.8rem }
  .test-history-item { display:grid;gap:.2rem;width:100%;padding:.55rem .65rem;border:1px solid var(--border-soft);
    border-radius:7px;background:var(--surface);color:var(--text);text-align:left;cursor:pointer }
  .test-history-item:hover { border-color:var(--accent);background:var(--surface-2) }
  .test-history-title { overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.78rem;font-weight:600 }
  .test-history-detail,.test-history-empty { color:var(--muted);font-size:.7rem }
  .test-history-empty { margin:.2rem 0 }
  .test-settings {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    align-items: end;
    gap: .5rem;
    padding-bottom: .9rem;
    border-bottom: 1px solid var(--border-soft);
  }
  .test-settings label { color: var(--muted); font-size: .72rem; }
  .test-topic-label { grid-column: 1 / -1; }
  .test-settings input,.test-settings select {
    height: 36px;
    min-width: 0;
    padding: 0 .6rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: .8rem;
  }
  .test-settings select { width: 68px; }
  .test-generate,.test-submit {
    min-height: 36px;
    padding: 0 .8rem;
    border: 1px solid var(--accent);
    border-radius: 7px;
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-size: .8rem;
    font-weight: 600;
  }
  .test-generate:disabled,.test-submit:disabled { opacity: .55; cursor: wait; }
  .test-status { padding: .8rem 0; color: var(--muted); font-size: .8rem; }
  .test-status.is-loading{display:flex;align-items:center;gap:.55rem}
  .test-status.is-loading::before{content:"";width:14px;height:14px;flex:none;border:2px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:test-spin .8s linear infinite}
  @keyframes test-spin{to{transform:rotate(360deg)}}
  .test-status:empty { display: none; }
  .test-progress { display: grid; gap: .55rem; margin: 0 0 .9rem; color: var(--muted); font-size: .75rem; }
  .test-progress-labels { display: flex; justify-content: space-between; gap: .75rem; }
  .test-progress-question { color: var(--text); font-weight: 650; }
  .test-progress-completed { text-align: right; }
  .test-progress-track { display: flex; gap: clamp(3px, 1vw, 6px); }
  .test-progress-track > span {
    flex: 1;
    min-width: 0;
    height: 6px;
    border-radius: 99px;
    background: color-mix(in srgb, var(--muted) 25%, var(--surface-3));
    transition: background-color .15s ease;
  }
  .test-progress-track > .is-answered { background: color-mix(in srgb, var(--accent) 56%, var(--surface-3)); }
  .test-progress-track > .is-current { background: var(--accent); }
  .test-questions { display: grid; gap: .75rem; }
  .test-question {
    padding: .85rem;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    background: var(--surface-2);
  }
  .test-question h3 { margin: 0 0 .7rem; color: var(--text); font-size: .91rem; font-weight: 600; line-height: 1.6; }
  .test-question h3 p { margin: 0; }
  .test-options { display: grid; gap: .45rem; }
  .test-option {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    padding: .6rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-2);
    cursor: pointer;
    font-size: .82rem;
    line-height: 1.55;
  }
  .test-option:has(input:checked) { border-color: var(--accent); background: var(--accent-weak); color: var(--text); }
  .test-option input { margin-top: .25rem; accent-color: var(--accent); }
  .test-option .test-option-id { flex: 0 0 auto; color: var(--muted); font-weight: 700; }
  .test-option p { margin: 0; }
  .test-navigation {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: .45rem;
    margin-top: 1.15rem;
  }
  .test-position { color: var(--text-2); font-size: .75rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .test-navigation :is(.test-previous, .test-submit) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .42rem;
    width: auto;
    max-width: 100%;
    min-height: 42px;
    padding: .45rem clamp(.42rem, 1.5vw, .85rem);
    border-radius: 9px;
    line-height: 1.25;
    cursor: pointer;
  }
  .test-navigation .test-previous { justify-self: start; }
  .test-navigation .test-submit { justify-self: end; }
  .test-navigation svg { width: .9rem; height: .9rem; flex: none; }
  .test-pane[dir="rtl"] .test-navigation svg { transform: scaleX(-1); }
  .test-navigation button:disabled { opacity: .6; cursor: default; }
  .test-navigation .test-previous:disabled:hover { background: var(--surface); }
  .test-navigation .test-submit:enabled:hover { background: color-mix(in srgb, var(--accent) 87%, var(--text)); }
  .test-navigation button:focus-visible,
  .test-pane .test-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

  .test-pane .test-question {
    padding: clamp(.85rem, 2vw, 1.2rem) clamp(.8rem, 2vw, 1.2rem) clamp(1.2rem, 3vw, 1.85rem);
    border-color: var(--border);
    border-radius: 14px;
    background: linear-gradient(150deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 54%, var(--surface)));
  }
  .test-question-number {
    display: grid;
    width: max-content;
    min-width: 1.85rem;
    min-height: 1.6rem;
    padding-inline: .35rem;
    place-items: center;
    margin-bottom: .6rem;
    border-radius: 7px;
    background: var(--accent-weak);
    color: color-mix(in srgb, var(--accent) 68%, var(--text));
    font-size: .78rem;
    font-weight: 700;
  }
  .test-pane .test-question h3 { margin-bottom: .8rem; font-size: .95rem; overflow-wrap: anywhere; }
  .test-pane .test-options { gap: .55rem; }
  :where(.test-pane) .test-option {
    align-items: baseline;
    min-height: 42px;
    padding: .55rem .75rem;
    border-radius: 10px;
    background: color-mix(in srgb, var(--surface-3) 68%, var(--surface-2));
    color: var(--text);
    overflow-wrap: anywhere;
  }
  .test-pane .test-option > :last-child { min-width: 0; }
  .test-pane .test-option input { flex: none; margin: 0; align-self: start; margin-block-start: .22rem; }
  .test-pane .test-option:has(input:enabled):hover { border-color: color-mix(in srgb, var(--accent) 56%, var(--border)); }
  .test-pane .test-option:has(input:checked:enabled) { background: var(--accent-weak); }
  .test-pane .test-option:has(input:disabled) { cursor: default; }
  .test-previous { min-height: 40px; padding: 0 .9rem; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; }
  .test-previous:hover { background: var(--surface-3); }
  .test-submit { width: 100%; min-height: 40px; }
  .test-results { margin: 0 0 1rem; padding: .9rem; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface-2); }
  .test-score-summary { display: flex; align-items: center; gap: .7rem; margin-bottom: .55rem; }
  .test-score-ring {
    position: relative;
    display: grid;
    flex: 0 0 3.5rem;
    width: 3.5rem;
    aspect-ratio: 1;
    place-items: center;
    border-radius: 50%;
    background: conic-gradient(from -90deg, #ff7a18 0 var(--score-angle), var(--surface-3) var(--score-angle) 360deg);
  }
  .test-score-ring::before { position: absolute; inset: .3rem; border-radius: inherit; background: var(--surface-2); content: ""; }
  .test-score { position: relative; margin: 0; color: var(--text); font-size: .9rem; font-weight: 750; }
  .test-score-copy { display: grid; min-width: 0; gap: .2rem; }
  .test-score-title { color: var(--text); font-size: .92rem; font-weight: 700; }
  .test-score-detail { margin: 0; color: var(--muted); font-size: .76rem; line-height: 1.4; }
  .test-option.is-correct-answer { border-color: color-mix(in srgb, #83b894 48%, var(--border)); background: color-mix(in srgb, #83b894 7%, var(--surface)); color: var(--text); }
  .test-option:has(input:checked).is-correct-answer { border-color: color-mix(in srgb, #83b894 48%, var(--border)); background: color-mix(in srgb, #83b894 7%, var(--surface)); }
  .test-option.is-correct-answer .test-option-id { color: #83b894; }
  .test-option.is-wrong-answer { border-color: color-mix(in srgb, #d99a9d 48%, var(--border)); background: color-mix(in srgb, #d99a9d 7%, var(--surface)); color: var(--text); }
  .test-option:has(input:checked).is-wrong-answer { border-color: color-mix(in srgb, #d99a9d 48%, var(--border)); background: color-mix(in srgb, #d99a9d 7%, var(--surface)); }
  .test-option.is-wrong-answer .test-option-id { color: #d99a9d; }
  .test-result-icon {
    display: inline-grid;
    flex: 0 0 1.25rem;
    width: 1.25rem;
    height: 1.25rem;
    place-items: center;
    border-radius: 50%;
    line-height: 1;
  }
  .test-result-icon svg { display: block; width: .75rem; height: .75rem; }
  .test-result-icon.correct { color: #83b894; background: color-mix(in srgb, #83b894 10%, var(--surface)); }
  .test-result-icon.incorrect { color: #d99a9d; background: color-mix(in srgb, #d99a9d 10%, var(--surface)); }
  .test-question-feedback {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    margin-top: .75rem;
    padding-top: .65rem;
    border-top: 1px solid var(--border-soft);
    font-size: .8rem;
  }
  .test-question-feedback-content { display: grid; min-width: 0; gap: .3rem; }
  .test-question-feedback-content strong { line-height: 1.4; }
  .test-question-feedback.correct { color: #83b894; }
  .test-question-feedback.incorrect { color: #d99a9d; }
  .test-question-feedback p { margin: 0; color: var(--text-2); }
  .test-question-feedback p p { margin: 0; }
  .test-result { padding: .65rem 0; border-top: 1px solid var(--border-soft); font-size: .8rem; }
  .test-result.correct { color: #83b894; }
  .test-result.incorrect { color: #d99a9d; }
  .test-result p { margin-top: .25rem; color: var(--text-2); }
  .test-result p p { margin: 0; }
  .test-pane [hidden] { display: none !important; }

  .chat-quiz { display: grid; gap: .55rem; margin: .4rem 0; }
  .chat-quiz-navigation { display: flex; align-items: center; gap: .55rem; }
  .chat-quiz-navigation .test-previous { flex: 0 0 auto; }
  .chat-quiz-navigation .test-submit { width: auto; flex: 1 1 auto; }
  .chat-quiz-summary { display: flex; align-items: center; justify-content: space-between; gap: .65rem; margin: 0; padding: .45rem .6rem; }
  .chat-quiz-summary .test-score-summary { margin: 0; }
  .chat-quiz-details { display: grid; gap: .75rem; }
  .chat-quiz-details-toggle { width: auto; min-height: 34px; justify-self: start; padding: 0 .75rem; }
  .chat-quiz [hidden] { display: none !important; }
  .chat-quiz-title { color: var(--text); font-size: 1rem; font-weight: 650; }
  .chat-quiz-prompt { margin-bottom: .7rem; color: var(--text); line-height: 1.75; }
  .chat-quiz-prompt p { margin: 0; }
  .chat-quiz .test-progress { margin: 0; }
  .chat-quiz .test-option p { margin: 0; }
  @media (max-width: 440px) {
    .chat-quiz-summary { flex-wrap: wrap; }
    .chat-quiz-details-toggle { flex: 1 1 100%; }
  }

.calc-pane {
    position: relative;
    inset: auto;
    display: none;
    flex: 0 0 auto;
    align-self: flex-start;
    width: min(360px, 55%);
    height: auto;
    max-width: none;
    max-height: calc(100% - 24px);
    min-width: 0;
    min-height: 0;
    margin: 12px;
    padding: 0;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.calc-pane[open] {
    display: flex;
}

/* A 760px centered chat leaves 402px per side: 360px pane, 30px clearance, 12px inset. */
@container assistant-main (min-width: 1564px) {
    .workspace:not(.book-open, .test-open) > .calc-pane[open]:not(:modal) {
        position: absolute;
        inset: calc(var(--assistant-header-height) + 12px) 12px auto auto;
        z-index: 3;
        max-height: calc(100% - var(--assistant-header-height) - 24px);
        margin: 0;
    }
}

@media (min-width: 821px) {
    .calc-pane { direction: ltr; }
}

.calc-head {
  color: var(--text);
  font-size: .84rem;
  font-weight: 650;
}

.book-head-controls :is(.book-control,.book-page-number) { height: 28px; }
.book-head-controls .book-control { width: 28px; }
.book-head-controls .book-fit { width: auto; min-width: 30px; }
.book-head-controls .book-page-number { width: 44px; }

@media (any-pointer: coarse) {
  .chat-page .composer-editor-wrap { --editor-font-size: 16px; }
  .chat-page .book-head-controls .book-page-number { font-size: 16px; }
}

@container book-pane (max-width: 500px) {
  .book-head .book-filename,
  .book-head .book-zoom,
  .book-head .book-live-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .book-head { gap: 3px; padding-inline: 6px; }
  .book-head .book-toolbar,
  .book-head .book-toolbar-group { gap: 2px; }
  .book-head .book-live-toggle { min-width: 0; padding-inline: 4px; }
  .book-head .book-head-controls .book-control:not(.book-fit) { width: 26px; }
  .book-head .book-page-number { width: 36px; }
}

.icon-btn.on {
    background: var(--accent-weak);
    color: var(--accent);
}

.book-toggle.minimized,
[data-test-toggle].minimized {
  border-color: color-mix(in srgb,var(--accent) 55%,var(--border));
  background: var(--accent-weak);
  color: var(--accent);
}

.compact-workspace .topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  grid-template-rows: calc(var(--assistant-header-height) - 1px);
  align-items: center;
  flex: 0 0 auto;
  height: auto;
  gap: 0 3px;
  padding-inline: 6px;
}
.compact-workspace .topbar .topbar-sidebar-toggles {
  display: flex;
  align-items: center;
  gap: 1px;
  grid-column: 1;
}
.compact-workspace .topbar-spacer,
.compact-workspace .assistant-tools-header :is([data-book-toggle], [data-test-toggle]),
.compact-workspace .header-chat-title {
  display: none;
}
.compact-workspace .assistant-tools-header { grid-column: 3; }
.compact-workspace .assistant-tools { padding: 0; border: 0; background: transparent; }
.compact-workspace .assistant-tools > [data-calc-toggle] {
  width: var(--assistant-header-control);
  height: var(--assistant-header-control);
  padding: 0;
}
.compact-workspace .assistant-tools > [data-calc-toggle] span { display: none; }
.compact-workspace .header-chat { grid-column: 4; }
.compact-workspace .topbar > [data-theme-toggle] { grid-column: 5; }
.compact-workspace .topbar > :is(.topbar-sidebar-toggles,.assistant-tools-header,.header-chat,[data-theme-toggle],.workspace-switch) { grid-row: 1; }
.compact-workspace .workspace-switch {
  display: flex;
  align-items: stretch;
  justify-self: center;
  justify-content: center;
  grid-column: 2;
  min-width: 0;
  max-width: 100%;
  min-height: var(--assistant-header-control);
  gap: 1px;
  padding: 2px;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: var(--surface-2);
}
.compact-workspace .workspace-switch button {
  min-width: 0;
  padding: 0 clamp(3px, 1.5vw, 10px);
  border-radius: 6px;
  color: var(--text-2);
  font: 650 .75rem/1.2 var(--font);
  white-space: nowrap;
}
.compact-workspace .workspace-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgb(0 0 0 / .13);
}
.compact-workspace .workspace-switch button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.compact-workspace .workspace-toolbar { display: contents; }
.compact-workspace .workspace-toolbar > :is(.book-head,.test-head) {
  grid-column: 1 / -1;
  min-height: 36px;
  height: auto;
  margin: 0;
  padding: 2px 0;
  border: 0;
  border-top: 1px solid var(--border-soft);
  background: transparent;
}
.compact-workspace .workspace-toolbar > [hidden],
.compact-workspace .workspace-toolbar .book-head:has(.book-head-controls[hidden]),
.compact-workspace .workspace-toolbar .book-head > b,
.compact-workspace .workspace-toolbar :is([data-book-fill],[data-book-close],[data-test-fill],[data-test-close]),
.compact-workspace .book-page-label {
  display: none;
}
.compact-workspace .book-head-controls {
  flex: 1 1 auto;
}
.compact-workspace .book-toolbar { flex-wrap: wrap; }
.compact-workspace .workspace-toolbar .book-page-number { width: 38px; font-size: 16px; }
.compact-workspace .test-history summary { min-height: 38px; }

@container assistant-main (max-width: 460px) {
  .compact-workspace .book-filename,
  .compact-workspace .book-zoom,
  .compact-workspace .test-head h2,
  .compact-workspace .test-copy span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .compact-workspace .book-live-toggle { min-width: 0; padding-inline: 4px; }
  .compact-workspace .test-copy { width: var(--assistant-header-control); padding: 0; }
}

.compact-workspace .workspace.book-open,
.compact-workspace .workspace.test-open { position: relative; flex-direction: column; }
.compact-workspace .workspace.book-open .book-pane.open,
.compact-workspace .workspace.test-open .test-pane.open {
  position: absolute;
  inset: 0;
  z-index: 5;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  border: 0;
}
.compact-workspace .workspace.book-open .test-pane,
.compact-workspace .workspace.test-open .book-pane { display: none; }
.compact-workspace .workspace.book-open .chat-column,
.compact-workspace .workspace.test-open .chat-column { display: none; }

@container assistant-main (max-width: 360px) {
  .compact-workspace .book-live-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .compact-workspace .workspace-switch button { padding-inline: 3px; font-size: .7rem; }
  .compact-workspace .book-toolbar { gap: 2px; }
  .compact-workspace .book-toolbar-group { gap: 2px; }
}

.calc-pane:modal {
  position: fixed;
  inset: auto max(8px, env(safe-area-inset-right)) max(8px, var(--chat-bottom, 0px), env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  width: min(500px, calc(100% - 20px));
  max-height: min(820px, calc(100% - var(--chat-bottom, 0px) - max(48px, 9dvh, env(safe-area-inset-top))));
  margin: 0 auto;
  border-radius: 17px;
}
.calc-pane:modal::backdrop { background: rgb(12 15 20 / .48); }

.workspace.fill-book,
.workspace.fill-test { position: relative; }
.workspace.fill-book .chat-column,
.workspace.fill-book .test-pane,
.workspace.fill-test .chat-column,
.workspace.fill-test .book-pane { display: none !important; }
.workspace.fill-book .book-pane.open,
.workspace.fill-test .test-pane.open {
  position: absolute;
  inset: 0;
  z-index: 20;
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  min-height: 0;
  border: 0;
}

@media (min-width: 821px) {
  .main:has(.workspace.fill-book) .book-pane.open {
    inset: 0;
    z-index: 20;
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    border: 0;
  }
}

.workspace:is(.fill-book, .fill-test):has(> .calc-pane[open]:not(:modal)) > :is(.book-pane, .test-pane).open {
  position: relative;
  inset: auto;
  flex: 1 1 0;
  width: auto;
}

@media (max-width: 520px) {
  .header-status { gap: .35rem; }
  .header-model { gap: .3rem; padding-inline: .4rem; }
}

@media (max-width: 520px) {
  .book-library-label { display: none; }
  .book-library-select { width: min(42%, 150px); min-width: 76px; font-size: .7rem; }
  .book-file-button { padding: .3rem .4rem; font-size: .72rem; }
  .book-page-label { display: none; }
  .book-page-total { font-size: .7rem; }
  .book-zoom { min-width: 32px; font-size: .7rem; }
  .book-page-area { padding: 10px; }
  .test-body { padding: .75rem; }
  .test-settings { grid-template-columns: minmax(0, 1fr) auto; }
  .test-settings select { grid-column: 1; }
  .test-generate { grid-column: 2; grid-row: 3; }
}

.calc-pane .calculator {
    flex: 1 1 auto;
    min-height: 0;
}


.steps-section {
    margin-top: 0.85rem;
}

.steps-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 0;
    background: transparent;
    padding: 0.35rem 0;
    color: var(--bs-secondary-color);
    font-size: 0.875rem;
    cursor: pointer;
}

.steps-toggle:hover {
    color: var(--bs-body-color);
}

.steps-toggle .steps-chevron {
    transition: transform 0.3s ease;
}

.steps-toggle.open .steps-chevron {
    transform: rotate(90deg);
}

.steps-collapse {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transition:
        grid-template-rows 0.4s ease,
        opacity 0.3s ease;
}

.steps-collapse-inner {
    min-height: 0;
    overflow: hidden;
}

.steps-collapse.open {
    grid-template-rows: 1fr;
    opacity: 1;
}

.steps {
    margin-top: 0.75rem;
    padding-left: 1rem;
    border-left: 2px solid var(--bs-border-color);
    color: var(--bs-secondary-color);
}


/* Sidebar button */
.sidebar-nav button.nav-link {
    width: 100%;
    border: 0;
  font-family: inherit;
    text-align: left;
    cursor: pointer;
}

/* Assistant interaction refinements. */
.chat-page .message-feature-cards{display:flex;align-items:center;flex-wrap:wrap;gap:.45rem;width:100%;margin:0 0 .5rem;padding:0 0 .45rem;border-bottom:1px solid var(--border-soft);color:var(--text-2)}
.chat-page .message-feature-card{display:inline-flex;align-items:center;gap:.3rem;min-width:0;max-width:100%;color:var(--text-2);font-size:.68rem;line-height:1.2}
.chat-page .message-feature-card>svg{width:14px;height:14px;flex:none;color:var(--accent)}
.chat-page .message-feature-card>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.chat-page .message-feature-card>small{flex:none;color:var(--accent);font-size:.64rem;font-weight:700}
.chat-page .composer-context-cost{flex:none;padding-inline-start:.35rem;border-inline-start:1px solid var(--border-soft);color:var(--accent);font-size:.65rem;font-weight:700}
.chat-page .composer-input-editor{scrollbar-width:thin;scrollbar-color:var(--border) transparent}
.chat-page .composer-input-editor::-webkit-scrollbar{width:5px}
.chat-page .composer-input-editor::-webkit-scrollbar-track{margin-block:7px;background:transparent}
.chat-page .composer-input-editor::-webkit-scrollbar-thumb{border-radius:999px;background:var(--border)}
.chat-page .solve-btn>svg,.solve-trigger-icon svg{width:17px;height:17px;flex:none;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.solve-trigger-icon{display:inline-flex}
.solve-btn small{margin-inline-start:auto}
#composer-book-cards{display:contents}
.composer-context .test-count-control select{height:26px;border:0;padding-inline:.25rem;color:var(--text);background:var(--surface)}
.chat-page .send{border-radius:50%}
.chat-page .composer-hint{margin:.25rem auto 0;padding:0 .5rem;font-size:.65rem;line-height:1.3}
@media(max-width:640px){.chat-page .stream{padding-inline:.75rem}}
/* Overlay */
.cs-settings-overlay {
    --cs-settings-accent: #315bdc;
    --cs-settings-accent-soft: #edf2ff;
    --cs-settings-text: #202432;
    --cs-settings-muted: #777f90;
    --cs-settings-border: #e5e8ef;
    --cs-settings-surface: #ffffff;
    --cs-settings-subtle: #f7f8fb;

    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    place-items: center;
    padding: 24px;
    background: rgba(13, 18, 32, 0.58);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.cs-settings-overlay.is-open {
    display: grid;
}

/* Main dialog */
.cs-settings-dialog {
    display: flex;
    flex-direction: column;
    width: min(960px, 100%);
    height: min(720px, calc(100dvh - 48px));
    min-height: 0;
    overflow: hidden;
    color: var(--cs-settings-text);
    background: var(--cs-settings-surface);
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 18px;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.25);
    animation: cs-settings-enter 180ms ease-out;
    outline: none;
}

@keyframes cs-settings-enter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.cs-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 26px;
    border-bottom: 1px solid var(--cs-settings-border);
    flex-shrink: 0;
}

.cs-settings-header h2 {
    margin: 0;
    font-size: 22px;
    line-height: 1.4;
    font-weight: 700;
    letter-spacing: -0.4px;
    color: var(--cs-settings-text);
}

.cs-settings-header p {
    margin: 4px 0 0;
    color: var(--cs-settings-muted);
    font-size: 13px;
}

.cs-settings-close {
    display: grid;
    flex-shrink: 0;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    color: var(--cs-settings-muted);
    background: var(--cs-settings-subtle);
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
}

.cs-settings-close:hover {
    background: var(--cs-settings-border);
    color: var(--cs-settings-text);
}

.cs-settings-close svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

/* Two-column layout */
.cs-settings-layout {
    display: grid;
    grid-template-columns: 245px minmax(0, 1fr);
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.cs-settings-sidebar {
    padding: 18px 12px;
    overflow-y: auto;
    background: var(--cs-settings-subtle);
    border-right: 1px solid var(--cs-settings-border);
}

.cs-settings-nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    min-height: 44px;
    margin-bottom: 5px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: #555d6e;
    background: transparent;
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: color 150ms ease, background 150ms ease;
}

.cs-settings-nav-item:hover {
    color: var(--cs-settings-text);
    background: #eceff5;
}

.cs-settings-nav-item.active {
    color: var(--cs-settings-accent);
    background: var(--cs-settings-accent-soft);
    border-color: #dbe4ff;
    font-weight: 600;
}

.cs-settings-nav-icon {
    display: grid;
    flex-shrink: 0;
    place-items: center;
    width: 23px;
    font-size: 19px;
    line-height: 1;
}

.cs-settings-chevron {
    display: none;
    margin-left: auto;
    font-size: 23px;
    line-height: 1;
    color: #9299a7;
}

/* Content area */
.cs-settings-content {
    min-width: 0;
    min-height: 0;
    padding: 28px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.cs-settings-panel[hidden] {
    display: none !important;
}

.cs-settings-panel-heading {
    margin-bottom: 24px;
}

.cs-settings-panel-heading h3 {
    margin: 0 0 6px;
    color: var(--cs-settings-text);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.cs-settings-panel-heading p,
.cs-settings-description {
    margin: 0;
    color: var(--cs-settings-muted);
    font-size: 13px;
    line-height: 1.65;
}

.cs-settings-card {
    padding: 22px;
    margin-bottom: 18px;
    border: 1px solid var(--cs-settings-border);
    border-radius: 13px;
    background: var(--cs-settings-surface);
}

.cs-settings-card h4,
.cs-settings-option-row h4,
.cs-settings-danger h4 {
    margin: 0 0 5px;
    color: var(--cs-settings-text);
    font-size: 14px;
    font-weight: 600;
}

.cs-settings-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 21px;
}

.cs-settings-field:last-of-type {
    margin-bottom: 0;
}

.cs-settings-field label {
    color: var(--cs-settings-text);
    font-size: 13px;
    font-weight: 600;
}

.cs-settings-field input,
.cs-settings-field select {
    width: 100%;
    min-height: 43px;
    padding: 10px 12px;
    color: var(--cs-settings-text);
    background: var(--cs-settings-surface);
    border: 1px solid #dce0e8;
    border-radius: 8px;
    font: inherit;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.cs-settings-field input:focus,
.cs-settings-field select:focus {
    border-color: var(--cs-settings-accent);
    box-shadow: 0 0 0 3px rgba(49, 91, 220, 0.12);
}

.cs-settings-field small {
    color: var(--cs-settings-muted);
    font-size: 11px;
    line-height: 1.5;
}

.cs-settings-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 22px;
}

.cs-settings-primary,
.cs-settings-secondary,
.cs-settings-danger-button {
    min-height: 39px;
    padding: 9px 15px;
    border-radius: 8px;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
}

.cs-settings-primary {
    color: #fff;
    background: var(--cs-settings-accent);
    border: 1px solid var(--cs-settings-accent);
}

.cs-settings-primary:hover {
    background: #274bc0;
}

.cs-settings-secondary {
    flex-shrink: 0;
    color: var(--cs-settings-text);
    background: var(--cs-settings-surface);
    border: 1px solid var(--cs-settings-border);
}

.cs-settings-secondary:hover {
    background: var(--cs-settings-subtle);
}

/* Theme choices */
.cs-settings-choice-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 17px;
}

.cs-settings-choice {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--cs-settings-border);
    border-radius: 10px;
    color: var(--cs-settings-text);
    background: var(--cs-settings-surface);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.cs-settings-choice.active {
    border-color: var(--cs-settings-accent);
    background: var(--cs-settings-accent-soft);
}

.cs-theme-preview {
    display: grid;
    place-items: center;
    height: 65px;
    border: 1px solid var(--cs-settings-border);
    border-radius: 6px;
}

.cs-theme-light {
    background: linear-gradient(#fff 0 35%, #f0f2f7 35% 100%);
}

.cs-theme-dark {
    background: linear-gradient(#242938 0 35%, #111520 35% 100%);
}

.cs-theme-system {
    color: var(--cs-settings-text);
    background: linear-gradient(90deg, #fff 50%, #222736 50%);
    font-size: 24px;
}

/* Option rows and separators */
.cs-settings-option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 3px 0;
}

.cs-settings-option-row > div {
    min-width: 0;
}

.cs-settings-option-row p {
    margin: 0;
    color: var(--cs-settings-muted);
    font-size: 12px;
    line-height: 1.6;
}

.cs-settings-option-row input[type="checkbox"] {
    flex-shrink: 0;
    width: 17px;
    height: 17px;
    accent-color: var(--cs-settings-accent);
    cursor: pointer;
}

.cs-settings-divider {
    height: 1px;
    margin: 20px 0;
    background: var(--cs-settings-border);
}

.cs-settings-eyebrow {
    display: block;
    margin-bottom: 10px;
    color: var(--cs-settings-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
}

.cs-settings-danger {
    padding: 17px;
    border: 1px solid #f1d4d4;
    border-radius: 10px;
    background: #fffafa;
}

.cs-settings-danger h4 {
    color: #b4232d;
}

.cs-settings-danger p {
    margin: 7px 0 15px;
    color: #826a6c;
    font-size: 12px;
    line-height: 1.6;
}

.cs-settings-danger-button {
    color: #b4232d;
    background: #fff;
    border: 1px solid #e9bfc2;
}

.cs-settings-danger-button:hover {
    background: #fff0f0;
}

/* Back navigation is mobile-only */
.cs-settings-back {
    display: none;
}

/* Mobile: full-screen settings */
@media (max-width: 700px) {
    .cs-settings-overlay {
        display: none;
        padding: 0;
        place-items: stretch;
        background: var(--cs-settings-surface);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .cs-settings-overlay.is-open {
        display: grid;
    }

    .cs-settings-dialog {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        min-height: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        animation: none;
    }

    .cs-settings-header {
        padding: max(16px, env(safe-area-inset-top)) 18px 16px;
    }

    .cs-settings-header h2 {
        font-size: 20px;
    }

    .cs-settings-layout {
        display: block;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    .cs-settings-sidebar {
        height: 100%;
        padding: 12px 16px max(20px, env(safe-area-inset-bottom));
        overflow-y: auto;
        border-right: 0;
        background: var(--cs-settings-surface);
    }

    .cs-settings-nav-item {
        min-height: 54px;
        margin-bottom: 4px;
        padding: 12px;
        border-color: transparent;
        border-radius: 10px;
        font-size: 14px;
    }

    .cs-settings-nav-item.active {
        border-color: transparent;
    }

    .cs-settings-chevron {
        display: inline;
    }

    /* Show the section list first */
    .cs-settings-dialog:not(.is-mobile-detail) .cs-settings-content {
        display: none;
    }

    /* After choosing a section, show its content */
    .cs-settings-dialog.is-mobile-detail .cs-settings-sidebar {
        display: none;
    }

    .cs-settings-dialog.is-mobile-detail .cs-settings-content {
        display: block;
        height: 100%;
        padding: 18px 18px max(24px, env(safe-area-inset-bottom));
        box-sizing: border-box;
    }

    .cs-settings-back {
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        margin: -6px 0 20px;
        padding: 4px 0;
        border: 0;
        color: var(--cs-settings-accent);
        background: transparent;
        font: inherit;
        font-size: 13px;
        cursor: pointer;
    }

    .cs-settings-panel-heading {
        margin-bottom: 20px;
    }

    .cs-settings-panel-heading h3 {
        font-size: 19px;
    }

    .cs-settings-card {
        padding: 17px;
        border-radius: 11px;
    }

    .cs-settings-choice-grid {
        gap: 8px;
    }

    .cs-settings-choice {
        padding: 7px;
    }

    .cs-theme-preview {
        height: 53px;
    }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .cs-settings-dialog {
        animation: none;
    }

    .cs-settings-close,
    .cs-settings-nav-item,
    .cs-settings-primary,
    .cs-settings-secondary {
        transition: none;
    }
}


.sidebar-nav button.nav-link {
    display: flex;
    align-items: center;
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
  font-family: inherit;
    text-align: left;
    cursor: pointer;
}

