* {
  box-sizing: border-box;
}

/* ── Theme variables (tuned to Vanta fog / 水墨 palette) ── */
:root {
  color-scheme: light;
  --background-color: #e8e4da;
  --text-color: #1c1b19;
  --dimmed-text-color: #6a6560;
  --link-color: #3d3a36;
  --border-color: #c4bfb4;
  --code-bg: rgba(244, 240, 232, 0.88);
  --btn-bg: #1c1b19;
  --btn-text: #e8e4da;
  --btn-bg-hover: #3d3a36;
  /* Glass backdrop behind content, over the animated background */
  --content-glass: rgba(232, 228, 218, 0.78);
}

[data-theme="dark"] {
  color-scheme: dark;
  --background-color: #141311;
  --text-color: #e8e4da;
  --dimmed-text-color: #8a8680;
  --link-color: #c4bfb4;
  --border-color: #3d3a36;
  --code-bg: #1e1c1a;
  --btn-bg: #e8e4da;
  --btn-text: #141311;
  --btn-bg-hover: #fff;
  --content-glass: rgba(20, 19, 17, 0.78);
}

html {
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none; /* no rubber-band / overscroll past the top or bottom */
  height: 100%;
  height: 100dvh;
  overflow: hidden; /* fixed viewport layout — only the message list scrolls */
}

body {
  font: normal 1.21em KaTeX_Main, Times New Roman, serif;
  background-color: var(--background-color);
  color: var(--text-color);
  line-height: 1.6;

  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  /* 100vh on mobile includes the area behind the URL/status bar; 100dvh is the
     visible viewport, so the header is not clipped by overflow:hidden. */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 27px;
  padding-top: max(27px, env(safe-area-inset-top, 0px));
  padding-right: max(27px, env(safe-area-inset-right, 0px));
  padding-bottom: max(27px, env(safe-area-inset-bottom, 0px));
  padding-left: max(27px, env(safe-area-inset-left, 0px));
}

/* ── Animated background layer ── */
#vanta-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  z-index: 0;
  pointer-events: none; /* animation must never block clicks */
}

/* Touch devices: promote layer + fallback tint if WebGL init is delayed. */
@media (pointer: coarse) {
  #vanta-bg {
    inset: 0;
    width: auto;
    height: auto;
    background-color: var(--background-color);
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}

#vanta-bg canvas {
  opacity: 0.99;
  /* Fade the fog canvas in so it doesn't "pop" after the late JS load. */
  animation: vanta-fade-in 0.6s ease-out;
}

@keyframes vanta-fade-in {
  from { opacity: 0; }
  to   { opacity: 0.99; }
}
/* ── Content layer above the animation, with soft-edged glass backdrop ── */
.page {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0; /* allow the message list to shrink and scroll internally */
  display: flex;
  flex-direction: column;
}

/* ── Glass card temporarily disabled for preview (restore by uncommenting) ──
.page::before {
  content: "";
  position: absolute;
  inset: -80px -110px;
  z-index: -1;
  background: var(--content-glass);
  border-radius: 0px;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 8%, black 92%, transparent),
                      linear-gradient(to right, transparent, black 10%, black 89%, transparent);
  -webkit-mask-composite: source-in;
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-image: linear-gradient(to bottom, transparent, black 8%, black 92%, transparent),
              linear-gradient(to right, transparent, black 10%, black 89%, transparent);
  mask-composite: intersect;
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
}
*/

header {
  position: relative;
  margin-bottom: 0px;
  flex-shrink: 0;
}

.header-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 2px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-color);
  border-radius: 6px;
}

.theme-toggle:hover {
  opacity: 0.65;
}

