:root{
  --story-text:var(--yoru-story-text,#eeeae4);
  --story-muted:var(--yoru-story-muted,#aaa6ad);
  --story-surface:var(--yoru-story-surface,rgba(20,19,22,.92));
  --story-surface-strong:var(--yoru-story-surface-strong,rgba(14,14,17,.97));
  --story-border:var(--yoru-story-border,rgba(241,232,218,.10));
  --story-shadow:0 18px 50px rgba(0,0,0,.22);
}

#chat-view .chat-layout{
  grid-template-columns:220px minmax(0,1fr);
  align-items:stretch;
  position:relative;
}

#chat-view .chat-layout > aside{
  min-width:0;
  overflow:hidden;
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:10px;
  border:1px solid var(--story-border);
  border-radius:17px;
  background:var(--story-surface-strong);
  box-shadow:var(--story-shadow);
}

#chat-view .chat-layout > aside #chat-character-card img{
  width:132px;
  height:132px;
  max-width:100%;
  display:block;
  object-fit:cover;
  object-position:center top;
  border-radius:16px;
  margin:0 auto 14px;
}

#chat-view .chat-layout > aside .secondary,
#chat-view .chat-layout > aside .text-button{
  max-width:100%;
}

#chat-view .chat-main{
  min-width:0;
  background:var(--story-surface-strong);
  box-shadow:var(--story-shadow);
}

#chat-view .chat-topline{
  display:flex;
  align-items:center;
  gap:14px;
}

#chat-view .chat-title-avatar{
  flex:0 0 auto;
  width:68px;
  height:68px;
  display:block;
  object-fit:cover;
  object-position:center top;
  border:1px solid var(--story-border);
  border-radius:14px;
  background:#0b0e14;
}

#chat-view .chat-title-avatar[hidden]{
  display:none;
}

#chat-view .chat-title-copy{
  min-width:0;
}

#chat-view .chat-title-copy h2{
  overflow-wrap:anywhere;
}

#chat-view .story-mobile-tools{
  display:none;
}

#chat-view .chat-stream{
  min-height:520px;
  max-height:70vh;
  background:
    radial-gradient(circle at 50% 0,var(--yoru-reading-glow,rgba(214,170,115,.035)),transparent 34%),
    linear-gradient(180deg,var(--yoru-reading,#141316),#111115);
  scrollbar-gutter:stable;
}

#chat-view .message{
  position:relative;
}

#chat-view .message .bubble{
  color:var(--story-text);
  max-width:min(86%,760px);
  overflow-wrap:anywhere;
  word-break:break-word;
}

#chat-view .message.assistant .bubble:not(.authored-rich-message){
  color:var(--story-text)!important;
  letter-spacing:.008em;
}
#chat-view .message.assistant .bubble:not(.authored-rich-message) p{
  margin:0 0 1.05em;
}
#chat-view .message.assistant .bubble:not(.authored-rich-message) p:last-child{
  margin-bottom:0;
}

#chat-view .message.user .bubble{
  color:var(--story-text);
  background:var(--yoru-player-bubble,#29262b);
}

#chat-view .authored-rich-message{
  width:100%;
  min-width:0!important;
  max-width:100%!important;
  overflow-x:hidden;
  border-left:0!important;
  padding-left:0!important;
}

#chat-view .authored-rich-message,
#chat-view .authored-rich-message *{
  min-width:0!important;
  max-width:100%!important;
  box-sizing:border-box;
}

#chat-view .authored-rich-message > *{
  width:100%!important;
  min-width:0!important;
  max-width:100%!important;
}

#chat-view .authored-rich-message img,
#chat-view .authored-rich-message video,
#chat-view .authored-rich-message iframe,
#chat-view .authored-rich-message table{
  max-width:100%!important;
}

#chat-view .authored-rich-message pre,
#chat-view .authored-rich-message code,
#chat-view .authored-rich-message p,
#chat-view .authored-rich-message li{
  overflow-wrap:anywhere;
  word-break:break-word;
}

#chat-view .authored-rich-message pre{
  white-space:pre-wrap;
}

.story-message-tools{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  margin-top:7px;
  opacity:.38;
  transition:opacity .15s ease;
}

