/* Zone on the web. The Android app's world (ui/theme/Theme.kt): ink on a cool off-white by day,
   off-white on near-black at night, one amber kept for what should catch the eye: your own
   entries, things still waiting, the relay notice. Built for one hand: actions sit low, targets
   are 44px or more. */

:root {
  color-scheme: light dark;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --raised: #ebecee;
  --ink: #121416;
  --muted: #474b50;
  --line: #ccd0d4;
  --line-strong: #73787d;
  --accent: #7a5200;
  --accent-soft: #f6e3bc;
  --accent-ink: #2a1b00;
  --primary: #121416;
  --on-primary: #ffffff;
  --error: #b3261e;
  --error-soft: #f9dedc;
  --select: #f6e3bc;
  --focus: #7a5200;

  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --r-s: 8px;
  --r-m: 12px;
  --r-l: 16px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --pad: max(1.25rem, env(safe-area-inset-left));
  --pad-r: max(1.25rem, env(safe-area-inset-right));
  --tabs-h: 4rem;
  --composer-h: 4.5rem;
  --toast-lift: var(--tabs-h);
}

body[data-view='zone'] {
  --toast-lift: calc(var(--tabs-h) + var(--composer-h));
}

body[data-view='setup'],
body[data-view='join'] {
  --toast-lift: 0px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e0f;
    --surface: #17191b;
    --raised: #1e2023;
    --ink: #e8e6e3;
    --muted: #a9acb0;
    --line: #33363a;
    --line-strong: #7d8186;
    --accent: #e2b04a;
    --accent-soft: #3a2c0c;
    --accent-ink: #f3d9a0;
    --primary: #e8e6e3;
    --on-primary: #0d0e0f;
    --error: #ffb4ab;
    --error-soft: #3b1512;
    --select: #3a2c0c;
    --focus: #e2b04a;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--line-strong) var(--bg);
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
  caret-color: var(--accent);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--select);
  color: var(--ink);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sprite {
  position: absolute;
}

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

svg {
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

code,
.id,
.keytext {
  font-family: var(--mono);
}

/* ─── layout ─────────────────────────────────────────────────────────────── */

.shell {
  max-width: 36rem;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) var(--pad-r) 0 var(--pad);
}

.view {
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 1.5rem);
}

body[data-view='zone'] .view {
  padding-bottom: calc(var(--tabs-h) + var(--composer-h) + env(safe-area-inset-bottom) + 1rem);
}

body[data-view='setup'] .view,
body[data-view='join'] .view {
  padding-bottom: calc(env(safe-area-inset-bottom) + 2rem);
}

.boot,
.noscript {
  margin: 30vh 0 0;
  color: var(--muted);
  text-align: center;
}

.bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 3.5rem;
  margin: 0 -0.5rem 0.25rem 0;
}

.bar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.bar .icon-btn:first-child {
  margin-left: -0.75rem;
}

.display {
  margin: 2.5rem 0 0.75rem;
  font-size: clamp(1.875rem, 7vw, 2.25rem);
  font-weight: 450;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.lede {
  margin: 0 0 1.75rem;
  max-width: 62ch;
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.55;
  text-wrap: pretty;
}

.fine,
.help {
  margin: 0.375rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.45;
  text-wrap: pretty;
}

.fine {
  margin-top: 2.5rem;
}

.install {
  display: grid;
  margin-top: 1.5rem;
}

.section {
  margin: 2.5rem 0 0.75rem;
  color: var(--muted);
  font-size: 1.0625rem;
  font-weight: 500;
}

.stack {
  display: grid;
  gap: 1.25rem;
}

.actions {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* ─── controls ───────────────────────────────────────────────────────────── */

.field {
  display: grid;
  gap: 0.375rem;
}

label,
summary {
  font-size: 0.9375rem;
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  min-height: 3.25rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-s);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  transition: border-color 160ms var(--ease-out);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}

input[readonly] {
  background: var(--raised);
  color: var(--muted);
}

#join-key {
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.875rem;
  word-break: break-all;
}

.more summary {
  width: fit-content;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  color: var(--muted);
  list-style: none;
}

