/* Scorpio web: mobile first. Every colour is a variable on :root (spec §4.3), light and dark. */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --fg: #1d1c1a;
  --muted: #6d6a64;
  --line: #e4e1da;
  --accent: #b2412e;
  --accent-fg: #ffffff;
  --accent-soft: #f6e4df;
  --mention: #9a3424;
  --forme: #fbeee9;
  --code-bg: #efece6;
  --ok: #2f7a43;
  --warn-bg: #fff4d6;
  --warn-fg: #6b4e00;
  --danger: #b3261e;
  --online: #2f9e55;
  --pin: #b45309;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151413;
    --surface: #1f1e1c;
    --fg: #ece9e3;
    --muted: #a19d95;
    --line: #34322e;
    --accent: #e0745f;
    --accent-fg: #1a0e0b;
    --accent-soft: #3a2420;
    --mention: #f0a08f;
    --forme: #2a1f1c;
    --code-bg: #2a2825;
    --ok: #7fc795;
    --warn-bg: #3a3118;
    --warn-fg: #f0d68a;
    --danger: #f2a39d;
    --online: #5fd08a;
    --pin: #f0b45a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0.5rem 0; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }
small { font-size: 0.8rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.warn { background: var(--warn-bg); color: var(--warn-fg); padding: 0.6rem 0.75rem; border-radius: 8px; font-size: 0.9rem; }
.sp { flex: 1; }
.row { display: flex; align-items: center; }
.gap { gap: 0.5rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }

/* top nav */
nav.top { display: flex; align-items: center; gap: 0.9rem; padding: 0.6rem 16px; border-bottom: 1px solid var(--line); background: var(--surface); font-size: 0.9rem; }
nav.top .brand { font-weight: 700; color: var(--fg); text-decoration: none; letter-spacing: 0.02em; }
nav.top .who { color: var(--muted); }
nav.top form { margin: 0; }

main.narrow { max-width: 560px; margin: 0 auto; padding: 1rem 16px 3rem; }
main.center { text-align: center; padding-top: 3rem; }
.logo { font-size: 2.2rem; letter-spacing: 0.04em; }
.lead { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); text-align: left; }
input, textarea {
  font: inherit; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.7rem; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.code { font-family: var(--mono); letter-spacing: 0.08em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  border-radius: 10px; padding: 0.55rem 1rem; min-height: 40px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--danger); }
