:root {
  --bg: #f5f2e8;
  --bg2: #ece7d6;
  --card: #fffdf7;
  --line: #e3dcc6;
  --text: #2f3a26;
  --muted: #7c846f;
  --matcha: #6f8f4e;
  --matcha-d: #57753b;
  --matcha-l: #dfe8cf;
  --matcha-xl: #eef3e4;
  --accent: #b88a4a;
  --danger: #b5523f;
  --shadow: 0 1px 2px rgba(60, 70, 40, .05), 0 8px 28px -12px rgba(60, 80, 30, .18);
  --r: 20px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b14; --bg2: #1d2219; --card: #20261c; --line: #313a2a;
    --text: #e6ead9; --muted: #98a189; --matcha: #94b46f; --matcha-d: #a9c785;
    --matcha-l: #2f3b25; --matcha-xl: #262f1f; --accent: #d1a668; --danger: #e07a64;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
.bg-leaf {
  position: fixed; inset: -20vh -10vw auto auto; width: 70vw; height: 70vh; pointer-events: none; z-index: 0;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--matcha) 16%, transparent), transparent);
  filter: blur(10px);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h2, h3 { margin: 0; }
.muted { color: var(--muted); }

/* ---------- header ---------- */
.top {
  position: relative; z-index: 1; max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 16px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-size: 18px; }
.brand span { white-space: nowrap; }
.brand b { color: var(--matcha); font-weight: 700; }
.me-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 55vw;
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px 6px 8px;
  font-size: 13px; color: var(--muted); transition: border-color .2s, transform .2s var(--ease);
}
.me-chip:hover { border-color: var(--matcha); transform: translateY(-1px); }
.me-chip #meName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-weight: 500; }
.dev-ico, .peer-ico { display: inline-grid; place-items: center; color: var(--matcha); }

.banner { max-width: 1100px; margin: 10px auto 0; padding: 10px 14px; border-radius: 12px; font-size: 14px; position: relative; z-index: 1; }
.banner.warn { background: #fbecd0; color: #6b4a14; margin-left: 16px; margin-right: 16px; }

/* ---------- layout ---------- */
.wrap { position: relative; z-index: 1; max-width: 1100px; margin: 0 auto; padding: 12px 16px 40px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 22px; animation: rise .5s var(--ease) both;
}
.card + .main-grid, .main-grid { margin-top: 18px; }
.main-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.main-grid > .card:nth-child(2) { animation-delay: .06s; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.count { font-size: 12px; font-weight: 600; background: var(--matcha-l); color: var(--matcha-d); border-radius: 999px; padding: 1px 8px; }
.count:empty { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- status ---------- */
.status-row { display: flex; justify-content: center; margin-bottom: 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px;
  background: var(--bg2); color: var(--muted); font-size: 13px; font-weight: 500; transition: background .3s, color .3s;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.wait .dot { animation: pulse 1.4s infinite; }
.pill.ok { background: var(--matcha-l); color: var(--matcha-d); }
.pill.err { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- pairing ---------- */
.pair-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 22px; align-items: start; transition: opacity .3s; }
.pair-col { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; min-width: 0; }
.pair-col h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.step { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; background: var(--matcha); color: #fff; }
.pair-or { align-self: stretch; display: flex; align-items: center; justify-content: center; position: relative; color: var(--muted); font-size: 13px; }
.pair-or::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; border-left: 1px dashed var(--line); }
.pair-or span { position: relative; background: var(--card); padding: 6px 0; }

.qr-box {
  border: 0; padding: 12px; border-radius: 18px; background: #fff;
  box-shadow: 0 0 0 1px var(--line), 0 6px 18px -10px rgba(60, 80, 30, .35);
  transition: transform .25s var(--ease);
}
.qr-box:hover { transform: scale(1.02); }
.qr { width: 168px; height: 168px; display: grid; place-items: center; }
.qr svg { width: 100%; height: 100%; display: block; animation: fadeIn .4s both; }
.code-line { display: flex; align-items: center; gap: 6px; }
.code { font-size: 28px; font-weight: 700; letter-spacing: .18em; color: var(--matcha-d); font-variant-numeric: tabular-nums; padding-left: .18em; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: transparent;
  display: inline-grid; place-items: center; color: var(--muted); transition: all .2s;
}
.icon-btn:hover { color: var(--matcha-d); border-color: var(--matcha); background: var(--matcha-xl); }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px 8px; border-radius: 8px; transition: color .2s, background .2s; }
.link-btn:hover { color: var(--matcha-d); background: var(--matcha-xl); }

.join-form { display: flex; gap: 8px; width: 100%; max-width: 320px; }
.join-form input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--bg); text-transform: uppercase; letter-spacing: .14em; font-weight: 600; font-size: 18px; text-align: center;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.join-form input:focus { border-color: var(--matcha); box-shadow: 0 0 0 4px color-mix(in srgb, var(--matcha) 18%, transparent); }
.join-form input::placeholder { letter-spacing: .05em; font-weight: 400; color: var(--muted); opacity: .6; font-size: 15px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); max-width: 320px; }

.lan { width: 100%; max-width: 360px; margin-top: 6px; animation: rise .4s var(--ease) both; }
.lan h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.lan-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lan-dev {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px 8px 10px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg); font-size: 14px; font-weight: 500;
  transition: all .2s var(--ease); animation: rise .35s var(--ease) both;
}
.lan-dev:hover { border-color: var(--matcha); background: var(--matcha-xl); transform: translateY(-2px); }
.lan-dev .dev-ico { width: 28px; height: 28px; border-radius: 9px; background: var(--matcha-l); }

