:root {
  --bg: #0e1116;
  --bg-side: #12161d;
  --bg-panel: #171c24;
  --bg-hover: #1e2530;
  --bg-active: #243044;
  --border: #262d38;
  --text: #e6e9ef;
  --muted: #8b95a5;
  --accent: #6ea8fe;
  --accent-soft: rgba(110, 168, 254, .12);
  --green: #4ade80;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --app-height: 100vh;
  --app-offset: 0px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%; margin: 0;
  overflow: hidden;
  overflow: clip; /* 対応ブラウザではページ自体をスクロールコンテナにしない */
  overscroll-behavior: none;
}
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }

/* iOS でキーボード表示時に入力欄へ自動スクロールされ、余白が出るのを防ぐ */
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.65;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button, select, a { touch-action: manipulation; }
.hidden { display: none !important; }

.app {
  display: flex;
  height: var(--app-height);
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 272px;
  flex: 0 0 272px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 700;
  letter-spacing: .2px;
}
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6ea8fe, #a78bfa);
  color: #0b0e13;
  font-size: 18px;
}
.brand-name { font-size: 16px; }
.brand-sub { color: var(--muted); font-weight: 500; margin-left: 4px; font-size: 13px; }

.new-session {
  margin: 0 12px 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  text-align: left;
  color: var(--text);
  transition: background .15s, border-color .15s;
}
.new-session:hover { background: var(--bg-hover); border-color: #3a4658; }
.new-session span { color: var(--accent); font-weight: 700; margin-right: 4px; }

.list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px 6px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* スクロールはこのボックスの中だけ許可する */
.session-list {
  flex: 1;
  min-height: 0;
  padding: 0 8px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.empty-hint { padding: 16px 10px; color: var(--muted); font-size: 12px; }

.session-item {
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 32px 9px 11px;
  border-radius: 8px;
  margin-bottom: 2px;
  cursor: pointer;
  border: 1px solid transparent;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-active); border-color: #32425c; }
.session-title-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600;
  overflow: hidden; white-space: nowrap;
}
.session-item.active .session-title-row { color: #cfe0ff; }
.session-title-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.session-state {
  width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto; background: var(--red);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}
.session-state.running { background: var(--green); animation: pulse 1.4s infinite; }
.session-state.permission { background: var(--amber); }
.session-unread {
  margin-left: auto; flex: 0 0 auto;
  min-width: 17px; height: 17px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; background: var(--accent); color: #0b1220;
  font-size: 10px; font-weight: 700; line-height: 1;
}
.session-sub { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-delete {
  position: absolute; right: 6px; top: 8px;
  border: 0; background: transparent; color: var(--muted);
  font-size: 15px; line-height: 1; padding: 3px 5px; border-radius: 5px;
  opacity: 0;
}
.session-item:hover .session-delete { opacity: 1; }
.session-delete:hover { background: #3a2328; color: var(--red); }

.sidebar-footer { border-top: 1px solid var(--border); padding: 12px 14px 14px; }
.field { display: block; margin-bottom: 9px; }
.field span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.field select {
  width: 100%; padding: 6px 8px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 7px; font-size: 12px;
}
.directory { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; }
.directory span { display: block; color: var(--muted); font-size: 11px; }
.directory code { font-family: var(--mono); font-size: 11px; color: #9db8e8; word-break: break-all; }

/* PWA: インストール導線 */
.install-app {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 10px; padding: 9px 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(110, 168, 254, .35);
  border-radius: 8px;
  color: #bcd6ff; font-size: 12px; font-weight: 600;
}
.install-app:hover { background: rgba(110, 168, 254, .2); }

.logout-app {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 10px; padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted); font-size: 12px;
}
.logout-app:hover { background: var(--bg-hover); color: var(--text); }

.debug-app, .notify-app, .console-app {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-bottom: 10px; padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted); font-size: 12px;
}
.debug-app:hover, .notify-app:hover, .console-app:hover {
  background: var(--bg-hover); color: var(--text);
}
.notify-app.on {
  color: #cfe0ff;
  border-color: rgba(110, 168, 254, .5);
  background: var(--accent-soft);
}
.notify-app:disabled { opacity: .55; }

/* ---------- Login ---------- */
.login-overlay {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--app-height);
  display: grid; place-items: center;
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(1200px 600px at 50% -10%, #1b2433 0%, var(--bg) 60%);
}
.login-card {
  width: min(360px, 100%);
  padding: 22px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.login-brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; }
.login-note { margin: 10px 0 16px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.login-field { display: block; margin-bottom: 12px; }
.login-field span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.login-field input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
  color: var(--text); font-size: 16px; /* iOS の入力時ズームを防ぐ */
}
.login-field input:focus { outline: none; border-color: #4c6691; }
.login-field input[readonly] { color: var(--muted); }
.login-error { margin: 0 0 12px; color: #ffc4c4; font-size: 12px; }
.login-submit {
  width: 100%; min-height: 46px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: #0b1220;
  font-weight: 700; font-size: 15px;
}
.login-submit:disabled { opacity: .6; }
.login-debug {
  width: 100%; margin-top: 10px; padding: 8px;
  background: transparent; border: 0;
  color: var(--muted); font-size: 11px; text-decoration: underline;
}

/* ---------- 画面情報（デバッグ） ---------- */
.update-banner {
  position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%); z-index: 120;
  padding: 10px 16px; border: 1px solid rgba(110, 168, 254, .5);
  border-radius: 10px;
  background: #1b2940; color: #cfe0ff;
  font-size: 12px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.debug-panel {
  position: fixed; top: max(10px, env(safe-area-inset-top)); right: 10px;
  z-index: 130;
  width: min(420px, calc(100vw - 20px));
  max-height: calc(var(--app-height) - 20px - env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  background: rgba(12, 16, 22, .97);
  border: 1px solid #3a4658; border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.debug-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.debug-actions { display: flex; gap: 6px; }
.debug-actions button {
  padding: 4px 9px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg-panel); color: var(--text); font-size: 11px;
}
.debug-body {
  margin: 0; padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  overflow: auto; font-family: var(--mono); font-size: 11px; line-height: 1.55;
  color: #c7d3e4; white-space: pre-wrap; word-break: break-all;
}

/* ---------- コンソール（アプリ内埋め込み） ---------- */
.console-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column;
  height: var(--app-height);
  background: #000;
}
.console-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
  background: var(--bg-side);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  flex: 0 0 auto;
}
.console-actions { display: flex; gap: 6px; }
.console-actions button {
  padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg-panel); color: var(--text); font-size: 12px;
}
.console-actions button:hover { background: var(--bg-hover); }
.console-body { position: relative; flex: 1; min-height: 0; background: #000; }
.console-keys {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; flex: 0 0 auto;
  background: #12161d;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.console-keys::-webkit-scrollbar { display: none; }
.console-key {
  flex: 0 0 auto;
  min-width: 42px;
  padding: 7px 10px;
  border: 1px solid #2b3340; border-radius: 7px;
  background: #1b2230; color: var(--text);
  font-family: var(--mono); font-size: 11px; line-height: 1;
  white-space: nowrap;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.console-key:active,
.console-key.active { background: #2c384c; border-color: #46566f; }
.console-key.danger { color: #ffb3b3; border-color: #5a2b2b; background: #2a1a1a; }
.console-key.danger:active,
.console-key.danger.active { background: #4a2323; border-color: #7b3a3a; }
.console-key.tmux { color: #a8d8ff; border-color: #2b3f56; background: #16202c; }
.console-key-sep {
  flex: 0 0 auto; width: 1px; height: 18px;
  background: #2b3340;
}
.console-body iframe {
  width: 100%; height: 100%; border: 0; background: #000;
  display: block;
}
.console-loading {
  position: absolute; inset: 0; z-index: 1;
  display: grid; place-items: center;
  color: var(--muted); font-size: 12px;
  background: #000; pointer-events: none;
}
.console-overlay.ready .console-loading { display: none; }

/* 貼り付けパネル（クリップボードを直接読めない環境用） */
.console-paste-overlay {
  position: absolute; inset: 0; z-index: 4;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.55);
}
.console-paste-panel {
  width: min(560px, 100%);
  max-height: calc(var(--app-height) - 24px);
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px;
  background: var(--bg-side);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}
.console-paste-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 13px;
}
.console-paste-head button {
  width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg-panel); color: var(--text); font-size: 13px;
}
#console-paste-text {
  width: 100%; min-height: 96px; max-height: 42vh;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #0e1116; color: var(--text);
  font-family: var(--mono); font-size: 16px; line-height: 1.5;
}
#console-paste-text:focus { outline: none; border-color: #4c6691; }
.console-paste-actions {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end;
}
.console-paste-actions button {
  padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-panel); color: var(--text); font-size: 12px;
}
.console-paste-actions button.primary {
  background: #2c5ea8; border-color: #3a74c9; color: #fff;
}
.console-paste-note { color: var(--muted); font-size: 11px; line-height: 1.4; }
.console-key.paste { color: #b7f7cf; border-color: #2d5a41; background: #15281e; }
.console-key.paste:active,
.console-key.paste.active { background: #1e3a2a; border-color: #3f7a58; }

@media (max-width: 480px) {
  .console-head { padding-left: 8px; padding-right: 8px; }
  .console-actions button { padding: 6px 8px; font-size: 11px; }
}

/* ---------- Main ---------- */
.main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.topbar {
  height: 50px; flex: 0 0 50px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 22, 29, .8);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); flex: 0 0 auto; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 128, .12); }
.status-dot.offline { background: var(--red); }
.status-text { color: var(--muted); font-size: 12px; white-space: nowrap; }
.divider { width: 1px; height: 16px; background: var(--border); }
.session-title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: 11px; font-family: var(--mono); white-space: nowrap; }

.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  border-radius: 6px; width: 28px; height: 28px; font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.mobile-menu { display: none; }

/* ---------- Messages ---------- */
/* スクロールはこのボックスの中だけ許可する */
.messages {
  flex: 1;
  min-height: 0;
  padding: 22px 0 10px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.messages-inner { max-width: 820px; margin: 0 auto; padding: 0 24px; }

.welcome { max-width: 520px; margin: 12vh auto; text-align: center; color: var(--muted); }
.welcome-mark { font-size: 44px; color: var(--accent); margin-bottom: 6px; }
.welcome h1 { color: var(--text); font-size: 22px; margin: 0 0 10px; }
.welcome p { margin: 4px 0; }
.welcome-tip { font-size: 12px; opacity: .8; }
.mobile-hint { display: none; }

.msg { display: flex; gap: 12px; margin-bottom: 20px; }
.msg-user { justify-content: flex-end; }
.msg-copy {
  align-self: flex-start; flex: 0 0 auto; white-space: nowrap;
  border: 1px solid #3c5a8a; background: #1d3050; color: #9dc3ff;
  border-radius: 8px; padding: 5px 9px; font-size: 12px; line-height: 1.4;
  cursor: pointer;
}
.msg-copy:hover, .msg-copy:focus-visible { background: #27406a; color: #fff; }
.user-bubble {
  max-width: 78%;
  background: #25324a;
  border: 1px solid #33445f;
  border-radius: 14px 14px 4px 14px;
  padding: 9px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.avatar {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #6ea8fe, #a78bfa); color: #0b0e13;
  display: grid; place-items: center; font-size: 15px; margin-top: 2px;
}
.assistant-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg-head .name { font-weight: 600; color: #b9c6da; }

.prose { word-break: break-word; }
.prose p { margin: 0 0 8px; }
.prose p:last-child { margin-bottom: 0; }
.prose pre {
  background: #0b0e13; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; margin: 8px 0;
}
.prose code {
  font-family: var(--mono); font-size: 12.5px;
  background: #222a36; padding: 1px 5px; border-radius: 4px;
}
.prose pre code { background: none; padding: 0; }
.prose ul { margin: 4px 0 8px; padding-left: 20px; }
.prose li { margin: 2px 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 12px 0 6px; font-size: 1.05em; }
.prose a { color: var(--accent); }
.prose img, .prose video { max-width: 100%; height: auto; }
.prose table { display: block; max-width: 100%; overflow-x: auto; }
.para-gap { height: 4px; }

.reasoning {
  border-left: 2px solid #4b5870; padding: 2px 0 2px 10px; margin: 0 0 10px;
  color: var(--muted); font-size: 12px; white-space: pre-wrap;
}
.reasoning summary { cursor: pointer; color: #93a2b8; }
.reasoning[open] summary { margin-bottom: 4px; }

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tool-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 11px;
  background: #1c2430; border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 9px; color: #a9b8cd;
}
.tool-chip.running { border-color: #6ea8fe66; color: #a9cbff; }
.tool-chip.error { border-color: #f8717166; color: #ffb4b4; }
.tool-chip .spin { animation: spin 1.2s linear infinite; display: inline-block; }

.msg-system, .msg-synthetic, .msg-shell, .msg-skill {
  justify-content: center;
  color: var(--muted); font-size: 11px; font-family: var(--mono);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 12px; width: fit-content; margin: 0 auto 14px;
  max-width: 80%; text-align: center;
}
.cursor-blink::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; }

/* ---------- Permission ---------- */
.permission-banner {
  margin: 10px 18px 0;
  background: #2a2415; border: 1px solid #6b5320; border-radius: 10px;
  padding: 10px 14px;
}
.permission-title { color: var(--amber); font-weight: 600; font-size: 12px; margin-bottom: 4px; }
.permission-desc { font-size: 12px; color: #d8cdb4; }
.permission-desc code { font-family: var(--mono); font-size: 11px; color: #ffd98a; }
.permission-actions { display: flex; gap: 8px; margin-top: 8px; }
.permission-actions button {
  border: 1px solid #6b5320; background: #3b3018; color: #ffe0a3;
  border-radius: 6px; padding: 4px 12px; font-size: 12px;
}
.permission-actions button:hover { background: #4b3c1e; }
.permission-actions .reject { border-color: #6b3030; background: #3b1f1f; color: #ffb4b4; }

/* ---------- Question form (question ツール) ---------- */
.form-banner { margin: 10px 18px 0; max-width: 820px; }
.form-card {
  background: #16243a; border: 1px solid #3c5a8a; border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px;
}
.form-card .permission-title { color: #9dc3ff; }
.form-field { margin-top: 10px; }
.form-field-title { color: #e6e9ef; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.form-field-desc { color: #a9b8cd; font-size: 12px; margin-bottom: 6px; white-space: pre-wrap; }
.form-options { display: flex; flex-wrap: wrap; gap: 8px; }
.form-option {
  border: 1px solid #3c5a8a; background: #1d3050; color: #cfe0ff;
  border-radius: 8px; padding: 9px 12px; font-size: 13px; text-align: left;
  min-height: 44px; line-height: 1.35;
}
.form-option:hover { background: #27406a; }
.form-option[aria-pressed="true"] {
  border-color: var(--accent); background: #2b4b7a; color: #fff;
  box-shadow: inset 0 0 0 1px #6ea8fe66;
}
.form-option small { display: block; color: #9fb2ce; font-size: 11px; }
.form-custom, .form-number {
  width: 100%; margin-top: 8px; padding: 9px 11px; min-height: 44px;
  border: 1px solid #3c5a8a; border-radius: 8px; background: #0e1828;
  color: #e6e9ef; font-size: 16px; /* iOS のフォーカス時ズームを防ぐ */
  box-sizing: border-box;
}
.form-external { color: #9dc3ff; font-size: 13px; }
.form-card .permission-actions button {
  border-color: #3c5a8a; background: #27406a; color: #d7e6ff;
}
.form-card .permission-actions .form-submit { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
.form-card .permission-actions button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Composer ---------- */
.composer-wrap { padding: 8px 24px 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-panel); border: 1px solid #333c4b;
  border-radius: 14px; padding: 10px 10px 10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.composer:focus-within { border-color: #4c6691; }
.composer textarea {
  flex: 1; resize: none; border: 0; background: transparent; outline: none;
  font-size: 16px; /* iOS のフォーカス時ズームを防ぐ */
  max-height: 180px; min-height: 26px; line-height: 1.5;
}
.composer textarea::placeholder { color: #6c7788; }
.composer-actions { display: flex; gap: 6px; }
.btn-send, .btn-stop {
  border: 0; border-radius: 9px; padding: 7px 14px; font-size: 13px; font-weight: 600;
  white-space: nowrap;
}
.btn-send { background: var(--accent); color: #0b1220; }
.btn-send:hover { background: #8bbaff; }
.btn-send:disabled { opacity: .45; cursor: not-allowed; }
.btn-send span { opacity: .7; font-size: 11px; }
.btn-stop { background: #4a2626; color: #ffb4b4; border: 1px solid #6b3030; }
.btn-stop:hover { background: #5d3030; }
.composer-note { max-width: 820px; margin: 6px auto 0; color: #5f6a7a; font-size: 10.5px; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  background: #2a2233; border: 1px solid #4b3a5c; color: #e9ddf5;
  padding: 9px 14px; border-radius: 9px; font-size: 12px;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s;
  max-width: 380px;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #3a2020; border-color: #6b3030; color: #ffc4c4; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3340; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Touch / mobile ---------- */
.scrim { display: none; }

@media (max-width: 760px) {
  .sidebar {
    position: fixed; z-index: 40; inset: 0 auto 0 0;
    width: min(86vw, 320px); flex-basis: auto;
    transform: translateX(-102%);
    transition: transform .24s ease;
    box-shadow: 12px 0 32px rgba(0, 0, 0, .45);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar.open { transform: none; }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(0, 0, 0, .55);
    opacity: 0; pointer-events: none; transition: opacity .24s ease;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }

  .topbar {
    height: calc(52px + env(safe-area-inset-top));
    flex-basis: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 10px 0;
  }
  .topbar-left, .topbar-right { gap: 5px; }
  .icon-btn { width: 40px; height: 40px; font-size: 18px; flex: 0 0 40px; }
  .mobile-menu { display: inline-grid; place-items: center; }
  .meta { display: none; }
  .session-title { font-size: 13px; }

  .new-session { min-height: 46px; font-size: 15px; margin-bottom: 12px; }
  .list-header { padding: 0 14px 8px; }
  .session-list { padding: 0 8px 12px; }
  .session-item { padding: 12px 46px 12px 12px; margin-bottom: 4px; }
  .session-title-row { font-size: 14px; }
  .session-sub { font-size: 11px; }
  .session-delete {
    opacity: 1; right: 4px; top: 50%; transform: translateY(-50%);
    width: 38px; height: 38px; display: grid; place-items: center;
    font-size: 20px;
  }
  .field select { min-height: 44px; font-size: 16px; }
  .sidebar-footer { padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); }
  .install-app { min-height: 44px; font-size: 13px; }
  .logout-app, .debug-app, .notify-app, .console-app { min-height: 42px; font-size: 13px; }
  .debug-panel { top: auto; bottom: 10px; right: 10px; left: 10px; width: auto; }
  .debug-body { font-size: 11px; }

  .messages { padding-top: 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .messages-inner { padding: 0 12px; }
  .welcome { margin: 7vh auto; padding: 0 6px; }
  .welcome-mark { font-size: 36px; }
  .welcome h1 { font-size: 19px; }
  .welcome-tip { line-height: 1.7; }
  .desktop-hint { display: none; }
  .mobile-hint { display: inline; }

  .msg { gap: 8px; margin-bottom: 16px; }
  .user-bubble { max-width: 88%; padding: 10px 13px; font-size: 15px; }
  .avatar { flex-basis: 26px; width: 26px; height: 26px; font-size: 14px; }
  .prose { font-size: 15px; }
  .prose pre { padding: 10px 12px; -webkit-overflow-scrolling: touch; }
  .prose code { font-size: 13px; }
  .reasoning summary { padding: 7px 0; }
  .tool-chip { padding: 4px 10px; }
  .msg-system, .msg-synthetic, .msg-shell, .msg-skill { max-width: 92%; }
  .msg-copy { opacity: 1; min-width: 44px; min-height: 44px; padding: 0 10px; }

  .permission-banner { margin: 8px 12px 0; padding: 10px 12px; }
  .form-banner { margin: 8px 12px 0; }
  .form-card { padding: 10px 12px; }
  .permission-actions { flex-wrap: wrap; }
  .permission-actions button { flex: 1 1 96px; min-height: 44px; padding: 8px 12px; font-size: 13px; }
  .form-option { flex: 1 1 120px; }

  .composer-wrap { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer { gap: 8px; padding: 8px 8px 8px 12px; border-radius: 16px; }
  .composer textarea {
    font-size: 16px; /* iOS の入力時ズームを防ぐ */
    max-height: 34vh;
  }
  .composer-actions { align-items: flex-end; }
  .btn-send, .btn-stop { min-height: 44px; padding: 10px 16px; font-size: 15px; }
  .btn-send span { display: none; }
  .composer-note { font-size: 10px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .toast {
    left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: none; text-align: center;
  }
}

/* キーボード表示中はセーフエリア分の余白を詰める */
.keyboard-open .composer-wrap { padding-bottom: 8px; }
.keyboard-open .composer-note { display: none; }
/* キーボードで表示領域が狭くなっても入力欄が会話を圧迫しないようにする */
.keyboard-open .composer textarea { max-height: 26vh; }

/* タッチ端末では入力欄を 16px 以上にして自動ズームを防ぐ */
@media (hover: none), (pointer: coarse) {
  input, textarea, select { font-size: 16px; }
}

@media (max-width: 420px) {
  .status-text, .divider { display: none; }
  .session-title { font-size: 12px; }
}

@media (max-height: 480px) and (max-width: 760px) {
  .welcome { margin: 3vh auto; }
  .composer textarea { max-height: 24vh; }
  .sidebar-footer .directory { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
