/*
 * Roundtable.
 *
 * The Round Table: everyone has an equal seat and nobody sits at the head.
 * Vellum and iron-gall ink in daylight, a smoke-dark oak hall at night. Colour
 * comes from heraldry and each tincture has one job: azure is what you can do,
 * gold marks whose turn it is (and focus), vert is done, gules is stop.
 *
 * Every colour is a token defined on :root, redefined for dark. Nothing takes
 * its only definition from inside a media query, because the default setting
 * on most machines stamps no theme at all.
 */

:root {
  color-scheme: light dark;

  --paper:      #efe6d2;
  --card:       #f7f0df;
  --sunk:       #e6dabf;
  --line:       #d8c9a6;
  --line-firm:  #c2ae84;

  --ink:        #271d16;
  --ink-soft:   #5a4a3b;
  --ink-faint:  #8c7a62;

  --brass:      #b8892b;
  --brass-soft: #f0e0b8;
  --moss:       #2f5d3a;
  --moss-soft:  #dde7d6;
  --clay:       #8e1f24;
  --clay-soft:  #f0d8d5;

  --azure:     #1e3a6e;
  --on-azure:  #f7f0df;
  --shadow: 0 1px 2px rgba(39, 29, 22, .08), 0 10px 26px -14px rgba(39, 29, 22, .28);
  --radius: 10px;

  --sans: "Alegreya", ui-serif, Georgia, "Times New Roman", serif;
  --serif: "IM Fell English", "Alegreya", ui-serif, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #1a1612;
    --card:       #231d17;
    --sunk:       #2b241c;
    --line:       #3a3026;
    --line-firm:  #4f4233;

    --ink:        #efe3c8;
    --ink-soft:   #c4b394;
    --ink-faint:  #8f7f66;

    --brass:      #d9ad4f;
    --brass-soft: #3a2e17;
    --moss:       #8fb98f;
    --moss-soft:  #22301f;
    --clay:       #e07a6e;
    --clay-soft:  #3a1f1c;

    --azure: #7f9fd6; --on-azure: #1a1612;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  --paper: #1a1612; --card: #231d17; --sunk: #2b241c;
  --line: #3a3026; --line-firm: #4f4233;
  --ink: #efe3c8; --ink-soft: #c4b394; --ink-faint: #8f7f66;
  --brass: #d9ad4f; --brass-soft: #3a2e17;
  --moss: #8fb98f; --moss-soft: #22301f;
  --clay: #e07a6e; --clay-soft: #3a1f1c;
  --azure: #7f9fd6; --on-azure: #1a1612;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

/*
 * Anything marked hidden is hidden, whatever else it is told.
 *
 * The browser's own rule for this is [hidden]{display:none}, which any class
 * of the same weight silently beats - and several here set display, so every
 * dialogue in this interface was permanently open and the lobby unreachable
 * behind them. Author-level and !important, so the attribute always wins.
 */
[hidden] { display: none !important; }


html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.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;
}

.mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--ink-soft); }

/* ---------- controls ---------- */

.btn {
  font: 500 14px/1 var(--sans);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-firm);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--sunk); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--azure);
  border-color: var(--azure);
  color: var(--on-azure);
}
.btn-primary:hover { filter: brightness(1.12); }

.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-quiet:hover { background: var(--sunk); color: var(--ink); }

.btn-lg { font-size: 16px; padding: 13px 26px; }
.btn-sm { font-size: 12px; padding: 5px 9px; }

.text-input, .ask-input, .code-input {
  font: 400 15px/1.5 var(--sans);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-firm);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
.text-input:focus, .ask-input:focus, .code-input:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px var(--brass-soft);
}

.notice {
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  margin: 12px 0 0;
}
.notice-bad { background: var(--clay-soft); color: var(--clay); }

/* ---------- lobby ---------- */

.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}
.lobby-inner { width: 100%; max-width: 480px; text-align: center; }

.wordmark {
  font: 400 68px/1 var(--serif);
  letter-spacing: -.01em;
  margin: 0;
}
.tagline {
  color: var(--ink-soft);
  margin: 10px 0 34px;
  font-size: 17px;
}

