:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #14181f;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #12a37f;
  --accent-text: #ffffff;
  --danger: #c8372d;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #171b22;
    --text: #eef1f5;
    --muted: #8b95a5;
    --line: #262c36;
    --accent: #4cc9a4;
    --accent-text: #06231b;
    --danger: #ff7b6e;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.dragging { outline: 3px dashed var(--accent); outline-offset: -10px; }

header, footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-left));
}

header { border-bottom: 1px solid var(--line); }

.brand {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.room {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

#room-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

footer {
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}

button, .button, input, textarea { font: inherit; color: inherit; }

button, .button {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  white-space: nowrap;
}

button:focus-visible, .button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.link { background: none; padding: 0; color: var(--accent); border-radius: 4px; }
.wide { width: 100%; }

.me {
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text);
  font-weight: 600;
  padding: 6px 14px;
}

.status { margin: 0 0 12px; text-align: center; color: var(--muted); font-size: 14px; }
.status.bad { color: var(--danger); }

.peers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.peer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.peer.drop { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.peer .send {
  width: 76px;
  height: 76px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  transition: transform 0.12s;
}

.peer .send:active { transform: scale(0.94); }
.peer .send svg { width: 36px; height: 36px; }
.peer .name { font-weight: 600; margin-top: 6px; overflow-wrap: anywhere; }
.peer .device { color: var(--muted); font-size: 13px; min-height: 1.2em; }
.peer .text { font-size: 14px; padding: 6px 12px; margin-top: 4px; }

.empty { text-align: center; padding: 48px 8px; }
.empty h1 { font-size: 22px; margin: 0 0 8px; }
.empty p { color: var(--muted); max-width: 44ch; margin: 0 auto 20px; }

.transfers { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; }

.transfer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.transfer .top { display: flex; gap: 10px; align-items: baseline; }
.transfer .title { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.transfer .state { color: var(--muted); font-size: 14px; }
.transfer.failed .state { color: var(--danger); }
.transfer progress { width: 100%; height: 6px; margin-top: 8px; accent-color: var(--accent); }

.files { list-style: none; margin: 8px 0 0; padding: 0; }

.files li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

.files li:first-child { border-top: 0; }
.files .fname { flex: 1; overflow-wrap: anywhere; }
.files .fsize { color: var(--muted); white-space: nowrap; }
.files .button { padding: 5px 12px; font-size: 14px; }
.files img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; }

.transfer .actions { display: flex; gap: 8px; margin-top: 10px; }
.transfer .actions button { padding: 6px 14px; font-size: 14px; }

dialog {
  width: min(92vw, 400px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  background: var(--card);
  color: var(--text);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h2 { margin: 0 0 8px; font-size: 19px; overflow-wrap: anywhere; }
dialog p { margin: 0 0 12px; }

.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; }

.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

input, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

textarea { resize: vertical; }

#qr {
  display: block;
  margin: 0 auto 10px;
  width: 232px;
  height: 232px;
  border-radius: 12px;
  background: #fff;
}

.code {
  text-align: center;
  font: 700 30px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.18em;
  margin: 6px 0 14px;
}

.join { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.join label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.join input { text-transform: uppercase; letter-spacing: 0.15em; font-family: ui-monospace, Menlo, Consolas, monospace; }

.close { display: block; margin: 14px auto 0; }

#text-body {
  margin: 0;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
}

@media (max-width: 420px) {
  #pair { padding: 8px 12px; font-size: 14px; }
  .peers { grid-template-columns: repeat(2, 1fr); }
}