/* ---------- connected bar ---------- */
.peer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-radius: 16px; background: var(--matcha-xl); border: 1px solid var(--matcha-l);
  animation: rise .4s var(--ease) both;
}
.peer-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.peer-ico { width: 44px; height: 44px; border-radius: 14px; background: var(--matcha); color: #fff; flex: none; }
.peer-name { font-weight: 600; font-size: 16px; }
.peer-sub { font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 999px; background: var(--matcha); color: #fff; }
.badge.relay { background: var(--accent); }
.badge.pending { background: var(--muted); }
.peer-actions { display: flex; gap: 8px; }
.relay-note { margin: 12px 0 0; font-size: 13px; color: var(--muted); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 10px 14px; border-radius: 12px; }
.pair.connected .pair-grid { display: none; }

/* ---------- buttons ---------- */
.btn {
  height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid transparent; font-weight: 600;
  transition: transform .15s var(--ease), background .2s, box-shadow .2s, opacity .2s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--matcha); color: #fff; box-shadow: 0 6px 16px -8px var(--matcha); }
.btn.primary:hover { background: var(--matcha-d); }
.btn.ghost { background: var(--card); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--matcha); color: var(--matcha-d); }
.btn.ghost.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.sm { height: 36px; padding: 0 14px; font-size: 13px; border-radius: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- send ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  padding: 30px 16px; border-radius: 18px; border: 2px dashed color-mix(in srgb, var(--matcha) 45%, var(--line));
  background: var(--matcha-xl); color: var(--matcha); transition: all .25s var(--ease);
}
.drop b { color: var(--text); font-weight: 600; margin-top: 6px; }
.drop span { font-size: 13px; color: var(--muted); }
.drop:hover, .drop.over { border-color: var(--matcha); background: var(--matcha-l); transform: translateY(-2px); }
body.dragging .drop { border-color: var(--matcha); background: var(--matcha-l); transform: scale(1.01); }
.text-form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.text-form textarea {
  width: 100%; resize: vertical; min-height: 84px; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--bg); outline: none; transition: border-color .2s, box-shadow .2s;
}
.text-form textarea:focus { border-color: var(--matcha); box-shadow: 0 0 0 4px color-mix(in srgb, var(--matcha) 18%, transparent); }
.text-form .btn { align-self: flex-end; }
.save-opt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); font-size: 13px; }

/* ---------- list ---------- */
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }
.empty svg { color: var(--matcha); }
.empty p { margin: 6px 0 0; }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px; border-radius: 16px; background: var(--bg); border: 1px solid var(--line);
  animation: rise .35s var(--ease) both; transition: border-color .3s, background .3s;
}
.item.done { border-color: var(--matcha-l); }
.item.failed { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.thumb {
  width: 44px; height: 44px; border-radius: 12px; background: var(--matcha-l); color: var(--matcha-d);
  display: grid; place-items: center; font-size: 11px; font-weight: 700; overflow: hidden; position: relative; text-transform: uppercase;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; animation: fadeIn .3s both; }
.thumb .dir {
  position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px; border-radius: 6px; display: grid; place-items: center;
  background: var(--card); color: var(--matcha-d); font-size: 10px; box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.item-main { min-width: 0; }
.item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 99px; background: var(--bg2); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--matcha), color-mix(in srgb, var(--matcha) 70%, #cfe3a8)); transition: width .3s linear; }
.item.done .bar, .item.text .bar { display: none; }
.item.paused .bar i { background: var(--accent); }
.item-actions { display: flex; gap: 6px; }
.item-actions .icon-btn { width: 34px; height: 34px; }
.text-body {
  margin-top: 4px; font-size: 14px; white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow: auto;
  background: var(--card); border-radius: 10px; padding: 8px 10px; border: 1px solid var(--line);
}
.text-body a { color: var(--matcha-d); }

/* ---------- footer ---------- */
.foot { display: flex; justify-content: center; gap: 8px 22px; flex-wrap: wrap; margin-top: 28px; color: var(--muted); font-size: 13px; }

/* ---------- overlays ---------- */
.qr-zoom {
  position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; animation: fadeIn .2s both; color: var(--muted);
}
.qr-zoom[hidden] { display: none; }
.qr-zoom-inner { background: #fff; padding: 18px; border-radius: 24px; width: min(86vw, 420px); aspect-ratio: 1; box-shadow: var(--shadow); animation: rise .3s var(--ease) both; }
.qr-zoom-inner svg { width: 100%; height: 100%; display: block; }
.toasts { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 420px); pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .4); display: flex; gap: 12px; align-items: center; animation: toastIn .3s var(--ease) both;
}
.toast.out { animation: toastOut .25s ease both; }
.toast .btn.sm { height: 32px; background: var(--matcha); color: #fff; }
.toast .btn.sm.ghost { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 35%, transparent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .main-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .brand { font-size: 16px; gap: 8px; }
  .me-chip { max-width: 46vw; }
  .card { padding: 18px 16px; border-radius: 18px; }
  .pair-grid { grid-template-columns: 1fr; gap: 14px; }
  .pair-or { padding: 2px 0; }
  .pair-or::before { top: 50%; bottom: auto; left: 0; right: 0; border-left: 0; border-top: 1px dashed var(--line); }
  .pair-or span { padding: 0 12px; }
  .qr { width: 150px; height: 150px; }
  .code { font-size: 24px; }
  .peer-actions { width: 100%; }
  .peer-actions .btn { flex: 1; }
  .item { grid-template-columns: 40px minmax(0, 1fr); }
  .thumb { width: 40px; height: 40px; }
  .item-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .item-actions:empty { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