.lobby-actions {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
}
.or {
  color: var(--ink-faint);
  font-size: 13px;
  margin: 20px 0 12px;
  display: flex; align-items: center; gap: 10px;
}
.or::before, .or::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

.join-form { display: flex; gap: 8px; }
.code-input {
  font-family: var(--mono);
  font-size: 19px;
  letter-spacing: .22em;
  text-align: center;
  text-transform: uppercase;
}
.code-input::placeholder { letter-spacing: .22em; color: var(--ink-faint); }

.how {
  list-style: none;
  margin: 34px 0 0;
  padding: 0;
  display: grid;
  gap: 14px;
  text-align: left;
  font-size: 14px;
  color: var(--ink-soft);
}
.how li { display: flex; gap: 12px; align-items: flex-start; }
.how span {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brass-soft);
  color: var(--brass);
  font: 500 12px/22px var(--mono);
  text-align: center;
}

/* ---------- name gate ---------- */

.gate {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 20;
}
.gate-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 26px;
  width: 100%; max-width: 380px;
  display: grid; gap: 12px;
}
.gate-card h2 { margin: 0; font: 400 27px/1.2 var(--serif); }
.gate-card p { margin: 0; font-size: 14px; }

/* ---------- room shell ---------- */

.room { height: 100%; display: flex; flex-direction: column; }

.room-head {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  flex-wrap: wrap;
}
.room-id { display: flex; align-items: baseline; gap: 9px; }
.room-label {
  font: italic 400 15px/1 var(--serif);
  color: var(--ink-faint);
}
.room-code {
  /* A code people read aloud: plain lining figures, not old-style ones. */
  font: 500 21px/1 var(--mono);
  letter-spacing: .16em;
}

.people { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.person {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 10px 3px 5px;
  font-size: 14px;
}
.person.is-speaking { border-color: var(--brass); background: var(--brass-soft); }
.person.is-you { font-weight: 500; }

/* Every seat carries a shield: a heater shield in the member's own colour. */
.pip {
  width: 22px; height: 25px;
  clip-path: polygon(0 0, 100% 0, 100% 56%, 50% 100%, 0 56%);
  display: grid; place-items: center; padding-bottom: 4px;
  font: 400 12px/1 var(--serif);
  color: #fff;
}
.person-turns { color: var(--ink-faint); font-size: 11px; font-family: var(--mono); }
.crown { font-size: 11px; color: var(--brass); }

.room-tools { display: flex; gap: 4px; align-items: center; }
.badge {
  font: 500 11px/1 var(--mono);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 5px 8px; border-radius: 6px;
  background: var(--brass-soft); color: var(--brass);
}

.room-body { flex: 1; display: flex; min-height: 0; }

/* ---------- thread ---------- */

.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 18px;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--ink-faint);
  max-width: 340px;
}
.empty h3 { font: 400 25px/1.2 var(--serif); color: var(--ink-soft); margin: 0 0 6px; }
.empty p { margin: 0; font-size: 14px; }