.theme-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.theme-icon-moon {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-icon-moon {
  display: block;
}

h1, h2 {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  line-height: 2rem;
  font-size: 1.5rem;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 0 0 0px 0;
}

.subtitle {
  color: var(--text-color);
  font-size: 1.05rem;
  margin: 0;
}

.home-photo {
  width: 600px;
  height: 150px;
  margin-top: 18px;
  margin-bottom:0px;
  display: block;
}

h2 {
  font-size: 20.25px;
  font-weight: 800;
  padding-bottom: 0px;
  margin-top: 25px;
  margin-bottom: 20px;
}

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-item {
  margin-bottom: 18px;
}

.post-date {
  font-size: 15px;
  line-height: 1.25rem;
  color: var(--dimmed-text-color);
  width: 83px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-style: italic;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
}

.post-date-blog {
  font-size: 13.5px;
  line-height: 1.25rem;
  color: var(--dimmed-text-color);
  width: 83px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-style: italic;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  margin-bottom:20px;
}

.post-title-link {
  display: flex;
  align-items: baseline;
  gap: 18px;
  color: var(--link-color);
  text-decoration: none;
  font-size: 18px;
  font-weight: normal;
  line-height: 1.5;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
}

.bio p {
  margin-bottom: 16px;
  color: var(--text-color);
}

.bio-title-text {
  position: relative;
  display: inline-block;
  padding-right: 15px;
}

.bio-title-link {
  position: absolute;
  top: 2px;
  right: -2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color);
  text-decoration: none;
  opacity: 0.55;
  border-radius: 4px;
  transition: opacity 0.15s ease;
}

.bio-title-link:hover {
  opacity: 1;
}

.bio-title-link svg {
  width: 14px;
  height: 14px;
  display: block;
  transform: rotate(11deg);
}

.post {
  margin-top: 0;
}

.post-title {
  font-size: 33.75px;
  font-weight: 800;
  margin: 0 0 13px 0;
  margin-top: 18px;
}

.post-content {
  margin-top: 24px;
}

.post-content h1,
.post-content h2,
.post-content h3 {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  margin-top: 32px;
  margin-bottom: 12px;
}

.post-content h2 {
  font-size: 1.2rem;
}

.post-content p {
  margin-bottom: 16px;
}

.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 24px 0;
}

.post-content [align="center"] img {
  margin-left: auto;
  margin-right: auto;
}

.post-figure {
  margin: 24px 0;
}

.post-figure img {
  margin: 0;
}

.post-figcaption {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--dimmed-text-color);
  text-align: center;
}

.post-content a {
  color: var(--link-color);
  text-decoration: none;
}

.post-content a:hover {
  text-decoration: underline;
}

.post-content pre {
  background: var(--code-bg);
  padding: 16px;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 16px 0;
}

.post-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875em;
}

.post-content pre code {
  font-size: 0.875rem;
}

.post-content blockquote {
  border-left: 3px solid var(--border-color);
  margin: 16px 0;
  padding-left: 16px;
  color: var(--dimmed-text-color);
}

.post-content ul,
.post-content ol {
  margin: 16px 0;
  padding-left: 24px;
}

.post-content li {
  margin-bottom: 8px;
}

.back-link {
  margin-top: 40px;
}

/* ── Admin ── */
.admin {
  margin-top: 0;
}

.admin-post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.admin-post-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.admin-post-date {
  font-size: 0.875rem;
  color: var(--dimmed-text-color);
  flex-shrink: 0;
}

.admin-post-title {
  color: var(--link-color);
  text-decoration: none;
  flex: 1;
}

.admin-post-title:hover {
  text-decoration: underline;
}

