:root {
  color-scheme: light;
  --font-scale: 0.9;
  --base-font-size: 13px;
  --ui-font: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --body-font: "Lora", Georgia, "Times New Roman", serif;
  --display-font: "Newsreader", "Source Serif 4", Georgia, "Times New Roman", serif;
  --app-font: var(--ui-font);
  --bg: #f9f9f7;
  --surface: #ffffff;
  --surface-soft: #f4f2ef;
  --surface-raised: rgba(255, 255, 255, 0.92);
  --text: #101010;
  --muted: #77716b;
  --thinking: #7b7873;
  --user-bubble: #f0efec;
  --send-bg: var(--text);
  --send-fg: var(--surface);
  --line: #e5e0db;
  --line-strong: #d7d0ca;
  --accent: #c96f47;
  --accent-strong: #ad5938;
  --accent-soft: #f3dfd3;
  --blue: #2f76c2;
  --danger: #bd3e3e;
  --shadow: 0 16px 48px rgba(31, 25, 18, 0.14);
  --font: var(--app-font);
  --serif: var(--display-font);
}

@font-face {
  font-family: "DM Sans";
  src: url("./fonts/DMSans-Regular.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("./fonts/PlusJakartaSans-Regular.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Lora";
  src: url("./fonts/Lora-Regular.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("./fonts/Newsreader-VariableFont_opsz,wght.ttf") format("truetype");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("./fonts/Newsreader-Italic-VariableFont_opsz,wght.ttf") format("truetype");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4";
  src: url("./fonts/SourceSerif4-Regular.ttf") format("truetype");
  font-display: swap;
}

:root[data-font-size="tiny"] {
  --font-scale: 0.84;
  --base-font-size: 12px;
}

:root[data-font-size="regular"] {
  --font-scale: 1;
  --base-font-size: 14px;
}

:root[data-font-size="large"] {
  --font-scale: 1.08;
  --base-font-size: 15px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1d1d1c;
  --surface: #2a2a28;
  --surface-soft: #2a2a28;
  --surface-raised: rgba(42, 42, 40, 0.94);
  --text: #c3c2b8;
  --muted: #96948b;
  --thinking: #96948b;
  --user-bubble: #101010;
  --send-bg: #f9f9f7;
  --send-fg: #101010;
  --line: #343431;
  --line-strong: #4b4a45;
  --accent: #dd8358;
  --accent-strong: #f1a077;
  --accent-soft: #101010;
  --blue: #82b9f2;
  --danger: #ff8178;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.34);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1d1d1c;
    --surface: #2a2a28;
    --surface-soft: #2a2a28;
    --surface-raised: rgba(42, 42, 40, 0.94);
    --text: #c3c2b8;
    --muted: #96948b;
    --thinking: #96948b;
    --user-bubble: #101010;
    --send-bg: #f9f9f7;
    --send-fg: #101010;
    --line: #343431;
    --line-strong: #4b4a45;
    --accent: #dd8358;
    --accent-strong: #f1a077;
    --accent-soft: #101010;
    --blue: #82b9f2;
    --danger: #ff8178;
    --shadow: 0 16px 48px rgba(0, 0, 0, 0.34);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--base-font-size);
  letter-spacing: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  display: block;
}

#app {
  min-height: 100svh;
  height: 100%;
  overflow: hidden;
}

.app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100svh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}

@media (min-width: 740px) {
  body {
    padding: 18px 0;
  }

  .app {
    height: calc(100svh - 36px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 34px;
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.22);
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--bg);
  transition: transform 220ms ease, filter 220ms ease;
}

