/* NeverSaved — cryptic, quiet, dark. No external fonts or assets: nothing loads from anywhere else. */
:root {
  --bg: #07090b;
  --bg-2: #0b0f12;
  --panel: #0e1317;
  --line: #1b252c;
  --line-2: #263540;
  --text: #cdd7dc;
  --dim: #6f8089;
  --faint: #3d4b53;
  --accent: #7dffb2;
  --accent-dim: #2f6b4b;
  --accent-ink: #04150c;
  --danger: #ff5f6d;
  --warn: #ffc56b;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(125, 255, 178, 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(120, 140, 255, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 3px),
    linear-gradient(90deg, rgba(125,255,178,0.025) 1px, transparent 1px);
  background-size: auto, 48px 48px;
}

#app {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto;
  min-height: 100%;
  padding: 20px 20px 32px;
  display: flex; flex-direction: column;
}

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 0 28px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.spark { width: 22px; height: 22px; color: var(--accent); fill: none; filter: drop-shadow(0 0 8px rgba(125,255,178,0.55)); flex: none; }
:root { --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif; }
.wordmark { font-weight: 700; letter-spacing: 0.2em; font-size: 14px; text-transform: uppercase; }
[data-theme] .wordmark { text-transform: none; }
.tag { margin-inline-start: auto; color: var(--dim); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }

/* ---------- type ---------- */
.kicker { color: var(--accent); opacity: 0.8; font-size: 12px; margin: 8px 0 6px; letter-spacing: 0.08em; }
h1 { font-size: clamp(26px, 5.4vw, 40px); line-height: 1.12; margin: 0 0 14px; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
.pulse { display: flex; align-items: center; gap: 10px; margin: -4px 0 16px; color: var(--dim); font-size: 13px; }
.pulse b { color: var(--accent); font-weight: 700; }
.lede { color: var(--dim); margin: 0 0 24px; max-width: 56ch; }
code { font-family: var(--mono); color: var(--accent); }

/* ---------- controls ---------- */
button, .primary {
  font: inherit; color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .15s, background .15s, color .15s, box-shadow .15s;
}
button:hover { border-color: var(--accent-dim); }
button:focus-visible, .primary:focus-visible, textarea:focus-visible, input:focus-visible + span {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button:disabled { opacity: .5; cursor: progress; }
.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 700; letter-spacing: 0.04em;
  box-shadow: 0 0 0 0 rgba(125,255,178,0), 0 8px 30px -12px rgba(125,255,178,0.6);
}
.primary:hover { background: #a6ffcb; border-color: #a6ffcb; }
.danger { color: var(--danger); border-color: rgba(255,95,109,0.35); }
.danger:hover { border-color: var(--danger); background: rgba(255,95,109,0.08); }
.primary.danger { background: var(--danger); color: #1a0306; border-color: var(--danger); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.row.end { justify-content: flex-end; margin-bottom: 0; }

/* ---------- create ---------- */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent), var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid; gap: 22px;
}
.field { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--dim); padding: 0; }
.field small { color: var(--faint); font-size: 12px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: 8px; width: max-content; overflow: hidden; }
.stepper button { border: 0; border-radius: 0; width: 46px; height: 44px; font-size: 20px; background: transparent; }
.stepper button:hover { background: rgba(125,255,178,0.06); }
.stepper output { min-width: 64px; text-align: center; font-size: 22px; font-weight: 700; color: var(--accent); border-inline: 1px solid var(--line-2); line-height: 44px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 8px 14px; border: 1px solid var(--line-2); border-radius: 8px; color: var(--dim); font-size: 13px; }
.seg input:checked + span { color: var(--accent); border-color: var(--accent-dim); background: rgba(125,255,178,0.07); }
#create-form .primary { justify-self: start; padding: 12px 22px; }

