:root {
  --bg: #0a0a0b;
  --side: #0c0c0e;
  --line: #1b1b1f;
  --fg: #c9c9cf;
  --hi: #f2f2f4;
  --dim: #6e6e78;
  --faint: #3d3d45;
  --accent: #b5f36b;
  --link: #8fb8ff;
  --code: #e6c384;
  --sel: #26292f;
  --add: #b5f36b;
  --del: #ff7a7a;
  --col: 780px;
  --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 13px/1.6 var(--mono); -webkit-font-smoothing: antialiased; }
#app { height: 100%; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--hi); }
[hidden] { display: none !important; }
::selection { background: var(--sel); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

input, select, button { font: inherit; color: inherit; }
input, select {
  background: transparent; border: 0; border-bottom: 1px solid var(--line);
  padding: 6px 0; outline: none; border-radius: 0;
}
input:focus { border-bottom-color: var(--dim); }
input::placeholder { color: var(--faint); }
select { cursor: pointer; }
select option { background: var(--side); }
button { background: none; border: 0; padding: 0; cursor: pointer; color: var(--dim); }
button:hover { color: var(--hi); }
button.on { color: var(--accent); }
button.danger:hover { color: var(--del); }
input[type=checkbox] { accent-color: var(--accent); vertical-align: -2px; }

.dim { color: var(--dim); }
.small { font-size: 12px; }
.grow { flex: 1; }
.logo { color: var(--hi); font-weight: 700; letter-spacing: -.02em; }
.blink { color: var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* login */
.login { height: 100%; display: flex; flex-direction: column; justify-content: center; width: min(320px, calc(100% - 32px)); margin: 0 auto; }
.login .logo { font-size: 22px; }
.login p { margin: 4px 0 28px; }
.login input { font-size: 15px; }
.err { color: var(--del); min-height: 1.6em; margin-top: 8px; }

/* home */
.home { max-width: 640px; margin: 0 auto; padding: 48px 16px; }
.home header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 48px; }
.home .logo { font-size: 16px; }
.newh { display: flex; gap: 20px; align-items: center; margin-bottom: 40px; flex-wrap: wrap; }
.newh input[name=name] { flex: 1; min-width: 180px; font-size: 14px; }
.newh button { color: var(--accent); }
.hlist { list-style: none; padding: 0; margin: 0; }
.hlist li { display: flex; align-items: baseline; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.hlist li a { color: var(--hi); font-size: 14px; }
.hlist .acts { margin-left: auto; display: flex; gap: 14px; opacity: 0; transition: opacity .15s; }
.hlist li:hover .acts { opacity: 1; }
.hlist .acts button:last-child:hover { color: var(--del); }
.online-home { margin-top: 32px; }
.online-home span { margin-right: 8px; }

/* shell */
.shell { display: flex; height: 100%; }
.side {
  width: 240px; flex: none; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 0 14px; overflow: hidden;
}
.side > * { flex: none; }
.side > .logo { padding: 0 18px; font-size: 14px; }
.hname { display: block; padding: 0 18px; margin: 2px 0 18px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hname::before { content: '← '; color: var(--faint); }
.side nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.grp { padding: 14px 18px 4px; color: var(--faint); font-size: 11px; text-transform: lowercase; letter-spacing: .06em; }
.item { display: flex; align-items: center; gap: 6px; padding: 3px 18px; color: var(--dim); border-left: 2px solid transparent; }
.item span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item:hover { color: var(--hi); }
.item.on { color: var(--hi); border-left-color: var(--accent); background: #ffffff05; }
.dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.newp { padding: 14px 18px 6px; text-align: left; }
.newp-form { display: flex; flex-direction: column; gap: 8px; padding: 0 18px 10px; }
.newp-form button { align-self: flex-start; color: var(--accent); }
.foot { padding: 14px 18px 0; border-top: 1px solid var(--line); margin-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.foot a:hover { color: var(--hi); }
.online span { margin-right: 8px; }
.online:empty { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar { height: 48px; flex: none; display: flex; align-items: center; gap: 16px; padding: 0 20px; border-bottom: 1px solid var(--line); position: relative; }
.bar .title { color: var(--hi); font-weight: 600; border: 0; min-width: 0; width: 28ch; padding: 0; text-overflow: ellipsis; }
.bar .tag { color: var(--dim); border: 0; font-size: 12px; padding: 0; }
.bar .menu { display: none; font-size: 16px; }
.peers { display: flex; gap: 10px; font-size: 12px; }
.status { font-size: 12px; }
.pop { position: absolute; right: 16px; top: 44px; background: var(--side); border: 1px solid var(--line); padding: 8px 14px; display: flex; flex-direction: column; gap: 6px; z-index: 5; align-items: flex-start; }

.body { flex: 1; min-height: 0; display: flex; }
.pane { flex: 1; min-width: 0; overflow: hidden; position: relative; }
#editor { height: 100%; }
.loading { color: var(--faint); padding: 36px 28px; max-width: var(--col); margin: 0 auto; }
.cm-var { color: var(--accent); background: #b5f36b12; border-radius: 3px; }

.preview, .diff { height: 100%; overflow-y: auto; padding: 36px 28px 30vh; }
.preview > *, .diff > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
.md { font-size: 14px; line-height: 1.75; }
.md h1, .md h2, .md h3 { color: var(--hi); line-height: 1.3; margin: 1.6em auto .6em; }
.md h1 { font-size: 20px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 2em auto; }
.md code { color: var(--code); }
.md pre { background: var(--side); border: 1px solid var(--line); padding: 12px 14px; overflow-x: auto; }
.md a { color: var(--link); }
.md blockquote { border-left: 2px solid var(--faint); margin-left: auto; padding-left: 14px; color: var(--dim); }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; }

.diffhead { display: flex; align-items: baseline; gap: 14px; margin-bottom: 20px; color: var(--hi); flex-wrap: wrap; }
.diffhead button:first-of-type { color: var(--accent); }
.diff pre { font: 14px/1.7 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 0 auto; }
.diff pre div { padding-left: 2ch; text-indent: -2ch; }
.diff .same { color: var(--dim); }
.diff .add { color: var(--add); background: #b5f36b0d; }
.diff .add::before { content: '+ '; }
.diff .del { color: var(--del); background: #ff7a7a0d; text-decoration: line-through; text-decoration-color: #ff7a7a55; }
.diff .del::before { content: '- '; }
.diff .same::before { content: '  '; }

.panel { width: 300px; flex: none; border-left: 1px solid var(--line); overflow-y: auto; padding: 16px 0; background: var(--side); }
.snap { display: flex; gap: 12px; padding: 0 18px 14px; border-bottom: 1px solid var(--line); }
.snap input { flex: 1; min-width: 0; }
.snap button { color: var(--accent); }
.vlist { list-style: none; margin: 0; padding: 8px 0; }
.vlist li { padding: 8px 18px; cursor: pointer; border-left: 2px solid transparent; }
.vlist li:hover { background: #ffffff05; }
.vlist li.on { border-left-color: var(--accent); }
.vlist li.empty { cursor: default; }
.vlist b { color: var(--hi); font-weight: 600; }
.note { color: var(--fg); font-size: 12px; margin-top: 2px; }

.switch { position: fixed; inset: 0; background: #000a; display: flex; justify-content: center; align-items: flex-start; padding-top: 16vh; z-index: 20; }
.switch .box { width: min(520px, calc(100% - 32px)); background: var(--side); border: 1px solid var(--line); }
.switch input { width: 100%; padding: 14px 16px; font-size: 14px; }
.switch ul { list-style: none; margin: 0; padding: 6px 0; max-height: 50vh; overflow-y: auto; }
.switch li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 16px; cursor: pointer; color: var(--dim); }
.switch li.on, .switch li:hover { color: var(--hi); background: #ffffff07; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 10px); background: var(--hi); color: var(--bg); padding: 6px 14px; font-size: 12px; opacity: 0; transition: .2s; pointer-events: none; z-index: 30; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .side { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; width: 260px; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax #0009; }
  .bar { padding: 0 16px; gap: 12px; }
  .bar .menu { display: block; }
  .bar .title { width: auto; flex: 1; }
  .bar .grow, .bar .tag, .peers, .status { display: none; }
  .panel { position: fixed; inset: 48px 0 0 auto; width: min(300px, 90vw); z-index: 8; }
  .preview, .diff { padding: 24px 16px 30vh; }
  .hlist .acts { opacity: 1; }
}
