:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg: #000000;
  --surface: #2f2f2f;
  --surface-hover: #383838;
  --surface-strong: #171717;
  --text: #ececec;
  --muted: #b4b4b4;
  --subtle: #8f8f8f;
  --border: #424242;
  --border-strong: #565656;
  --button: #f4f4f4;
  --button-text: #171717;
  --shadow: 0 18px 50px rgb(0 0 0 / 45%);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --viewport-height: 100dvh;
  --viewport-top: 0px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.drawer-open { overflow: hidden; }
button, input, textarea { font: inherit; }
button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  appearance: none;
  -webkit-appearance: none;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
button:disabled { cursor: default; }
::selection { background: #ececec; color: #171717; }

#app {
  position: fixed;
  top: var(--viewport-top);
  right: 0;
  left: 0;
  height: var(--viewport-height);
  padding-top: env(safe-area-inset-top);
  display: flex;
  flex-direction: column;
}
#chrome-left {
  position: absolute;
  z-index: 1;
  top: calc(env(safe-area-inset-top) + 8px);
  left: max(8px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 4px;
}
#status-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: #7ecf8a;
  box-shadow: 0 0 0 3px rgb(126 207 138 / 12%);
}
#status-dot.cold { background: var(--subtle); box-shadow: none; }
#status-dot.thinking { animation: pulse 1.25s ease-in-out infinite; }
#status-dot.offline { background: #d28a8a; box-shadow: 0 0 0 3px rgb(210 138 138 / 12%); }
#model-picker {
  max-width: min(38vw, 180px);
  min-height: 44px;
  padding: 0 24px 0 7px;
  border: 0;
  border-radius: 7px;
  outline: 0;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: .75rem;
}
#model-picker:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
#model-picker:disabled { opacity: .55; }
#model { color: var(--subtle); font-size: .7rem; white-space: nowrap; }
#menu-toggle {
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  transition: color 160ms var(--ease), background-color 160ms var(--ease), transform 120ms var(--ease);
}
#menu-toggle:active { background: var(--surface); color: var(--text); transform: scale(.97); }
#menu-toggle svg, #drawer-close svg, #notebook-back svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#messages {
  width: min(100%, 48rem);
  min-height: 0;
  flex: 1;
  margin: 0 auto;
  padding: 56px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 26px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
#empty { width: 100%; margin: auto; padding: 48px 16px; text-align: center; }
#empty h1 { margin: 0; font-size: 1.3rem; font-weight: 600; letter-spacing: -.025em; }
#empty p { margin: 8px 0 0; color: var(--muted); font-size: .925rem; }
article { width: 100%; align-self: flex-start; animation: message-in 160ms var(--ease) both; }
article p {
  max-width: 70ch;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.65;
}
article.user {
  width: auto;
  max-width: 86%;
  align-self: flex-end;
  padding: 10px 16px;
  border-radius: 20px 20px 6px 20px;
  background: var(--surface);
}
article.user p { line-height: 1.5; }
article.waiting { padding-left: 14px; border-left: 2px solid var(--border-strong); color: var(--muted); }
article.waiting::before {
  content: "Waiting for you";
  display: block;
  margin-bottom: 6px;
  color: var(--subtle);
  font-size: .75rem;
  font-weight: 600;
}
article.assistant.responding p { min-height: 1.65em; }
.response-loader {
  height: 1.65em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.response-loader i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: response-dot 1.1s ease-in-out infinite;
}
.response-loader i:nth-child(2) { animation-delay: 120ms; }
.response-loader i:nth-child(3) { animation-delay: 240ms; }
article.streaming p::after {
  content: "";
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  display: inline-block;
  vertical-align: -.15em;
  background: var(--text);
  animation: response-caret 700ms steps(1) infinite;
}
article.response-error { color: #d5b9b9; }
article.model-error {
  padding: 14px;
  border: 1px solid #693f43;
  border-radius: 12px;
  background: #241719;
}
article.model-error strong { display: block; margin-bottom: 5px; color: #efc7ca; font-size: .9rem; }
article.model-error p { color: #d5b9b9; font-size: .9rem; line-height: 1.5; }
.model-error-meta { margin-top: 5px !important; color: #aa898c !important; font-size: .75rem !important; }
.model-error-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.model-error-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 0 13px;
  border-radius: 7px;
  background: #3a2629;
  color: #efc7ca;
  font-size: .82rem;
  font-weight: 600;
}
.model-error-actions button:first-child { background: #efc7ca; color: #241719; }

#composer {
  width: min(100%, 48rem);
  flex: none;
  margin: 0 auto;
  padding: 8px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--bg);
}
#input-row {
  position: relative;
  isolation: isolate;
  min-height: 52px;
  padding: 10px 8px 10px 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#input-row::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 2px 0;
  border: 1px solid var(--border);
  border-radius: 32px;
  background: var(--surface);
  box-shadow: 0 3px 14px rgb(0 0 0 / 18%);
  transition: border-color 160ms var(--ease), box-shadow 180ms var(--ease);
}
#input-row:focus-within {
}
#input-row:focus-within::before {
  border-color: var(--border-strong);
  box-shadow: 0 8px 24px rgb(0 0 0 / 42%);
}
textarea {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 4px 10px 0;
  border: 0;
  outline: 0;
  resize: none;
  overflow-y: auto;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 24px;
}
textarea:focus, textarea:focus-visible { outline: 0; box-shadow: none; }
textarea::placeholder { color: var(--muted); opacity: 1; }
textarea:disabled { opacity: .65; }
#send-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
}
#send-btn:active:not(:disabled) { transform: scale(.94); }
#send-btn:disabled { background: #5a5a5a; color: #282828; }
#send-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#composer-hint { display: none; padding-top: 7px; color: var(--subtle); text-align: center; font-size: .72rem; }

