:root {
  --bg: #212121;
  --panel: #171717;
  --panel-hover: #2a2a2a;
  --border: #2f2f2f;
  --text: #ececec;
  --muted: #8e8e8e;
  --accent: #10a37f;
  --user-bubble: #2f2f2f;
  --assistant-bubble: transparent;
  --link: #7aa6ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

#app { display: flex; height: 100vh; position: relative; }

#sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  transition: width 0.2s ease, flex-basis 0.2s ease, padding 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}

#app.sidebar-collapsed #sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
}

#sidebar-toggle {
  position: absolute;
  top: 12px;
  left: 260px;
  transform: translateX(-50%);
  width: 22px;
  height: 32px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left 0.2s ease;
}
#sidebar-toggle:hover { background: var(--panel-hover); color: var(--text); }
#sidebar-toggle .chev { display: inline-block; transition: transform 0.2s ease; }
#app.sidebar-collapsed #sidebar-toggle { left: 0; transform: translateX(4px); }
#app.sidebar-collapsed #sidebar-toggle .chev { transform: rotate(180deg); }

#sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 20;
}

#new-chat {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
#new-chat:hover { background: var(--panel-hover); }

#conversations {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  overflow-y: auto;
  flex: 1;
}
#conversations li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
#conversations li:hover { background: var(--panel-hover); }
#conversations li.active { background: var(--panel-hover); }
#conversations li .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#conversations li .del {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 14px;
  visibility: hidden;
}
#conversations li:hover .del { visibility: visible; }
#conversations li .del:hover { color: #e06c6c; }

#view-profile {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  margin-top: 6px;
}
#view-profile:hover { background: var(--panel-hover); }

#logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  margin-top: 6px;
}
#logout:hover { background: var(--panel-hover); color: #e06c6c; }

.profile-pane {
  max-width: 760px;
  margin: 16px auto 40px;
  padding: 0 24px;
  line-height: 1.6;
}
.profile-pane .profile-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.profile-pane .profile-body h1,
.profile-pane .profile-body h2,
.profile-pane .profile-body h3 { margin: 18px 0 8px; }
.profile-pane .profile-body p { margin: 0 0 12px; }
.profile-pane .profile-body ul,
.profile-pane .profile-body ol { padding-left: 22px; margin: 8px 0; }
.profile-pane .profile-body li { margin: 3px 0; }
.profile-pane .profile-body :not(pre) > code {
  background: #2f2f2f;
  padding: 1px 5px;
  border-radius: 4px;
}

#footer {
  color: var(--muted);
  font-size: 11px;
  padding: 8px 4px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
}

