/* ---- tokens: light is the base, dark redefines only values ---- */
:root{
  --ground:#f2f1ee; --dot:#d3d0c9; --surface:#fbfaf8; --surface-2:#eceae5;
  --line:#dcd9d2; --line-2:#c3bfb6; --ink:#1b1c1f; --ink-2:#54565d; --muted:#84868e;
  --ok:#4f9a68;
  --shadow-1:0 1px 2px rgba(22,22,26,.07), 0 6px 18px rgba(22,22,26,.07);
  --shadow-2:0 2px 6px rgba(22,22,26,.10), 0 18px 44px rgba(22,22,26,.14);
  --chrome:rgba(251,250,248,.82);
  --n-plain:#fbfaf8; --n-red:#f9e7e2; --n-amber:#f8efd9; --n-green:#e6f1e3; --n-blue:#e3edf8; --n-violet:#ebe7f7;
  --r:10px;
}
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    --ground:#16181b; --dot:#292c32; --surface:#202328; --surface-2:#272b31;
    --line:#31353d; --line-2:#464c56; --ink:#e9e8e4; --ink-2:#b1b3b9; --muted:#868992;
    --ok:#5fb07c;
    --shadow-1:0 1px 2px rgba(0,0,0,.44), 0 6px 18px rgba(0,0,0,.32);
    --shadow-2:0 2px 8px rgba(0,0,0,.5), 0 20px 48px rgba(0,0,0,.44);
    --chrome:rgba(32,35,40,.84);
    --n-plain:#22252a; --n-red:#332522; --n-amber:#332d20; --n-green:#212f25; --n-blue:#1f2b35; --n-violet:#292633;
  }
}
:root[data-theme="dark"]{
  --ground:#16181b; --dot:#292c32; --surface:#202328; --surface-2:#272b31;
  --line:#31353d; --line-2:#464c56; --ink:#e9e8e4; --ink-2:#b1b3b9; --muted:#868992;
  --ok:#5fb07c;
  --shadow-1:0 1px 2px rgba(0,0,0,.44), 0 6px 18px rgba(0,0,0,.32);
  --shadow-2:0 2px 8px rgba(0,0,0,.5), 0 20px 48px rgba(0,0,0,.44);
  --chrome:rgba(32,35,40,.84);
  --n-plain:#22252a; --n-red:#332522; --n-amber:#332d20; --n-green:#212f25; --n-blue:#1f2b35; --n-violet:#292633;
}

