:root {
  color-scheme: dark;
  --page: #101312;
  --panel: #191e1b;
  --inset: #141815;
  --line: #343e36;
  --text: #edf0e8;
  --muted: #abb7ac;
  --accent: #ddaf83;
  --green: #b5cfab;
  font: 16px/1.55 system-ui, sans-serif;
}

* {box-sizing: border-box}
[hidden] {display: none !important}
body {margin: 0; background: var(--page); color: var(--text)}
h1, h2, p {margin: 0}
h2 {font-size: 1.15rem}
p {color: var(--muted)}
a {color: var(--accent)}
button, input, select, textarea {font: inherit}
button, input, select, textarea {border: 1px solid var(--line); border-radius: 5px; color: var(--text); background: var(--inset)}
button {padding: .48rem .8rem; cursor: pointer}
button:hover:not(:disabled) {border-color: var(--accent)}
button:disabled {opacity: .5; cursor: default}
:focus-visible {outline: 2px solid var(--accent); outline-offset: 3px}
label {display: grid; gap: .35rem; color: var(--muted); font-size: .9rem}
input:not([type=checkbox], [type=range]), select, textarea {width: 100%; padding: .63rem .75rem}
::placeholder {color: var(--muted); opacity: 1}
header, main {width: min(100% - 3rem, 1440px); margin-inline: auto}
header {display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.15rem 0; border-bottom: 1px solid var(--line)}
header h1 {display: flex; align-items: center; gap: .75rem; font-size: 1.28rem; letter-spacing: -.025em; white-space: nowrap}
header img {width: 2.4rem; height: 2.4rem}
#status, #account, #turn-state {font-size: .88rem; color: var(--muted)}
#status {color: var(--green); text-align: end}
main {padding-block: 1rem 2rem}
#notice {margin-bottom: 1rem; color: var(--accent); white-space: pre-wrap; overflow-wrap: anywhere}
#notice:empty {display: none}
.panel {border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-width: 0}
#gate, #device, #memory {padding: 1.35rem}
#gate {max-width: 460px; margin: 10vh auto 0; border-top: 2px solid var(--accent)}
#gate p, #device p {margin-block: .5rem}
#login {display: grid; gap: 1rem; margin-top: 1.25rem}
#enter, #send {background: var(--accent); border-color: var(--accent); color: #211810; font-weight: 700}
.topbar {display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: .85rem}
.topbar > div {display: flex; align-items: center; flex-wrap: wrap; gap: .75rem}
#account {font-weight: 600}
#device {margin-bottom: .85rem}
#device-code {display: block; font: 600 1.55rem/1.4 monospace; color: var(--accent); margin-top: .5rem}

.layout {display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: .85rem}
aside.panel {display: flex; flex-direction: column; gap: .8rem; padding: 1rem; background: #161b17}
aside button {width: 100%; text-align: left}
#new {background: #26352a; color: var(--green); border-color: #455b49; font-weight: 650}
#threads, #history-list {display: grid; gap: .35rem; min-width: 0}
#threads:empty {display: none}
#threads button, #history-list button {overflow: hidden; text-overflow: ellipsis; white-space: nowrap}
.folder-list {font: .8rem/1.5 ui-monospace, monospace; color: var(--muted); border-top: 1px solid var(--line); padding-top: .85rem; margin-top: auto}
#thread-history {width: min(540px, calc(100% - 2rem)); max-height: 80vh; padding: 1rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text)}
#thread-history::backdrop {background: #080b09bd}
.history-heading {display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem}
#history-list {max-height: 55vh; overflow: auto}
#close-history, #more-history {width: auto}
#more-history {margin-top: .6rem}

.chat {display: flex; flex-direction: column; min-height: 72dvh; padding: 1rem}
#thread-title {font-weight: 650; padding: 0 .25rem .7rem; border-bottom: 1px solid var(--line)}
#messages {height: clamp(240px, 47dvh, 680px); overflow: auto; padding: 1rem clamp(0rem, 3vw, 2.75rem); scrollbar-color: var(--line) transparent}
#messages:empty {
  background-image: radial-gradient(ellipse at center, transparent 5%, var(--panel) 74%),
    repeating-linear-gradient(30deg, transparent 0 27px, #34443a 27px 28px),
    repeating-linear-gradient(-30deg, transparent 0 27px, #34443a 27px 28px);
  background-position: center;
}
.message {overflow-wrap: anywhere; white-space: pre-wrap; border: 1px solid var(--line); border-radius: 7px; padding: .8rem 1rem; margin-bottom: .75rem; background: var(--inset)}
.message.user {margin-left: min(9vw, 7rem); background: #26342a; border-color: #405346}
.message .who {color: var(--green); margin-bottom: .22rem; font-size: .85rem; font-weight: 650}
#activity {color: var(--muted); font-size: .875rem; max-height: 5rem; overflow: auto; margin-block: .25rem}
#compose {margin-top: auto; border: 1px solid #465148; border-radius: 7px; padding: .8rem; background: var(--inset)}
#compose:focus-within {border-color: #9b826b}
#compose.drag-target {outline: 2px dashed var(--accent); outline-offset: 4px; background: #243027}
#prompt {padding: .4rem; background: transparent; border: 0; resize: vertical; min-height: 5rem}
.composer-tools, .sendbar, .compact {display: flex; align-items: center; flex-wrap: wrap; gap: .5rem}
.composer-tools {gap: .6rem 1rem}
.sendbar {margin-top: .65rem}
#turn-state {margin-right: auto}
.effort-control input {inline-size: 5rem; accent-color: var(--accent)}
.effort-control output {color: var(--text); min-width: 3.5rem}
.checkbox input {accent-color: var(--accent)}
#attachments {display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .65rem}
#attachments:empty {display: none}
#attachments > div {display: grid; gap: .3rem; max-width: 12.5rem; padding: .4rem; border: 1px solid var(--line); border-radius: 5px; overflow-wrap: anywhere}
#attachments img {width: 5rem; height: 3.5rem; object-fit: cover; border-radius: 3px}
#attachments button, #attachments span {font-size: .875rem}
#outputs {border-top: 1px solid var(--line); padding: .65rem .25rem .25rem}
#outputs h2 {font-size: .95rem}
#output-files {padding-left: 1.25rem; max-height: 9rem; overflow: auto; margin: .3rem 0; overflow-wrap: anywhere}
.approval {display: grid; gap: .65rem; padding: .85rem; margin-block: .6rem; border: 1px solid #77604c; border-radius: 6px}
.approval pre, #memory pre {white-space: pre-wrap; overflow-wrap: anywhere}
#memory {margin-top: .85rem}
.sr {position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%)}

@media (max-width: 720px) {
  header, main {width: calc(100% - 1.5rem)}
  .layout {grid-template-columns: minmax(0, 1fr)}
  aside.panel {display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end}
  #threads, .folder-list {grid-column: 1 / -1}
  #threads {max-height: 7rem; overflow: auto}
  .chat {padding: .75rem}
}

@media (max-width: 360px) {
  aside.panel {grid-template-columns: minmax(0, 1fr)}
}