.screen.diary-screen {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.app.drawer-open .screen {
  transform: translateX(min(74vw, 348px));
  filter: brightness(0.96);
}

.status-space {
  height: env(safe-area-inset-top);
}

.topbar {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  min-height: 58px;
  padding: 0 12px;
  background: var(--bg);
  z-index: 2;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text);
  line-height: 1;
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

.icon-button svg,
.round-send svg,
.new-chat svg,
.tiny-icon svg,
.message-actions svg {
  width: 18px;
  height: 18px;
  margin: auto;
  flex: 0 0 auto;
}

.icon-button:active,
.icon-button.is-active {
  background: var(--surface-soft);
}

.icon-button.danger {
  color: var(--danger);
}

.model-trigger {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 5px 8px;
  border-radius: 10px;
}

.model-trigger:active {
  background: var(--surface-soft);
}

.model-title {
  display: grid;
  grid-template-columns: 18px minmax(0, auto) 18px;
  justify-content: center;
  align-items: center;
  column-gap: 3px;
  width: 100%;
  max-width: min(220px, 100%);
  font-size: calc(20px * var(--font-scale));
  font-weight: 700;
  line-height: 1.05;
}

.model-title::before {
  content: "";
  width: 18px;
  height: 18px;
}

.model-title span {
  min-width: 0;
  max-width: calc(100vw - 150px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.model-title svg {
  justify-self: center;
}

.model-subtitle {
  max-width: 100%;
  color: var(--muted);
  font-size: calc(14px * var(--font-scale));
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-title {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
}

.page-title strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(18px * var(--font-scale));
  line-height: 1.05;
}

.page-title span {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  line-height: 1.1;
}

.notice-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 34px;
  margin: 0 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 74%, transparent);
  font-size: calc(12px * var(--font-scale));
  overflow: hidden;
  z-index: 2;
}

.notice-bar:not(.is-alert) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  height: 34px;
  padding: 0 12px;
}

.notice-bar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice-bar button {
  color: var(--blue);
  font-weight: 650;
}

.notice-bar.is-alert {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-soft));
}

.notice-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.notice-bar.is-alert button {
  color: var(--blue);
  font-weight: 700;
}

.notice-bar-inner {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 0;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
}

.notice-count {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  font-weight: 600;
}

.notice-bar.is-expanded {
  max-height: none;
  height: auto;
  overflow: visible;
  border-radius: 16px;
  padding: 4px 0;
}

.notice-bar.is-expanded .notice-bar-inner {
  padding: 0 12px;
}

.notice-capsule {
  margin: 0 6px 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}

.notice-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: calc(12px * var(--font-scale));
}

.notice-row:last-child {
  border-bottom: 0;
}

.notice-row button {
  color: var(--blue);
  font-weight: 700;
  font-size: calc(11px * var(--font-scale));
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--blue) 10%, transparent);
}

.notice-row.danger button {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.notice-row-more {
  padding: 8px 12px;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  text-align: center;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 18px 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  position: relative;
  z-index: 1;
}

.messages.has-content {
  padding-top: 8px;
}

.empty-state,
.private-state {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 0 22px 10vh;
  text-align: center;
}

.mark {
  color: var(--accent);
}

.empty-state .mark {
  width: 42px;
  height: 42px;
}

.empty-title {
  margin: 0;
  color: #3e3833;
  font-family: var(--display-font);
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 500;
  line-height: 1.05;
}

:root[data-theme="dark"] .empty-title {
  color: #efe7df;
}

.private-state {
  gap: 14px;
}

.private-state p {
  max-width: 340px;
  margin: 0;
  color: var(--text);
  font-size: calc(13px * var(--font-scale));
  line-height: 1.28;
}

.private-state a {
  color: var(--text);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.diary-page {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px calc(18px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
}

.diary-page > .diary-results {
  flex: 1;
}

.diary-page > .tool-list,
.diary-page > .memory-list {
  flex: 1;
}

.workspace-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.workspace-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.file-preview-page {
  z-index: 18;
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.file-deleted-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}

.file-deleted-body .deleted-note {
  max-width: 360px;
  text-align: center;
}

.file-preview-page iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.file-detail-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
  overflow: hidden;
}

.file-detail-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

.file-detail-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  justify-self: end;
}

.diary-tools {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  background: var(--bg);
}

.search-box {
  min-height: 42px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 0 12px;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: calc(14px * var(--font-scale));
}

.diary-results {
  display: grid;
  gap: 10px;
  align-content: start;
}

.diary-results.is-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.diary-entry-card {
  min-width: 0;
}

.diary-entry-card > button {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-align: left;
}

.diary-entry-card.as-row > button {
  grid-template-columns: minmax(0, 1fr) auto;
}

.diary-entry-card.as-row .diary-entry-head,
.diary-entry-card.as-row h2,
.diary-entry-card.as-row .diary-entry-meta,
.diary-entry-card.as-row .tag-list {
  grid-column: 1 / -1;
}

.diary-entry-card.is-deleted > button {
  opacity: 0.78;
}

.diary-entry-card .run-btn-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--accent-strong);
  padding: 0;
  margin-left: auto;
  flex-shrink: 0;
  cursor: pointer;
  pointer-events: auto;
}

