:root {
  --bg: #0f1220;
  --card: #171b2e;
  --card2: #1f2440;
  --text: #e8ebf5;
  --muted: #9aa3c4;
  --primary: #6c8cff;
  --primary-d: #4f6ef0;
  --accent: #ffd24a;
  --danger: #ff6b6b;
  --ok: #3ddc97;
  --line: #2a3050;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #12152a, #0f1220ee);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; }
.brand h1 { font-size: 17px; margin: 0; }
.sub { font-size: 11px; color: var(--muted); margin: 2px 0 0; }
.status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 0 transparent; }
.dot.on { background: var(--ok); }
.dot.busy { background: var(--accent); }
.dot.err { background: var(--danger); }

main { max-width: 720px; margin: 0 auto; padding: 14px 12px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 10px; line-height: 1.5; }
.empty { font-size: 13px; color: var(--muted); text-align: center; padding: 8px; }
.foot { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }

/* buttons */
.btn {
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary-d); color: #fff; font-weight: 600; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.tiny { padding: 5px 9px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 12px; }
.link { background: none; border: none; color: var(--primary); font-size: 12px; cursor: pointer; }

/* my code */
.codebox { display: flex; gap: 8px; align-items: center; }
.codebox code { flex: 1; background: #0c0f1d; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; word-break: break-all; color: var(--accent); }
.editrow { display: flex; gap: 6px; margin-top: 10px; }
.editrow input { flex: 1; }
input, select {
  background: #0c0f1d; border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 9px 10px; font-size: 14px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }

/* devices */
.addform { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 12px; }
.devicelist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.device {
  display: flex; align-items: center; gap: 10px; background: var(--card2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
.device .name { font-weight: 600; font-size: 14px; }
.device .code { font-size: 11px; color: var(--muted); word-break: break-all; }
.device .grow { flex: 1; min-width: 0; }
.device .acts { display: flex; gap: 6px; flex-shrink: 0; }
.iconbtn { background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); width: 34px; height: 34px; font-size: 15px; cursor: pointer; }
.iconbtn:hover { color: var(--text); border-color: var(--primary); }
.iconbtn.del:hover { color: var(--danger); border-color: var(--danger); }

/* send */
.sendbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.check input { width: auto; }
.dropzone { border: 1.5px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; }
.dropzone.drag { border-color: var(--primary); background: #1a2040; }

.gallery-tools { display: flex; align-items: center; gap: 8px; margin: 10px 0 6px; font-size: 13px; color: var(--muted); }
.spacer { flex: 1; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; touch-action: pan-y; }
.thumb {
  position: relative; aspect-ratio: 1/1; border-radius: 10px; overflow: hidden;
  background: #0c0f1d; border: 2px solid transparent; cursor: pointer; user-select: none;
  touch-action: manipulation;
}
.thumb img, .thumb video, .thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.thumb .badge {
  position: absolute; top: 4px; right: 4px; min-width: 20px; height: 20px; padding: 0 5px;
  background: var(--primary); color: #fff; border-radius: 10px; font-size: 12px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
}
.thumb.selected .badge { display: flex; }
.thumb .ftype { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: #0008; padding: 1px 5px; border-radius: 6px; }
.thumb .dur { position: absolute; right: 4px; bottom: 4px; font-size: 10px; background: #0008; padding: 1px 5px; border-radius: 6px; }

.progress { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.pitem { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 9px; font-size: 13px; }
.pitem .ptitle { display: flex; justify-content: space-between; margin-bottom: 6px; }
.bar { height: 6px; background: #0c0f1d; border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .15s; }

/* receive */
.recvlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recvitem { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 9px; font-size: 13px; }
.recvitem .rhead { display: flex; justify-content: space-between; margin-bottom: 6px; }
.recvitem a.save { color: var(--primary); font-size: 12px; }

/* modal */
.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 340px; width: 100%; }
.modal-card h3 { margin: 0 0 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: #000c; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 60; }

.hidden { display: none !important; }

@media (max-width: 480px) {
  .addform { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}
