:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Segoe UI", sans-serif;
  color: #202725;
  background: #f6f8f7;
  --bg: #f6f8f7;
  --surface: #fff;
  --surface-2: #eef3f0;
  --fg: #202725;
  --muted: #68736f;
  --border: #dce3df;
  --strong-border: #bfc9c4;
  --accent: #15834f;
  --accent-dark: #0c6139;
  --accent-soft: #e1f3e8;
  --danger: #d14b3f;
  --warning: #b77a18;
  --mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    linear-gradient(#dce3df55 1px, transparent 1px),
    linear-gradient(90deg, #dce3df55 1px, transparent 1px);
  background-size: 32px 32px;
}
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #15834f3d;
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 1180px);
  height: 100vh;
  height: 100dvh;
  min-height: 100dvh;
  margin: auto;
  padding: max(18px, env(safe-area-inset-top)) 20px max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template: auto minmax(0, 1fr) / 320px minmax(0, 1fr);
  gap: 16px;
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: #fffffff2;
}
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 39px; height: 39px; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--fg); border-radius: 9px;
}
.brand-mark i { display: block; width: 5px; height: 12px; border-radius: 4px; background: #fff; }
.brand b, .brand small { display: block; }
.brand b { font: 700 13px/1.2 var(--mono); letter-spacing: .08em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 11px; }

.connection { display: flex; align-items: center; gap: 12px; }
.device-identity {
  min-height: 31px; padding: 5px 9px; border: 1px solid var(--border); background: #fbfcfb;
  display: grid; align-content: center; gap: 1px; text-align: left;
}
.device-identity span { color: var(--muted); font: 700 8px var(--mono); letter-spacing: .1em; }
.device-identity code { color: var(--fg); font: 700 10px var(--mono); user-select: all; }
.device-identity:hover { border-color: var(--accent); background: var(--accent-soft); }
#status {
  margin: 0; padding: 7px 10px 7px 27px; position: relative;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); font: 600 11px/1 var(--mono); text-transform: uppercase;
}
#status::before {
  content: ""; position: absolute; left: 10px; top: 50%; width: 7px; height: 7px;
  border-radius: 50%; transform: translateY(-50%); background: var(--warning);
  box-shadow: 0 0 0 3px #b77a1820;
}
#status[data-state="ready"] { color: var(--accent-dark); background: var(--accent-soft); border-color: #b7dcc6; }
#status[data-state="ready"]::before { background: var(--accent); box-shadow: 0 0 0 3px #15834f20; }
#status[data-state="error"] { color: #9b2f27; background: #fae8e6; border-color: #efc2bd; }
#status[data-state="error"]::before { background: var(--danger); }
.protocol { display: flex; align-items: center; gap: 7px; color: var(--muted); font: 600 10px var(--mono); }
.protocol select { border: 1px solid var(--strong-border); background: var(--surface); padding: 7px 28px 7px 9px; color: var(--fg); }

.console-panel, .dialogue-panel { border: 1px solid var(--border); background: var(--surface); min-height: 0; }
.console-panel { padding: 28px; display: flex; flex-direction: column; overflow: hidden; }
.eyebrow { color: var(--accent); font: 700 10px/1 var(--mono); letter-spacing: .15em; }
.console-heading h1 { margin: 14px 0 13px; font-size: clamp(28px, 4vw, 42px); line-height: 1.08; letter-spacing: -.04em; }
.console-heading p { margin: 0; max-width: 230px; color: var(--muted); font-size: 13px; line-height: 1.65; }

