/* cws-remote. One signal colour with one meaning: amber = it is your turn. */
:root {
  --base: #151c27;
  --surface: #1d2634;
  --raised: #273244;
  --line: #2f3c51;
  --text: #e8edf4;
  --muted: #8e9bb0;
  --turn: #f3b648;       /* waiting for you, your move */
  --turn-ink: #2a1f08;
  --work: #43c6b1;
  --idle: #6b788d;
  --danger: #f07a6a;
  --screen: #10161f;
  --r-s: 8px; --r-m: 12px; --r-l: 18px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* Desktop scrollbars: thin and dark instead of the light default with arrow buttons. */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
  ::-webkit-scrollbar-button { display: none; }
}
html, body { height: 100%; margin: 0; }
body { background: var(--base); color: var(--text); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--turn); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg circle { fill: currentColor; stroke: none; }
code { font-family: var(--mono); font-size: .92em; background: var(--raised); padding: 1px 5px; border-radius: 5px; }

/* ---- header bar (list and session) */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px; background: rgba(21, 28, 39, .92);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar-title { flex: 1; min-width: 0; }
.bar h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar p { margin: 1px 0 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border: 0;
  border-radius: var(--r-m); background: transparent; color: var(--muted); }
.icon:hover, .icon:active { background: var(--raised); color: var(--text); }

/* state: a dot and a word */
.state { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 13px; color: var(--muted); }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.state.waiting { color: var(--turn); }
.state.waiting::before { background: var(--turn); box-shadow: 0 0 0 4px rgba(243, 182, 72, .18); }
.state.working { color: var(--work); }
.state.working::before { background: var(--work); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* overflow menu */
.menu { position: absolute; right: 12px; top: calc(100% + 6px); width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45); }
.menu-label { margin: 6px 10px 4px; font-size: 12px; color: var(--muted); }
.menu button { display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0;
  border-radius: var(--r-s); background: transparent; }
.menu button small { display: block; font-size: 12px; color: var(--muted); }
.menu button:hover { background: var(--raised); }
.menu button[aria-checked="true"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--turn); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

/* ---- login */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
#login-form { width: 100%; max-width: 340px; }
.mark { width: 48px; height: 48px; border-radius: var(--r-m); background: var(--surface);
  border: 1px solid var(--line); display: grid; place-items: center; margin-bottom: 18px; }
.mark span { font: 600 24px/1 var(--mono); color: var(--turn); }
#login h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
#login p.muted { margin: 4px 0 24px; }
#login label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
input, textarea { font: inherit; color: var(--text); width: 100%; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-m); padding: 12px 14px; }
input:focus, textarea:focus { outline: none; border-color: var(--turn); }
#code { font-family: var(--mono); letter-spacing: .3em; font-size: 18px; }
.primary { width: 100%; margin-top: 22px; padding: 13px; border: 0; border-radius: var(--r-m);
  background: var(--turn); color: var(--turn-ink); font-weight: 650; }
.error { color: var(--danger); font-size: 14px; min-height: 1.3em; margin: 10px 0 0; }
.primary:disabled { opacity: .45; cursor: default; }
a.icon { text-decoration: none; }

/* ---- new session */
#new { max-width: 760px; margin: 0 auto; }
.new-form { padding: 14px 16px 28px; }
.new-form label { display: block; margin: 18px 0 6px; font-size: 13px; color: var(--muted); }
#projects { list-style: none; margin: 10px 0 0; padding: 0; max-height: 44dvh; overflow: auto;
  border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface); }
#projects button { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; width: 100%;
  padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
#projects li:last-child button { border-bottom: 0; }
#projects button[aria-selected="true"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--turn); }
#projects button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#projects small { flex: none; font-size: 12px; color: var(--work); }
#projects .none { padding: 14px; }
select { font: inherit; color: var(--text); width: 100%; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-m); padding: 12px 14px; }

/* ---- session list */
#list { max-width: 760px; margin: 0 auto; }
#panes { list-style: none; margin: 0; padding: 6px 0 24px; }
#panes a { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; padding: 14px 16px;
  color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); }