.turn { display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.turn-main { min-width: 0; }
.turn-head {
  display: flex; align-items: baseline; gap: 9px;
  margin-bottom: 4px; flex-wrap: wrap;
}
.turn-who { font-weight: 600; font-size: 14px; }
.turn-when { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }

.turn-ask {
  background: var(--sunk);
  border-radius: var(--radius);
  padding: 9px 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.turn-state {
  font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  font-family: var(--mono);
}
.state-waiting { background: var(--sunk); color: var(--ink-faint); }
.state-running { background: var(--brass-soft); color: var(--brass); }
.state-done { background: var(--moss-soft); color: var(--moss); }
.state-failed, .state-cancelled { background: var(--clay-soft); color: var(--clay); }

.turn-output {
  margin-top: 8px;
  border-left: 2px solid var(--line-firm);
  padding-left: 13px;
  display: grid; gap: 6px;
}
.say { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 2px 0; }
.act {
  font-family: var(--mono); font-size: 12px;
  color: var(--ink-soft);
  display: flex; gap: 7px; align-items: baseline;
}
.act b { color: var(--brass); font-weight: 500; }
.act-path { overflow-wrap: anywhere; }

.turn-commit {
  margin-top: 7px; font-family: var(--mono); font-size: 11px;
  color: var(--ink-faint);
}
.turn-error {
  margin-top: 7px;
  background: var(--clay-soft); color: var(--clay);
  border-radius: 8px; padding: 8px 11px; font-size: 13px;
}

.turn-actions { margin-top: 7px; display: flex; gap: 6px; }

/* ---------- composer ---------- */

.composer {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 12px 24px 14px;
}
.status-line {
  margin: 0 0 8px; min-height: 18px;
  font-size: 13px; color: var(--ink-soft);
  display: flex; align-items: center; gap: 8px;
}
.ask-form { display: flex; gap: 9px; align-items: flex-end; }
.ask-form .btn { white-space: nowrap; }
.ask-input { resize: none; max-height: 190px; overflow-y: auto; }
.hint { margin: 7px 0 0; font-size: 11px; color: var(--ink-faint); }

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--brass);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none; opacity: .8; }
  .btn { transition: none; }
}

/* ---------- rail ---------- */

.rail {
  width: 310px; flex: none;
  border-left: 1px solid var(--line);
  background: var(--card);
  display: flex; flex-direction: column;
  min-height: 0;
}
.rail-tabs { display: flex; border-bottom: 1px solid var(--line); }
.rail-tab {
  flex: 1; background: none; border: 0;
  border-bottom: 2px solid transparent;
  padding: 11px 8px;
  font: 500 13px/1 var(--sans);
  color: var(--ink-faint); cursor: pointer;
}
.rail-tab.is-on { color: var(--ink); border-bottom-color: var(--brass); }
.rail-tab:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }

.rail-panel { flex: 1; overflow-y: auto; padding: 14px; min-height: 0; }

.queue { display: grid; gap: 9px; }
.queue-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--paper);
}
.queue-item.is-running { border-color: var(--brass); background: var(--brass-soft); }
.queue-who { font-size: 12px; font-weight: 600; margin-bottom: 3px; }
.queue-ask {
  font-size: 13px; color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.queue-pos {
  font-family: var(--mono); font-size: 11px; color: var(--ink-faint);
}
.rail-empty { color: var(--ink-faint); font-size: 13px; text-align: center; padding: 22px 0; }

.files { display: grid; gap: 1px; }
.file-row {
  display: flex; justify-content: space-between; gap: 8px;
  background: none; border: 0; width: 100%;
  text-align: left; cursor: pointer;
  font: 400 13px/1.4 var(--mono);
  color: var(--ink);
  padding: 6px 8px; border-radius: 6px;
  overflow-wrap: anywhere;
}
.file-row:hover { background: var(--sunk); }
.file-row:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }

.rail-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); margin: 14px 0 7px;
}
.rail-head:first-child { margin-top: 0; }

.log-row { font-size: 12px; padding: 5px 8px; border-radius: 6px; }
.log-row:hover { background: var(--sunk); }
.log-sha { font-family: var(--mono); color: var(--brass); font-size: 11px; }
.log-who { color: var(--ink-faint); font-size: 11px; }

.file-view {
  position: absolute; inset: 0;
  background: var(--card);
  display: flex; flex-direction: column;
}
.rail-panel { position: relative; }
.file-view-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.file-body {
  flex: 1; margin: 0; padding: 12px;
  overflow: auto;
  font-size: 12px; line-height: 1.6;
  white-space: pre;
  tab-size: 2;
}

.room-error { margin: 0; border-radius: 0; }

/* ---------- narrow ---------- */

.mob-tabs { display: none; }