.btn.big { padding: 0.8rem 1rem; min-height: 48px; }
.btn.disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled { opacity: 0.6; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
details.dev { margin-top: 2rem; text-align: left; }
details.dev summary { color: var(--muted); cursor: pointer; font-size: 0.9rem; }

ul.rooms, ul.devices { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
ul.rooms a { display: flex; flex-direction: column; padding: 0.8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--fg); }
ul.rooms span { color: var(--muted); font-size: 0.9rem; }
ul.devices li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
ul.devices li div { display: flex; flex-direction: column; }
ul.devices form { margin: 0; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; margin: 0 0 1rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 600; }

/* ---------- room ---------- */
body.room { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.roombar {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.5rem 12px; padding-top: max(0.5rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line); min-height: 52px;
}
.roombar .back { font-size: 1.6rem; line-height: 1; text-decoration: none; color: var(--fg); padding: 0 0.4rem 0.2rem 0; }
.roombar .title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.roombar .title b, .roombar .title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roombar .title span { color: var(--muted); font-size: 0.8rem; }
.chip {
  font: inherit; font-size: 0.8rem; font-weight: 600; border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  border-radius: 999px; padding: 0.3rem 0.65rem; cursor: pointer; white-space: nowrap;
}
#btn-mentions { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.status { text-align: center; font-size: 0.85rem; padding: 0.35rem 16px; background: var(--warn-bg); color: var(--warn-fg); white-space: pre-line; }

.feed { flex: 1; overflow-y: auto; padding: 0.5rem 12px 1rem; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg { padding: 0.45rem 0.6rem; margin: 0.15rem 0; border-radius: 10px; border-left: 3px solid transparent; }
.msg.forme { background: var(--forme); border-left-color: var(--accent); }
.msg.flash { outline: 2px solid var(--accent); }
.msg .meta { display: flex; align-items: baseline; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); }
.msg .from { color: var(--fg); font-size: 0.9rem; }
.msg.mine .from { color: var(--accent); }
.msg .tag { font-size: 0.7rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 0.3rem; }
.msg .tag.bc { border-color: var(--accent); color: var(--accent); }
.msg .replybtn { font: inherit; font-size: 0.75rem; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0 0 0 0.3rem; }
.msg.system { text-align: center; color: var(--muted); font-size: 0.8rem; border: 0; padding: 0.2rem; }
.quote { display: block; font-size: 0.85rem; color: var(--muted); border-left: 2px solid var(--line); padding: 0.1rem 0.5rem; margin: 0.25rem 0; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { display: flex; align-items: center; gap: 0.5rem; color: var(--accent); font-size: 0.75rem; font-weight: 600; margin: 0.6rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--accent); opacity: 0.5; }
.empty { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 30vh; }
.more { display: block; margin: 0.5rem auto; font: inherit; font-size: 0.85rem; color: var(--accent); background: none; border: 0; cursor: pointer; }

.md { overflow-wrap: anywhere; }
.md p { margin: 0.2rem 0; }
.md p.h { font-weight: 700; }
.md ul, .md ol { margin: 0.2rem 0; padding-left: 1.3rem; }
.md blockquote { margin: 0.3rem 0; padding-left: 0.6rem; border-left: 3px solid var(--line); color: var(--muted); }
.md code { font-family: var(--mono); font-size: 0.85em; background: var(--code-bg); padding: 0.05rem 0.3rem; border-radius: 4px; }
.md pre { background: var(--code-bg); padding: 0.6rem; border-radius: 8px; overflow-x: auto; margin: 0.3rem 0; }
.md pre code { background: none; padding: 0; font-size: 0.82rem; }
.md .mention { color: var(--mention); font-weight: 600; }
.md .tablewrap { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 0.85rem; margin: 0.3rem 0; }
.md th, .md td { border: 1px solid var(--line); padding: 0.25rem 0.5rem; text-align: left; vertical-align: top; }

.panel {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 75vh; overflow-y: auto; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18); padding: 0.75rem 16px calc(1rem + env(safe-area-inset-bottom));
}
.panelhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.x { font: inherit; font-size: 1.4rem; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0.2rem 0.4rem; }
ul.members, ul.pins { list-style: none; padding: 0; margin: 0; }
ul.pins li.pin { padding: 0.6rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
ul.pins .pinby { font-size: 0.75rem; color: var(--pin); font-weight: 600; margin-bottom: 0.2rem; }
ul.pins .meta { display: flex; align-items: baseline; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); }
ul.pins .from { color: var(--fg); font-size: 0.9rem; }
.msg.pinned .seq { color: var(--pin); font-weight: 600; }
.ic-pin {
  display: inline-block; width: 0.9em; height: 0.9em; margin-right: 0.2em; vertical-align: -0.1em; background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M10.2 1.3l4.5 4.5-1.4.4-2.6 2.6.3 3.1-1.3 1.3-2.8-2.8-3.6 3.6-.9-.9 3.6-3.6L3.2 6.7l1.3-1.3 3.1.3 2.6-2.6z'/></svg>") center/contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M10.2 1.3l4.5 4.5-1.4.4-2.6 2.6.3 3.1-1.3 1.3-2.8-2.8-3.6 3.6-.9-.9 3.6-3.6L3.2 6.7l1.3-1.3 3.1.3 2.6-2.6z'/></svg>") center/contain no-repeat;
}
#btn-pins .ic-pin { color: var(--pin); }
ul.members li { display: flex; gap: 0.6rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
ul.members li p { margin: 0.15rem 0 0; font-size: 0.85rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-top: 0.45rem; flex: none; }
.dot.on { background: var(--online); }
.dot.left { background: transparent; border: 1px solid var(--muted); }
.panel .sub { margin: 1.2rem 0 0.4rem; font-size: 0.9rem; color: var(--muted); }
pre.invite { white-space: pre-wrap; word-break: break-word; background: var(--code-bg); padding: 0.75rem; border-radius: 8px; font-family: var(--font); font-size: 0.9rem; user-select: all; }

.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 0.5rem 12px; padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); position: relative; }
.composer .row { gap: 0.4rem; align-items: flex-end; }
.composer textarea { resize: none; max-height: 180px; min-height: 40px; line-height: 1.4; }
.composer .at { font: inherit; font-weight: 700; width: 40px; height: 40px; flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); cursor: pointer; }
.composer .btn { flex: none; }
.replying { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); padding: 0 0 0.4rem; }
.replying span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker {
  position: absolute; left: 12px; right: 12px; bottom: calc(100% + 4px); max-height: 40vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
.picker button { display: block; width: 100%; text-align: left; font: inherit; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 0.6rem 0.8rem; color: var(--fg); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 761px) {
  .feed, .composer .row, .replying { max-width: 860px; margin-left: auto; margin-right: auto; width: 100%; }
  .panel { left: auto; right: 16px; bottom: 80px; width: 380px; border-radius: 16px; border: 1px solid var(--line); }
}