#drawer-overlay {
  position: fixed;
  z-index: 20;
  top: var(--viewport-top);
  right: 0;
  left: 0;
  height: var(--viewport-height);
  background: rgb(0 0 0 / 58%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms var(--ease), visibility 0s linear 180ms;
}
#drawer-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; transition-delay: 0s; }
#drawer {
  position: fixed;
  z-index: 30;
  top: var(--viewport-top);
  left: 0;
  width: min(320px, 86vw);
  height: var(--viewport-height);
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform 220ms var(--ease), visibility 0s linear 220ms;
}
#drawer.open { visibility: visible; pointer-events: auto; transform: translateX(0); transition-delay: 0s; }
#drawer-header {
  min-height: 64px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
#drawer-brand { display: flex; align-items: center; gap: 10px; }
#drawer-brand img { width: 28px; height: 28px; flex: none; }
#drawer-title { font-size: 1.25rem; font-weight: 650; letter-spacing: -.02em; }
#drawer-close { display: grid; place-items: center; border-radius: 8px; color: var(--muted); }
#drawer-nav { flex: none; display: flex; flex-direction: column; gap: 2px; padding: 12px 0; }
.drawer-row {
  min-height: 42px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: .925rem;
  font-weight: 500;
  text-decoration: none;
  touch-action: manipulation;
  transition: background-color 160ms var(--ease);
}
.drawer-row:active { background: var(--surface); }
.drawer-row svg { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#drawer-chats {
  min-height: 0;
  flex: 1;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--border);
}
#drawer-chats-heading {
  min-height: 36px;
  flex: none;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#drawer-chats-title { margin: 0; font-size: .8rem; font-weight: 650; color: var(--muted); }
