:root{
  --bg:#f7f8fa;
  --surface:#ffffff;
  --surface-soft:#f4f6f8;
  --surface-user:#eef2f6;
  --text:#1f2937;
  --muted:#667085;
  --muted-2:#8a94a3;
  --line:#e5e8ed;
  --line-strong:#d7dce3;
  --accent:#29364a;
  --accent-soft:#eef1f5;
  --danger:#b42318;
  --radius:18px;
  --shadow:0 14px 40px rgba(16,24,40,.07);
}
*{box-sizing:border-box}
html,body{height:100%;overflow:hidden}
body{
  margin:0;
  color:var(--text);
  background:var(--bg);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Hiragino Kaku Gothic ProN","Yu Gothic",Meiryo,sans-serif;
  -webkit-font-smoothing:antialiased;
}
button,select,textarea{font:inherit}
button,a,select{ -webkit-tap-highlight-color:transparent }
button:focus-visible,a:focus-visible,select:focus-visible,textarea:focus-visible{
  outline:2px solid #667085;
  outline-offset:2px;
}

.app-shell{
  width:min(920px,100%);
  height:100dvh;
  min-height:0;
  margin:0 auto;
  background:var(--surface);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  box-shadow:0 0 0 1px rgba(16,24,40,.03),var(--shadow);
}
.app-header{
  flex:0 0 auto;
  border-bottom:1px solid var(--line);
  background:rgba(255,255,255,.96);
  backdrop-filter:blur(12px);
  z-index:20;
}
.header-inner{
  height:62px;
  padding:0 18px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.brand{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
  color:inherit;
  text-decoration:none;
}
.brand-avatar{
  width:36px;height:36px;border-radius:50%;
  object-fit:cover;background:#fff;border:1px solid var(--line);
}
.brand-copy{display:flex;flex-direction:column;min-width:0;line-height:1.15}
.brand-title{font-size:16px;font-weight:720;letter-spacing:.01em;white-space:nowrap}
.brand-sub{font-size:10px;color:var(--muted);margin-top:4px;white-space:nowrap}
.beta-badge{
  font-size:9px;color:var(--muted);
  padding:3px 6px;border:1px solid var(--line);
  border-radius:999px;white-space:nowrap;
}
.header-actions{display:flex;align-items:center;gap:7px}
.icon-button,.new-chat-button{
  border:1px solid var(--line);
  background:#fff;color:#475467;
  cursor:pointer;
}
.icon-button{
  width:36px;height:36px;border-radius:10px;padding:8px;
  display:inline-flex;align-items:center;justify-content:center;
}
.icon-button svg{width:18px;height:18px}
.icon-button:hover,.new-chat-button:hover{background:#f7f8fa}
.new-chat-button{
  min-height:36px;border-radius:10px;padding:7px 11px;
  display:inline-flex;align-items:center;gap:6px;
  font-size:12px;font-weight:600;
}
.new-chat-button svg{width:16px;height:16px}

.chat{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  overscroll-behavior:contain;
  scrollbar-gutter:stable;
  padding:26px 22px 34px;
  scroll-behavior:smooth;
}
.welcome{
  width:min(720px,100%);
  margin:7vh auto 0;
  text-align:center;
}
.welcome-mark{margin-bottom:12px}
.welcome-avatar{
  width:78px;height:78px;border-radius:50%;
  object-fit:cover;border:1px solid var(--line);
  background:#fff;
  box-shadow:0 8px 24px rgba(16,24,40,.07);
}
.welcome h1{
  margin:0;
  font-size:26px;
  line-height:1.35;
  letter-spacing:.01em;
  font-weight:720;
}
.welcome-lead{
  max-width:620px;
  margin:10px auto 0;
  color:#596579;
  font-size:14px;
  line-height:1.8;
}
.prompt-grid{
  margin:28px auto 0;
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px;
  text-align:left;
}
.prompt-card{
  min-height:76px;
  padding:13px 15px;
  border:1px solid var(--line);
  border-radius:14px;
  background:#fff;
  cursor:pointer;
  color:var(--text);
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  justify-content:center;
  transition:background .15s ease,border-color .15s ease,transform .15s ease;
}
.prompt-card:hover{
  background:#fafbfc;
  border-color:var(--line-strong);
  transform:translateY(-1px);
}
.prompt-card-title{font-size:13px;font-weight:700}
.prompt-card-text{font-size:11px;color:var(--muted);margin-top:5px;line-height:1.5}
.welcome-note{
  margin:18px auto 0;
  color:var(--muted-2);
  font-size:10px;
  line-height:1.7;
}

/* Conversation */
.turn{width:min(760px,100%);margin:0 auto 26px}
.user-message{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:5px;
  margin-bottom:20px;
}
.user-label,.assistant-label{
  color:var(--muted-2);
  font-size:10px;
  line-height:1;
}
.user-bubble{
  max-width:78%;
  padding:11px 14px;
  border-radius:17px 17px 5px 17px;
  background:var(--surface-user);
  font-size:14px;
  line-height:1.75;
  white-space:pre-wrap;
  word-break:break-word;
}
.user-actions{height:28px;display:flex;align-items:center;justify-content:flex-end}
.mini-icon-button{
  border:0;background:transparent;color:#7a8494;
  width:28px;height:28px;border-radius:8px;padding:6px;cursor:pointer;
  display:inline-flex;align-items:center;justify-content:center;
}
.mini-icon-button:hover{background:#f2f4f7;color:#344054}
.mini-icon-button svg{width:15px;height:15px}

.assistant-message{
  display:grid;
  grid-template-columns:32px minmax(0,1fr);
  gap:10px;
  align-items:start;
}
.assistant-avatar{
  width:30px;height:30px;border-radius:50%;
  object-fit:cover;border:1px solid var(--line);background:#fff;
}
.assistant-content{min-width:0}
.assistant-label{margin:2px 0 8px}
.answer-body{
  font-size:14px;
  line-height:1.85;
  color:#263142;
  word-break:break-word;
}
.answer-body p{margin:0 0 13px}
.answer-body p:last-child{margin-bottom:0}

/* v2.3: 生成途中はプレーンテキストで即時表示し、完了時に整形する */
.streaming-answer{
  white-space:pre-wrap;
  min-height:1.85em;
}
.streaming-answer::after{
  content:"";
  display:inline-block;
  width:2px;
  height:1.05em;
  margin-left:2px;
  vertical-align:-.14em;
  background:#667085;
  border-radius:1px;
  animation:streamCaret .9s steps(1,end) infinite;
}
@keyframes streamCaret{
  0%,48%{opacity:.75}
  49%,100%{opacity:0}
}
.answer-heading{
  margin:20px 0 8px;
  font-size:14px;
  line-height:1.5;
  font-weight:750;
  color:#1d2939;
}
.answer-heading:first-child{margin-top:0}
.answer-list{
  margin:0 0 14px;
  padding-left:1.45em;
}
.answer-list li{margin:4px 0;padding-left:.15em}
.answer-numbered{list-style:decimal}
.web-citation{
  display:inline-flex;
  align-items:center;justify-content:center;
  min-width:18px;height:18px;
  margin:0 2px;
  padding:0 5px;
  border:1px solid #d0d5dd;
  border-radius:999px;
  background:#f8fafc;
  color:#475467;
  text-decoration:none;
  font-size:9px;
  line-height:1;
  vertical-align:baseline;
  transform:translateY(-1px);
}
.web-citation:hover{background:#eef2f6;color:#1d2939}

.thinking-row{
  min-height:38px;
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--muted);
  font-size:13px;
}
.thinking-dots{display:inline-flex;align-items:center;gap:4px;height:18px}
.thinking-dots span{
  width:5px;height:5px;border-radius:50%;background:#667085;
  animation:harunoDot 1.15s infinite ease-in-out;
}
.thinking-dots span:nth-child(2){animation-delay:.15s}
.thinking-dots span:nth-child(3){animation-delay:.30s}
@keyframes harunoDot{
  0%,60%,100%{transform:translateY(0);opacity:.3}
  30%{transform:translateY(-4px);opacity:1}
}

.answer-actions{
  display:flex;
  align-items:center;
  gap:2px;
  margin-top:9px;
}
.answer-action{
  border:0;background:transparent;color:#667085;
  height:30px;border-radius:8px;padding:6px 8px;
  display:inline-flex;align-items:center;gap:5px;
  cursor:pointer;font-size:11px;
}
.answer-action:hover{background:#f2f4f7;color:#344054}
.answer-action svg{width:15px;height:15px}
.provenance{
  display:flex;flex-wrap:wrap;gap:5px;
  margin:8px 0 0;
}
.provenance-badge{
  font-size:9px;line-height:1;
  color:#667085;
  border:1px solid var(--line);
  background:#fafbfc;
  border-radius:999px;
  padding:5px 7px;
}

.source-details{
  margin-top:10px;
  border-top:1px solid #edf0f3;
  padding-top:4px;
}
.source-details summary{
  list-style:none;
  min-height:34px;
  display:flex;
  align-items:center;
  gap:7px;
  color:#475467;
  font-size:11px;
  font-weight:650;
  cursor:pointer;
}
.source-details summary::-webkit-details-marker{display:none}
.source-chevron{
  width:14px;height:14px;transition:transform .15s ease;
}
.source-details[open] .source-chevron{transform:rotate(90deg)}
.source-count{
  min-width:19px;height:19px;padding:0 6px;border-radius:999px;
  display:inline-flex;align-items:center;justify-content:center;
  color:#667085;background:#f2f4f7;font-size:9px;
}
.source-list{display:flex;flex-direction:column;gap:0;padding:0 0 4px 20px}
.source-link{
  color:#344054;text-decoration:none;
  font-size:11px;line-height:1.55;
  padding:7px 0;
  border-top:1px solid #f0f2f5;
}
.source-link:first-child{border-top:0}
.source-link:hover{text-decoration:underline}
.source-domain{display:block;color:#98a2b3;font-size:9px;margin-top:2px}

.followups{
  margin-top:11px;
  display:flex;
  gap:7px;
  flex-wrap:wrap;
}
.followup{
  border:1px solid var(--line);
  background:#fff;
  color:#475467;
  border-radius:999px;
  padding:7px 10px;
  font-size:11px;
  line-height:1.35;
  cursor:pointer;
}
.followup:hover{background:#f7f8fa}

/* Inline edit */
.inline-edit-shell{
  width:min(620px,94%);
  border:1px solid var(--line-strong);
  border-radius:16px;
  background:var(--surface-user);
  padding:9px 10px 8px;
}
.inline-edit-textarea{
  width:100%;
  min-height:90px;
  max-height:240px;
  resize:none;
  border:0;
  outline:0;
  color:var(--text);
  background:transparent;
  padding:4px 5px 8px;
  line-height:1.65;
}
.inline-edit-actions{display:flex;justify-content:flex-end;gap:7px}
.inline-edit-cancel,.inline-edit-submit{
  border-radius:999px;
  padding:7px 12px;
  font-size:11px;
  font-weight:650;
  cursor:pointer;
}
.inline-edit-cancel{border:1px solid #d0d5dd;background:#fff;color:#475467}
.inline-edit-submit{border:0;background:var(--accent);color:#fff}

/* Composer */
.composer-area{
  flex:0 0 auto;
  padding:10px 14px calc(8px + env(safe-area-inset-bottom));
  background:linear-gradient(to top,#fff 84%,rgba(255,255,255,.96));
  border-top:1px solid rgba(229,232,237,.9);
}
.composer-shell{
  width:min(790px,100%);
  margin:0 auto;
  border:1px solid var(--line-strong);
  border-radius:20px;
  background:#fff;
  box-shadow:0 8px 24px rgba(16,24,40,.07);
  padding:7px 8px 6px 10px;
}
.composer-input{
  width:100%;
  min-height:38px;
  max-height:150px;
  resize:none;
  border:0;
  outline:0;
  padding:7px 5px 4px;
  color:var(--text);
  background:transparent;
  font-size:14px;
  line-height:1.55;
}
.composer-toolbar{
  display:flex;
  align-items:center;
  gap:8px;
  min-height:36px;
}
.length-control{
  display:inline-flex;
  align-items:center;
  gap:5px;
  color:#667085;
  font-size:10px;
}
.length-control select{
  border:0;
  background:#f3f5f7;
  color:#475467;
  border-radius:999px;
  padding:5px 22px 5px 8px;
  font-size:10px;
  cursor:pointer;
}
.keyboard-hint{
  color:#98a2b3;
  font-size:9px;
  margin-left:auto;
}
.send-button{
  width:34px;height:34px;
  margin-left:auto;
  flex:0 0 auto;
  border:0;
  border-radius:50%;
  background:var(--accent);
  color:#fff;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
}
.send-button:disabled{opacity:.38;cursor:not-allowed}
.send-button svg{width:17px;height:17px}
.stop-square{
  width:10px;height:10px;border-radius:2px;background:#fff;display:block;
}
.composer-note{
  width:min(790px,100%);
  margin:6px auto 0;
  color:#98a2b3;
  text-align:center;
  font-size:9px;
  line-height:1.45;
}

/* Modal */
.modal{
  border:0;
  padding:0;
  width:min(540px,calc(100% - 28px));
  border-radius:18px;
  background:transparent;
}
.modal::backdrop{background:rgba(16,24,40,.26);backdrop-filter:blur(2px)}
.modal-card{
  background:#fff;border:1px solid var(--line);border-radius:18px;
  box-shadow:0 24px 70px rgba(16,24,40,.18);
  padding:20px;
}
.modal-head{display:flex;justify-content:space-between;gap:14px;align-items:flex-start}
.modal-head h2{margin:0;font-size:17px}
.modal-head p{margin:5px 0 0;color:#667085;font-size:11px;line-height:1.6}
.modal-section{margin-top:17px}
.modal-section h3{margin:0 0 5px;font-size:12px}
.modal-section p{margin:0;color:#596579;font-size:11px;line-height:1.75}
.modal-links{display:flex;flex-wrap:wrap;gap:8px;margin-top:19px}
.modal-links a,.modal-links button{
  border:1px solid var(--line);background:#fff;color:#475467;
  border-radius:10px;padding:8px 10px;text-decoration:none;font-size:11px;cursor:pointer;
}
.modal-links a:hover,.modal-links button:hover{background:#f7f8fa}

.status-error{
  color:#7a271a;
  background:#fff5f3;
  border:1px solid #fecdca;
  border-radius:12px;
  padding:10px 12px;
  font-size:12px;
  line-height:1.65;
}

@media (max-width:700px){
  body{background:#fff}
  .app-shell{box-shadow:none}
  .header-inner{height:56px;padding:0 12px}
  .brand-avatar{width:32px;height:32px}
  .brand-title{font-size:15px}
  .brand-sub{display:none}
  .beta-badge{font-size:8px}
  .new-chat-button{width:36px;height:36px;padding:8px;border-radius:10px}
  .new-chat-button span{display:none}
  .new-chat-button svg{width:18px;height:18px}
  .chat{padding:18px 13px 24px}
  .welcome{margin-top:4vh}
  .welcome-avatar{width:70px;height:70px}
  .welcome h1{font-size:22px}
  .welcome-lead{font-size:13px}
  .prompt-grid{grid-template-columns:1fr;gap:8px;margin-top:22px}
  .prompt-card{min-height:64px;padding:11px 13px}
  .turn{margin-bottom:23px}
  .user-bubble{max-width:90%;font-size:13px;padding:10px 12px}
  .assistant-message{grid-template-columns:27px minmax(0,1fr);gap:8px}
  .assistant-avatar{width:26px;height:26px}
  .answer-body{font-size:13px;line-height:1.82}
  .answer-heading{font-size:13px}
  .followups{
    flex-wrap:nowrap;
    overflow-x:auto;
    padding-bottom:3px;
    scrollbar-width:none;
  }
  .followups::-webkit-scrollbar{display:none}
  .followup{flex:0 0 auto}
  .composer-area{padding:8px 8px calc(7px + env(safe-area-inset-bottom))}
  .composer-shell{border-radius:18px;padding-left:9px}
  .composer-input{font-size:16px;min-height:36px}
  .keyboard-hint{display:none}
  .length-control>span{display:none}
  .length-control select{font-size:10px}
  .composer-note{font-size:8px;padding:0 8px}
  .inline-edit-shell{width:100%}
}

@media (prefers-reduced-motion:reduce){
  *{scroll-behavior:auto!important}
  .thinking-dots span{animation:none;opacity:.55}
  .prompt-card{transition:none}
}
