/* Paper aesthetics on purpose: the test client should feel like the e-Paper
   device it stands in for (spec §7), not like a dashboard. */

:root {
  --ink: #14110f;
  --ink-soft: #6b6560;
  --paper: #f4f1ea;
  --card: #fffdf8;
  --rule: #d9d3c7;
  --good: #1f6f45;
  --bad: #a3312b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(360px, 1fr);
  gap: 2rem;
  padding: 2rem;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
  }
}

/* --- device ---------------------------------------------------------------- */

.device {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.card {
  width: min(100%, 340px);
  aspect-ratio: 1;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 12px 28px -18px rgba(0, 0, 0, 0.5);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 1rem 1.25rem;
}

.card-top,
.card-bottom {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.card-bottom {
  justify-content: center;
  font-family: var(--mono);
  border-top: 1px solid var(--rule);
  padding-top: 0.6rem;
}

.glyph {
  font-size: 1.1rem;
  color: var(--ink);
}

.agent {
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.link {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.link.up {
  color: var(--good);
}

.card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.state-glyph {
  font-size: 3.5rem;
  line-height: 1;
}

.state-name {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
}

/* A real e-Paper card does not animate (spec §7) — states swap, they do not
   fade. The only nod to liveness is a static invert while listening. */
.card[data-state='listening'] {
  background: var(--ink);
  color: var(--card);
  border-color: var(--ink);
}

.card[data-state='listening'] .agent,
.card[data-state='listening'] .glyph {
  color: var(--card);
}

.card[data-state='listening'] .state-name,
.card[data-state='listening'] .card-top,
.card[data-state='listening'] .card-bottom {
  color: #b9b2a7;
  border-color: #3a352f;
}

.card[data-state='error'] {
  border-color: var(--bad);
}

#latency.good {
  color: var(--good);
}
#latency.bad {
  color: var(--bad);
}

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

.ptt {
  width: min(100%, 340px);
  padding: 1.5rem;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: center;
  touch-action: none;
  user-select: none;
  transition: transform 60ms ease;
}

.ptt:active:not(:disabled) {
  background: var(--ink);
  color: var(--card);
  transform: translateY(1px);
}

.ptt:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.ptt-label {
  font-size: 1.05rem;
  font-weight: 600;
}

.ptt-hint {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.ptt:active:not(:disabled) .ptt-hint {
  color: #b9b2a7;
}

kbd {
  font-family: var(--mono);
  font-size: 0.72rem;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 0.3em;
}

.controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--ink);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- panel ----------------------------------------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 0;
}

.connect {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.connect label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.connect input {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card);
  color: var(--ink);
  min-width: 0;
}

.connect input:focus {
  outline: 2px solid var(--ink);
  outline-offset: -1px;
}

.log-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
}

.log-head h2 {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  font-weight: 600;
}

.log {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0 0;
  overflow-y: auto;
  flex: 1;
  min-height: 12rem;
  max-height: 60vh;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.65;
}

.entry {
  display: grid;
  grid-template-columns: 4.5rem 1rem 1fr;
  gap: 0.4rem;
  color: var(--ink);
  word-break: break-all;
}

.entry .t {
  color: var(--ink-soft);
}

.entry.out .d {
  color: var(--ink-soft);
}
.entry.in .d {
  color: var(--good);
}
.entry.err .m {
  color: var(--bad);
}
.entry.ok .m {
  color: var(--good);
}
