:root{
  --ink-deep:#101d17;
  --ink-panel:#182920;
  --ink-panel-2:#1f342a;
  --parchment:#f1e8d6;
  --parchment-dim:#cfc6ae;
  --brass:#b8925a;
  --brass-bright:#dcb679;
  --claret:#8a3b46;
  --mist:#7d9686;
  --hairline:rgba(184,146,90,0.28);
  --shadow:0 10px 30px rgba(0,0,0,0.35);
  --radius:10px;
  --font-display:'Cormorant Garamond', Georgia, serif;
  --font-ui:'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
[data-theme="light"]{
  --ink-deep:#f5efe2;
  --ink-panel:#e6dcc8;
  --ink-panel-2:#ded1b9;
  --parchment:#1c2820;
  --parchment-dim:#4a594f;
  --brass:#8c642d;
  --brass-bright:#6e4c1d;
  --mist:#52695c;
  --hairline:rgba(140,100,45,0.25);
  --shadow:0 8px 24px rgba(0,0,0,0.08);
}
[data-theme="light"] body{
  background:
    radial-gradient(ellipse at top, rgba(140,100,45,0.08), transparent 60%),
    var(--ink-deep);
}
[data-theme="light"] .msg-row.user .bubble{
  background:linear-gradient(180deg, #42281d, #2b1910);
  border:1px solid #5c3a29;
  color:#f5efe2;
}
[data-theme="light"] .msg-row.model .bubble{
  background:linear-gradient(180deg, rgba(255,255,255,0.7), rgba(255,255,255,0.4));
  border:1px solid var(--hairline);
}
[data-theme="light"] .code-wrap{ background:#1c2620; }
[data-theme="light"] .field input[type=text],
[data-theme="light"] .field input[type=password],
[data-theme="light"] .field select{ background:#fbf8f2; }
*{box-sizing:border-box;}

html,body{height:100%;}
body{
  margin:0;
  background:
    radial-gradient(ellipse at top, rgba(184,146,90,0.06), transparent 60%),
    var(--ink-deep);
  color:var(--parchment);
  font-family:var(--font-ui);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
::selection{ background:rgba(184,146,90,0.35); }

/* Letterhead header */
header.letterhead{
  flex:0 0 auto;
  padding:14px 20px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  background:linear-gradient(180deg, var(--ink-panel), rgba(24,41,32,0.4));
  border-bottom:1px solid var(--hairline);
}
.brand{
  display:flex;
  align-items:center;
  gap:12px;
}
.crest{
  width:38px;height:38px;
  border:1px solid var(--brass);
  border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-family:var(--font-display);
  font-weight:700;
  font-size:15px;
  color:var(--brass-bright);
  letter-spacing:1px;
  flex-shrink:0;
  background:radial-gradient(circle at 35% 30%, rgba(220,182,121,0.18), transparent 70%);
}
.brand-text h1{
  margin:0;
  font-family:var(--font-display);
  font-weight:600;
  font-size:22px;
  letter-spacing:0.3px;
  color:var(--parchment);
  line-height:1.1;
}
.brand-text .subtitle{
  margin:1px 0 0;
  font-size:11px;
  letter-spacing:1.6px;
  text-transform:uppercase;
  color:var(--mist);
}
.rule{
  display:none;
}
.icon-btn{
  background:transparent;
  border:1px solid transparent;
  color:var(--parchment-dim);
  width:34px !important;
  height:34px !important;
  border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;
  transition:all .18s ease;
}
.icon-btn:hover{
  color:var(--brass-bright);
  border-color:var(--hairline);
  background:rgba(184,146,90,0.08);
}
.icon-btn.listening{
  color: #e65c5c;
  border-color: #e65c5c;
  animation: pulse-mic 1.5s infinite;
}
.icon-btn.active{
  color: var(--brass-bright);
  border-color: var(--brass);
  background: rgba(184,146,90,0.18);
}
.action-link-btn,
.bubble .action-link-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  margin: 6px 4px 6px 0;
  border-radius: 6px;
  border: 1px solid #8c6239 !important;
  background: #8C642E !important;
  color: #f5eedf !important;
  text-decoration: none !important;
  font-family: var(--font-ui, sans-serif);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: background 0.15s ease, transform 0.15s ease;
}

.action-link-btn:hover,
.bubble .action-link-btn:hover {
  background: #4d2f1c !important;
  color: #ffffff !important;
  transform: translateY(-1px);
}


  @keyframes pulse-mic {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
  }

  .icon-btn svg{width:19px;height:19px;}

  /* Chat area */
  main#chat{
    flex:1 1 auto;
    overflow-y:auto;
    overflow-anchor:none;
    padding:22px 16px 10px;
    display:flex;
    flex-direction:column;
    gap:16px;
    scroll-behavior:smooth;
  }

  main#chat::-webkit-scrollbar{width:8px;}
  main#chat::-webkit-scrollbar-thumb{background:rgba(184,146,90,0.25); border-radius:8px;}

  .msg-row{
    display:flex;
    max-width:860px;
    width:100%;
    margin:0 auto;
    gap:10px;
    align-items:flex-start;
  }
  .msg-row.user{ justify-content:flex-end; }
  .msg-row.model{ justify-content:flex-start; }
  .msg-row.system-note{ justify-content:center; }

  .crest-img{
    width:38px;height:38px;
    border-radius:50%;
    border:1px solid var(--brass);
    object-fit:cover;
    flex-shrink:0;
  }
  .avatar-img{
    width:30px;height:30px;
    border-radius:50%;
    border:1px solid var(--hairline);
    object-fit:cover;
    flex-shrink:0;
    margin-top:4px;
  }
  .avatar{
    width:30px;height:30px;
    border-radius:50%;
    border:1px solid var(--hairline);
    flex-shrink:0;
    display:flex;align-items:center;justify-content:center;
    font-family:var(--font-display);
    font-size:13px;
    font-weight:700;
    color:var(--brass-bright);
    background:var(--ink-panel-2);
    margin-top:4px;
  }
  .msg-row.user .avatar{ order:2; color:var(--parchment); }

  .bubble{
    padding:12px 16px;
    border-radius:var(--radius);
    line-height:1.55;
    max-width:78%;
    word-wrap:break-word;
    box-shadow:var(--shadow);
    position:relative;
  }
  .msg-row.user .bubble{
    background:linear-gradient(180deg, #24382c, #1c2e24);
    border:1px solid var(--hairline);
    font-family:var(--font-ui);
    font-size:14.5px;
    color:var(--parchment);
    border-top-right-radius:3px;
  }
  .msg-row.model .bubble{
    background:linear-gradient(180deg, rgba(241,232,214,0.05), rgba(241,232,214,0.02));
    border:1px solid var(--hairline);
    font-family:var(--font-display);
    font-size:17.5px;
    color:var(--parchment);
    border-top-left-radius:3px;
  }
  .msg-row.model .bubble p{ margin:0 0 10px; }
  .msg-row.model .bubble p:last-child{ margin-bottom:0; }
  .msg-row.model .bubble ul, .msg-row.model .bubble ol{ margin:0 0 10px; padding-left:22px; }
  .msg-row.model .bubble a{ color:var(--brass-bright); }
  .msg-row.model .bubble strong{ color:var(--brass-bright); font-weight:700;}
  .msg-row.model .bubble blockquote{
    margin:8px 0; padding:2px 14px;
    border-left:2px solid var(--brass);
    color:var(--parchment-dim);
    font-style:italic;
  }
  .msg-row.system-note .bubble{
    font-family:var(--font-ui);
    font-size:12.5px;
    color:var(--mist);
    background:transparent;
    box-shadow:none;
    border:1px dashed var(--hairline);
    max-width:90%;
    text-align:center;
  }

  .text-copy-wrap{
    margin:10px 0;
    border-radius:8px;
    border:1px solid var(--hairline);
    background:rgba(184,146,90,0.04);
    overflow:hidden;
  }
  .text-copy-body{
    padding:12px 14px;
    font-size:14.5px;
    line-height:1.6;
    color:var(--parchment);
    white-space:pre-wrap;
    word-break:break-word;
  }

  .code-wrap{
    font-family:var(--font-ui);
    margin:10px 0;
    border-radius:8px;
    overflow:hidden;
    border:1px solid var(--hairline);
    background:#0d1712;
  }

  .code-head{
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:6px 12px;
    background:rgba(184,146,90,0.08);
    border-bottom:1px solid var(--hairline);
    font-size:11.5px;
    color:#B1BCB6;
    letter-spacing:0.5px;
    text-transform:uppercase;
  }
  .copy-btn{
    background:transparent;
    border:1px solid #C9B79D;
    color:#C9B79D;
    font-family:var(--font-ui);
    font-size:11px;
    padding:3px 9px;
    border-radius:5px;
    cursor:pointer;
    transition:all .15s ease;
  }
  .copy-btn:hover{ 
    color:#fff; border-color:#fff; }

  .prose-copy-wrap{
    margin:12px 0;
    padding:14px 16px 28px;
    border-radius:var(--radius);
    border:1px solid rgba(0,0,0,0.08);
    background: #FFFF88;
    color: slategray;
    position:relative;
    font-family:inherit;
    font-size:0.95em;
    line-height:1.55;
    white-space:pre-wrap;
    word-break:break-word;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
  }

.prose-copy-wrap::before,
.prose-copy-wrap::after{
  content:"";
  position:absolute;
  right:0; bottom:0;
  width:44px; height:44px;
  pointer-events:none;
  transition: width .25s ease, height .25s ease, clip-path .25s ease, background .25s ease;
}
.prose-copy-wrap::before{
  z-index:1;
  background: linear-gradient(315deg,
    transparent 38%,
    rgba(0, 0, 0, 0.16) 44%,
    rgba(0, 0, 0, 0.42) 50%,
    rgba(0, 0, 0, 0.24) 58%,
    rgba(0, 0, 0, 0.08) 72%,
    transparent 82%);
}
.prose-copy-wrap::after{
  z-index:2;
  clip-path: polygon(44px 0, 0 44px, 0 8px, 0.62px 4.94px, 2.34px 2.34px, 4.94px 0.62px, 8px 0);
  background: linear-gradient(315deg,
    rgba(0, 0, 0, 0.32) 0%,
    rgba(0, 0, 0, 0.10) 8%,
    #ded896 24%,
    #f3edb0 58%,
    #fffbe0 100%);
}
.prose-copy-wrap:has(.corner-copy-btn:hover)::before, .prose-copy-wrap:has(.corner-copy-btn:hover)::after,
.prose-copy-wrap:has(.corner-copy-btn:active)::before, .prose-copy-wrap:has(.corner-copy-btn:active)::after,
.prose-copy-wrap:has(.corner-copy-btn:focus-visible)::before, .prose-copy-wrap:has(.corner-copy-btn:focus-visible)::after{
  width:64px; height:64px;
}
.prose-copy-wrap:has(.corner-copy-btn:hover)::before,
.prose-copy-wrap:has(.corner-copy-btn:active)::before,
.prose-copy-wrap:has(.corner-copy-btn:focus-visible)::before{
  background: linear-gradient(315deg,
    transparent 36%,
    rgba(0, 0, 0, 0.20) 44%,
    rgba(0, 0, 0, 0.48) 50%,
    rgba(0, 0, 0, 0.28) 58%,
    rgba(0, 0, 0, 0.10) 74%,
    transparent 86%);
}
.prose-copy-wrap:has(.corner-copy-btn:hover)::after,
.prose-copy-wrap:has(.corner-copy-btn:active)::after,
.prose-copy-wrap:has(.corner-copy-btn:focus-visible)::after{
  clip-path: polygon(64px 0, 0 64px, 0 10px, 0.77px 6.17px, 2.93px 2.93px, 6.17px 0.77px, 10px 0);
}
.prose-copy-wrap .corner-copy-btn{
  position: absolute;
  bottom: 0;
  right: 0;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 8px 0 0 8px;
  color: #55502c;
  transition: width .25s ease, height .25s ease, padding .25s ease, color .15s ease;
}

.prose-copy-wrap .corner-copy-btn:hover,
.prose-copy-wrap .corner-copy-btn:active,
.prose-copy-wrap .corner-copy-btn:focus-visible{
  width: 64px;
  height: 64px;
  padding: 14px 0 0 14px;
  color: #1a1a08;
}
.prose-copy-wrap .corner-copy-btn svg{
  width: 12px;
  height: 12px;
  transition: transform .25s ease;
}
.prose-copy-wrap .corner-copy-btn:hover svg,
.prose-copy-wrap .corner-copy-btn:active svg,
.prose-copy-wrap .corner-copy-btn:focus-visible svg{
  transform: scale(1.15);
}

  .code-wrap pre{
    margin:0;
    padding:12px 14px;
    overflow-x:auto;
    font-size:13px;
    line-height:1.5;
  }
  .code-wrap code{ font-family:'SF Mono', Consolas, 'Courier New', monospace; }
  .msg-row.model .bubble code:not(pre code){
    font-family:'SF Mono', Consolas, monospace;
    background:rgba(184,146,90,0.14);
    padding:1px 5px;
    border-radius:4px;
    font-size:0.82em;
    color:var(--brass-bright);
  }
  .code-wrap .hljs .hljs-attribute {
    color: #9BBDDE
  }

  .code-wrap pre,
  pre code.hljs {
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
  }

  .typing{
    display:inline-flex;
    gap:4px;
    align-items:center;
    padding:2px 4px;
  }
  .typing span{
    width:6px;height:6px;border-radius:50%;
    background:var(--brass);
    opacity:0.35;
    animation:pulse 1.1s infinite ease-in-out;
  }
  .typing span:nth-child(2){ animation-delay:0.15s; }
  .typing span:nth-child(3){ animation-delay:0.3s; }
  @keyframes pulse{
    0%,80%,100%{ opacity:0.25; transform:scale(0.85); }
    40%{ opacity:1; transform:scale(1); }
  }

  /* Composer */
  footer#composer{
    flex:0 0 auto;
    padding:12px 10px 16px; /* Slightly tighter padding */
    background:linear-gradient(0deg, var(--ink-panel), rgba(24,41,32,0));
    border-top:1px solid var(--hairline);
  }
  .composer-label-row{
    display:flex;
    align-items:baseline;
    justify-content:space-between;
    max-width:860px;
    margin:0 auto 6px;
    padding:0 4px;
    gap:12px;
  }
  .composer-label-row label[for="input"]{
    font-size:12px;
    text-transform:uppercase;
    letter-spacing:1px;
    color:var(--mist);
    flex-shrink:0;
  }
  .thinking-ticker{
    font-size:14px;
    font-style:italic;
    color:var(--brass-bright);
    font-family:var(--font-display);
    white-space:nowrap;
    overflow:hidden;
    text-overflow:clip;
    flex:1;
    min-width:0;
  }
  .composer-inner{

    max-width:860px;
    margin:0 auto;
    display:flex;
    flex-direction:column;
    gap:6px;
    background:var(--ink-panel-2);
    border:1px solid var(--hairline);
    border-radius:14px;
    padding:10px 12px;
    transition:border-color .2s ease;
    min-height:54px;
  }
  textarea#input{
    flex:1;
    resize:none;
    background:transparent;
    border:none;
    outline:none;
    color:var(--parchment);
    font-family:var(--font-ui);
    font-size:15px;
    line-height:1.4;
    padding:8px 0;
    min-height:24px;
    max-height:45vh;
    overflow-y: hidden;
  }


  .composer-inner:focus-within{ border-color:var(--brass); }
  .composer-actions{
    display:flex;
    align-items:center;
    gap:2px; /* Tightened gap between icons to save space */
  }

  textarea#input::placeholder{ color:var(--mist); }
  #send-btn{
    background:var(--brass);
    border:none;
    width:34px !important;
    height:34px !important;
    border-radius:10px;
    display:flex;align-items:center;justify-content:center;
    cursor:pointer;
    flex-shrink:0;
    transition:all .15s ease;
    color:var(--ink-deep);
  }
  #send-btn:hover{ background:var(--brass-bright); transform:translateY(-1px); }
  #send-btn:disabled{ opacity:0.4; cursor:not-allowed; transform:none; }
  #send-btn svg{ width:17px;height:17px; }
  .hint{
    max-width:860px;
    margin:6px auto 0;
    font-size:11px;
    color:var(--mist);
    text-align:right;
    padding-right:4px;
  }
  .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;
  }

  /* Empty state */
  .empty-state{
    margin:auto;
    text-align:center;
    max-width:420px;
    padding:20px;
  }
  .empty-state .crest-lg{
    width:64px;height:64px;
    border:1px solid var(--brass);
    border-radius:50%;
    margin:0 auto 18px;
    display:flex;align-items:center;justify-content:center;
    font-family:var(--font-display);
    font-weight:700;
    font-size:24px;
    color:var(--brass-bright);
    background:radial-gradient(circle at 35% 30%, rgba(220,182,121,0.16), transparent 70%);
  }
  .empty-state h2{
    font-family:var(--font-display);
    font-weight:600;
    font-size:24px;
    margin:0 0 8px;
    color:var(--parchment);
  }
  .empty-state p{
    font-size:13.5px;
    color:var(--mist);
    line-height:1.6;
    margin:0 0 18px;
  }
  .empty-state button{
    background:transparent;
    border:1px solid var(--brass);
    color:var(--brass-bright);
    font-family:var(--font-ui);
    font-size:13px;
    padding:9px 18px;
    border-radius:8px;
    cursor:pointer;
    transition:all .15s ease;
  }
  .empty-state button:hover{ background:rgba(184,146,90,0.12); }

  /* Conversation archive & Library tabs */
  .archive-header{
    display:flex;
    align-items:center;
    justify-content:space-between;
    max-width:860px;
    width:100%;
    margin:0 auto 10px;
  }
  .archive-header h2{
    margin:0;
    font-family:var(--font-display);
    font-weight:600;
    font-size:24px;
    color:var(--parchment);
  }
  .archive-tab-nav {
    display: flex;
    gap: 4px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
    padding-left: 8px;
    border-bottom: 2px solid var(--hairline);
  }
  .archive-tab-btn {
    padding: 8px 18px;
    font-size: 13.5px;
    font-family: var(--font-ui);
    font-weight: 600;
    letter-spacing: 0.3px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    background: var(--ink-panel);
    border: 1px solid var(--hairline);
    border-bottom: none;
    color: var(--mist);
    cursor: pointer;
    position: relative;
    top: 2px;
    transition: all 0.18s ease;
  }
  .archive-tab-btn:hover {
    color: var(--parchment);
    background: var(--ink-panel-2);
  }
  .archive-tab-btn.active {
    background: var(--ink-panel-2);
    border-color: var(--brass);
    border-bottom: 2px solid var(--ink-panel-2);
    color: var(--brass-bright);
    z-index: 2;
  }
  [data-theme="light"] .archive-tab-btn.active {
    background: var(--ink-panel-2);
    border-bottom-color: var(--ink-panel-2);
    color: var(--parchment);
  }
  .archive-panel-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 860px;
    width: 100%;
    margin: 12px auto 10px;
  }

  #archive-overlay{
    display:none;
    position:fixed;
    inset:0;
    background:var(--ink-deep);
    z-index:90;
    flex-direction:column;
    padding:18px 16px;
  }
  #archive-overlay.open{ display:flex; }
  .archive-header{
    display:flex;
    align-items:center;
    justify-content:space-between;
    max-width:860px;
    width:100%;
    margin:0 auto 14px;
  }
  .archive-header h2{
    margin:0;
    font-family:var(--font-display);
    font-weight:600;
    font-size:20px;
    color:var(--parchment);
  }
  .archive-list{
    max-width:860px;
    width:100%;
    margin:0 auto;
    overflow-y:auto;
    display:flex;
    flex-direction:column;
    gap:8px;
  }
  .archive-row{
    display:flex;
    align-items:center;
    gap:10px;
    background:var(--ink-panel-2);
    border:1px solid var(--hairline);
    border-radius:10px;
    padding:8px 10px;
  }
  #close-archives {
    font-size: 30px !important;
    width: 40px !important;
    height: 40px !important;
    line-height: 1;
    color: var(--parchment-dim);
  }
  #close-archives:hover {
    color: var(--parchment);
  }
  #refine-titles-btn {
    background: #ffffff !important;
    border: 1.5px solid var(--brass) !important;
    padding: 6px 10px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 38px;
  }
  #refine-titles-btn svg {
    width: 18px !important;
    height: 18px !important;
  }
  .story-book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 16px;
    padding: 8px 0;
  }
  .story-book-card {
    aspect-ratio: 2 / 3;
    background: linear-gradient(145deg, #3a2216 0%, #20120a 100%);
    border: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: 6px;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 6px 14px rgba(0,0,0,0.5);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
    text-align: center;
    position: relative;
  }
  .story-book-card.dragging{
    opacity: 0.5;
    transform: scale(1.03);
    z-index: 5;
  }
  .story-drag-handle{
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--brass-bright);
    background: rgba(0,0,0,0.35);
    border-radius: 5px;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .story-drag-handle:active{ cursor: grabbing; }
  .story-book-card:hover {
    transform: translateY(-2px);
    border-color: var(--brass-bright);
  }
   .archive-panel-toolbar input[type="text"] {
    flex: 0 1 280px;
    background: var(--ink-panel-2);
    border: 1px solid var(--hairline);
    color: var(--parchment);
    font-family: var(--font-ui);
    font-size: 13px;
    padding: 7px 12px;
    border-radius: 8px;
    outline: none;
  }
  .story-book-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    font-style: italic;
    color: #f5eedf !important;
    line-height: 1.35;
    margin-top: 4px;
    letter-spacing: 0.3px;
  }
  .story-book-meta {
    font-size: 11.5px;
    color: #cfc4b0 !important;
    margin-bottom: 8px;
  }

  .story-book-card .read-story-btn {
    background: #ffffff !important;
    color: #1a261f !important;
    border: 1px solid rgba(0,0,0,0.15) !important;
    font-weight: 700;
  }
  .story-book-card .read-story-btn:hover {
    background: #f7f3eb !important;
  }

  .archive-title-wrap {
    flex:1;
    display:flex;
    flex-direction:column;
    min-width:0;
  }
  .archive-input{
    flex:1;
    background:transparent;
    border:none;
    outline:none;
    color:var(--parchment);
    font-family:var(--font-ui);
    font-size:14px;
    padding:6px 4px 0;
  }
  .archive-timestamp{
    font-family:var(--font-ui);
    font-size:12px;
    color:var(--mist);
    padding:0 4px 4px;
  }
  .meta-line{
    font-family:var(--font-ui);
    font-size:11px;
    color:var(--mist);
    margin-top:8px;
    padding-top:7px;
    border-top:1px solid var(--hairline);
    letter-spacing:0.2px;
  }
  .archive-btn{
    background:var(--brass);
    border:none;
    color:var(--ink-deep);
    padding:8px 16px;
    border-radius:8px;
    cursor:pointer;
    font-weight:600;
    font-size:13px;
    flex-shrink:0;
  }
  .archive-btn:hover{ background:var(--brass-bright); }

  /* Modal Styling */
  .modal-overlay{
    display:none;
    position:fixed;
    inset:0;
    z-index:1000;
    background:rgba(0,0,0,0.55);
    align-items:center;
    justify-content:center;
    padding:16px;
  }
  .modal-overlay.open{ display:flex; }
  .modal{
    background:var(--ink-panel);
    border:1px solid var(--hairline);
    border-radius:14px;
    box-shadow:var(--shadow);
    width:100%;
    max-width:520px;
    max-height:90vh;
    display:flex;
    flex-direction:column;
    padding:20px;
  }
  .modal-header{
    display:flex;
    align-items:center;
    justify-content:space-between;
    margin-bottom:14px;
  }
  #voice-settings-btn {
    background: #fff;
    border: solid var(--brass) 2px;
    font-size: 15px;
  }
  .modal-header h2{
    font-family:var(--font-display);
    font-size:24px;
    color:var(--parchment);
    margin:0;
  }
  .modal-body{ overflow-y:auto; flex:1; padding-right:4px; }
  .field{ margin-bottom:18px; }
  .field > label{
    display:block;
    font-size:11.5px;
    text-transform:uppercase;
    letter-spacing:0.8px;
    color:var(--parchment-dim);
    margin-bottom:7px;
  }

    .btn-secondary:hover{ 
    border-color:var(--claret); 
    color:var(--claret) 
  }

  /* Character Voices modal */
  .voice-modal-intro{
    font-size:12px;
    color:var(--parchment-dim);
    margin-top:0;
  }
  .voice-row{
    border-bottom:1px solid var(--hairline);
    padding:10px 0;
  }
  .voice-row-header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-bottom:6px;
  }
  .voice-row-header strong{
    font-family:var(--font-display);
    font-size:16px;
    color:var(--parchment);
  }
  .voice-row .test-voice-btn{
    padding:4px 10px;
    font-size:11px;
  }
  .voice-slider-row{
    display:flex;
    align-items:center;
    gap:8px;
    font-size:12px;
    color:var(--parchment-dim);
    margin-bottom:4px;
  }
  .voice-slider-row:last-child{ margin-bottom:0; }
  .voice-slider-row input[type="range"]{ flex:1; }
  .voice-val{
    width:34px;
    text-align:right;
    color:var(--parchment-dim);
  }

  input[type="range"]{
    -webkit-appearance:none;
    appearance:none;
    height:4px;
    background:var(--ink-deep);
    border-radius:2px;
    outline:none;
  }
  input[type="range"]::-webkit-slider-thumb{
    -webkit-appearance:none;
    appearance:none;
    width:16px;
    height:16px;
    border-radius:50%;
    background:var(--brass);
    border:1px solid var(--brass-bright);
    cursor:pointer;
  }
  input[type="range"]::-moz-range-thumb{
    width:16px;
    height:16px;
    border-radius:50%;
    background:var(--brass);
    border:1px solid var(--brass-bright);
    cursor:pointer;
  }
  input[type="range"]::-moz-range-track{
    background:var(--ink-deep);
    height:4px;
    border-radius:2px;
  }

  /* Settings Section Cards & Headers */
  .settings-section {
    background: var(--ink-panel-2);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 16px 18px 18px;
    margin-bottom: 18px;
  }
  .settings-section:last-child { margin-bottom: 0; }
  .section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(184, 146, 90, 0.15);
  }
  .section-numeral {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    color: var(--brass-bright);
    background: rgba(184, 146, 90, 0.15);
    border: 1px solid var(--hairline);
    padding: 1px 7px;
    border-radius: 4px;
    letter-spacing: 0.5px;
  }
  .section-title {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    color: var(--parchment);
    letter-spacing: 0.5px;
    margin: 0;
    flex: 1;
  }
  .auth-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--ink-deep);
    border: 1px solid var(--hairline);
    margin-bottom: 14px;
  }
  details.overrides-details summary {
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--brass-bright);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
  }
  details.overrides-details summary::-webkit-details-marker { display: none; }
  details.overrides-details summary::before {
    content: "▸";
    display: inline-block;
    transition: transform 0.2s;
  }
  details.overrides-details[open] summary::before {
    transform: rotate(90deg);
  }

  /* Footer Styling */
  .modal-footer {
    padding: 14px 0 0 0;
    display: flex;
    gap: 10px;
    border-top: 1px solid var(--hairline, #eee);
    margin-top: 15px;
  }

  .field input[type=text], .field input[type=password], .field select{
    width:100%;
    background:var(--ink-deep);
    border:1px solid var(--hairline);
    color:var(--parchment);
    font-family:var(--font-ui);
    font-size:14px;
    padding:10px 12px;
    border-radius:8px;
    outline:none;
    transition:border-color .15s ease;
  }
  .field input:focus, .field select:focus{ border-color:var(--brass); }
    .field select:disabled{ opacity:0.5; }
  .theme-radio-group{
    display:flex;
    background:var(--ink-deep);
    border:1px solid var(--hairline);
    border-radius:8px;
    padding:3px;
    gap:4px;
  }
  .theme-radio-group label{
    flex:1;
    text-align:center;
    padding:8px;
    margin:0;
    font-size:12.5px;
    color:var(--parchment-dim);
    border-radius:6px;
    cursor:pointer;
    text-transform:none;
    letter-spacing:0;
  }
  .theme-radio-group input{ display:none; }
  .theme-radio-group label:has(input:checked){
    background:var(--brass);
    color:var(--ink-deep);
    font-weight:600;
  }

  .key-row{ display:flex; gap:8px; }
  .key-row input{ flex:1; }
  .key-row button{
    background:transparent;
    border:1px solid var(--hairline);
    color:var(--parchment-dim);
    border-radius:8px;
    padding:0 12px;
    cursor:pointer;
    font-size:12px;
  }
  .key-row button:hover{ border-color:var(--brass); color:var(--brass-bright); }
  .field-help{ font-size:11.5px; color:var(--mist); margin-top:6px; line-height:1.5; }
  .field-help a{ color:var(--brass-bright); }
  .status-msg{
    font-size:12.5px;
    padding:9px 12px;
    border-radius:8px;
    margin-bottom:14px;
    display:none;
  }
  .status-msg.show{ display:block; }
  .status-msg.error{ background:rgba(138,59,70,0.18); border:1px solid var(--claret); color:#B8484B; }
  .status-msg.ok{ background:rgba(184,146,90,0.12); border:1px solid var(--brass); color:var(--brass-bright); }
  .status-msg.loading{ background:rgba(125,150,134,0.1); border:1px solid var(--hairline); color:var(--mist); }
  .model-badge{
    display:inline-block;
    font-size:10px;
    letter-spacing:0.5px;
    text-transform:uppercase;
    color:var(--ink-deep);
    background:var(--brass-bright);
    padding:2px 6px;
    border-radius:4px;
    margin-left:6px;
    vertical-align:middle;
  }

  .btn-primary, .btn-secondary{
    flex:1;
    padding:11px 14px;
    border-radius:9px;
    font-family:var(--font-ui);
    font-size:13.5px;
    font-weight:600;
    cursor:pointer;
    transition:all .15s ease;
  }
  .btn-primary{
    background:var(--brass);
    border:1px solid var(--brass);
    color:var(--ink-deep);
  }
  .btn-primary:hover{ background:var(--brass-bright); }
  .btn-secondary{
    background:transparent;
    border:1px solid var(--hairline);
    color:var(--parchment-dim);
  }
  .btn-secondary:hover{ 
    border-color:var(--claret); 
    color:var(--claret) 
  }

  /* Image attachment preview */
  .image-preview-bar{
    max-width:860px;
    margin:0 auto 8px;
    display:none;
    align-items:center;
    gap:10px;
  }
  .image-preview-bar.show{ display:flex; }
  .img-thumb-wrap{
    position:relative;
    display:inline-block;
  }
  .img-thumb-wrap img{
    height:60px;
    border-radius:6px;
    border:1px solid var(--hairline);
    object-fit:cover;
  }
  .img-thumb-remove{
    position:absolute;
    top:-6px; right:-6px;
    background:var(--claret);
    color:#fff;
    border:none;
    border-radius:50%;
    width:18px; height:18px;
    font-size:12px;
    line-height:1;
    cursor:pointer;
    display:flex; align-items:center; justify-content:center;
  }
  .bubble-img{
    max-width:100%;
    max-height:300px;
    border-radius:6px;
    margin-bottom:8px;
    display:block;
  }
  .msg-row.user .bubble{
  background:linear-gradient(180deg, #24382c, #1c2e24);
  border:1px solid var(--hairline);
  font-family:var(--font-ui);
  font-size:14.5px;
  color:var(--parchment);
  border-top-right-radius:3px;
  }
  .convo-select{
    appearance:none; -webkit-appearance:none;
    background:var(--ink-panel-2);
    border:1px solid var(--hairline);
    color:var(--parchment);
    padding:0 28px 0 12px;
    height:38px;
    border-radius:10px;
    font-family:var(--font-ui);
    font-size:13px;
    cursor:pointer;
    outline:none;
  }
  .convo-wrap{ 
    position:relative; margin-left:auto; display:flex; align-items:center; 
  }
  .footnote-ref {
    color: var(--brass-bright);
    text-decoration: none;
    cursor: pointer;
    font-weight: 600;
    padding: 0 1px;
    border-radius: 3px;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .footnote-ref:hover, .footnote-ref:focus-visible {
    background: rgba(184, 146, 90, 0.22);
    outline: none;
  }
  .footnote-highlight {
    animation: highlight-fade 2s ease-out;
    border-radius: 4px;
  }
  @keyframes highlight-fade {
    from { background: rgba(255, 255, 0, 0.3); }
    to { background: transparent; }
  }

  .bubble h4 { border-top:1px solid var(--hairline); padding-top:10px; margin:10px 0 5px; }


  #convo-type {
    -webkit-appearance: none;
    appearance: none;
    width: 36px;
    padding-left: 8px !important;
    transition: width 0.2s;
  }
#convo-type:focus { width: 180px !important; }

.composer-inner {
  display: grid;
  width: 100%;
  margin: 0px auto;
}

/* Treat both the pseudo-element and the textarea as the same grid cell */
.composer-inner::after,
.composer-inner textarea {
  grid-area: 1 / 1 / 2 / 2;
  font: inherit;
  padding: 0.5rem;
  border: 1px solid #ccc;
}

/* This invisible pseudo-element stretches the container */
.composer-inner::after {
  content: attr(data-replicated-value) " ";
  white-space: pre-wrap;
  visibility: hidden;
}

.composer-inner textarea {
  resize: none;
  overflow: hidden;
}

.tooltip-btn {
  position: relative;
}

.tooltip-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 8px;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: nowrap;
  background-color: #1f2937;
  color: #ffffff;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 50;
}

.tooltip-btn:hover::after,
.tooltip-btn:focus-visible::after {
  visibility: visible;
  animation: tooltipAutoHide 1.4s ease forwards;
}

@keyframes tooltipAutoHide {
  0%   { opacity: 0; transform: translateX(-50%) translateY(4px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(0); }
}

  /* Speed control responsive row */
  .speed-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }
  .speed-control-row #test-voice-btn {
    height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    flex-shrink: 0;
  }

  @media (max-width:600px){
    header.letterhead{ padding:12px 14px 10px; }
    .brand-text h1{ font-size:19px; }

    /* Test voice button drops beneath slider on small screens */
    .speed-control-row #test-voice-btn {
      width: 100%;
      margin-top: 4px;
    }

    /* Half-in / half-out avatar styling to maximize bubble width */
    main#chat {
      padding: 18px 8px 10px;
      gap: 20px;
    }
    .msg-row {
      position: relative;
      margin: 0;
      width: 100%;
    }
    .msg-row .avatar,
    .msg-row .avatar-img {
      position: absolute;
      top: -10px;
      z-index: 5;
      width: 28px;
      height: 28px;
      margin: 0;
      box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    }
    .msg-row.model .avatar-img {
      left: 6px;
    }
    .msg-row.user .avatar {
      right: 6px;
    }
    .bubble {
      max-width: 95% !important;
      font-size: 15px;
      padding-top: 14px;
    }
    .msg-row.model .bubble {
      font-size: 16.5px;
      padding-left: 28px; /* subtle clearance for the crest */
      margin-left: 10px;
      margin-right: auto;
    }
    .msg-row.user .bubble {
      padding-right: 28px; /* subtle clearance for the 'Y' badge */
      margin-right: 10px;
      margin-left: auto;
    }
  }