.facts { list-style: none; padding: 0; margin: 26px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.facts li { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 2px; }
.facts b { color: var(--accent); font-size: 18px; }
.facts span { color: var(--dim); font-size: 12px; }

/* ---------- share / join ---------- */
.sharecard {
  display: flex; align-items: center; gap: 16px;
  border: 1px solid var(--line-2); border-radius: 14px;
  padding: 16px 20px; margin: 0 0 18px; max-width: 420px;
  background:
    radial-gradient(240px 120px at 0% 50%, rgba(125,255,178,0.12), transparent 70%),
    var(--bg-2);
}
.sharecard .spark { width: 40px; height: 40px; }
.sharecard strong { display: block; font-size: 20px; }
.sharecard span { color: var(--dim); font-size: 12px; letter-spacing: 0.06em; }
.sharecard.big { padding: 22px 26px; margin-bottom: 28px; }
.sharecard.big .spark { width: 54px; height: 54px; }
.sharecard.big strong { font-size: 26px; }

.linkbox {
  border: 1px dashed var(--accent-dim); border-radius: 8px;
  padding: 12px 14px; background: rgba(125,255,178,0.03);
  word-break: break-all; font-size: 13px; user-select: all;
}
.warn { color: var(--warn); font-size: 13px; margin: 6px 0 22px; opacity: .9; }
.warn code { color: var(--warn); }
.rules { list-style: none; padding: 0; margin: 0 0 26px; display: grid; gap: 8px; }
.rules li { padding-inline-start: 22px; position: relative; color: var(--text); }
.rules li::before { content: "›"; position: absolute; inset-inline-start: 4px; color: var(--accent); }
#btn-join, #btn-enter, #v-ended .primary { align-self: flex-start; padding: 12px 26px; }
.err { color: var(--danger); font-size: 13px; margin: 10px 0 0; }

/* ---------- room ---------- */
body[data-view="v-room"] #app { height: 100dvh; min-height: 0; padding-bottom: 12px; }
body[data-view="v-room"] .brand { padding-bottom: 12px; }
.room { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.room-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding-block: 8px; padding-inline: 14px 10px; background: var(--bg-2);
  font-size: 12px;
}
.status { display: flex; align-items: center; gap: 8px; color: var(--dim); }
.sep { color: var(--faint); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.fp { padding: 4px 10px; font-size: 12px; color: var(--dim); border-style: dashed; letter-spacing: 0.06em; }
.fp span { color: var(--accent); }
.actions { margin-inline-start: auto; display: flex; gap: 6px; }
.actions button { padding: 6px 12px; font-size: 12px; }
.banner { margin-top: 8px; padding: 8px 12px; border-radius: 8px; border: 1px solid rgba(255,197,107,0.35); color: var(--warn); font-size: 12px; }

.stage { position: relative; flex: 1; min-height: 0; margin: 10px 0; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(7,9,11,0.6); overflow: hidden; }
.watermark { position: absolute; inset: 0; pointer-events: none; z-index: 2; background-repeat: repeat; }
.log {
  list-style: none; margin: 0; padding: 16px;
  height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.log > :first-child { margin-top: auto; }
.log > li { flex-shrink: 0; } /* never squash bubbles; the log scrolls instead */
.sys { color: var(--faint); font-size: 12px; text-align: center; padding: 2px 0; }
.sys::before { content: "— "; }
.sys::after { content: " —"; }
.msg {
  position: relative; max-width: min(78%, 520px);
  align-self: flex-start;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 4px 12px 12px 12px; padding: 8px 12px 10px;
  overflow: hidden;
  animation: in .25s ease-out;
  transition: opacity .6s, filter .6s, transform .6s;
}
.msg.mine { align-self: flex-end; border-color: var(--accent-dim); background: rgba(125,255,178,0.05); border-radius: 12px 4px 12px 12px; }
.who { display: block; font-size: 11px; color: var(--dim); letter-spacing: 0.06em; margin-bottom: 2px; }
.mine .who { color: var(--accent); opacity: .8; }
.body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.fuse { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--accent-dim); transform-origin: left; animation: fuse linear forwards; }
@keyframes fuse { to { transform: scaleX(0); } }
@keyframes in { from { opacity: 0; transform: translateY(4px); } }
.msg.gone { opacity: 0; filter: blur(6px); transform: scale(.98); }

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; font: inherit; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 11px 14px; min-height: 46px; max-height: 160px; line-height: 1.45;
}
.composer textarea::placeholder { color: var(--faint); }
.composer textarea:focus { border-color: var(--accent-dim); outline: none; }
.composer .primary { height: 46px; }

/* ---------- emoji + photos ---------- */
.composer .tool {
  width: 46px; height: 46px; padding: 0; flex: none;
  background: transparent; border-color: transparent; color: var(--dim);
}
.composer .tool:hover, .composer .tool[aria-expanded="true"] { color: var(--text); border-color: var(--line-2); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.emoji-panel {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px;
  max-height: 168px; overflow-y: auto; margin: 0 0 8px; padding: 8px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2);
}
.emoji-panel button { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 8px 0; border-radius: 8px; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.emoji-panel button:hover { background: var(--panel); }
.msg.photo { padding: 6px 6px 8px; }
.msg.photo .who { padding: 2px 6px 0; }
.msg .pic {
  display: block; max-width: 100%; max-height: 340px; margin-top: 4px; border-radius: 10px;
  pointer-events: none; user-select: none; -webkit-user-select: none; -webkit-user-drag: none;
}
.msg .note { padding: 2px 6px; font-style: italic; opacity: .75; }
.msg .once {
  display: block; width: 100%; margin-top: 4px; padding: 22px 14px; border-radius: 10px;
  border: 1px dashed var(--line-2); background: var(--bg-2); color: var(--text); font-size: 14px;
}
.msg.mine .once { background: transparent; color: inherit; }
.photo-confirm img { display: block; max-width: 100%; max-height: min(200px, 30vh); margin: 0 auto 12px; border-radius: 10px; }
.photo-confirm label { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.photo-confirm input { width: 18px; height: 18px; accent-color: var(--accent); }
body.veiled .emoji-panel { filter: blur(14px) saturate(0); }

/* footer links + /verify page (generated by the server) */
.foot-links { margin: 28px 0 0; font-size: 13px; color: var(--dim); text-align: center; }
.foot-links a, .page a { color: var(--dim); }
.page h2 { font-size: 18px; margin: 28px 0 8px; }
.page ol { padding-inline-start: 20px; display: grid; gap: 6px; color: var(--dim); }
.release { font-size: 15px; color: var(--dim); }
.release strong { font-family: var(--mono); font-size: 20px; color: var(--text); letter-spacing: .04em; margin-inline-start: 6px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); margin: 16px 0 24px; }
.hashes { width: 100%; border-collapse: collapse; font-size: 12px; }
.hashes th, .hashes td { text-align: start; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.hashes .hash { word-break: break-all; color: var(--dim); }
.page .brand a.wordmark { text-decoration: none; }

/* create options, invite links, QR, knocks, timer */
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--faint); font-size: 12px; }
.links { display: grid; gap: 14px; margin: 0 0 14px; }
.link-row { display: grid; gap: 6px; }
.link-row .row { margin: 0; }
.link-row button { padding: 6px 12px; font-size: 13px; }
.link-label { margin: 0; font-size: 12px; color: var(--dim); }
.link-row code.linkbox { display: block; font-size: 12px; }
dialog .links { max-height: 52vh; overflow-y: auto; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; color: #000; border-radius: 12px; }
.qr svg { width: min(280px, 70vw); height: auto; display: block; }
.knocks { display: grid; gap: 6px; margin-top: 8px; }
.knocks:empty { display: none; }
.knock {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px;
  border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--bg-2); font-size: 14px;
}
.knock span { flex: 1; min-width: 160px; }
.knock button { padding: 6px 14px; font-size: 13px; }
.actions .panic { color: var(--danger); border-style: dashed; }
.rec-bar {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding-block: 8px; padding-inline: 14px 10px;
  border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--bg-2); font-size: 14px;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
#rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { flex: 1; color: var(--dim); font-size: 12px; }
.rec-bar button { padding: 6px 12px; font-size: 13px; }
.composer .tool[aria-pressed="true"] { color: var(--danger); }
.msg.voice audio { display: block; width: min(280px, 64vw); height: 40px; margin-top: 6px; }
@media (max-width: 560px) { .rec-hint { display: none; } }
.timer { color: var(--warn); font-variant-numeric: tabular-nums; }
.timer.soon { color: var(--danger); font-weight: 600; }
#join-wait { margin-top: 14px; }

/* photo cleaning: loader line + "removed before sending" checklist */
.photo-status {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2);
  color: var(--dim); font-size: 13px;
}
.spin {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-2); border-top-color: var(--text);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.scrub { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; background: var(--panel); }
.scrub-title { margin: 0 0 4px !important; font-size: 13px; font-weight: 600; color: var(--text) !important; }
.scrub ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 13px; color: var(--dim); }
.scrub li::before { content: "✓"; display: inline-block; width: 18px; font-weight: 700; color: #1f8a5b; }
[data-mode="dark"] .scrub li::before { color: #4fd69c; }
@media (max-width: 560px) { .composer .tool { width: 38px; } }
.notice { margin: 8px 0 0; font-size: 11px; color: var(--faint); text-align: center; }
.notice b { color: var(--dim); font-weight: 600; }

/* ---------- privacy veil ---------- */
body.veiled .stage, body.veiled .composer, body.veiled .room-bar { filter: blur(14px) saturate(0); }
.shield {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; text-align: center;
  background: rgba(5,7,9,0.82); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  cursor: pointer;
}
.shield[hidden] { display: none; }
.shield .spark { width: 40px; height: 40px; margin-bottom: 8px; }
.shield p { margin: 0; font-weight: 700; }
.shield small { color: var(--dim); }
@media print { body * { display: none !important; } }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line-2); border-radius: 14px; padding: 22px;
  background: var(--bg-2); color: var(--text); max-width: min(460px, calc(100vw - 32px));
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.8);
}
dialog::backdrop { background: rgba(3,5,7,0.7); backdrop-filter: blur(6px); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog p { margin: 0 0 14px; color: var(--dim); }
#dlg-extra:empty { display: none; }
#dlg-extra { margin-bottom: 14px; }

/* ---------- ended ---------- */
#v-ended { padding-top: 6vh; }

/* ---------- small screens ---------- */
@media (max-width: 560px) {
  #app { padding: 14px 14px 20px; }
  .tag { display: none; }
  .facts { grid-template-columns: 1fr; }
  .room-bar { padding: 8px; }
  .actions { margin-inline-start: 0; width: 100%; }
  .actions button { flex: 1; }
  .msg { max-width: 88%; }
  .fp { margin-inline-start: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =====================================================================
   Theme candidates (preview with ?theme=midnight or ?theme=ghost)
   ===================================================================== */
:root { --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; --wm: #9fffc9; }

/* ---------- 2. Midnight: calm navy + violet, soft and rounded ---------- */
:root[data-theme="midnight"] {
  --bg: #0b0e1f; --bg-2: #12162e; --panel: #171c3a; --line: #232a4f; --line-2: #313a68;
  --text: #e8e9f8; --dim: #9ca2cc; --faint: #5f6594;
  --accent: #a193ff; --accent-dim: #4e46a8; --accent-ink: #0b0e1f;
  --danger: #ff6b81; --warn: #ffc979; --radius: 18px; --wm: #c9c2ff;
}
[data-theme="midnight"] body {
  font-family: var(--sans); font-size: 16px; line-height: 1.6;
  background: radial-gradient(900px 520px at 85% -10%, rgba(161,147,255,0.16), transparent 60%),
              radial-gradient(700px 420px at -10% 110%, rgba(90,140,255,0.10), transparent 60%), var(--bg);
}
[data-theme="midnight"] .grain, [data-theme="midnight"] .kicker { display: none; }
[data-theme="midnight"] .spark { filter: drop-shadow(0 0 10px rgba(161,147,255,0.6)); }
[data-theme="midnight"] .wordmark { letter-spacing: 0.02em; font-weight: 600; font-size: 16px; }
[data-theme="midnight"] .tag { text-transform: none; letter-spacing: 0; font-size: 12px; }
[data-theme="midnight"] h1 { font-weight: 650; letter-spacing: -0.02em; font-size: clamp(30px, 6vw, 46px); }
[data-theme="midnight"] button, [data-theme="midnight"] .primary { border-radius: 999px; }
[data-theme="midnight"] .primary { font-weight: 600; letter-spacing: 0; box-shadow: 0 10px 30px -12px rgba(161,147,255,0.7); }
[data-theme="midnight"] .primary:hover { background: #b8adff; border-color: #b8adff; }
[data-theme="midnight"] .card { background: var(--bg-2); border-radius: 22px; padding: 24px; }
[data-theme="midnight"] .label { text-transform: none; letter-spacing: 0; font-size: 13px; }
[data-theme="midnight"] .stepper, [data-theme="midnight"] .seg span { border-radius: 999px; }
[data-theme="midnight"] .stepper button:hover, [data-theme="midnight"] .seg input:checked + span { background: rgba(161,147,255,0.14); }
[data-theme="midnight"] .pulse { display: inline-flex; width: max-content; padding: 4px 14px 4px 10px; border-radius: 999px; background: #1c2148; color: #c9c2ff; }
[data-theme="midnight"] .sharecard { border-radius: 22px; background: radial-gradient(240px 120px at 0% 50%, rgba(161,147,255,0.18), transparent 70%), var(--bg-2); }
[data-theme="midnight"] .linkbox { border-radius: 14px; background: rgba(161,147,255,0.06); }
[data-theme="midnight"] .msg { border-radius: 6px 18px 18px 18px; padding: 10px 14px 12px; }
[data-theme="midnight"] .msg.mine { background: #2a2470; border-color: #3d36a0; border-radius: 18px 6px 18px 18px; }
[data-theme="midnight"] .composer textarea { border-radius: 22px; padding: 12px 18px; }
[data-theme="midnight"] .stage { background: rgba(11,14,31,0.6); }
[data-theme="midnight"] .shield { background: rgba(11,14,31,0.85); }
[data-theme="midnight"] .sys::before, [data-theme="midnight"] .sys::after { content: ""; }

/* ---------- 6. Ghost: bright, clean, minimal ---------- */
:root[data-theme="ghost"] {
  color-scheme: light;
  --bg: #fafafa; --bg-2: #ffffff; --panel: #f2f2f3; --line: #e7e7e9; --line-2: #d9d9dd;
  --text: #111113; --dim: #6b6b72; --faint: #a6a6ad;
  --accent: #111113; --accent-dim: #c9c9cf; --accent-ink: #ffffff;
  --danger: #d92d20; --warn: #a15c00; --radius: 14px; --wm: #111113;
  --blue: #2a7fff;
}
[data-theme="ghost"] body { font-family: var(--sans); font-size: 16px; line-height: 1.6; background: var(--bg); }
[data-theme="ghost"] .grain, [data-theme="ghost"] .kicker, [data-theme="ghost"] .tag { display: none; }
[data-theme="ghost"] .spark { color: var(--text); filter: none; }
[data-theme="ghost"] .brand .spark { width: 28px; height: 28px; }
[data-theme="ghost"] .wordmark { font-family: var(--serif); font-style: italic; font-weight: 700; letter-spacing: -0.01em; font-size: 21px; color: var(--text); }
[data-theme="ghost"] h1 { font-weight: 450; letter-spacing: -0.025em; font-size: clamp(30px, 6vw, 48px); line-height: 1.1; }
[data-theme="ghost"] .lede { font-size: 17px; }
[data-theme="ghost"] .primary { font-weight: 500; letter-spacing: 0; box-shadow: none; border-radius: 10px; }
[data-theme="ghost"] .primary:hover { background: #2c2c30; border-color: #2c2c30; }
[data-theme="ghost"] button { border-radius: 10px; }
[data-theme="ghost"] button:not(.primary):not(.danger) { background: var(--bg-2); }
[data-theme="ghost"] button:not(.primary):hover { border-color: #b5b5bc; }
[data-theme="ghost"] .card { background: var(--bg-2); border-radius: 18px; padding: 24px; box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px -12px rgba(0,0,0,0.08); }
[data-theme="ghost"] .label { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--dim); }
[data-theme="ghost"] .stepper button:hover { background: var(--panel); }
[data-theme="ghost"] .seg input:checked + span { color: var(--text); border-color: var(--text); background: var(--panel); }
[data-theme="ghost"] .dot { background: var(--blue); box-shadow: none; }
[data-theme="ghost"] .pulse b, [data-theme="ghost"] .facts b { color: var(--text); font-weight: 600; }
[data-theme="ghost"] .facts li { border-top-color: var(--line-2); }
[data-theme="ghost"] .sharecard { background: var(--bg-2); border-radius: 18px; box-shadow: 0 8px 24px -14px rgba(0,0,0,0.15); }
[data-theme="ghost"] .linkbox { background: var(--panel); border: 1px solid var(--line); }
[data-theme="ghost"] code { color: var(--text); }
[data-theme="ghost"] .rules li::before { color: var(--blue); }
[data-theme="ghost"] .room-bar, [data-theme="ghost"] .stage { background: var(--bg-2); }
[data-theme="ghost"] .fp span { color: var(--text); }
[data-theme="ghost"] .msg { background: var(--panel); border-color: transparent; border-radius: 6px 18px 18px 18px; padding: 10px 14px 12px; }
[data-theme="ghost"] .msg.mine { background: #111113; color: #fff; border-color: #111113; border-radius: 18px 6px 18px 18px; }
/* Ghost: each person's name in their own colour; the message itself is the biggest, plainest text */
.msg[data-c="0"] { --deep: #2a6fdb; --bright: #6ea8ff; }
.msg[data-c="1"] { --deep: #c2416b; --bright: #ff7aa2; }
.msg[data-c="2"] { --deep: #1f8a5b; --bright: #4fd69c; }
.msg[data-c="3"] { --deep: #b45309; --bright: #f5b454; }
.msg[data-c="4"] { --deep: #7c4dcc; --bright: #b99bff; }
.msg[data-c="5"] { --deep: #0e7c86; --bright: #4cd3df; }
.msg[data-c="6"] { --deep: #c2410c; --bright: #ff9a62; }
.msg[data-c="7"] { --deep: #a23bb0; --bright: #e78ef0; }
[data-theme="ghost"] .msg .who { color: var(--deep); font-size: 12px; font-weight: 600; letter-spacing: 0; margin-bottom: 3px; }
[data-theme="ghost"] .msg.mine .who { color: var(--bright); opacity: 1; }
[data-theme="ghost"] .who .you { display: none; }
[data-theme="ghost"] .body { font-size: 15px; line-height: 1.45; }
[data-theme="ghost"] .fuse { background: var(--blue); opacity: .5; }
[data-theme="ghost"] .composer textarea { background: var(--bg-2); border-radius: 14px; }
[data-theme="ghost"] .composer textarea:focus { border-color: #9a9aa2; }
[data-theme="ghost"] .shield { background: rgba(250,250,250,0.86); }
[data-theme="ghost"] .shield .spark { color: var(--text); }
[data-theme="ghost"] dialog { box-shadow: 0 30px 80px -20px rgba(0,0,0,0.25); }
[data-theme="ghost"] dialog::backdrop { background: rgba(250,250,250,0.6); }
[data-theme="ghost"] .sys::before, [data-theme="ghost"] .sys::after { content: ""; }
[data-theme="ghost"] body { transition: background-color .25s, color .25s; }

/* Ghost: light/dark toggle button */
[data-theme="ghost"] .mode-toggle {
  display: inline-flex; margin-inline-start: auto; width: 38px; height: 38px; padding: 0;
  border-radius: 50%; color: var(--dim);
}
[data-theme="ghost"] .mode-toggle:hover { color: var(--text); }
.mode-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mode-toggle .i-sun, [data-mode="dark"] .mode-toggle .i-moon { display: none; }
[data-mode="dark"] .mode-toggle .i-sun { display: block; }

/* Ghost dark */
:root[data-theme="ghost"][data-mode="dark"] {
  color-scheme: dark;
  --bg: #0e0e10; --bg-2: #17171a; --panel: #212125; --line: #2a2a2f; --line-2: #37373d;
  --text: #f1f1f3; --dim: #9b9ba3; --faint: #5f5f67;
  --accent: #f1f1f3; --accent-dim: #3c3c43; --accent-ink: #0e0e10;
  --danger: #ff6b5e; --warn: #f0b45a; --wm: #ffffff; --blue: #5b9dff;
}
[data-theme="ghost"][data-mode="dark"] .primary:hover { background: #d6d6db; border-color: #d6d6db; }
[data-theme="ghost"][data-mode="dark"] button:not(.primary):hover { border-color: #4b4b52; }
[data-theme="ghost"][data-mode="dark"] .card,
[data-theme="ghost"][data-mode="dark"] .sharecard { box-shadow: none; }
[data-theme="ghost"][data-mode="dark"] .msg.mine { background: #f1f1f3; color: #0e0e10; border-color: #f1f1f3; }
[data-theme="ghost"][data-mode="dark"] .msg .who { color: var(--bright); }
[data-theme="ghost"][data-mode="dark"] .msg.mine .who { color: var(--deep); }
[data-theme="ghost"][data-mode="dark"] .composer textarea:focus { border-color: #5a5a62; }
[data-theme="ghost"][data-mode="dark"] .shield { background: rgba(14,14,16,0.88); }
[data-theme="ghost"][data-mode="dark"] dialog { box-shadow: 0 30px 80px -20px rgba(0,0,0,0.8); }
[data-theme="ghost"][data-mode="dark"] dialog::backdrop { background: rgba(0,0,0,0.55); }

/* =====================================================================
   Language: toggle button, Arabic type, and right-to-left (dir="rtl" is set on <html> by i18n.js)
   ===================================================================== */
html[data-i18n-wait] body { visibility: hidden; } /* no flash of English before the Arabic text is in */
:root { --ar: "Segoe UI", "Noto Sans Arabic", "Geeza Pro", Tahoma, "Arabic Typesetting", sans-serif; }

button.lang-toggle {
  display: inline-flex; margin-inline-start: auto; flex: none;
  min-width: 38px; height: 38px; padding: 0 10px; border-radius: 999px;
  color: var(--dim); font-size: 14px; font-weight: 600; letter-spacing: 0; line-height: 1;
}
button.lang-toggle:hover { color: var(--text); }
.tag ~ button.lang-toggle { margin-inline-start: 12px; }
.mode-toggle:not([hidden]) ~ button.lang-toggle { margin-inline-start: 0; }
.mode-toggle:not([hidden]) { margin-inline-start: auto; }

/* things that must stay left-to-right inside Arabic text: links, codes, fingerprints, hashes, timers */
.linkbox, .hashes .hash { direction: ltr; text-align: left; unicode-bidi: isolate; }
#fingerprint, .release strong, .timer, #rec-time, code, .page td code { unicode-bidi: isolate; }
#fingerprint, .release strong, #rec-time, .hashes code { direction: ltr; }
.hashes td:first-child code { direction: ltr; }

[dir="rtl"] .rules li::before { content: "‹"; }
[dir="rtl"] .kicker [aria-hidden="true"] { display: none; }
/* bubble "tail" corner moves to the other side */
[dir="rtl"] .msg { border-radius: 12px 4px 12px 12px; }
[dir="rtl"] .msg.mine { border-radius: 4px 12px 12px 12px; }
[dir="rtl"][data-theme="midnight"] .msg { border-radius: 18px 6px 18px 18px; }
[dir="rtl"][data-theme="midnight"] .msg.mine { border-radius: 6px 18px 18px 18px; }
[dir="rtl"][data-theme="ghost"] .msg { border-radius: 18px 6px 18px 18px; }
[dir="rtl"][data-theme="ghost"] .msg.mine { border-radius: 6px 18px 18px 18px; }
/* vanish bar shrinks toward the reading-start side */
[dir="rtl"] .fuse { left: auto; right: 0; transform-origin: right; }
[dir="rtl"] .sharecard { background: radial-gradient(240px 120px at 100% 50%, rgba(125,255,178,0.12), transparent 70%), var(--bg-2); }
[dir="rtl"][data-theme="midnight"] .sharecard { background: radial-gradient(240px 120px at 100% 50%, rgba(161,147,255,0.18), transparent 70%), var(--bg-2); }
[dir="rtl"][data-theme="ghost"] .sharecard { background: var(--bg-2); }
[dir="rtl"] .composer textarea { text-align: start; }
[dir="rtl"] .doc .diagram svg { direction: ltr; } /* the picture keeps its left-to-right flow */

/* Arabic: a proper Arabic font first, a little more line height, and no letter-spacing (it breaks the joined letters) */
html[lang="ar"] body, html[lang="ar"] button, html[lang="ar"] textarea, html[lang="ar"] dialog { font-family: var(--ar); }
html[lang="ar"] body { line-height: 1.75; }
html[lang="ar"] h1 { line-height: 1.4; letter-spacing: 0; }
html[lang="ar"][data-theme="ghost"] body { line-height: 1.75; }
html[lang="ar"] .doc h2, html[lang="ar"] .doc .promise, html[lang="ar"] .doc .diagram .lbl, html[lang="ar"] .doc .diagram .sub { font-family: var(--ar); }
html[lang="ar"] .doc p, html[lang="ar"] .doc li { line-height: 1.85; }
html[lang="ar"] .body, html[lang="ar"][data-theme="ghost"] .body { line-height: 1.7; }
html[lang="ar"] code, html[lang="ar"] .linkbox, html[lang="ar"] .hash { font-family: var(--mono); }
html[lang="ar"] *:not(.wordmark):not(.fp):not(.fp *) { letter-spacing: normal !important; text-transform: none !important; }
html[lang="ar"] .wordmark { letter-spacing: -0.01em; }

/* =====================================================================
   Phones & small screens (kept last so it wins over everything above)
   ===================================================================== */
/* Keep content clear of the notch and the home bar on newer phones. */
#app {
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}
body[data-view="v-room"] #app { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
html, body { overflow-x: hidden; }
/* Dialogs always fit the screen and scroll inside if needed. */
dialog { max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }
button, .seg span, .primary { touch-action: manipulation; }

@media (max-width: 560px) {
  #app {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  /* iPhones zoom in when a text box uses text smaller than 16px. */
  textarea, input[type="text"], input:not([type]) { font-size: 16px; }
  /* Comfortable thumb targets. */
  .seg span { min-height: 40px; display: flex; align-items: center; padding: 8px 14px; }
  .stepper button { width: 52px; height: 48px; }
  .stepper output { line-height: 48px; }
  dialog { width: calc(100vw - 20px); padding: 18px; }
  dialog .row.end button { flex: 1; min-height: 44px; }

  /* Room bar: status on one line (wrapping cleanly), then the action buttons in an even row. */
  .room-bar { gap: 6px 8px; padding: 8px; }
  .status { flex-wrap: wrap; row-gap: 2px; min-width: 0; font-size: 12px; }
  .status > span { white-space: nowrap; }
  .actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; width: 100%; margin: 0; }
  .actions button { white-space: nowrap; padding: 8px 4px; font-size: 12px; min-height: 38px; min-width: 0; }

  /* Message bar: text box gets the whole width; emoji / photo / voice and Send sit underneath. */
  .composer {
    display: grid; gap: 6px;
    grid-template-columns: auto auto auto 1fr auto;
    grid-template-areas: "ta ta ta ta ta" "em ph vo . go";
  }
  .composer textarea { grid-area: ta; }
  .composer #btn-emoji { grid-area: em; }
  .composer #btn-photo { grid-area: ph; }
  .composer #btn-voice { grid-area: vo; }
  .composer button[type="submit"] { grid-area: go; height: 44px; padding: 0 22px; }
  .composer .tool { width: 44px; height: 44px; }
  .notice { font-size: 10.5px; margin-top: 6px; }

  .knock { padding: 10px; }
  .knock span { min-width: 100%; }
  .knock button { flex: 1; min-height: 40px; }
  .rec-bar { padding: 8px; }
  .rec-bar button { min-height: 38px; }
  .link-row button { flex: 1; min-height: 40px; white-space: nowrap; padding: 8px 6px; font-size: 12px; }
  .emoji-panel { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); max-height: 30dvh; }
  .msg .pic { max-height: 46dvh; }
  h1 { font-size: clamp(26px, 8vw, 34px); }
}

/* Very small phones (320px wide). */
@media (max-width: 360px) {
  #app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .actions button { font-size: 11px; }
  .msg { max-width: 92%; }
}

/* Phones turned sideways: give the chat the height. */
@media (max-height: 500px) and (orientation: landscape) {
  body[data-view="v-room"] .brand,
  body[data-view="v-room"] .notice { display: none; }
  body[data-view="v-room"] #app { padding-top: max(8px, env(safe-area-inset-top)); }
  .composer { grid-template-areas: none; grid-template-columns: none; display: flex; }
  .composer textarea { max-height: 72px; }
  .emoji-panel { max-height: 40dvh; }
  .stage { margin: 6px 0; }
}

/* Tablets: a little wider reading column for the chat. */
@media (min-width: 900px) {
  body[data-view="v-room"] #app { max-width: 860px; }
}