.more summary::-webkit-details-marker {
  display: none;
}

.more summary::after {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 200ms var(--ease-out);
}

.more[open] summary::after {
  transform: translateY(1px) rotate(-135deg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.25rem;
  padding: 0 1.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: 500 0.9375rem/1 var(--sans);
  cursor: pointer;
  transition:
    background-color 160ms var(--ease-out),
    transform 160ms var(--ease-out);
}

@media (hover: hover) {
  .btn:hover {
    background: var(--raised);
  }
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

@media (hover: hover) {
  .btn.primary:hover {
    background: color-mix(in srgb, var(--primary) 86%, var(--bg));
  }
}

.btn.danger {
  width: 100%;
  border-color: var(--error);
  color: var(--error);
}

@media (hover: hover) {
  .btn.danger:hover {
    background: var(--error-soft);
  }
}

.btn.small {
  min-height: 2.75rem;
  padding: 0 1rem;
  font-size: 0.875rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: progress;
}

.btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

@media (hover: hover) {
  .icon-btn:hover {
    background: var(--raised);
  }
}

.icon-btn:disabled,
.icon-btn[aria-disabled='true'] {
  color: var(--muted);
}

h1:focus {
  outline: none;
}

.icon-btn.spin svg {
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error {
  margin: 0;
  padding: 0.75rem 1rem;
  border-radius: var(--r-s);
  background: var(--error-soft);
  color: var(--error);
  font-size: 0.9375rem;
}

/* ─── join: the camera ───────────────────────────────────────────────────── */

.scanner {
  position: relative;
  aspect-ratio: 1;
  margin-bottom: 1.25rem;
  overflow: hidden;
  border-radius: var(--r-l);
  background: #000;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  inset: 18%;
  border: 2px solid #e2b04a;
  border-radius: var(--r-m);
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.35);
}

.scan-hint {
  position: absolute;
  inset: auto 1rem 4.75rem;
  margin: 0;
  color: #fff;
  font-size: 0.9375rem;
  text-align: center;
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.6);
}

.btn.on-media {
  position: absolute;
  inset: auto 1rem 1rem;
  border-color: rgb(255 255 255 / 0.7);
  background: rgb(0 0 0 / 0.45);
  color: #fff;
}

/* ─── the zone ───────────────────────────────────────────────────────────── */

.syncline {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.syncline.bad {
  color: var(--accent);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
  padding: 0.875rem 0.5rem 0.875rem 1rem;
  border-radius: var(--r-m);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.notice p {
  flex: 1;
  margin: 0.125rem 0 0;
  font-size: 0.9375rem;
}

.notice .icon-btn {
  width: 2.75rem;
  height: 2.75rem;
  margin: -0.5rem 0 -0.5rem;
  color: inherit;
}

.empty {
  margin: 3rem 0;
  max-width: 34ch;
}

.empty h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 500;
}

.empty p {
  margin: 0;
  color: var(--muted);
  text-wrap: pretty;
}

.items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--line);
}

.meta {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  margin: 0 0 0.25rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.who {
  color: var(--ink);
  font-weight: 500;
  font-size: 0.875rem;
}

.mine .who {
  color: var(--accent);
}

.meta time {
  font-variant-numeric: tabular-nums;
}

.state {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  font-size: 0.75rem;
}

.state svg {
  width: 0.9375rem;
  height: 0.9375rem;
  stroke-width: 2;
  align-self: center;
}

.state.pending {
  color: var(--accent);
  font-weight: 500;
}

.text {
  margin: 0;
  font-size: 1.0625rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  width: 100%;
  min-height: 3.5rem;
  margin: 0.25rem 0 0;
  padding: 0.5rem 0.75rem 0.5rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms var(--ease-out);
}

@media (hover: hover) {
  .attachment:hover {
    border-color: var(--line-strong);
  }
}

.attachment > span {
  display: grid;
  min-width: 0;
}

.attachment .name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment .sub {
  color: var(--muted);
  font-size: 0.8125rem;
}

.composer {
  position: fixed;
  inset: auto 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)) 0;
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  max-width: 36rem;
  margin: 0 auto;
  padding: 0.625rem calc(var(--pad-r) - 0.5rem) 0.625rem calc(var(--pad) - 0.75rem);
  background: var(--raised);
}