.diary-entry-card .run-btn-icon:active {
  background: var(--accent);
  color: #fff;
}

.file-meta {
  justify-content: space-between !important;
}

.diary-entry-head,
.diary-entry-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
}

.diary-entry-head {
  justify-content: space-between;
}

.diary-entry-card h2 {
  margin: 0;
  font-size: calc(15px * var(--font-scale));
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.diary-entry-card p {
  margin: 0;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.diary-empty {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.diary-empty strong {
  color: var(--text);
  font-size: calc(15px * var(--font-scale));
}

.diary-detail-layer {
  z-index: 18;
  align-items: stretch;
  background: var(--bg);
}

.diary-detail-sheet {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: 100%;
  min-height: 100%;
  background: var(--bg);
}

.diary-detail-meta {
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.diary-detail-scroll {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
}

.thread {
  display: grid;
  gap: 12px;
  padding-bottom: 10px;
}

.message {
  display: grid;
  gap: 4px;
}

.message.user {
  justify-items: end;
}

.bubble {
  max-width: min(84%, 360px);
  padding: 12px 16px;
  border-radius: 22px;
  font-family: var(--body-font);
  line-height: 1.50;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  border-bottom-right-radius: 8px;
  background: var(--user-bubble);
}

.message-images {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message-images-stack {
  position: relative;
  display: block;
  min-height: 180px;
}

.msg-image {
  max-width: 100%;
  max-height: 260px;
  width: auto;
  height: auto;
  border-radius: 12px;
  object-fit: cover;
  cursor: pointer;
}

.msg-image-stacked {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px solid var(--bubble-bg, #f9f9f7);
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  transition: transform .15s ease;
}

.msg-image-stacked:hover {
  transform: translateY(0) scale(1.02) !important;
  z-index: 99 !important;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

.lightbox-body {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 90vw;
  max-height: 85vh;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-counter {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.7);
  font-size: 14px;
}

.context-bar {
  padding: 4px 16px 2px;
  text-align: right;
  font-size: 10px;
  color: var(--muted);
  opacity: .6;
}

.context-bar-warn span {
  color: var(--warn, #e67e22);
  opacity: .8;
}

.msg-tokens {
  display: block;
  text-align: right;
  font-size: 9px;
  color: var(--muted);
  opacity: .35;
  margin-top: 2px;
  user-select: none;
}

.assistant-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.assistant-row.no-avatar {
  grid-template-columns: minmax(0, 1fr);
}

.assistant-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  line-height: 1;
}

.assistant-body {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding-top: 3px;
}

.user-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: flex-end;
}

.user-body {
  min-width: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  line-height: 1;
}

.assistant-text {
  min-width: 0;
  padding-top: 0;
  font-family: var(--body-font);
  line-height: 1.52;
  white-space: normal;
  overflow-wrap: anywhere;
}

.assistant-text p {
  margin: 0 0 0.72em;
}

.assistant-text p:last-child,
.assistant-text ul:last-child,
.assistant-text ol:last-child,
.assistant-text .code-block:last-child {
  margin-bottom: 0;
}

.assistant-text strong {
  font-weight: 760;
}

.assistant-text em {
  font-style: italic;
}

.assistant-text code:not(.code-block code) {
  padding: 0.08em 0.28em;
  border-radius: 5px;
  background: var(--surface-soft);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
}

.assistant-text ul,
.assistant-text ol {
  margin: 0.35em 0 0.75em;
  padding-left: 1.25em;
}

.assistant-text li {
  margin: 0.16em 0;
}

.md-heading {
  margin: 0.78em 0 0.32em;
  font-family: var(--body-font);
  font-weight: 760;
  line-height: 1.22;
}

.md-heading:first-child {
  margin-top: 0;
}

.md-h1 {
  font-size: calc(18px * var(--font-scale));
}

.md-h2 {
  font-size: calc(17px * var(--font-scale));
}

.md-h3,
.md-h4 {
  font-size: calc(16px * var(--font-scale));
}

.thinking-block {
  margin: 0;
  color: var(--thinking);
}

.thinking-summary {
  width: 100%;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 1px 0 1px 4px;
  cursor: pointer;
  font-size: calc(12px * var(--font-scale));
  line-height: 1.28;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
}

.thinking-summary svg:last-child {
  justify-self: end;
  transition: transform 160ms ease;
}

.thinking-block.is-open .thinking-summary svg:last-child {
  transform: rotate(90deg);
}

.thinking-content {
  padding: 1px 0 2px 24px;
  line-height: 1.32;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code-block {
  --code-line-height: 1.45em;
  margin: 10px 0;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-soft) 72%, var(--surface));
  font-family: var(--ui-font);
  white-space: normal;
}

.code-head {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px 6px 11px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
}

.code-head > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: lowercase;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.code-actions button {
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: calc(11px * var(--font-scale));
  line-height: 1;
}

.code-block pre {
  margin: 0;
  padding: 10px 11px;
  overflow: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: calc(11px * var(--font-scale));
  line-height: var(--code-line-height);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

.code-block.is-collapsed pre {
  max-height: calc(var(--code-line-height) * var(--code-lines) + 20px);
}

.message-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  color: var(--muted);
}

.message-actions button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  line-height: 1;
}

.message-actions button:active,
.message-actions button.is-active {
  background: var(--surface-soft);
  color: var(--text);
}

.user-actions {
  justify-self: end;
  margin-top: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.message-meta {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
}

.typing-dot {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 22px;
}

.typing-dot i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}

.typing-dot i:nth-child(2) {
  animation-delay: 160ms;
}

.typing-dot i:nth-child(3) {
  animation-delay: 320ms;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }

  40% {
    opacity: 1;
  }
}

.tool-calls-capsules {
  display: grid;
  gap: 5px;
  max-width: 100%;
  min-width: 0;
}

.tool-capsule {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: calc(11px * var(--font-scale));
  font-family: var(--ui-font);
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  min-width: 0;
}

.tool-capsule > span:last-child,
.tool-capsule .capsule-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.tool-capsule svg {
  flex-shrink: 0;
}

.tool-capsule.is-done {
  color: var(--text);
  border-color: var(--line-strong);
}

.tool-capsule.is-denied {
  color: var(--danger);
  border-color: var(--danger);
}

.tool-capsule.is-error {
  color: var(--danger);
  border-color: var(--danger);
}

.msg-capsule {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: calc(11px * var(--font-scale));
  font-family: var(--ui-font);
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  cursor: default;
  max-width: 100%;
  overflow: hidden;
  min-width: 0;
}

.msg-capsule > span:last-child,
.msg-capsule .capsule-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.msg-capsule svg {
  flex-shrink: 0;
}

.msg-capsule.is-fail {
  color: var(--danger);
  border-color: var(--danger);
  cursor: pointer;
}

.tool-capsule.has-detail,
.msg-capsule.has-detail,
.msg-capsule.is-success.has-detail {
  cursor: pointer;
}

.capsule-detail {
  display: none;
}

.tool-capsule.is-open,
.msg-capsule.is-open {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  border-radius: 8px;
  padding: 6px 10px;
  white-space: normal;
}

.tool-capsule.is-open .capsule-summary,
.msg-capsule.is-open .capsule-summary {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.tool-capsule.is-open .capsule-detail,
.msg-capsule.is-open .capsule-detail {
  display: block;
  grid-column: 1 / -1;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  max-height: 180px;
  min-width: 0;
  color: var(--muted);
}

.msg-capsule-item {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
}

.msg-capsule-detail {
  display: none;
  padding: 4px 6px 2px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: calc(11px * var(--font-scale));
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-width: 420px;
  overflow: auto;
  max-height: 140px;
}

.msg-capsule-detail.is-open {
  display: block;
}

.composer-wrap {
  padding: 10px 18px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 86%, color-mix(in srgb, var(--bg) 0%, transparent));
  z-index: 3;
}

.edit-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 0 4px 8px;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
}

.edit-banner span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-banner button {
  color: var(--blue);
  font-weight: 650;
}

.composer {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.07);
}

.composer .icon-button {
  width: 30px;
  height: 30px;
}

.app.private-mode .composer {
  border-style: dashed;
}

.composer textarea {
  width: 100%;
  min-height: 34px;
  max-height: 132px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: max(16px, calc(15px * var(--font-scale)));
  line-height: 1.18;
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer-actions {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) 30px 36px;
  align-items: center;
  column-gap: 4px;
}

.composer-actions [data-action="voice-placeholder"] {
  grid-column: 4;
}

.composer-actions .round-send {
  grid-column: 5;
}

.composer-actions .web-search-toggle {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--muted);
  line-height: 1;
  padding: 0;
}

