:root {
  --bg: #0b0f17;
  --bg-soft: #111826;
  --panel: #151d2c;
  --panel-2: #1b2436;
  --line: #26314a;
  --text: #e8edf7;
  --muted: #94a2bd;
  --accent: #60a5fa;
  --accent-ink: #0b1020;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fb;
    --bg-soft: #eef1f8;
    --panel: #ffffff;
    --panel-2: #f2f5fb;
    --line: #dde3ef;
    --text: #131a27;
    --muted: #5d6a83;
    --accent: #2563eb;
    --accent-ink: #ffffff;
    --shadow: 0 8px 24px rgba(18, 28, 50, .10);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute hides an element only via a user-agent rule, which
   ANY author `display` declaration outranks — specificity doesn't even come
   into it. Several components here set `display`, so without this line their
   `hidden` attribute is silently inert and they are permanently on screen.
   This is the one place `!important` is the correct tool: it has to beat every
   author rule in the file, including ones added later. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

h2 {
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- top bar ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; }

.brand-mark {
  width: 20px; height: 20px; border-radius: 6px;
  background: linear-gradient(140deg, var(--accent), #a78bfa);
}

.self { display: flex; align-items: center; gap: 10px; }

.self-name input {
  width: 10.5em;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-align: right;
}

.self-name input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
}

.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}

.status[data-state="online"] .dot { background: var(--good); }
.status[data-state="connecting"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status[data-state="offline"] .dot { background: var(--bad); }

@keyframes pulse { 50% { opacity: .3; } }

/* ---- layout ---- */

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: grid;
  gap: 26px;
}

.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* ---- peers ---- */

.peer-grid {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.peer-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, transform .1s, background .15s;
}

.peer-tile:hover { border-color: var(--accent); }
.peer-tile:active { transform: scale(.985); }
.peer-tile.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

.peer-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
}

.peer-name { font-weight: 600; word-break: break-word; }

.peer-state { font-size: 12px; color: var(--muted); min-height: 1.2em; }
.peer-state[data-s="connected"] { color: var(--good); }
.peer-state[data-s="failed"] { color: var(--bad); }

.peer-actions { display: flex; gap: 6px; }

.empty {
  grid-column: 1 / -1;
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---- buttons & inputs ---- */

.btn {
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.subtle { background: transparent; color: var(--muted); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

input[type="text"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

input[type="text"]:focus-visible,
select:focus-visible,
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- compose ---- */

.compose-row { display: grid; gap: 10px; }
.compose-row textarea { width: 100%; resize: vertical; min-height: 56px; }
.compose-actions { display: flex; gap: 8px; }
.compose-actions select { flex: 1; min-width: 0; }

/* ---- transfers ---- */

.transfer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.transfer {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}

.transfer-head {
  display: flex; align-items: baseline; gap: 8px;
  justify-content: space-between;
  font-size: 14px;
}

.transfer-name { font-weight: 600; overflow-wrap: anywhere; }
.transfer-meta { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.bar { height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .18s linear; }

.transfer[data-state="done"] .bar > i { background: var(--good); }
.transfer[data-state="failed"] .bar > i, .transfer[data-state="rejected"] .bar > i { background: var(--bad); }

.transfer-body {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 8em;
  overflow: auto;
}

.transfer-links { display: flex; flex-wrap: wrap; gap: 8px; }
.transfer-links a, .transfer-links button {
  font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; font-family: inherit;
}

/* ---- pairing ---- */

.pair-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.pair-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.pair-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.pair-card .row { display: flex; gap: 8px; flex-wrap: wrap; }
.pair-card .row input { flex: 1; min-width: 6em; text-transform: uppercase; letter-spacing: .12em; }

.code {
  font: 600 26px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .16em;
  overflow-wrap: anywhere;
}

.qr-card { justify-items: center; }
.qr-card img { background: #fff; border-radius: 10px; padding: 8px; width: 180px; height: 180px; }
.qr-url { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; text-align: center; }

.fineprint { color: var(--muted); font-size: 12px; line-height: 1.6; border-top: 1px solid var(--line); padding-top: 16px; }
.fineprint p { margin: 0; }

/* Shown only when the page is served without HTTPS, where WebRTC cannot run. */
.insecure {
  margin: 0;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bad) 15%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line));
  color: var(--bad);
  font-size: 13px;
}

/* ---- drop veil ---- */

.drop-veil {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(3px);
  pointer-events: none;
  font-size: 18px; font-weight: 600;
}

/* ---- dialog ---- */

dialog.offer {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 18px;
  max-width: min(420px, 92vw);
  box-shadow: var(--shadow);
}

dialog.offer::backdrop { background: rgba(0, 0, 0, .5); }
dialog.offer h3 { margin: 0 0 4px; font-size: 17px; }
.offer-from { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.offer-files {
  list-style: none; margin: 0 0 12px; padding: 0;
  display: grid; gap: 4px;
  max-height: 40vh; overflow: auto;
  font-size: 13px;
}

.offer-files li { display: flex; justify-content: space-between; gap: 12px; }
.offer-files .sz { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.warn {
  margin: 0 0 12px; font-size: 12px; color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 10px; padding: 8px 10px;
}

dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }

/* ---- toasts ---- */

.toasts {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  display: grid; gap: 8px;
  width: min(440px, calc(100vw - 24px));
}

.toast {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  animation: rise .18s ease-out;
}

.toast[data-kind="error"] { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.toast[data-kind="good"] { border-color: color-mix(in srgb, var(--good) 50%, var(--line)); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
