:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #121826;
  --muted: #5b6577;
  --border: #dde3ec;
  --accent: #0f6fff;
  --accent-ink: #ffffff;
  --accent-soft: #e5efff;
  --danger: #d23a3a;
  --ok: #17a34a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1018;
    --surface: #151b26;
    --surface-2: #1d2532;
    --text: #e8edf5;
    --muted: #97a2b5;
    --border: #283244;
    --accent: #4b8fff;
    --accent-ink: #06101f;
    --accent-soft: #17284a;
    --danger: #ff6b6b;
    --ok: #3ddc84;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  max-width: 1120px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .875rem; cursor: pointer; max-width: 55vw;
}
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }

.view { max-width: 1120px; width: 100%; margin: 0 auto; padding: 8px 16px 32px; flex: 1; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 10px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .drop:focus-visible, input:focus-visible, textarea:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 14px 28px; font-size: 1.05rem; min-height: 52px; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; }
.btn.danger:hover { border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }

/* Landing */
.hero { max-width: 640px; margin: 7vh auto 40px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.1rem); letter-spacing: -0.02em; }
.lead { color: var(--muted); font-size: 1.1rem; margin: 16px auto 28px; max-width: 540px; }
.hero-actions { margin-bottom: 28px; }
.join { display: inline-flex; flex-direction: column; gap: 8px; align-items: center; }
.join label { color: var(--muted); font-size: .9rem; }
.join-row { display: flex; gap: 8px; }
.join input {
  font: 600 1.15rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em; text-transform: uppercase;
  width: 11.5ch; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-align: center;
}
.resume { margin-top: 20px; color: var(--muted); }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 900px; margin: 0 auto; }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.step h3 { margin: 10px 0 4px; font-size: 1.05rem; }
.step p { margin: 0; color: var(--muted); font-size: .95rem; }
.num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* Room */
#room { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.connect { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 12px; }
.connect h2 { font-size: 1.05rem; }
.qr-wrap { background: #fff; border-radius: 12px; padding: 10px; align-self: center; border: 1px solid var(--border); }
.qr-wrap img { display: block; width: 200px; height: 200px; }
.connect p { margin: 0; }
.code {
  font: 700 1.6rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .14em;
  text-align: center; padding: 12px; background: var(--surface-2); border-radius: 10px; user-select: all;
}
.devices-title { font-size: .95rem; margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.count { background: var(--surface-2); border-radius: 999px; padding: 0 8px; font-size: .8rem; }
.devices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.devices li { display: flex; align-items: center; gap: 10px; font-size: .92rem; }
.devices svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.devices .me { color: var(--muted); font-size: .8rem; }
.room-meta p { margin: 0; }

.share { display: flex; flex-direction: column; gap: 16px; }
.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 36px 16px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { width: 40px; height: 40px; color: var(--accent); }
.drop-title { font-weight: 600; margin: 8px 0 2px; font-size: 1.05rem; }
.drop p { margin: 0; }
.drop u { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.mobile-only { display: none; }

.text-form { display: flex; gap: 8px; align-items: stretch; }
.text-form textarea {
  flex: 1; min-width: 0; font: inherit; resize: vertical; min-height: 44px; max-height: 240px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}

.uploads, .items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.upload { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
.upload .top { display: flex; justify-content: space-between; gap: 8px; }
.upload .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload.error { border-color: var(--danger); color: var(--danger); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.items-head { display: flex; align-items: center; justify-content: space-between; }
.items-head h2 { font-size: 1.05rem; }
.item {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center;
  border: 1px solid var(--border); border-radius: 12px; padding: 10px; animation: pop .25s ease-out;
}
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } to { transform: none; opacity: 1; } }
.thumb {
  width: 48px; height: 48px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center;
  overflow: hidden; color: var(--muted); font: 700 .7rem/1 ui-monospace, monospace; text-transform: uppercase; border: 0; padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
button.thumb { cursor: zoom-in; }
.info { min-width: 0; }
.info .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info .meta { color: var(--muted); font-size: .8rem; }
.item .text { white-space: pre-wrap; word-break: break-word; font-size: .95rem; max-height: 8.5em; overflow: auto; }
.actions { display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; min-height: 40px; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.del:hover { color: var(--danger); border-color: var(--danger); }
.empty { text-align: center; padding: 20px 0; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); max-width: min(960px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.dialog-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-body { display: grid; place-items: center; background: var(--surface-2); }
.preview-body img, .preview-body video { max-width: 100%; max-height: 80vh; display: block; }
.preview-body iframe { width: 100%; height: 80vh; border: 0; background: #fff; }

.footer { text-align: center; padding: 16px; }
.footer a { color: inherit; }

@media (max-width: 860px) {
  #room { grid-template-columns: 1fr; }
  .connect { position: static; order: 2; }
  .share { order: 1; }
}
@media (max-width: 640px) {
  .steps { grid-template-columns: 1fr; }
  .hero { margin-top: 4vh; }
  .panel { padding: 16px; }
}
@media (hover: none) and (pointer: coarse) {
  .mobile-only { display: flex; }
  .mobile-only .btn { flex: 1; }
  .desk { display: none; }
  .drop { padding: 28px 16px; }
}