.admin-post-edit {
  color: var(--dimmed-text-color);
  text-decoration: none;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.admin-post-edit:hover {
  color: var(--link-color);
}

.admin-empty {
  color: var(--dimmed-text-color);
  font-style: italic;
  margin-bottom: 12px;
}

.admin-error {
  color: #cc0000;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.admin-input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 0.95rem;
  background: var(--background-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  margin-bottom: 12px;
  font-family: inherit;
  box-sizing: border-box;
}

.admin-textarea {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 0.9rem;
  background: var(--background-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
}

.admin-btn {
  padding: 8px 24px;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  font-family: inherit;
}

.admin-btn:hover {
  background: var(--btn-bg-hover);
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

.admin-link {
  color: var(--dimmed-text-color);
  text-decoration: none;
  font-size: 0.9rem;
}

.admin-link:hover {
  text-decoration: underline;
}

/* ── Admin Media ── */
.admin-media-section {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

.admin-media-upload {
  margin-bottom: 20px;
}

.admin-media-upload-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-file-input {
  font-size: 0.9rem;
  font-family: inherit;
  flex: 1;
}

.admin-btn-small {
  padding: 6px 16px;
  font-size: 0.85rem;
}

.admin-media-hint {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--dimmed-text-color);
}

.admin-media-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.admin-media-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.admin-media-item:last-child {
  border-bottom: none;
}

.admin-media-preview {
  width: 80px;
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--code-bg);
  border-radius: 2px;
}

.admin-media-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.admin-media-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--dimmed-text-color);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.admin-media-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.admin-media-name {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.admin-media-size {
  font-size: 0.75rem;
  color: var(--dimmed-text-color);
}

.admin-media-delete-btn {
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--background-color);
  color: #cc0000;
  border: 1px solid #cc0000;
  font-family: inherit;
  border-radius: 2px;
  flex-shrink: 0;
}

.admin-media-delete-btn:hover {
  background: #cc0000;
  color: #fff;
}

.admin-media-empty {
  color: var(--dimmed-text-color);
  font-style: italic;
  font-size: 0.9rem;
}

.admin-media-error {
  color: #cc0000;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.get-in-touch {
  margin: 0;
  color: var(--dimmed-text-color);
}

.get-in-touch-link {
  color: var(--link-color);
  text-decoration: none;
  font-size: 18px;
  font-weight: normal;
  line-height: 0.5rem;
  margin: 0;
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
}

/* ── Chat with me section ── */
.chat-desc a {
  color: var(--link-color);
  text-decoration: none;
}

.chat-desc a:hover {
  text-decoration: underline;
}

/* ── Agent page ── */
.site-footer {
  margin-top: auto; /* push to the bottom of the viewport-height page */
  padding-top: 6px;
  font-size: 0.8rem;
  color: #000; /* light theme: black footer text */
  text-align: right;
  flex-shrink: 0;
}

[data-theme="dark"] .site-footer {
  color: var(--dimmed-text-color); /* dark theme: keep dimmed */
}

.site-footer a {
  color: var(--link-color);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer p {
  margin: -4px;
}

/* ── Language toggle ── */
[data-lang="en"] .lang-zh {
  display: none;
}

[data-lang="zh"] .lang-en {
  display: none;
}

/* ── Chat interface ── */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-top: 24px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  /* Right padding > left so the 8px scrollbar doesn't crowd the text. */
  padding: 0 12px 0 2px;
  scrollbar-gutter: stable;
}

/* Theme-aware scrollbar for the message list (Chrome/Safari/Edge) */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--dimmed-text-color);
}

/* Firefox */
.chat-messages {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.chat-message {
  margin-bottom: 16px;
  /* Fade messages in so the text doesn't abruptly "pop" on load / send. */
  animation: message-fade-in 0.25s ease-out;
}

/* User messages sit on the right side of the chat column. */
.chat-message-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  cursor: pointer;
}

.chat-messages.is-generating .chat-message-user {
  cursor: default;
}

.chat-edit {
  align-self: stretch;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 18px;
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chat-edit-text {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text-color);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 0;
}

.chat-edit-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.chat-edit-cancel {
  background: var(--border-color);
  color: var(--dimmed-text-color);
}

.chat-edit-cancel:hover {
  color: var(--text-color);
}

.chat-edit-ok {
  background: #000;
  color: #fff;
}

[data-theme="dark"] .chat-edit-ok {
  background: #fff;
  color: #000;
}

.chat-edit-ok:disabled {
  cursor: default;
  opacity: 0.45;
  background: var(--border-color);
  color: var(--dimmed-text-color);
}