@media (min-width: 36rem) {
  .composer {
    border-radius: var(--r-l) var(--r-l) 0 0;
  }
}

.composer textarea {
  flex: 1;
  min-height: 3rem;
  max-height: 10rem;
  padding: 0.6875rem 1rem;
  resize: none;
  line-height: 1.5;
}

.composer .icon-btn {
  flex: none;
}

.attach {
  position: relative;
}

.attach:focus-within {
  outline: 2px solid var(--focus);
}

.send svg {
  color: var(--accent);
}

/* ─── share ──────────────────────────────────────────────────────────────── */

.qr {
  display: grid;
  place-items: center;
  width: min(100%, 20rem);
  aspect-ratio: 1;
  margin: 0 auto 1.5rem;
  padding: 0;
  border-radius: var(--r-l);
  background: #fff;
  color: #121416;
  overflow: hidden;
}

.qr svg {
  width: 100%;
  height: 100%;
  stroke: none;
}

.keytext {
  margin: 1.5rem 0 0;
  padding: 0.75rem 1rem;
  border-radius: var(--r-s);
  background: var(--raised);
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
  word-break: break-all;
  user-select: all;
}

/* ─── members ────────────────────────────────────────────────────────────── */

.members {
  margin: 0;
  padding: 0;
  list-style: none;
}

.members li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--line);
}

.members li > div {
  flex: 1;
  min-width: 0;
}

.members p {
  margin: 0;
}

.members .name {
  font-weight: 500;
}

.members .sub {
  color: var(--muted);
  font-size: 0.875rem;
}

.members .id {
  color: var(--muted);
  font-size: 0.8125rem;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1.25rem;
  margin: 0 0 1.75rem;
  font-size: 0.875rem;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ─── tabs ───────────────────────────────────────────────────────────────── */

.tabs {
  position: fixed;
  inset: auto 0 0;
  /* Full-width bar, tabs held to the content column. */
  padding-inline: max(env(safe-area-inset-left), calc((100% - 36rem) / 2));
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.tabs a {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.125rem;
  height: var(--tabs-h);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
}

.tabs a svg {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  transition: color 160ms var(--ease-out);
}

.tabs a[aria-current='page'] {
  color: var(--ink);
}

.tabs a[aria-current='page'] svg {
  color: var(--accent);
  stroke-width: 2;
}

/* ─── dialog, toast ──────────────────────────────────────────────────────── */

.confirm {
  width: min(calc(100% - 2.5rem), 26rem);
  padding: 1.5rem;
  border: 0;
  border-radius: var(--r-l);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
}

.confirm::backdrop {
  background: rgb(0 0 0 / 0.4);
}

.confirm[open] {
  animation: rise 240ms var(--ease-out);
}

@keyframes rise {
  from {
    transform: translateY(0.75rem);
    opacity: 0.4;
  }
}

.confirm h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 500;
}

.confirm p {
  margin: 0 0 1.25rem;
  color: var(--muted);
}

.confirm .actions {
  grid-template-columns: 1fr 1fr;
}

.toast {
  position: fixed;
  inset: auto var(--pad-r) calc(var(--toast-lift) + env(safe-area-inset-bottom) + 0.75rem)
    var(--pad);
  z-index: 3;
  max-width: 34rem;
  margin: 0 auto;
  padding: 0.875rem 1.125rem;
  border-radius: var(--r-m);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.9375rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
  transition:
    opacity 200ms var(--ease-out),
    transform 260ms var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: none;
}

.toast:empty {
  display: none;
}

/* Reduced motion: things still fade and the sync glyph still turns (slowly), but nothing slides. */
@media (prefers-reduced-motion: reduce) {
  .toast,
  .btn:active {
    transform: none;
  }
  .confirm[open] {
    animation: none;
  }
  .icon-btn.spin svg {
    animation-duration: 2.4s;
  }
}
