:root {
  color-scheme: light;
  --paper: #f8f8f5;
  --surface: #fff;
  --ink: #182721;
  --muted: #56635c;
  --accent: #18564a;
  --accent-dark: #124237;
  --line: #d7dfd8;
  --tint: #e9f1eb;
  --focus: #1a6d57;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; width: 100%; background: var(--paper); color: var(--ink); }
body { overflow: hidden; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, select { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .53; }
a { color: var(--accent); text-underline-offset: .18em; }
button:focus-visible, select:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
textarea:focus-visible { outline: none; }
svg { display: block; width: 21px; height: 21px; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  height: var(--viewport-height, 100dvh);
  overflow: hidden;
}

.topbar {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.topbar-inner {
  margin: 0 auto;
  min-height: 65px;
  max-width: 760px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand, .header-actions { display: flex; align-items: center; gap: 9px; }
.brand img { border-radius: 11px; }
h1 { margin: 0; font-size: 1.26rem; font-weight: 700; letter-spacing: -.025em; }
.connection {
  min-height: 44px;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 24px;
  padding: 0 9px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #727a74; }
.connection[data-state="online"] .status-dot, .connection[data-state="paired"] .status-dot { background: #2b7656; }
.connection[data-state="offline"] .status-dot, .connection[data-state="disconnected"] .status-dot { background: #a44034; }
.connection[data-state="offline"], .connection[data-state="disconnected"] { color: #8e352d; }
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
}
.connection:hover, .icon-button:hover { background: var(--tint); }

.workspace { min-height: 0; }
.pair, .offline-panel { height: 100%; overflow: auto; padding: clamp(24px, 11vh, 95px) 18px 28px; }
.pair-card {
  max-width: 376px;
  padding: 25px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
}
.panel-icon { display: block; border-radius: 16px; margin-bottom: 18px; }
h2 { margin: 0; font-size: clamp(1.51rem, 7vw, 2rem); font-weight: 665; line-height: 1.13; letter-spacing: -.032em; }
.pair-card > p, .welcome > p { margin: 10px 0 0; color: var(--muted); line-height: 1.52; }
.pair-card label { display: block; margin: 22px 0 7px; font-weight: 600; font-size: .88rem; }
.pair-card input {
  width: 100%;
  min-height: 49px;
  padding: 9px 13px;
  border: 1px solid #9eada4;
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  letter-spacing: .1em;
}
.primary {
  width: 100%;
  min-height: 47px;
  margin-top: 12px;
  padding: 8px 15px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 11px;
  font-weight: 650;
}
.primary:hover, .send:hover { background: var(--accent-dark); }
.pair-card .notice { color: #8e352d; margin-top: 11px; }
.notice:empty, .chat-notice:empty { display: none; }
.small { font-size: .89rem; }

.chat { height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.conversation {
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.thread { max-width: 760px; margin: 0 auto; padding: 23px 18px 17px; }
.welcome { margin: clamp(31px, 12vh, 110px) 6px 0; }
.welcome .panel-icon { margin-bottom: 17px; }
.welcome > p { font-size: .96rem; }
.messages { display: grid; gap: 20px; }
.message { min-width: 0; font-size: 1rem; line-height: 1.56; overflow-wrap: anywhere; }
.message p { margin: 0; white-space: pre-wrap; }
.message-who { display: block; margin-bottom: 5px; font-size: .79rem; font-weight: 650; color: var(--muted); }
.message-user {
  justify-self: end;
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 17px 17px 4px 17px;
  background: var(--tint);
}
.message-warden { padding: 0 0 0 4px; }
.message-warden .message-who { color: var(--accent-dark); }
.chat-notice { margin: 18px 0 0 4px; color: var(--muted); font-size: .88rem; line-height: 1.43; }
.chat-notice[data-error="true"] { color: #8e352d; }
.source-list { margin-top: 10px; color: var(--muted); font-size: .88rem; }
.source-list summary, .file .preview summary { padding: 8px 0; cursor: pointer; color: var(--accent-dark); }
.source-list ul { margin: 0 0 0 16px; padding-left: 4px; }
.source-list li { margin-bottom: 5px; }

.file { margin-top: 13px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.file-name { display: block; margin-bottom: 7px; color: var(--ink); font-size: .94rem; }
.file-actions { display: flex; flex-wrap: wrap; gap: 6px 9px; align-items: center; }
.file-actions a, .file-actions button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: .86rem;
  line-height: 1.25;
  font-weight: 640;
  color: var(--accent-dark);
  background: var(--tint);
  border: 1px solid var(--line);
  border-radius: 9px;
  text-decoration: none;
}
.file-actions a:hover { text-decoration: underline; }
.preview { margin-top: 5px; }
.preview iframe { width: 100%; height: clamp(220px, 52vh, 410px); display: block; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.file-status { color: var(--muted); font-size: .84rem; margin-top: 5px; }
.file-status:empty { display: none; }

.composer-area {
  background: var(--paper);
  padding: 0 max(12px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.composer {
  max-width: 726px;
  margin: 0 auto;
  border: 1px solid #aebdb3;
  border-radius: 19px;
  background: var(--surface);
  padding: 8px 8px 6px;
  box-shadow: 0 3px 14px rgba(24,39,33,.06);
}
.composer:focus-within { border-color: #71978a; }
.composer textarea {
  display: block;
  min-height: 41px;
  max-height: 150px;
  width: 100%;
  resize: none;
  overflow-y: auto;
  border: 0;
  padding: 8px 8px 4px;
  color: var(--ink);
  background: transparent;
  font-size: 1rem;
  line-height: 1.35;
}
.composer textarea::placeholder { color: var(--muted); opacity: 1; }
.composer-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mode-control {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding-left: 8px;
  gap: 5px;
  color: var(--muted);
}
.mode-control svg { width: 17px; height: 17px; }
.mode-control select {
  min-height: 44px;
  min-width: 108px;
  font-size: 1rem;
  border: 0;
  padding: 3px 4px;
  color: var(--accent-dark);
  background: var(--surface);
}
.send {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}
.send:disabled { background: #e3ebe5; color: #617369; opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.no-script { padding: 0 18px; }

@media (min-width: 720px) {
  .topbar-inner { padding: 8px 17px; }
  .thread { padding-right: 17px; padding-left: 17px; }
  .welcome { margin-left: 6px; }
}
@media (max-width: 350px) {
  .topbar-inner { padding-left: 11px; padding-right: 11px; }
  .connection { padding-left: 5px; padding-right: 5px; }
  .brand, .header-actions { gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