*{box-sizing:border-box}
img{max-width:100%}
[hidden]{display:none!important}
body{
  margin:0; background:var(--ground); color:var(--ink);
  font-family:"Instrument Sans",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size:14px; line-height:1.45; -webkit-font-smoothing:antialiased;
  height:100dvh; overflow:hidden; overscroll-behavior:none;
}
.mono{font-family:"JetBrains Mono",ui-monospace,SFMono-Regular,Menlo,monospace}
button{font:inherit; color:inherit; background:none; border:0; cursor:pointer}
:focus-visible{outline:2px solid var(--me,#8a8d95); outline-offset:2px}

/* ---- canvas ---- */
#stage{
  position:fixed; inset:0; touch-action:none; cursor:grab;
  background-color:var(--ground);
  background-image:radial-gradient(var(--dot) 1.1px, transparent 1.1px);
}
#stage.panning{cursor:grabbing}
#world{position:absolute; top:0; left:0; width:0; height:0; transform-origin:0 0}

/* ---- items ---- */
.item{
  position:absolute; border:1px solid var(--line); border-radius:var(--r);
  background:var(--surface); box-shadow:var(--shadow-1);
  display:flex; flex-direction:column; overflow:hidden;
}
.item.sel{box-shadow:var(--shadow-2), 0 0 0 2px var(--me,#8a8d95)}
.item.peered{box-shadow:var(--shadow-1), 0 0 0 2px var(--pc,#8a8d95)}
.grab{
  height:16px; flex:0 0 16px; cursor:grab; position:relative;
  display:flex; align-items:center; justify-content:center; opacity:0; transition:opacity .12s;
}
.item:hover .grab, .item.sel .grab{opacity:1}
.grab::before{content:""; width:26px; height:3px; border-radius:2px; background:var(--line-2)}
.grab:active{cursor:grabbing}
.xbtn{
  position:absolute; right:2px; top:0; width:17px; height:17px; border-radius:5px;
  color:var(--muted); font-size:14px; line-height:1; display:grid; place-items:center;
}
.xbtn:hover{background:var(--surface-2); color:var(--ink)}
.rs{position:absolute; right:0; bottom:0; width:17px; height:17px; cursor:nwse-resize; opacity:0; transition:opacity .12s}
.item:hover .rs, .item.sel .rs{opacity:1}
.rs::after{content:""; position:absolute; right:3px; bottom:3px; width:7px; height:7px; border-right:2px solid var(--line-2); border-bottom:2px solid var(--line-2)}

.note textarea{
  flex:1; width:100%; border:0; resize:none; background:transparent; color:var(--ink);
  font:inherit; padding:0 11px 10px; outline:none; caret-color:var(--me,var(--ink));
}
.note textarea::placeholder{color:var(--muted)}
.note[data-c="plain"]{background:var(--n-plain)}
.note[data-c="red"]{background:var(--n-red)}
.note[data-c="amber"]{background:var(--n-amber)}
.note[data-c="green"]{background:var(--n-green)}
.note[data-c="blue"]{background:var(--n-blue)}
.note[data-c="violet"]{background:var(--n-violet)}

.media .frame{flex:1; min-height:0; display:grid; place-items:center; background:var(--surface-2); overflow:hidden}
.media img, .media video{max-width:100%; max-height:100%; width:100%; height:100%; object-fit:contain; display:block}
.media .file{display:flex; flex-direction:column; align-items:center; gap:7px; padding:14px; text-align:center}
.media .file .ext{font-size:11px; letter-spacing:.1em; padding:3px 8px; border:1px solid var(--line-2); border-radius:5px; color:var(--ink-2)}
.media .file .fname{font-size:12px; color:var(--muted); word-break:break-all; max-width:100%}
.media .file a{color:var(--ink-2); font-size:12px; text-underline-offset:2px}
.busy{display:flex; flex-direction:column; align-items:center; gap:8px; color:var(--muted); font-size:12px}
.spin{width:18px; height:18px; border:2px solid var(--line-2); border-top-color:var(--ink-2); border-radius:50%; animation:sp .7s linear infinite}
@keyframes sp{to{transform:rotate(360deg)}}
.meta{display:flex; align-items:center; gap:8px; padding:6px 9px 7px; border-top:1px solid var(--line); min-height:31px}
.meta input{
  flex:1; min-width:0; border:0; background:transparent; color:var(--ink); font:inherit; font-size:12px;
  outline:none; padding:2px 4px; border-radius:4px; caret-color:var(--me,var(--ink));
}
.meta input::placeholder{color:var(--muted)}
.meta input:focus{background:var(--surface-2)}
.dims{font-size:11px; color:var(--muted); white-space:nowrap}
.swatches{display:flex; gap:5px; padding:0 10px 9px}
.sw{width:14px; height:14px; border-radius:50%; border:1px solid var(--line-2); padding:0}
.sw[aria-pressed="true"]{box-shadow:0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink-2)}

/* ---- peer cursors ---- */
.cursor{position:absolute; pointer-events:none; transform-origin:0 0; z-index:9}
.cursor svg{display:block; filter:drop-shadow(0 1px 2px rgba(0,0,0,.35))}
.cursor .tag{
  position:absolute; left:13px; top:16px; font-size:11px; font-weight:600; color:#fff;
  padding:2px 7px; border-radius:99px; white-space:nowrap; box-shadow:var(--shadow-1);
}

/* ---- chrome ---- */
.bar{
  position:fixed; top:0; left:0; right:0; display:flex; align-items:flex-start;
  justify-content:space-between; gap:12px; padding:10px 12px; pointer-events:none; z-index:20;
}
.bar>*{pointer-events:auto}
.pill{
  display:flex; align-items:center; background:var(--chrome);
  -webkit-backdrop-filter:blur(14px); backdrop-filter:blur(14px);
  border:1px solid var(--line); border-radius:var(--r); box-shadow:var(--shadow-1); padding:4px;
}
.tbtn{display:flex; align-items:center; gap:7px; padding:6px 10px; border-radius:7px; color:var(--ink-2); white-space:nowrap}
.tbtn:hover{background:var(--surface-2); color:var(--ink)}
.tbtn[disabled]{opacity:.4; cursor:default}
.tbtn[disabled]:hover{background:none; color:var(--ink-2)}
.tbtn svg{flex:0 0 auto}
.bname{font-weight:600; color:var(--ink); max-width:34vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.caret{color:var(--muted)}
.anchor{position:relative}

.menu{
  position:absolute; top:calc(100% + 6px); left:0; min-width:236px; max-height:62vh; overflow:auto;
  background:var(--surface); border:1px solid var(--line); border-radius:var(--r);
  box-shadow:var(--shadow-2); padding:5px; z-index:30;
}
.menu[hidden]{display:none}
.mi{display:flex; align-items:center; gap:9px; width:100%; text-align:left; padding:7px 9px; border-radius:7px; color:var(--ink-2)}
.mi:hover{background:var(--surface-2); color:var(--ink)}
.mi.on{color:var(--ink); font-weight:600}
.mi .dot{width:5px; height:5px; border-radius:50%; background:var(--ink); flex:0 0 5px; opacity:0}
.mi.on .dot{opacity:1}
.mi .nm{flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.msep{height:1px; background:var(--line); margin:5px 3px}

.who{display:flex; align-items:center; gap:7px; padding:5px 9px 5px 7px}
.stack{display:flex}
.av{
  width:25px; height:25px; border-radius:50%; display:grid; place-items:center;
  font-size:11px; font-weight:700; color:#fff; border:2px solid var(--surface); margin-right:-7px;
}
.av:last-child{margin-right:0}
.av.more{background:var(--surface-2); color:var(--ink-2)}
.conn{width:6px; height:6px; border-radius:50%; background:var(--ok)}
.conn.off{background:var(--muted)}

.tools{position:fixed; left:12px; bottom:12px; display:flex; gap:8px; flex-wrap:wrap; z-index:20; max-width:calc(100vw - 24px)}
.zval{font-size:12px; color:var(--muted); min-width:46px; text-align:center; font-variant-numeric:tabular-nums}
.hint{position:fixed; right:12px; bottom:12px; font-size:11.5px; color:var(--muted); z-index:20; text-align:right; pointer-events:none; line-height:1.7}
.hint kbd{font-family:"JetBrains Mono",monospace; font-size:10.5px; border:1px solid var(--line); border-radius:4px; padding:1px 4px; color:var(--ink-2)}

/* ---- dialogs / empty ---- */
.veil{position:fixed; inset:0; background:rgba(10,10,12,.4); display:grid; place-items:center; z-index:50; padding:20px}
.veil[hidden]{display:none}
.card{width:100%; max-width:390px; background:var(--surface); border:1px solid var(--line); border-radius:14px; box-shadow:var(--shadow-2); padding:20px}
.card h2{margin:0 0 5px; font-size:17px; font-weight:600; text-wrap:balance}
.card p{margin:0 0 17px; color:var(--muted); font-size:13px}
.field{display:block; margin-bottom:15px}
.field span{display:block; font-size:11px; letter-spacing:.08em; text-transform:uppercase; color:var(--muted); margin-bottom:6px}
.field input{width:100%; padding:9px 11px; border:1px solid var(--line-2); border-radius:8px; background:var(--ground); color:var(--ink); font:inherit; outline:none}
.field input:focus{border-color:var(--me,var(--ink-2))}
.colors{display:flex; gap:9px; flex-wrap:wrap}
.ck{width:27px; height:27px; border-radius:50%; border:2px solid transparent; padding:0}
.ck[aria-pressed="true"]{border-color:var(--ink)}
.row{display:flex; gap:8px; justify-content:flex-end; align-items:center}
.primary{padding:9px 16px; border-radius:8px; background:var(--ink); color:var(--ground); font-weight:600}
.ghost{padding:9px 14px; border-radius:8px; color:var(--ink-2)}
.ghost:hover{background:var(--surface-2)}
.danger{color:#d3543f}

#toast{
  position:fixed; left:50%; bottom:18px; transform:translateX(-50%);
  background:var(--ink); color:var(--ground); padding:9px 15px; border-radius:99px;
  font-size:13px; box-shadow:var(--shadow-2); z-index:60; max-width:min(92vw,480px); text-align:center;
}
#toast[hidden]{display:none}

.drop{position:fixed; inset:0; z-index:40; display:grid; place-items:center; background:rgba(10,10,12,.32); pointer-events:none}
.drop[hidden]{display:none}
.drop b{background:var(--surface); border:2px dashed var(--line-2); border-radius:14px; padding:18px 26px; font-weight:600}

.blank{position:fixed; inset:0; display:grid; place-items:center; z-index:10; padding:20px; text-align:center}
.blank[hidden]{display:none}
.blank h1{font-size:20px; font-weight:600; margin:0 0 6px}
.blank p{color:var(--muted); margin:0 0 18px; font-size:13px}

@media (max-width:600px){
  .hint{display:none}
  .bname{max-width:38vw}
  .tbtn .lbl{display:none}
  .tbtn{padding:8px}
  .bar{padding:8px}
  .tools{left:8px; bottom:8px}
}
@media (prefers-reduced-motion:reduce){*{transition:none!important; animation:none!important}}