#panes a:hover { background: var(--surface); }
#panes a::before { content: ""; grid-row: 1 / span 3; align-self: start; margin-top: 7px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--idle); }
#panes a.working::before { background: var(--work); }
#panes a.waiting { background: linear-gradient(90deg, rgba(243, 182, 72, .10), transparent 70%);
  box-shadow: inset 3px 0 0 var(--turn); }
#panes a.waiting::before { background: var(--turn); }
.row-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.row-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-state { font-size: 13px; color: var(--muted); flex: none; }
a.waiting .row-state { color: var(--turn); }
a.working .row-state { color: var(--work); }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-ask { margin-top: 6px; font-size: 14px; color: var(--turn); }
.notice { margin: 12px 16px 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r-m);
  background: var(--surface); color: var(--muted); font-size: 14px; }
.empty { margin: 48px 20px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ---- one session: header, question, screen fills the rest, dock at the bottom */
#pane:not(.hidden) { height: 100dvh; display: flex; flex-direction: column; }
#pane .bar { position: relative; }
.question { flex: none; padding: 10px 16px; background: rgba(243, 182, 72, .12);
  border-bottom: 1px solid rgba(243, 182, 72, .35); color: var(--turn); font-size: 14px; }
#screen { flex: 1; min-height: 0; margin: 0; padding: 12px 14px; overflow: auto; background: var(--screen);
  font-family: var(--mono); font-size: 12px; line-height: 1.4; font-variant-ligatures: none; tab-size: 8;
  color: #d6dde8; overscroll-behavior: contain;
  /* Reserve the scrollbar's width up front: line lengths are measured from clientWidth before the
     text goes in, so a scrollbar appearing afterwards would push separator lines onto a new line. */
  scrollbar-gutter: stable; }
#screen.fit { white-space: pre; overflow-x: hidden; }
#screen.wrap { white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; }
#screen.scroll { white-space: pre; }

.dock { flex: none; padding: 8px 10px max(10px, env(safe-area-inset-bottom)); background: var(--base);
  border-top: 1px solid var(--line); }
/* all keys always visible: two even rows on a phone (1 2 3 Enter Esc / up down Mode Ctrl-C),
   one row on wide screens */
.keys { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 2px 0 8px; }
.keys button { min-width: 0; height: 38px; padding: 0 6px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface); font-size: 14px; font-variant-numeric: tabular-nums; }
.keys button:active { background: var(--raised); transform: scale(.96); }
.keys button.danger { grid-column: span 2; color: var(--danger); border-color: rgba(240, 122, 106, .45); }
@media (min-width: 640px) {
  .keys { display: flex; }
  .keys button { min-width: 48px; padding: 0 14px; }
  .keys button.danger { grid-column: auto; }
}
.suggest { display: flex; align-items: baseline; gap: 8px; max-width: 100%; margin: 0 0 8px; padding: 8px 12px;
  border: 1px dashed rgba(243, 182, 72, .55); border-radius: var(--r-m); background: transparent;
  color: var(--text); text-align: left; }
.suggest-label { flex: none; font-size: 12px; color: var(--turn); }
#suggest-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest:active { background: var(--surface); }
.composer { display: flex; align-items: flex-end; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-l); padding: 6px 6px 6px 14px; }
.composer:focus-within { border-color: var(--turn); }
.composer textarea { flex: 1; border: 0; background: transparent; padding: 8px 0; resize: none;
  max-height: 40vh; line-height: 1.4; }
.send { flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--turn); color: var(--turn-ink); }
.send svg { stroke-width: 2.4; }
.dock .error:empty { display: none; }

/* wider screens: a little air around the terminal */
@media (min-width: 900px) {
  #screen { margin: 12px 16px 0; border: 1px solid var(--line); border-radius: var(--r-m); }
  .dock { padding: 10px 16px 14px; border-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .state.working::before { animation: none; }
  .keys button:active { transform: none; }
}
.suggest.jump { border-style: solid; border-color: rgba(67, 198, 177, .55); }
.suggest.jump .suggest-label { color: var(--work); }