.composer-actions .web-search-toggle.is-active {
  background: var(--surface-soft);
  color: var(--blue);
}

.attachment-pill {
  min-width: 0;
  display: none;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.attachment-pill.has-attachment {
  display: flex;
}

.round-send {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--send-bg);
  color: var(--send-fg);
  padding: 0;
}

.round-send.stop {
  background: var(--danger);
}

.drawer {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 5;
  width: min(78vw, 360px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: calc(22px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  background: var(--bg);
  transform: translateX(-100%);
  transition: transform 220ms ease;
  border-right: 1px solid var(--line);
}

.app.drawer-open .drawer {
  transform: translateX(0);
}

.drawer-scrim {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  background: rgba(0, 0, 0, 0.08);
}

.app.drawer-open .drawer-scrim {
  display: block;
}

.drawer-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-family: var(--display-font);
  font-size: calc(24px * var(--font-scale));
  font-weight: 700;
  line-height: 1;
}

.brand .mark {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
}

.new-chat {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  line-height: 1;
  padding: 0;
}

.drawer-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding-right: 2px;
}

.nav {
  display: grid;
  gap: 1px;
  margin: 10px 0 14px;
}

.nav-row,
.chat-row,
.settings-row {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 2px 7px;
  border-radius: 10px;
  text-align: left;
}

