:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #08090b; color: #d5dae1; font-size: 16px;
  --raised: #1a1a1a; --line: #2b2b2b; --muted: #abb0b8; --accent: #4ef0c4;
}
* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body {
  position: fixed; top: var(--viewport-top, 0px); left: 0; right: 0;
  height: var(--viewport-height, 100dvh); max-width: 960px; margin: 0 auto;
  display: flex; flex-direction: column; overflow: hidden;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
header {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px; border-bottom: 1px solid var(--line);
}
h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: -.3px; }
h2 { font-size: 24px; font-weight: 500; letter-spacing: -.6px; text-wrap: balance; }
p { line-height: 1.6; color: var(--muted); }
.connection { position: relative; }
.connection summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px; min-width: 44px; cursor: pointer;
  list-style: none; font-size: 13px; color: var(--muted);
}
.connection summary::-webkit-details-marker { display: none; }
#status[data-connected="true"] { color: var(--accent); }
.connection-panel {
  position: absolute; right: 0; top: 100%; z-index: 2; width: min(280px, calc(100vw - 32px));
  max-height: calc(var(--viewport-height, 100dvh) - 100px); overflow: auto;
  background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.connection-panel p { margin: 0 0 4px; font-size: 14px; }
main, #controls { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }
#welcome { margin: auto 0; padding: 24px; overflow: auto; }
#welcome img { border-radius: 12px; }
#error {
  flex-shrink: 0; max-height: 88px; overflow: auto; color: #ffc46b; background: var(--raised);
  margin: 0; padding: 10px 16px; font-size: 14px; border-bottom: 1px solid var(--line);
}
.toolbar { display: flex; flex: 1; min-width: 0; gap: 8px; align-items: center; }
#new { background: transparent; border-color: transparent; font-size: 14px; padding: 8px; min-width: 44px; }
.session-picker { position: relative; flex: 1; min-width: 0; }
.session-picker label { display: block; font-size: 11px; font-weight: 500; color: var(--muted); padding-left: 4px; }
.session-picker select { appearance: none; height: 44px; width: 100%; min-width: 0; text-overflow: ellipsis; padding: 0 20px 0 4px; min-height: 44px; background: transparent; border-color: transparent; font-size: 15px; font-weight: 600; }
button, select, textarea { font: inherit; color: inherit; background: var(--raised); border: 1px solid var(--line); border-radius: 6px; }
button, select { min-height: 44px; padding: 8px 12px; }
button { cursor: pointer; touch-action: manipulation; }
@media (hover: hover) { button:hover { background: #262626; } }
button:active { background: #323232; }
button:disabled, select:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.output { flex: 1; min-height: 0; position: relative; }
#empty-output { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; pointer-events: none; text-align: center; }
#empty-output h2 { font-size: 22px; margin: 0 0 8px; }
#empty-output p { font-size: 14px; margin: 0; }
#terminal[data-raw="true"] { white-space: pre; overflow-wrap: normal; }
#terminal {
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; overflow: auto; overscroll-behavior: contain;
  height: 100%; padding: 16px 16px 56px; margin: 0;
  font: 16px/1.5 ui-monospace, "SF Mono", Menlo, monospace; tab-size: 4;
}
#latest {
  position: absolute; right: 16px; bottom: 12px; border-radius: 6px;
  background: var(--raised); font-size: 14px; z-index: 1;
}
#compose { flex-shrink: 0; padding: 8px 16px max(12px, env(safe-area-inset-bottom)); }
.attachments {
  display: flex; gap: 8px; overflow-x: auto; overscroll-behavior: contain;
  list-style: none; margin: 0 0 8px; padding: 0;
}
.attachments li {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  min-height: 44px; max-width: 220px; padding: 4px 8px 4px 4px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 6px;
}
.attachments img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; background: #111; }
.attachments span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.attachments button { min-width: 44px; min-height: 44px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); }
#stop {
  width: 100%; margin: 0 0 8px; color: #ffc46b; background: var(--raised);
}
.entry { display: flex; align-items: flex-end; gap: 4px; padding: 4px; background: var(--raised); border: 1px solid var(--line); border-radius: 6px; }
.entry:focus-within { border-color: var(--muted); }
#attach-toggle, #keys-toggle { background: transparent; border-color: transparent; color: var(--muted); padding: 8px; min-width: 44px; font-size: 14px; }
#attach-toggle { display: grid; place-items: center; }
textarea {
  display: block; flex: 1; min-width: 0; width: 100%; resize: none; padding: 10px 4px;
  border: 0; background: transparent; border-radius: 4px; min-height: 44px; max-height: min(120px, calc(var(--viewport-height, 100dvh) * .2)); line-height: 22px; overflow-y: auto;
}
textarea::placeholder { color: var(--muted); }
#send { flex: 0 0 44px; min-height: 44px; font-size: 24px; line-height: 1; background: var(--accent); color: #08090b; border-color: var(--accent); font-weight: 600; }
#send:focus-visible { outline-color: #08090b; outline-offset: -4px; }
#keys-toggle[aria-expanded="true"] { color: var(--accent); background: var(--raised); }
.keys { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; max-height: calc(var(--viewport-height, 100dvh) * .3); overflow: auto; }
.keys button { min-width: 0; padding: 8px 0; font-size: 14px; }
#paste { grid-column: 1 / -3; }
#interrupt { grid-column: -3 / -1; color: #ffc46b; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }
@media (max-width: 429px) { .keys { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 700px) { #terminal { padding: 20px 24px; } header, #compose { padding-left: 24px; padding-right: 24px; } }
@media (max-height: 450px) { header { padding-top: 0; padding-bottom: 0; } textarea { max-height: 68px; } #compose { padding-top: 6px; } }

.session-chevron { position: absolute; right: 4px; bottom: 14px; color: var(--muted); pointer-events: none; font-size: 13px; }