@keyframes message-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.chat-message .chat-role {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  
  letter-spacing: 0.04em;
  color: var(--dimmed-text-color);
  margin-bottom: 2px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.chat-message .chat-body {
  word-wrap: break-word;
}

.chat-message-user .chat-body,
.chat-message .chat-md-pending {
  white-space: pre-wrap;
}

.chat-message .chat-md > :first-child { margin-top: 0; }
.chat-message .chat-md > :last-child { margin-bottom: 0; }
.chat-message .chat-md p { margin: 0.5em 0; }
.chat-message .chat-md ul,
.chat-message .chat-md ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}
.chat-message .chat-md pre {
  overflow-x: auto;
  padding: 0.75em 1em;
  margin: 0.5em 0;
  border-radius: 6px;
  background: var(--code-bg);
  font-size: 0.88em;
}
.chat-message .chat-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.chat-message .chat-md pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.chat-message .chat-md blockquote {
  margin: 0.5em 0;
  padding-left: 0.8em;
  border-left: 3px solid var(--border-color);
  color: var(--dimmed-text-color);
}
.chat-message .chat-md a { color: var(--link-color); }
.chat-message .chat-md h1,
.chat-message .chat-md h2,
.chat-message .chat-md h3,
.chat-message .chat-md h4 {
  font-size: 1em;
  margin: 0.8em 0 0.4em;
}
.chat-message .chat-md table {
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.92em;
}
.chat-message .chat-md th,
.chat-message .chat-md td {
  border: 1px solid var(--border-color);
  padding: 0.2em 0.5em;
}
.chat-message .chat-md hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 0.8em 0;
}
.chat-message .chat-md img { max-width: 100%; }

/* Collapsible reasoning trace (<think>...</think>) from assistant messages.
   Open/closed state is persisted by JS in localStorage (key: think_open).
   The chevron-down SVG in the summary rotates 180° to become chevron-up. */
.chat-message .chat-think {
  font-size: 0.7em;
  font-style: italic;
  color: var(--dimmed-text-color);
  margin: 0em 0;
}
.chat-message .chat-think summary {
  cursor: pointer;
  user-select: none;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
}
.chat-message .chat-think summary::-webkit-details-marker { display: none; }
.chat-message .chat-think-chevron {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.chat-message .chat-think[open] > summary .chat-think-chevron {
  transform: rotate(180deg);
}
.chat-message .chat-think-body {
  padding: 0.2em 0 0.4em 1em;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-message-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  padding: 0;
  background: none;
  border: none;
  color: var(--dimmed-text-color);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.chat-message-copy:hover {
  color: var(--text-color);
}
.chat-message:hover .chat-message-copy,
.chat-message-copy:focus-visible {
  opacity: 1;
}
@media (hover: none) {
  .chat-message-copy { opacity: 1; }
}
.chat-message-copy svg {
  width: 16px;
  height: 16px;
  display: block;
}

.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dimmed-text-color);
  animation: chat-typing-bounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-typing span { animation: none; opacity: 0.6; }
}

.chat-stopped-note {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--dimmed-text-color);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Mock assistant replies (storage demo phase — no real Agent / LLM yet) */
.chat-message-mock .chat-role {
  font-style: italic;
}

.chat-message-mock .chat-body {
  opacity: 0.75;
}

.chat-composer {
  position: relative;
  margin-top: 16px;
  margin-bottom: 40px;
}