.nav-row:active,
.chat-row:active,
.settings-row:active,
.nav-row.is-active,
.chat-row.is-active {
  background: var(--surface-soft);
}

.row-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(14px * var(--font-scale));
}

button.row-label {
  padding: 0;
  text-align: left;
}

.section-title {
  margin: 10px 8px 4px;
  color: var(--muted);
  font-size: calc(13px * var(--font-scale));
  font-weight: 600;
}

.chat-list {
  display: grid;
  gap: 0;
}

.chat-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-height: 32px;
}

.chat-row .row-label {
  font-size: calc(14px * var(--font-scale));
}

.tiny-icon {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--muted);
  line-height: 1;
}

.tiny-icon:active {
  background: var(--surface-soft);
  color: var(--text);
}

.drawer-empty {
  margin: 8px;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
}

.drawer-foot {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.profile-button {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 12px;
  text-align: left;
}

.profile-button:active {
  background: var(--surface-soft);
}

.avatar {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 800;
  line-height: 1;
  font-size: calc(15px * var(--font-scale));
  overflow: hidden;
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

.profile-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-popover {
  display: none;
  position: absolute;
  z-index: 10;
  top: calc(env(safe-area-inset-top) + 58px);
  left: 50%;
  width: min(292px, calc(100% - 80px));
  transform: translateX(-50%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 18px 18px;
  background: var(--surface-raised);
  box-shadow: 0 16px 48px rgba(31, 25, 18, 0.14);
}

.model-popover.is-visible {
  display: block;
}

.popover-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 9;
  background: rgba(0, 0, 0, 0.08);
}

.popover-backdrop.is-visible {
  display: block;
}

:root[data-theme="dark"] .popover-backdrop {
  background: rgba(0, 0, 0, 0.24);
}

.model-option {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 8px;
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.model-option:last-child {
  border-bottom: 0;
}

.model-option:active {
  background: var(--surface-soft);
}

.option-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(16px * var(--font-scale));
  font-weight: 650;
}

.option-subtitle {
  margin-top: 4px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(12px * var(--font-scale));
}

.model-divider {
  height: 10px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.sheet-layer {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.18);
  overflow: hidden;
  overscroll-behavior: none;
}

.settings-page-layer {
  align-items: stretch;
  background: var(--bg);
  overscroll-behavior: none;
}

.settings-sheet,
.action-sheet {
  max-height: min(92svh, 760px);
  overflow: hidden;
  border-radius: 26px 26px 0 0;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.settings-sheet {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
}

.settings-page-layer .settings-sheet {
  max-height: none;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  overscroll-behavior: none;
}

.sheet-head {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  align-items: center;
  min-height: 70px;
  padding: 4px 12px 0;
}

.settings-page-layer .sheet-head {
  min-height: calc(62px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}

.sheet-title {
  text-align: center;
  font-size: calc(18px * var(--font-scale));
  font-weight: 760;
}

.sheet-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
}

.account-pill {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
}

.account-pill {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 74px;
  padding: 12px 14px;
}

.account-pill strong,
.account-pill > span:not(.avatar) {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-pill > span:not(.avatar) span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-section {
  margin-top: 14px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
}

.settings-section-head {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  cursor: pointer;
  list-style: none;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
}

.settings-section-head::-webkit-details-marker {
  display: none;
}

.settings-section-head h2 {
  margin: 0;
  font-family: var(--ui-font);
  font-size: calc(14px * var(--font-scale));
  font-weight: 650;
  line-height: 1.05;
}

.settings-section-head svg {
  justify-self: end;
  color: var(--muted);
  transition: transform 160ms ease;
}

.settings-section.is-open .settings-section-head svg {
  transform: rotate(90deg);
}

.settings-panel {
  display: none;
  padding: 0 14px 14px;
}

.settings-section.is-open .settings-panel {
  display: block;
}

.app-brand-editor {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.app-icon-preview {
  width: 74px;
  height: 74px;
  border: 1px solid var(--line);
  border-radius: 18px;
  object-fit: cover;
  background: var(--surface-soft);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.app-brand-actions {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.field:first-of-type {
  margin-top: 0;
}

.field label {
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  font-weight: 650;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  background: var(--surface);
  padding: 8px 10px;
  font-size: calc(14px * var(--font-scale));
}

.field textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.28;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.field-hint {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  line-height: 1.25;
}

.backup-option {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  color: var(--text);
  font-size: calc(13px * var(--font-scale));
  line-height: 1.35;
  cursor: pointer;
}

.backup-option input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.field-actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.btn-minor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: calc(13px * var(--font-scale));
  cursor: pointer;
  transition: background .12s ease;
}

.btn-minor:hover {
  background: var(--hover-bg, rgba(0,0,0,.05));
}

.model-editor {
  display: grid;
  gap: 14px;
}

.model-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.model-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.model-card-head strong {
  font-size: calc(14px * var(--font-scale));
}

.model-stream-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
  background: var(--surface);
}

.model-stream-btn:active {
  background: var(--surface-soft);
}

.model-edit-row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 8px;
  padding: 10px 12px 0;
}

.model-edit-row input {
  min-width: 0;
}

.model-sliders {
  display: grid;
  gap: 0;
  padding: 4px 0 6px;
}

.slider-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
}

.slider-row label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  font-weight: 650;
  white-space: nowrap;
}

.slider-row label span {
  color: var(--text);
  font-weight: 700;
  font-size: calc(12px * var(--font-scale));
}

.slider-row input[type="range"] {
  width: 100%;
  height: 24px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

.slider-row input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: var(--line-strong);
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -5.5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
}

.slider-row input[type="range"]:focus {
  outline: 0;
}

.param-none-btn {
  min-width: 32px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: calc(9px * var(--font-scale));
  font-weight: 700;
  padding: 0 7px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.param-none-btn.is-none {
  background: var(--line-strong);
  color: var(--surface);
  border-color: var(--line-strong);
}

.settings-row {
  min-height: 48px;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  padding: 8px 0;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
}

.settings-row:last-child {
  border-bottom: 0;
}

.row-value {
  color: var(--muted);
  font-size: calc(13px * var(--font-scale));
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line-strong);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 180ms ease;
}

.switch.is-on {
  background: var(--accent);
}

.switch.is-on::after {
  transform: translateX(20px);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface-soft);
}

.segmented button {
  min-height: 36px;
  border-radius: 8px;
  color: var(--muted);
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.08);
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.settings-actions.single {
  grid-template-columns: 1fr;
}

.api-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.api-actions .primary-button {
  grid-column: 1 / -1;
}

.tool-list,
.memory-list,
.diary-list,
.version-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.tool-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.tool-item:first-child {
  border-top: 0;
}

.tool-item strong,
.diary-list-item strong {
  display: block;
  font-size: calc(13px * var(--font-scale));
}

.tool-item p,
.diary-list-item p,
.local-card p,
.version-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  line-height: 1.35;
}

