:root {
  color-scheme: light dark;
  --canvas: #eef2f7;
  --surface: #fff;
  --surface-alt: #f4f7fb;
  --ink: #162237;
  --muted: #4e5c73;
  --line: #c4cedd;
  --accent: #204eb3;
  --accent-ink: #fff;
  --focus: #2059d1;
  --online: #056443;
  --offline: #9b361d;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #101722;
    --surface: #192334;
    --surface-alt: #202e42;
    --ink: #eef3fc;
    --muted: #b3c1d7;
    --line: #50617b;
    --accent: #a6c4ff;
    --accent-ink: #112046;
    --focus: #bfd4ff;
    --online: #86dfb9;
    --offline: #ffb39e;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.shell {
  max-width: 48rem;
  margin-inline: auto;
  padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
}

.masthead {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-block-end: 1rem;
}

.mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: .8rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.35rem;
  font-weight: 800;
}

.brand {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .13em;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }

#session, .panel, #verification-box, #approvals, #history, form {
  display: grid;
  gap: .75rem;
  min-width: 0;
}

.panel {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: .9rem;
  background: var(--surface);
}

#verification-box {
  padding: .75rem;
  border-radius: .65rem;
  background: var(--surface-alt);
}

#verification {
  color: var(--accent);
  font-size: clamp(1.5rem, 7vw, 2.5rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: .08em;
  unicode-bidi: isolate;
}

.session-state, .approval-actions, .composer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem .75rem;
}

.badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: .6rem;
  padding: .2rem .55rem;
  background: var(--surface-alt);
  font-size: .85rem;
  font-weight: 650;
}

[data-state="online"] { color: var(--online); }
[data-state="offline"] { color: var(--offline); }
.muted { color: var(--muted); font-size: .9rem; }

.transcript {
  max-height: min(58vh, 34rem);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-inline-end: .35rem;
  border-radius: .5rem;
}

.entry, .approval {
  display: grid;
  gap: .3rem;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--surface-alt);
  padding: .65rem .75rem;
}

.entry.user-entry { border-inline-start: .25rem solid var(--accent); }
.stream { margin-block-start: .75rem; }
#history:empty + .stream { margin-block-start: 0; }
.approvals { border-inline-start: .25rem solid var(--offline); }
.approval-actions { margin-block-start: .25rem; }
.approval .muted:empty { display: none; }
.text { white-space: pre-wrap; unicode-bidi: plaintext; }

.tasks, .deliveries {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tasks li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
  padding-block: .35rem;
}

.tasks li + li { border-block-start: 1px solid var(--line); }
.tasks .badge { flex: none; }
.deliveries { color: var(--muted); font-size: .9rem; }
.deliveries li + li { margin-block-start: .2rem; }

label { font-weight: 650; }
textarea, button { font: inherit; }

textarea {
  display: block;
  width: 100%;
  min-height: 5.5rem;
  max-height: 50vh;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: .65rem;
  padding: .65rem;
  background: var(--surface-alt);
  color: var(--ink);
}

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: .65rem;
  padding: .45rem .9rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
}

button.secondary, #phone-sign-in {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

#phone-sign-in, #online-devices button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .55rem .95rem;
}

#phone-sign-in {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  font-weight: 700;
  text-decoration: none;
}

button:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
button:focus-visible, textarea:focus-visible, .transcript:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.composer-actions { justify-content: space-between; }
#check-pair { justify-self: start; }

.history-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.history-results { display: grid; gap: .65rem; }
.history-group ul { display: grid; gap: .4rem; margin: .4rem 0 0; padding: 0; list-style: none; }
.history-group button { width: 100%; text-align: start; overflow-wrap: anywhere; }
#history-name { margin-block-end: .5rem; }
#history-status:empty { display: none; }
#history-more { justify-self: start; }

@media (max-width: 30rem) {
  .shell { padding-inline: .75rem; }
  .panel { padding: .8rem; }
  .approval-actions button { flex: 1 1 auto; }
  .composer-actions button { width: 100%; }
}