.chat-composer.composer-open {
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.composer-card {
  padding: 8px 8px 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.composer-summary {
  padding: 6px 10px 8px;
  font-size: 0.88rem;
  color: var(--dimmed-text-color);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.composer-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-color);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

.composer-option:hover:not(:disabled),
.composer-option.is-active:not(:disabled) {
  background: var(--border-color);
}

.composer-option:disabled {
  opacity: 0.5;
  cursor: default;
}

.composer-option-hint {
  font-size: 0.75rem;
  color: var(--dimmed-text-color);
}

/* ── Gemini-style chat input ── */
.chat-input {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 10px;
  padding: 10px 10px 10px 18px;
  background: var(--code-bg);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-textarea {
  min-width: 0;
}

.chat-usage {
  position: absolute;
  right: 14px;
  top: calc(100% + 6px);
  font-size: 11px;
  line-height: 1.2;
  color: var(--dimmed-text-color);
  pointer-events: none;
  user-select: none;
}

.chat-usage[hidden] {
  display: none;
}

.chat-composer.composer-open .chat-input {
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* When the chat input is focused: no blue ring — instead the glass fades to a
   transparent halo around the input, revealing the animation behind it.
   (Temporarily disabled along with the glass card above.) */
.page.chat-focus::before {
  background: radial-gradient(circle at 50% 80%, transparent 0%, transparent 6%, var(--content-glass) 28%);
}

.chat-textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text-color);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 0;
}

.chat-textarea::placeholder {
  color: var(--dimmed-text-color);
}

.chat-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--border-color);
  color: var(--dimmed-text-color);
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.chat-send:disabled {
  cursor: default;
  opacity: 0.45;
}

.chat-send:not(:disabled) {
  background: #000;
  color: #fff;
}

/* Dark theme: white button so it stands out against the dark glass. */
[data-theme="dark"] .chat-send:not(:disabled) {
  background: #fff;
  color: #000;
}

.chat-send.chat-send-stop:not(:disabled) {
  background: #c44;
  color: #fff;
}

[data-theme="dark"] .chat-send.chat-send-stop:not(:disabled) {
  background: #e06050;
  color: #fff;
}

.chat-send-icon {
  width: 20px;
  height: 20px;
  display: block;
}

/* ── Left-edge icon rail (panel-left + message-circle-plus) ── */
.icon-rail {
  position: fixed;
  left: max(16px, env(safe-area-inset-left, 0px));
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  /* Frosted glass: low alpha so the Vanta fog blur visibly through */
  background: rgba(236, 232, 224, 0.32);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  backdrop-filter: blur(14px) saturate(180%);
  border: 1px solid rgba(90, 86, 80, 0.22);
  border-radius: 22px;
  box-shadow: 0 4px 18px rgba(28, 27, 25, 0.14);
}

[data-theme="dark"] .icon-rail {
  background: rgba(18, 17, 16, 0.45);
  border-color: rgba(200, 196, 188, 0.12);
}

.icon-rail-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-color);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-rail-btn:hover {
  background: var(--code-bg);
}

.icon-rail-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* Hide the floating rail while the sidebar is open — its icons live in the
   sidebar's own toolbar (top-right) in that state. */
body.sidebar-open .icon-rail {
  display: none;
}

/* Viewport top-right: local Agent loop toggle (hidden unless localhost). */
.header-loop-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  width: 38px;
  height: 38px;
  background: rgba(236, 232, 224, 0.32);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  backdrop-filter: blur(14px) saturate(180%);
  border: 1px solid rgba(90, 86, 80, 0.22);
  box-shadow: 0 4px 18px rgba(28, 27, 25, 0.14);
}
[data-theme="dark"] .header-loop-toggle {
  background: rgba(18, 17, 16, 0.45);
  border-color: rgba(200, 196, 188, 0.12);
}
body.loop-debug-open .header-loop-toggle {
  display: none;
}

/* ── Sidebar (full-bleed slide-in from viewport left edge, frosted glass) ── */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: 280px;
  z-index: 40;
  /* Slide from off-screen; visibility defers until transform completes so the
     frosted-glass GPU layer composites in one frame (no flash). */
  transform: translateX(-100%);
  visibility: hidden;
  pointer-events: none;
  will-change: transform, backdrop-filter;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0s linear 0.28s;
}

.sidebar.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0s linear 0s;
}

.sidebar-inner {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  /* Frosted glass: full-height surface, flush against the viewport edge */
  background: rgba(236, 232, 224, 0.32);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  border-right: 1px solid rgba(90, 86, 80, 0.22);
  border-radius: 0 16px 16px 0;
  box-shadow: 0 6px 24px rgba(28, 27, 25, 0.14);
}