.tool-item small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
}

.tool-item.is-disabled {
  opacity: 0.6;
}

.tool-toggle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 4px;
}

.tool-item .switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line-strong);
}

.tool-item .switch::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
  transition: transform 180ms ease;
}

.tool-item .switch.is-on {
  background: var(--accent);
}

.tool-item .switch.is-on::after {
  transform: translateX(20px);
}

.local-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.local-stats button {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
  font-weight: 700;
  padding: 0 6px;
}

.local-stats button:active,
.local-stats button.is-active {
  background: var(--surface-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.local-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.45fr);
  gap: 10px;
  align-items: end;
}

.memory-editor {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
}

.local-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.local-card.is-deleted {
  opacity: 0.78;
}

.local-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.level-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  font-weight: 750;
  white-space: nowrap;
}

.local-date,
.local-meta {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
}

.local-meta {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.tag-list span {
  min-height: 22px;
  border-radius: 999px;
  padding: 3px 8px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent-strong);
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
}

.local-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.local-actions button {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  font-size: calc(12px * var(--font-scale));
  font-weight: 700;
}

.empty-local {
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  font-size: calc(12px * var(--font-scale));
}

.diary-layout {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.diary-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-align: left;
}

.diary-list-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.diary-list-item small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
}

.diary-list-item p {
  grid-column: 1 / -1;
}