@media (max-width: 860px) {
  .room { height: 100dvh; }
  .room-head { flex-wrap: wrap; gap: 8px 12px; padding: 10px 14px; }
  .room-tools {
    order: 3; width: 100%;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .room-tools::-webkit-scrollbar { display: none; }
  .room-tools .btn { white-space: nowrap; font-size: 13px; padding: 6px 10px; }
  .people { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }

  .room-body { flex-direction: column; }
  .room[data-view="table"] .rail { display: none; }
  .room:not([data-view="table"]) .thread { display: none; }
  .rail { width: auto; border-left: 0; flex: 1; max-height: none; min-height: 0; }
  .rail-tabs { display: none; }

  .transcript { padding: 14px; }
  .composer { padding: 8px 12px 10px; }
  .composer .hint { display: none; }
  .ask-tools .btn { white-space: nowrap; }
  .ask-tools .pick { max-width: 140px; }
  .ask-form { flex-wrap: wrap; }
  .ask-input { flex: 1 1 100%; font-size: 16px; } /* 16px stops iOS zooming on focus */
  .ask-form .btn { flex: 1; min-height: 44px; }

  .mob-tabs {
    display: flex; border-top: 1px solid var(--line); background: var(--card);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mob-tab {
    flex: 1; min-height: 52px; border: 0; background: none;
    font: 500 14px/1 var(--sans); color: var(--ink-soft);
    border-top: 2px solid transparent; cursor: pointer;
  }
  .mob-tab.is-on { color: var(--ink); border-top-color: var(--brass); }
  .mob-count {
    display: inline-block; min-width: 18px; padding: 2px 5px; margin-left: 4px;
    border-radius: 999px; background: var(--brass); color: var(--card); font-size: 11px;
  }
  .wordmark { font-size: 52px; }
}

.gate-actions { display: flex; gap: 8px; justify-content: flex-end; }
.gate-card .hint { margin: 0; }
.gate-card .hint a { color: var(--ink-soft); }
.link-btn {
  background: none; border: 0; padding: 0; font: inherit; color: inherit;
  text-decoration: underline; cursor: pointer;
}
.link-btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.notice-good { background: var(--moss-soft); color: var(--moss); }
.notice-working { background: var(--sunk); color: var(--ink-soft); }
.remote-link {
  font-family: var(--mono); font-size: 11px;
  color: var(--ink-faint); max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.queue-who { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.queue-bump { margin-left: auto; font-weight: 400; }

/* ---------- choosing where your turns run ---------- */

.ask-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pick {
  font: 500 13px/1 var(--sans);
  color: var(--ink); background: var(--card);
  border: 1px solid var(--line-firm); border-radius: 7px;
  padding: 7px 9px; cursor: pointer; max-width: 190px;
}
.pick.wide { max-width: none; width: 100%; padding: 10px 12px; font-size: 15px; }
.pick:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* Whose account a turn ran on. Quiet: it matters when you look, not before. */
.turn-agent {
  font-family: var(--mono); font-size: 11px;
  color: var(--ink-faint);
}
.own-key {
  font-size: 10px; color: var(--moss);
  border: 1px solid var(--moss); border-radius: 999px;
  padding: 1px 5px; line-height: 1.4;
}
.gate-card .pick { margin: 0; }

/* Read by AI agents that fetch the page as text; never shown to people. */
.agent-hint { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* The running turn's "is typing": three dots, what it is doing, how long. */
.typing { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.typing .elapsed { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--brass); animation: rt-dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes rt-dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .7; } }

/* Pictures: waiting to send, and shared in notes. */
.attach { cursor: pointer; }
.attached { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { position: relative; }
.chip img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line-firm); display: block; }
.chip button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: var(--ink); color: var(--card); font-size: 13px; line-height: 1; cursor: pointer;
}
.note-pics { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.note-pics img { max-width: min(280px, 100%); max-height: 220px; border-radius: 10px; border: 1px solid var(--line); display: block; }
.pic-gone { font-size: 12px; color: var(--ink-faint); font-style: italic; }

/* ---------- the hall ---------- */
/* Headings and the room's names are set in a face cut from early English type. */
h1, h2, h3, .gate-card h2 { font-family: var(--serif); font-weight: 400; }
.room-head { border-bottom: 1px solid var(--brass); box-shadow: inset 0 -3px 0 -2px var(--line); }
.turn-who { font-family: var(--serif); font-size: 16px; }