.message:hover .story-message-tools,
.message:focus-within .story-message-tools{
  opacity:1;
}

.story-message-tools button,
.story-variant-switcher button,
.story-inspiration-chip,
.story-copy-chip{
  border:1px solid var(--story-border);
  background:var(--yoru-tool-raised,#1b191e);
  color:var(--story-muted);
  border-radius:9px;
  padding:6px 9px;
  cursor:pointer;
  font-size:12px;
}

.story-message-tools button:hover,
.story-variant-switcher button:hover,
.story-inspiration-chip:hover,
.story-copy-chip:hover{
  color:var(--story-text);
  border-color:rgba(214,170,115,.24);
  background:rgba(214,170,115,.08);
}

.story-message-tools button:disabled,
.story-variant-switcher button:disabled{
  opacity:.38;
  cursor:not-allowed;
}

.story-variant-switcher{
  display:flex;
  align-items:center;
  gap:7px;
  margin-top:8px;
  color:var(--story-muted);
  font-size:11px;
}

.story-variant-switcher button{
  padding:4px 8px;
}

.story-edited-badge{
  font-size:10px;
  color:#aeb5c1;
  border:1px solid var(--story-border);
  border-radius:999px;
  padding:2px 6px;
}

.story-inspiration-panel{
  margin-top:10px;
  padding:11px;
  border:1px solid var(--story-border);
  background:rgba(18,17,20,.82);
  border-radius:12px;
  display:grid;
  gap:8px;
}

.story-inspiration-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  color:var(--story-muted);
  font-size:12px;
}

.story-inspiration-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  gap:7px;
  align-items:stretch;
}

.story-inspiration-chip{
  text-align:left;
  line-height:1.5;
}

.story-copy-chip{
  width:38px;
  padding:0;
}

.story-inline-editor{
  display:grid;
  gap:9px;
  width:min(100%,760px);
}

.story-inline-editor textarea{
  min-height:150px;
  line-height:1.8;
  resize:vertical;
  position:static;
  inset:auto;
  transform:none;
}

.story-inline-actions{
  display:flex;
  justify-content:flex-end;
  gap:7px;
}

.story-inline-actions button{
  width:auto;
}

.story-busy{
  opacity:.68;
  pointer-events:none;
}

#chat-view .composer{
  display:flex;
  gap:9px;
  padding:13px;
  background:var(--yoru-tool,#101116);
  border-top:1px solid var(--story-border);
}

#chat-view .composer textarea{
  min-height:58px;
  max-height:180px;
  min-width:0;
}

#chat-view .composer .primary{
  width:92px;
  align-self:stretch;
}

#chat-view .composer .story-cancel-generation{
  width:92px;
  flex:0 0 auto;
  align-self:stretch;
  padding-inline:8px;
}

@media(max-width:1180px) and (min-width:821px){
  #chat-view .chat-layout{
    grid-template-columns:190px minmax(0,1fr);
  }
}