.signal { width: 190px; height: 190px; margin: auto; position: relative; display: grid; place-items: center; }
.signal::before, .signal::after, .signal > span {
  content: ""; position: absolute; inset: 50%; border: 1px solid #a6b5ae; border-radius: 50%;
  transform: translate(-50%, -50%);
}
.signal::before { width: 178px; height: 178px; border-style: dashed; animation: rotate 18s linear infinite; }
.signal::after { width: 138px; height: 138px; }
.signal > span:nth-of-type(1) { width: 102px; height: 102px; border-color: #15834f50; }
.signal > span:nth-of-type(2) { width: 12px; height: 12px; inset: 20px auto auto 88px; background: var(--accent); border: 4px solid #dff3e7; }
.signal > span:nth-of-type(3) { width: 7px; height: 7px; inset: auto 19px 54px auto; background: var(--fg); }
.signal-core {
  z-index: 1; width: 66px; height: 66px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: 18px; background: var(--fg); box-shadow: 0 9px 24px #20272524;
}
.signal-core i { width: 6px; height: 17px; border-radius: 5px; background: white; }
.capabilities { margin: 0; border-top: 1px solid var(--border); }
.capabilities div { padding: 10px 0; display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); }
.capabilities dt { font: 700 10px var(--mono); color: var(--muted); }
.capabilities dd { margin: 0; font-size: 11px; font-weight: 650; }

.dialogue-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.section-title { padding: 20px 22px 17px; display: flex; align-items: end; justify-content: space-between; border-bottom: 1px solid var(--border); }
.section-title h2, .dialog-header h2 { margin: 7px 0 0; font-size: 20px; letter-spacing: -.02em; }
.vision-button {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--strong-border);
  background: var(--surface); color: var(--fg); padding: 8px 11px; font-size: 12px; font-weight: 650;
}
.vision-button:hover { background: var(--surface-2); border-color: #8e9d96; }
.vision-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; }

#transcript {
  min-height: 0; padding: 12px 22px; overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain; scrollbar-gutter: stable;
  scrollbar-color: var(--strong-border) transparent;
}
.empty { height: 100%; min-height: 170px; display: flex; align-items: center; justify-content: center; gap: 16px; color: var(--muted); }
.empty-index { font: 500 34px var(--mono); color: #c9d1cd; }
.empty strong { display: block; color: var(--fg); font-size: 13px; }
.empty p { margin: 5px 0 0; font-size: 12px; }
article { padding: 13px 0; display: grid; grid-template-columns: 58px 1fr; border-bottom: 1px solid var(--border); }
article strong { color: var(--accent-dark); font: 700 10px/1.55 var(--mono); text-transform: uppercase; }
article p { margin: 0; max-width: 620px; font-size: 14px; line-height: 1.6; }

.composer { border-top: 1px solid var(--border); background: #fbfcfb; }
.voice-row { padding: 14px 22px; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--border); }
#talk {
  min-width: 190px; min-height: 58px; border: 0; background: var(--fg); color: #fff;
  display: grid; grid-template: auto auto / 34px 1fr; align-items: center; text-align: left; padding: 10px 18px;
  touch-action: none; transition: transform .15s ease, background .15s ease;
}
#talk b {
  grid-row: 1 / 3; width: 18px; height: 27px; border: 2px solid currentColor; border-radius: 10px; position: relative;
}
#talk b::after { content: ""; position: absolute; left: 50%; bottom: -7px; width: 10px; height: 5px; transform: translateX(-50%); border-bottom: 2px solid currentColor; }
#talk span { font-size: 14px; font-weight: 700; }
#talk small { color: #aeb7b3; font: 600 9px var(--mono); letter-spacing: .08em; }
#talk:disabled { opacity: .45; cursor: not-allowed; }
#talk.active { background: var(--danger); transform: translateY(1px); }
#talk.listening { background: var(--accent-dark); }
#talk.speaking { background: var(--danger); }
#talk.listening b { animation: live-pulse 1.6s ease-out infinite; }
.voice-row > p { margin: 0; color: var(--fg); font: 600 11px/1.5 var(--mono); }
.voice-row > p i { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--accent); }
.voice-row > p span { color: var(--muted); font-size: 9px; }
#text-form { padding: 12px 22px 17px; }
#text-form > label { display: block; margin-bottom: 7px; color: var(--muted); font: 700 9px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
#text-form > div { display: flex; border: 1px solid var(--strong-border); background: var(--surface); }
#text-form input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; padding: 12px 13px; font-size: 16px; color: var(--fg); }
#text-form button {
  border: 0; border-left: 1px solid var(--strong-border); background: var(--accent); color: #fff;
  min-width: 88px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 700;
}
#text-form button:hover { background: var(--accent-dark); }
#text-form button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }

dialog {
  width: min(92vw, 520px); padding: 0; border: 1px solid var(--strong-border); border-radius: 0;
  background: var(--surface); color: var(--fg); box-shadow: 0 24px 80px #20272530;
}
dialog::backdrop { background: #20272599; }
#vision-panel:not([open]) { position: fixed; inset: 50% auto auto 50%; transform: translate(-50%, -50%); display: block; }
#vision-panel[hidden] { display: none; }
#vision-form, #device-form { padding: 22px; display: grid; gap: 12px; }
#vision-form video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #101513; border: 1px solid var(--border); }
#vision-form label, #device-form label { color: var(--muted); font: 700 10px var(--mono); }
#vision-form input, #device-form input { width: 100%; padding: 11px 12px; border: 1px solid var(--strong-border); border-radius: 0; color: var(--fg); }
#vision-form > button { min-height: 44px; border: 0; background: var(--accent); color: white; font-weight: 700; }
#device-form > p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
#device-error { min-height: 16px; color: var(--danger); font-size: 11px; }
.device-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.device-actions button { min-height: 40px; padding: 0 13px; border: 1px solid var(--strong-border); background: var(--surface); color: var(--fg); font-weight: 650; }
.device-actions button[type="submit"] { border-color: var(--accent); background: var(--accent); color: white; }
#device-reset { margin-right: auto; }

@keyframes rotate { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 #ffffff55; }
  50% { box-shadow: 0 0 0 7px #ffffff00; }
}
@media (max-width: 760px) {
  .app-shell { padding-inline: 12px; grid-template: auto auto minmax(0, 1fr) / 1fr; gap: 10px; }
  .topbar { grid-column: 1; padding: 8px 10px; }
  .brand small, .protocol > span { display: none; }
  .connection { gap: 7px; }
  .device-identity { padding-inline: 7px; }
  .device-identity span { display: none; }
  .device-identity code { font-size: 9px; }
  #status { padding-inline-end: 8px; max-width: 128px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .protocol select { max-width: 112px; }
  .console-panel { padding: 18px; min-height: 170px; display: grid; grid-template-columns: 1fr 130px; align-items: center; }
  .console-heading h1 { margin-block: 9px; font-size: 27px; }
  .console-heading p { font-size: 11px; }
  .signal { width: 126px; height: 126px; }
  .signal::before { width: 120px; height: 120px; }
  .signal::after { width: 94px; height: 94px; }
  .signal > span:nth-of-type(1) { width: 70px; height: 70px; }
  .signal > span:nth-of-type(2) { inset: 9px auto auto 58px; }
  .signal > span:nth-of-type(3) { inset: auto 9px 36px auto; }
  .signal-core { width: 50px; height: 50px; border-radius: 14px; }
  .capabilities { grid-column: 1 / -1; display: none; }
  .dialogue-panel { min-height: 0; }
  .section-title { padding: 15px 16px 12px; }
  #transcript { padding-inline: 16px; }
  .voice-row { padding: 11px 16px; }
  #talk { flex: 1; min-width: 0; }
  #text-form { padding: 10px 16px 14px; }
}
@media (max-width: 390px) {
  .topbar { flex-wrap: wrap; }
  .brand b { font-size: 11px; }
  .brand-mark { width: 35px; height: 35px; }
  .connection { width: 100%; display: grid; grid-template-columns: 1fr auto; }
  .device-identity { min-width: 0; }
  #status { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  .protocol { grid-column: 2; grid-row: 1; }
  .console-panel { grid-template-columns: 1fr 105px; min-height: 145px; }
  .signal { width: 102px; height: 102px; transform: scale(.82); }
  .console-heading h1 { font-size: 23px; }
  .voice-row > p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