.msg {
  max-width: 760px;
  margin: 0 auto 18px;
  padding: 0 24px;
  display: flex;
  gap: 14px;
}
.msg .role {
  flex: 0 0 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg.user .role { background: #5b5bd6; }
.msg .content {
  flex: 1;
  word-wrap: break-word;
}
.msg.user .content {
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: 18px;
  align-self: flex-start;
  max-width: calc(100% - 44px);
  white-space: pre-wrap;
}
.msg.assistant .content {
  white-space: normal;
  background: var(--panel);
  padding: 10px 14px;
  border-radius: 18px;
  max-width: calc(100% - 44px);
}
.msg.assistant .content p { margin: 0 0 10px; }
.msg.assistant .content p:last-child { margin-bottom: 0; }
.msg.assistant .content ul,
.msg.assistant .content ol { margin: 6px 0; }
.msg.assistant .content li { margin: 2px 0; }
.msg.assistant .content li > p { margin: 0; }
.msg.assistant .content pre { margin: 8px 0; }
.msg pre {
  background: #0f0f0f;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
}
.msg code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; }
.msg.assistant .content p:first-child { margin-top: 0; }
.msg.assistant .content p:last-child { margin-bottom: 0; }
.msg.assistant .content h1,
.msg.assistant .content h2,
.msg.assistant .content h3 { margin: 14px 0 6px; }
.msg.assistant .content :not(pre) > code {
  background: #2f2f2f;
  padding: 1px 5px;
  border-radius: 4px;
}
.msg.assistant .content table { border-collapse: collapse; margin: 8px 0; }
.msg.assistant .content th,
.msg.assistant .content td { border: 1px solid var(--border); padding: 4px 8px; }
.msg.assistant .content a { color: var(--link); }
.msg.assistant .content ul,
.msg.assistant .content ol { padding-left: 22px; }

.tool-card {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #181818;
  font-size: 13px;
}
.tool-card > summary {
  cursor: pointer;
  padding: 6px 10px;
  color: var(--muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.tool-card > summary::-webkit-details-marker { display: none; }
.tool-card > summary::before {
  content: "▸";
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.15s;
}
.tool-card[open] > summary::before { content: "▾"; }
.tool-card .tool-name { color: var(--text); font-family: "SF Mono", Menlo, Consolas, monospace; }
.tool-card .tool-body { padding: 0 10px 10px; }
.tool-card pre {
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.45;
}
.tool-card .tool-result-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 8px;
}
.tool-card .tool-result {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}
.tool-card .tool-preview {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
  margin-left: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.tool-think {
  background: #15191e;
  border-color: #26303a;
}
.tool-think .tool-name { color: #9ab6d8; }
.tool-think .tool-thoughts {
  color: #c8d4e4;
  font-style: italic;
  white-space: pre-wrap;
  padding: 4px 4px 0;
  line-height: 1.55;
}

.veil {
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

#composer {
  padding: 12px 24px 20px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#input {
  flex: 1;
  background: #2f2f2f;
  color: #fff;
  caret-color: #fff;
  border: 1px solid #555;
  border-radius: 18px;
  padding: 12px 14px;
  font: inherit;
  resize: none;
  max-height: 240px;
  outline: none;
}
#input::placeholder { color: #b8b8b8; opacity: 1; }
#input:focus { border-color: #777; }
#send {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 18px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
#send:disabled { opacity: 0.4; cursor: not-allowed; }

.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 20vh;
  font-size: 18px;
}

/* ---------------------------------------------------------------------- */
/* Daily theme: agent-chosen palette, background image, and avatar.       */
/* ---------------------------------------------------------------------- */

body.themed-bg {
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.55)),
    var(--bg-image);
  background-size: cover, cover;
  background-position: center, center;
  background-attachment: fixed, fixed;
  background-repeat: no-repeat, no-repeat;
}
body.themed-bg #app,
body.themed-bg #main { background: transparent; }
body.themed-bg #sidebar {
  background-color: color-mix(in srgb, var(--panel) 78%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
body.themed-bg .msg.user .content {
  background-color: color-mix(in srgb, var(--user-bubble) 40%, transparent);
}
body.themed-bg .msg.assistant .content {
  background-color: color-mix(in srgb, var(--panel) 40%, transparent);
}

.msg .role { overflow: hidden; }
.msg .role img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.msg.assistant .role:has(img) { background: transparent; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.empty-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  opacity: 0.9;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.empty-glyph { font-size: 56px; line-height: 1; }

.studio-hero {
  max-width: 760px;
  margin: 28px auto 18px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.studio-hero img {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}
.studio-glyph { font-size: 96px; line-height: 1; }
.studio-mood {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  font-style: italic;
}
.studio-note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  width: 100%;
  max-width: 720px;
  padding-bottom: 14px;
}

#conversations li.studio { font-weight: 500; }
#conversations li.studio:hover { background: var(--panel-hover); }

#app.studio-open #composer { display: none; }
#app.studio-open #main {
  padding-bottom: 14px;
}

body.logged-out #app,
body.logged-out #sidebar-toggle,
body.logged-out #sidebar-scrim { display: none; }

#login-pane[hidden] { display: none; }
#login-pane {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
  padding: 24px;
}
#login-form {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}
#login-form h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
}
#login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
#login-form label span { padding-left: 2px; }
#login-form input {
  background: #2f2f2f;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
}
#login-form input:focus { border-color: #555; }
#login-form #login-submit {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  margin-top: 4px;
}
#login-form #login-submit:disabled { opacity: 0.5; cursor: not-allowed; }
#login-error {
  color: #e88;
  font-size: 13px;
  min-height: 1.2em;
  text-align: center;
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80vw;
    max-width: 300px;
    flex-basis: 80vw;
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  #app:not(.sidebar-collapsed) #sidebar { transform: translateX(0); }
  #app.sidebar-collapsed #sidebar {
    width: 80vw;
    flex-basis: 80vw;
    padding-left: 12px;
    padding-right: 12px;
    border-right-color: var(--border);
    transform: translateX(-100%);
  }
  #app:not(.sidebar-collapsed) #sidebar-scrim { display: block; }
  #sidebar-toggle {
    left: 0 !important;
    transform: translateX(8px) !important;
  }
  #app:not(.sidebar-collapsed) #sidebar-toggle { left: 80vw !important; transform: translateX(-110%) !important; }
  #main { width: 100%; }
  .msg { padding: 0 14px; gap: 10px; }
  .msg .role { flex: 0 0 26px; height: 26px; font-size: 11px; }
  #messages { padding: 16px 0 12px; }
  #composer { padding: 8px 12px 14px; gap: 6px; }
  #input { padding: 10px 12px; font-size: 16px; }
  #send { padding: 10px 14px; }
  .profile-pane { padding: 0 14px; }
}