#archived-toggle {
  min-width: 0;
  min-height: 44px;
  padding: 0 6px;
  border-radius: 6px;
  color: var(--muted);
  font-size: .75rem;
}
#session-status { margin: 10px 8px; color: var(--muted); font-size: .8rem; }
#session-status:empty { display: none; }
#session-list, #archived-list { flex: none; display: flex; flex-direction: column; gap: 2px; }
#session-list { min-height: 0; }
#archived-list { padding-top: 6px; border-top: 1px solid var(--border); }
#archived-list[hidden] { display: none; }
.session-item { border-radius: 8px; }
.session-item.active { background: var(--surface); }
.session-main { min-height: 54px; display: flex; align-items: stretch; }
.session-open {
  min-width: 0;
  min-height: 54px;
  flex: 1;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
  border-radius: 8px;
  text-align: left;
}
.session-title { width: 100%; overflow: hidden; color: var(--text); font-size: .875rem; font-weight: 520; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { width: 100%; overflow: hidden; color: var(--subtle); font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
.session-more, .session-restore { flex: none; align-self: center; border-radius: 7px; color: var(--muted); }
.session-more { display: grid; place-items: center; }
.session-more svg { width: 20px; height: 20px; fill: currentColor; }
.session-restore { min-width: 0; padding: 0 8px; font-size: .75rem; font-weight: 600; }
.session-actions, .session-rename { padding: 2px 8px 9px; display: flex; align-items: center; gap: 6px; }
.session-actions button, .session-rename button {
  min-width: 0;
  min-height: 44px;
  padding: 0 9px;
  border-radius: 6px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
}
.session-rename input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  outline: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
.session-rename input:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }
#notebook-top {
  width: min(100%, 48rem);
  min-height: 56px;
  flex: none;
  margin: 0 auto;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 4px;
}
#notebook-top h1 { font-size: 1.25rem; font-weight: 650; letter-spacing: -.02em; }
#notebook-back { min-width: 44px; min-height: 44px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); }
#notebook-tabs {
  width: min(100%, 48rem);
  flex: none;
  margin: 0 auto;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.notebook-tab {
  position: relative;
  padding: 0 12px;
  color: var(--subtle);
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
}
.notebook-tab.active { color: var(--text); }
.notebook-tab.active::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 0;
  left: 12px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--text);
}
#notebook-content {
  width: min(100%, 48rem);
  min-height: 0;
  flex: 1;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  color: var(--text);
  font-size: .925rem;
  line-height: 1.55;
}
.notebook-state { padding: 24px 4px; color: var(--muted); }
.notebook-card { padding: 16px 4px; border-bottom: 1px solid var(--border); }
.notebook-card strong { display: block; margin-bottom: 6px; font-size: .925rem; font-weight: 600; }
.notebook-card-ts { margin-bottom: 6px; color: var(--subtle); font-size: .75rem; }
.notebook-evidence { margin-top: 6px; color: var(--muted); font-size: .8rem; }
.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 (hover: hover) and (pointer: fine) {
  #menu-toggle:hover, #drawer-close:hover, #notebook-back:hover, .notebook-tab:hover, #archived-toggle:hover, .session-open:hover, .session-more:hover, .session-restore:hover, .session-actions button:hover, .session-rename button:hover { background: var(--surface-hover); color: var(--text); }
  .model-error-actions button:hover { filter: brightness(1.12); }
  .drawer-row:hover { background: var(--surface); }
  #send-btn:hover:not(:disabled) { background: #ffffff; }
}
@media (min-width: 40rem) {
  #messages { padding: 56px 24px 32px; gap: 30px; }
  article.user { max-width: 75%; }
  #composer { padding: 10px 24px max(14px, env(safe-area-inset-bottom)); }
  #drawer { padding-right: 20px; padding-left: max(20px, env(safe-area-inset-left)); }
}
@media (min-width: 40rem) and (pointer: fine) {
  #composer-hint { display: block; }
}
@media (max-height: 32rem) and (orientation: landscape) {
  #messages { padding-bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  article.streaming p::after { animation: none; opacity: .65; }
}
@keyframes message-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes response-dot { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
@keyframes response-caret { 50% { opacity: 0; } }
.identity-status { display: inline-block; margin-bottom: 6px; padding: 2px 8px; border-radius: 4px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.identity-proposed { background: #3a3520; color: #d4b85c; }
.identity-ratified { background: #1e3326; color: #6abf8a; }
.identity-rejected { background: #352020; color: #bf6a6a; }
.identity-retired { background: var(--surface); color: var(--muted); }
.identity-actions { display: flex; gap: 8px; margin-top: 10px; }
.identity-btn { min-width: 0; min-height: 32px; padding: 4px 14px; border-radius: 6px; font-size: .8rem; font-weight: 600; }
.identity-btn.ratify { background: #1e3326; color: #6abf8a; }
.identity-btn.ratify:hover { background: #264030; }
.identity-btn.reject { background: #352020; color: #bf6a6a; }
.identity-btn.reject:hover { background: #402828; }
.identity-btn:disabled { opacity: .5; cursor: default; }