[data-theme="dark"] .sidebar-inner {
  background: rgba(18, 17, 16, 0.48);
  border-right-color: rgba(200, 196, 188, 0.12);
}

.sidebar-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 4px 6px 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.18);
  flex-shrink: 0;
}

.sidebar-toolbar-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-color);
  cursor: pointer;
  transition: background 0.15s ease;
}

.sidebar-toolbar-btn:hover {
  background: var(--code-bg);
}

.sidebar-toolbar-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dimmed-text-color);
  padding: 10px 8px 6px;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
}

.sidebar-group:first-child .sidebar-group-title {
  padding-top: 2px;
}

.sidebar-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  background: transparent;
  border: none;
  border-radius: 8px;
  text-align: left;
  color: var(--text-color);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.35;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s ease;
}

.sidebar-item:hover {
  background: var(--code-bg);
}

.sidebar-item.active {
  background: var(--code-bg);
  font-weight: 600;
}

.sidebar-empty {
  padding: 12px 10px;
  color: var(--dimmed-text-color);
  font-style: italic;
  font-size: 0.88rem;
}

/* ── Login gate ── */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
}
.auth-gate[hidden],
.header-login[hidden],
.header-logout[hidden],
.header-loop-toggle[hidden] {
  display: none !important;
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 28px 24px 24px;
  background: var(--content-glass);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}
.auth-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-color);
  border-radius: 6px;
}
.auth-close:hover {
  opacity: 0.65;
}
.auth-close svg {
  width: 18px;
  height: 18px;
  display: block;
}
.auth-card h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
  padding: 0;
}
.auth-lead {
  margin: 0 0 16px;
  color: var(--dimmed-text-color);
  font-size: 0.95rem;
}
.auth-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--dimmed-text-color);
  margin-bottom: 6px;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.auth-input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 14px;
  font: inherit;
  font-size: 1rem;
  background: var(--background-color);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}
.auth-error {
  color: #cc0000;
  font-size: 0.88rem;
  margin: 0 0 12px;
}
.auth-submit {
  width: 100%;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 8px;
}
.auth-submit:hover:not(:disabled) {
  background: var(--btn-bg-hover);
}
.auth-submit:disabled {
  opacity: 0.5;
  cursor: default;
}


/* ── Local Agent loop inspector (right sidebar, mirrors the left session list) ── */
.loop-debug {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: 280px;
  z-index: 40;
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  will-change: transform, backdrop-filter;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0s linear 0.28s;
}
.loop-debug.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              visibility 0s linear 0s;
}
.loop-debug-inner {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  background: rgba(236, 232, 224, 0.32);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  border-left: 1px solid rgba(90, 86, 80, 0.22);
  border-radius: 16px 0 0 16px;
  box-shadow: 0 6px 24px rgba(28, 27, 25, 0.14);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
}
[data-theme="dark"] .loop-debug-inner {
  background: rgba(18, 17, 16, 0.48);
  border-left-color: rgba(200, 196, 188, 0.12);
}
.loop-debug-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 4px 6px 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(127, 127, 127, 0.18);
  flex-shrink: 0;
}
.loop-debug-title {
  flex: 1;
  min-width: 0;
  color: var(--dimmed-text-color);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.loop-debug-clear {
  background: none;
  border: none;
  color: var(--link-color);
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 6px;
}
.loop-debug-clear:hover {
  background: var(--code-bg);
}
.loop-debug-empty {
  margin: 0;
  padding: 8px 10px 10px;
  color: var(--dimmed-text-color);
  font-style: italic;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.88rem;
}
.loop-debug-empty[hidden] {
  display: none !important;
}
.loop-debug-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 8px 10px 10px;
  overflow-y: auto;
  list-style: none;
}
.loop-debug-item {
  margin-bottom: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-color);
}
.loop-debug-item:last-child {
  margin-bottom: 0;
}
