:root {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #292d29;
  background: #f5f4ef;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --muted: #697168;
  --line: #dedfd5;
  --green: #365f49;
  --green-dark: #254b37;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, textarea, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #739d84;
  outline-offset: 3px;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button:not(:disabled) { cursor: pointer; }
.app {
  height: 100vh;
  height: 100dvh;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}
.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--line);
}
.actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.button {
  min-height: 42px;
  padding: 10px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
  color: #424b40;
  font-size: 14px;
  line-height: 1.3;
  transition: background-color .15s;
}
.button:not(:disabled):hover { background: #e8ece2; }
.button.quiet { background: transparent; border-color: transparent; }
.button.primary { color: #fff; border-color: var(--green); background: var(--green); font-weight: 600; }
.button.primary:not(:disabled):hover { background: var(--green-dark); }
.button.small { min-height: 38px; padding: 8px 12px; flex-shrink: 0; font-size: 12px; }
main { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.gate { max-width: 510px; margin: auto; padding: 40px 12px; text-align: center; overflow-y: auto; }
.gate-symbol {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 24px;
  border-radius: 22px;
  background: #e7ebe0;
  color: var(--green);
  font-size: 32px;
}
.eyebrow { color: var(--green); font-size: 12px; font-weight: 600; letter-spacing: .1em; }
h2 { font-size: clamp(23px, 4vw, 31px); font-weight: 550; line-height: 1.4; }
.gate h2 { margin: 14px 0; }
.gate > p:not(.eyebrow) { color: var(--muted); font-size: 15px; line-height: 1.9; }
.gate .button { margin-top: 14px; }
.login { display: grid; gap: 10px; max-width: 320px; margin: 18px auto 0; text-align: left; }
.login-field { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
.login-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ced4c5;
  border-radius: 12px;
  background: #fffefb;
  color: inherit;
  font-size: 16px;
  line-height: 1.5;
}
.login-field input:focus { border-color: #739d84; box-shadow: 0 0 0 2px #739d841f; }
.login-field input:focus-visible { outline: 3px solid #739d84; outline-offset: 1px; }
#login-submit { width: 100%; margin-top: 4px; }
.history {
  flex-shrink: 0;
  max-height: min(42vh, 360px);
  margin: 0 0 10px;
  padding: 10px 12px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfaf4;
}
.history-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-header h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .02em; }
.history-header .button { min-height: 30px; padding: 4px 9px; font-size: 16px; line-height: 1; }
.chat-list { display: grid; gap: 4px; margin: 9px 0 0; padding: 0; list-style: none; }
.chat-entry { display: flex; align-items: stretch; gap: 4px; min-width: 0; border-radius: 9px; }
.chat-entry[data-current="true"] { background: #e8edde; }
.chat-open {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 8px 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
}
.chat-open:not(:disabled):hover { background: #eef1e9; }
.chat-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { flex-shrink: 0; color: var(--muted); font-size: 11px; }
.chat-delete {
  flex-shrink: 0;
  width: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}
.chat-delete:not(:disabled):hover { background: #f3e3da; color: #8b4635; }
.history-empty { margin: 9px 0 0; color: var(--muted); font-size: 13px; }
.chat { position: relative; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.status-bar { display: flex; gap: 9px; align-items: center; padding: 12px 2px; flex-shrink: 0; }
.status-dot { flex-shrink: 0; height: 7px; width: 7px; background: #ad8438; border-radius: 50%; }
.status-dot.ready { background: #568364; }
.status-bar p { flex: 1; color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0; overflow-wrap: anywhere; max-height: 100px; overflow-y: auto; }
.notice {
  margin: 0 0 10px;
  padding: 12px 15px;
  border: 1px solid #e8c8ae;
  border-radius: 12px;
  background: #fff4e9;
  color: #80502b;
  font-size: 13px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  max-height: 25vh;
  overflow-y: auto;
  flex-shrink: 0;
}
.conversation { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 16px 18px 24px; }
#messages { max-width: 780px; margin: 0 auto; }
.message { margin: 0 0 26px; min-width: 0; }
.message .speaker { margin: 0 0 7px; color: var(--muted); font-size: 12px; font-weight: 600; }
.message-body { min-width: 0; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.9; }
.message.user { margin-left: auto; width: fit-content; max-width: 90%; }
.message.user .speaker { text-align: right; }
.message.user .message-body { background: #e8edde; border: 1px solid #dde4d3; padding: 12px 17px; border-radius: 18px 5px 18px 18px; }
.message.assistant .message-body { padding: 2px 0; }
.thinking { color: var(--muted); font-style: italic; }
.markdown-body { white-space: normal; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: .65em 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 { margin: 1.1em 0 .45em; font-weight: 650; line-height: 1.4; letter-spacing: normal; }
.markdown-body h1 { font-size: 1.55em; }
.markdown-body h2 { font-size: 1.35em; }
.markdown-body h3 { font-size: 1.18em; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 1.05em; }
.markdown-body ul, .markdown-body ol { margin: .65em 0; padding-left: 1.65em; }
.markdown-body li { margin: .2em 0; }
.markdown-body li > p, .markdown-body li > ul, .markdown-body li > ol { margin: .25em 0; }
.markdown-body input[type="checkbox"] { margin-right: .45em; accent-color: var(--green); }
.markdown-body blockquote { margin: .85em 0; padding: .1em 0 .1em 1em; border-left: 3px solid #bac9b4; color: #596653; }
.markdown-body a { color: var(--green-dark); text-decoration: underline; text-underline-offset: .15em; overflow-wrap: anywhere; }
.markdown-body a:hover { color: #1c6c3b; }
.markdown-body code, .markdown-body pre, .tool-detail-content pre { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.markdown-body code { padding: .12em .35em; border-radius: 4px; background: #e9ede2; font-size: .88em; }
.markdown-body pre { max-width: 100%; margin: .85em 0; padding: 12px 14px; overflow-x: auto; border: 1px solid #d9dfd2; border-radius: 9px; background: #edf0e7; white-space: pre; overflow-wrap: normal; line-height: 1.65; tab-size: 4; }
.markdown-body pre code { padding: 0; border-radius: 0; background: transparent; font-size: .87em; }
.markdown-table-scroll { max-width: 100%; margin: .85em 0; overflow-x: auto; border: 1px solid #d9dfd2; border-radius: 8px; }
.markdown-body table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: .92em; line-height: 1.6; }
.markdown-body th, .markdown-body td { padding: 8px 12px; border: 1px solid #d9dfd2; text-align: left; }
.markdown-body th { background: #e9ede2; font-weight: 600; }
.markdown-body tr:nth-child(even) td { background: #f0f2eb; }
.markdown-body hr { margin: 1.25em 0; border: 0; border-top: 1px solid var(--line); }
.tool-list { display: grid; gap: 6px; min-width: 0; margin: 0 0 10px; padding: 0; list-style: none; }
.tool-entry { min-width: 0; max-width: 100%; border: 1px solid #d6ddd3; border-radius: 9px; background: #f1f4ed; color: #374a3b; font-size: 12px; line-height: 1.6; }
.tool-entry details { min-width: 0; }
.tool-entry summary { position: relative; padding: 8px 11px 8px 27px; border-radius: 8px; cursor: pointer; list-style: none; }
.tool-entry summary::-webkit-details-marker { display: none; }
.tool-entry summary::before { content: "›"; position: absolute; top: 8px; left: 11px; color: var(--muted); font-size: 16px; line-height: 1.2; }
.tool-entry details[open] > summary::before { transform: rotate(90deg); }
.tool-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 3px 12px; min-width: 0; }
.tool-name { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.tool-status { overflow-wrap: anywhere; color: #425b47; }
.tool-summary { display: block; margin-top: 2px; color: #5b6859; overflow-wrap: anywhere; white-space: pre-wrap; }
.tool-detail-content { min-width: 0; padding: 0 11px 11px; }
.tool-detail-content section { min-width: 0; margin-top: 9px; }
.tool-section-label { margin: 0 0 4px; font-weight: 600; }
.tool-detail-content pre { max-width: 100%; max-height: 340px; max-height: min(340px, 45vh); margin: 0; padding: 9px 10px; overflow: auto; border: 1px solid #dae0d4; border-radius: 6px; background: #fcfdf8; color: #303c31; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.65; tab-size: 4; }
.tool-empty { margin: 4px 0 0; color: var(--muted); }
.tool-truncated { margin: 0 0 5px; color: #80502b; font-size: 11px; }
.tool-entry[data-status="running"] { border-color: #9cac95; background: #edf2e5; }
.tool-entry[data-status="error"] { border-color: #d9bbae; background: #faf0e9; }
.tool-entry[data-status="error"] .tool-status { color: #8b4635; }
.scroll-bottom { position: absolute; z-index: 1; right: 22px; bottom: 160px; box-shadow: 0 3px 16px #283b2020; font-size: 12px; }
.compose { flex-shrink: 0; padding: 12px 0 max(14px, env(safe-area-inset-bottom)); }
.compose.dragging .compose-box { border-color: #739d84; box-shadow: 0 0 0 2px #739d841f; }
.attach-button { flex-shrink: 0; align-self: stretch; min-width: 56px; padding: 8px 10px; color: var(--muted); }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 9px; padding: 0; list-style: none; }
.attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 7px;
  border: 1px solid #d6ddd3;
  border-radius: 10px;
  background: #f1f4ed;
  color: #374a3b;
  font-size: 12px;
  line-height: 1.4;
}
.attachment-item[data-uploading="true"] { opacity: .65; }
.attachment-thumb { width: 44px; height: 44px; flex-shrink: 0; object-fit: cover; border: 1px solid #d9dfd2; border-radius: 7px; background: #fff; }
.attachment-kind { flex-shrink: 0; padding: 4px 6px; border-radius: 6px; background: #e2e8da; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.attachment-meta { display: grid; gap: 1px; min-width: 0; }
.attachment-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.attachment-size { color: var(--muted); font-size: 11px; }
.attachment-remove { flex-shrink: 0; width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; }
.attachment-remove:not(:disabled):hover { background: #f3e3da; color: #8b4635; }
.compose-box { display: flex; align-items: flex-end; gap: 12px; padding: 12px; background: #fffefb; border: 1px solid #ced4c5; border-radius: 18px; box-shadow: 0 4px 20px #39462c06; }
.compose-box:focus-within { border-color: #739d84; box-shadow: 0 0 0 2px #739d841f; }
.message-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; padding: 0; list-style: none; }
.message-attachments img { display: block; max-width: min(280px, 100%); max-height: 220px; border: 1px solid #d9dfd2; border-radius: 10px; background: #fff; }
.attachment-file {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid #d6ddd3;
  border-radius: 9px;
  background: #f6f8f2;
  color: #374a3b;
  font-size: 12px;
  overflow-wrap: anywhere;
  text-decoration: none;
}
.attachment-file:hover { background: #eef1e9; }
textarea {
  display: block;
  width: 100%;
  flex: 1;
  min-width: 0;
  min-height: 52px;
  max-height: 180px;
  resize: none;
  padding: 5px 4px;
  border: 0;
  outline: none;
  background: transparent;
  color: inherit;
  font-size: 16px;
  line-height: 1.6;
  overflow-y: auto;
}
textarea:focus-visible { outline: none; }
textarea::placeholder { color: #81877c; }
textarea:disabled { opacity: .65; }
#send { flex-shrink: 0; min-width: 68px; }
.compose-footer { display: flex; justify-content: space-between; gap: 12px; padding: 0 5px; }
.compose-footer p { font-size: 11px; color: var(--muted); margin: 9px 0 0; line-height: 1.5; }
dialog { max-width: min(460px, calc(100% - 36px)); padding: 26px; border: 1px solid var(--line); border-radius: 20px; background: #fffefb; color: inherit; box-shadow: 0 16px 80px #1b2b2330; }
dialog::backdrop { background: #202b2366; }
dialog h2 { margin: 0 0 14px; font-size: 23px; }
dialog p { font-size: 14px; line-height: 1.8; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@media (max-width: 600px) {
  .app { padding-right: max(14px, env(safe-area-inset-right)); padding-left: max(14px, env(safe-area-inset-left)); }
  .header { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: 14px; gap: 8px; align-items: flex-start; }
  .actions { gap: 0; max-width: none; }
  .actions .button { padding: 9px 7px; font-size: 12px; }
  .status-bar { padding: 9px 0; }
  .history { max-height: 38vh; padding: 8px 10px; }
  .conversation { padding: 12px 4px 18px; }
  .message-body { font-size: 15px; }
  .message.user { max-width: 94%; }
  .markdown-body pre { padding: 10px; }
  .markdown-body th, .markdown-body td { padding: 7px 9px; }
  .tool-header { gap: 3px 8px; }
  .tool-detail-content { padding-right: 8px; padding-left: 8px; }
  .compose { padding-top: 9px; }
  .compose-box { gap: 6px; padding: 9px; border-radius: 15px; }
  .attach-button { min-width: 46px; padding: 8px 6px; }
  .attachment-name { max-width: 140px; }
  .message-attachments img { max-height: 180px; }
  .compose-footer { flex-wrap: wrap; gap: 0 10px; }
  .compose-footer p { font-size: 10px; margin-top: 6px; }
  .scroll-bottom { bottom: 155px; right: 8px; }
}
@media (max-width: 360px) {
  .actions .button { padding-right: 6px; padding-left: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