.diary-content {
  margin-top: 12px;
  line-height: 1.55;
}

.diary-detail-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.deleted-note {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  color: var(--danger);
  font-size: calc(12px * var(--font-scale));
  line-height: 1.35;
}

.version-list h4 {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: calc(12px * var(--font-scale));
}

.version-item {
  padding-left: 10px;
  border-left: 2px solid var(--line-strong);
}

.version-item span {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
}

.version-content {
  margin-top: 6px;
  padding: 9px;
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: calc(12px * var(--font-scale));
  line-height: 1.45;
}

.history-row {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  gap: 10px;
  cursor: pointer;
}

.history-row:active {
  background: var(--surface-soft);
}

.history-row + .history-row {
  margin-top: 8px;
}

.history-row-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.history-row-time {
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-row svg {
  flex-shrink: 0;
  color: var(--muted);
}

.tool-approval-layer {
  z-index: 20;
  align-items: center;
  justify-items: center;
  padding: 18px;
}

.tool-approval-sheet {
  width: min(440px, 100%);
  overflow: hidden;
  border-radius: 18px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.compact-head {
  min-height: 58px;
}

.tool-approval-body {
  padding: 0 18px 18px;
}

.tool-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-approval-body p {
  color: var(--muted);
  font-size: calc(13px * var(--font-scale));
  line-height: 1.4;
}

.tool-approval-body pre {
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: calc(12px * var(--font-scale));
  white-space: pre-wrap;
  word-break: break-word;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 999px;
  padding: 0 16px;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1;
}

.primary-button svg,
.secondary-button svg,
.danger-button svg,
.settings-row > svg,
.nav-row > svg,
.action-row > svg {
  justify-self: center;
  align-self: center;
  flex: 0 0 auto;
}

.primary-button {
  background: var(--text);
  color: var(--surface);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.danger-button {
  border: 1px solid color-mix(in srgb, var(--danger) 44%, var(--line));
  background: transparent;
  color: var(--danger);
}

.hidden-file {
  display: none;
}

.action-sheet {
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}

.action-popover-backdrop {
  position: absolute;
  inset: 0;
  z-index: 11;
  border: 0;
  background: transparent;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

.action-popover {
  position: absolute;
  left: 18px;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 12;
  min-width: 200px;
  padding: 6px 0;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 8px 32px rgba(31, 25, 18, 0.16);
  overflow: hidden;
}

.action-row {
  width: 100%;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.action-row:last-child {
  border-bottom: 0;
}

.action-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.splash {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  padding: 18svh 28px calc(46px + env(safe-area-inset-bottom));
  background: var(--bg);
  transition: opacity 320ms ease, visibility 320ms ease;
}

.splash.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-brand {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-family: var(--display-font);
  font-size: calc(38px * var(--font-scale));
  font-weight: 760;
}

.splash-brand .mark {
  width: 46px;
  height: 46px;
}

.splash-foot {
  color: var(--muted);
  font-size: calc(13px * var(--font-scale));
  font-weight: 800;
  letter-spacing: 0;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(420px, calc(100vw - 40px));
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  border-radius: 999px;
  background: rgba(25, 24, 23, 0.92);
  color: #fff;
  padding: 10px 14px;
  font-size: calc(12px * var(--font-scale));
  line-height: 1.3;
  transition: opacity 180ms ease, transform 180ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.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;
}

@media (max-width: 360px) {
  .model-title {
    font-size: calc(18px * var(--font-scale));
  }

  .model-subtitle {
    font-size: calc(13px * var(--font-scale));
  }

  .notice-bar {
    font-size: calc(11px * var(--font-scale));
  }

  .composer-wrap {
    padding-inline: 12px;
  }

  .local-filters,
  .local-stats {
    grid-template-columns: 1fr;
  }
}

.md-image {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  margin: 6px 0;
  display: block;
}

@keyframes entry-flash {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); background: var(--surface); }
  15% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
  30% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); background: var(--surface); }
  45% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
  60% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); background: var(--surface); }
  75% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
  90% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); background: var(--surface); }
}

.diary-entry-card.is-highlight,
.local-card.is-highlight,
.local-card.is-highlight > button {
  animation: entry-flash 2.5s ease-in-out;
}