@media(max-width:820px){
  #chat-view{
    padding:10px 0 28px;
  }

  #chat-view .chat-layout{
    grid-template-columns:1fr;
    min-height:calc(100vh - 108px);
    overflow:hidden;
    border-radius:18px;
  }

  #chat-view .chat-sidebar,
  #chat-view .chat-layout > aside{
    display:none!important;
  }

  #chat-view .chat-main{
    position:relative;
    z-index:1;
    width:100%;
    min-width:0;
    justify-self:center;
    border-color:rgba(255,255,255,.1);
    background:var(--story-surface-strong);
  }

  #chat-view .chat-topline{
    gap:12px;
    padding:13px 14px;
    background:var(--story-surface-strong);
  }

  #chat-view .chat-title-avatar{
    width:58px;
    height:58px;
    border-radius:12px;
  }

  #chat-view .chat-topline h2{
    font-size:26px;
  }

  #chat-view .story-mobile-tools{
    display:flex;
    order:40;
    gap:7px;
    padding:9px 10px calc(9px + env(safe-area-inset-bottom,0px));
    overflow-x:auto;
    overscroll-behavior-x:contain;
    scrollbar-width:none;
    -webkit-overflow-scrolling:touch;
    border-top:1px solid var(--story-border);
    border-bottom:1px solid var(--story-border);
    background:var(--yoru-tool,#101116);
    box-shadow:0 -12px 28px rgba(0,0,0,.22);
  }

  #chat-view .story-mobile-tools::-webkit-scrollbar{
    display:none;
  }

  #chat-view .story-mobile-tools button{
    flex:0 0 auto;
    min-height:40px;
    white-space:nowrap;
    word-break:keep-all;
    border:1px solid var(--story-border);
    border-radius:10px;
    padding:8px 11px;
    color:var(--story-text);
    background:var(--yoru-tool-raised,#1b191e);
    cursor:pointer;
    font-size:13px;
  }

  #chat-view .chat-topline{order:10}
  #chat-view .chat-stream{order:20}
  #chat-view #game-ui{order:25}
  #chat-view .usage-bar{order:30}
  #chat-view .composer{order:50}

  #chat-view .chat-stream{
    min-height:58vh;
    max-height:none;
    padding:14px 10px;
    background:
      radial-gradient(circle at 50% 0,var(--yoru-reading-glow,rgba(214,170,115,.035)),transparent 34%),
      linear-gradient(180deg,var(--yoru-reading,#141316),#111115);
  }

  #chat-view .message .bubble{
    max-width:100%;
    text-shadow:0 1px 8px rgba(0,0,0,.22);
  }

  #chat-view .message.user .bubble{
    max-width:94%;
    background:rgba(41,38,43,.90);
    backdrop-filter:blur(5px);
  }

  #chat-view .authored-rich-message{
    overflow-x:hidden;
  }

  #chat-view .authored-rich-message > div:first-child{
    width:100%!important;
    max-width:100%!important;
    margin:0!important;
    padding:14px 9px!important;
    background:rgba(18,17,20,.34)!important;
    border-radius:14px!important;
    box-shadow:none!important;
  }

  #chat-view .authored-rich-message > div:first-child > div,
  #chat-view .authored-rich-message > div:first-child > details{
    max-width:100%!important;
  }

  .story-message-tools{
    opacity:.76;
  }

  .story-inspiration-panel{
    background:rgba(18,17,20,.86);
    backdrop-filter:blur(7px);
  }
}

@media(max-width:560px){
  #chat-view .chat-stream{
    padding:10px 6px;
  }

  #chat-view .chat-topline{
    gap:10px;
    padding:11px 12px;
  }

  #chat-view .chat-title-avatar{
    width:50px;
    height:50px;
    border-radius:11px;
  }

  #chat-view .story-mobile-tools{
    padding:8px 7px calc(8px + env(safe-area-inset-bottom,0px));
  }

  #chat-view .chat-topline .eyebrow{
    font-size:10px;
  }

  #chat-view .chat-topline h2{
    font-size:25px;
  }

  #chat-view .usage-bar{
    gap:8px 12px;
    padding:8px 11px;
  }

  #chat-view .composer{
    padding:10px;
  }

  #chat-view .composer .primary{
    width:70px;
  }

  #chat-view .composer .story-cancel-generation{
    width:70px;
  }

  .story-inspiration-row{
    grid-template-columns:minmax(0,1fr) 34px;
  }
}

@media(max-width:820px){
  .story-inline-editor{width:100%;max-width:100%}
  .story-inline-editor textarea{
    width:100%;
    min-height:180px;
    max-height:52dvh;
    overflow:auto;
    position:static!important;
    inset:auto!important;
    transform:none!important;
    font-size:16px;
  }
}

/* The portrait has its own space; prose follows a comfortable reading measure. */
#chat-view[data-bao-surface="play"] .chat-layout > aside #chat-character-card img{
  width:100%;height:auto;max-height:260px;object-fit:contain;
  border-radius:14px;margin-bottom:18px;background:var(--story-surface);
}
#chat-view[data-bao-surface="play"] .message.assistant .bubble p{margin-block:0 1.15em}
#chat-view[data-bao-surface="play"] .message.assistant .bubble p:last-child{margin-bottom:0}
#chat-view[data-bao-surface="play"] .chat-title-copy h2{line-height:1.45;letter-spacing:.025em}
#chat-view[data-bao-surface="play"] .chat-title-copy p{line-height:1.7;color:var(--story-muted)}
