:root {
  --accent: #e8590c;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --fg: #1b1b1a;
  --muted: #6b6a66;
  --line: #e3e1db;
  --soft: #f0eee9;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --err: #b42318;
  --err-bg: #fdecea;
  --bubble-in: #ffffff;
  --bubble-out: #e8590c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211; --panel: #1c1c1b; --fg: #f2f1ee; --muted: #a3a29d; --line: #2e2d2b; --soft: #252523;
    --ok: #4ac26b; --ok-bg: #16301f; --warn: #e3b341; --warn-bg: #3a2f10; --err: #ff7b6b; --err-bg: #3d1b17;
    --bubble-in: #2a2a28; --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
nav a.on { color: var(--fg); background: var(--soft); }
main { max-width: 1240px; margin: 0 auto; padding: 24px; }

/* banner */
#banner .b { max-width: 1240px; margin: 12px auto 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-size: 14px; }
#banner .b + .b { margin-top: 8px; }
#banner .b code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }

/* controls */
button, .btn { font: inherit; font-weight: 600; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); padding: 8px 14px; cursor: pointer; min-height: 38px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--err); }
button.link { border: 0; background: none; color: var(--muted); padding: 6px; min-height: 0; }
button:disabled { opacity: .55; cursor: default; }
input, textarea, select { font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.pagehead { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* chips / pills */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 6px 12px; min-height: 0; font-size: 13px; }
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.accent { background: var(--accent); color: #fff; }

/* story cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .1s, border-color .1s; }
.card:hover { border-color: var(--muted); transform: translateY(-1px); }
.card .cover { aspect-ratio: 16/9; background: var(--soft) center/cover no-repeat; }
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .who { font-weight: 700; }
.card .q { color: var(--muted); font-size: 13px; }
.card .preview { font-size: 15px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty b { color: var(--fg); display: block; font-size: 17px; margin-bottom: 6px; }

/* story detail */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
@media (max-width: 980px) { .split { grid-template-columns: 1fr; } }
.thread { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: #fff; border-bottom-right-radius: 4px; }
.bubble.out.staff { background: #3b5bdb; }
.bubble.out.system { background: var(--soft); color: var(--muted); border: 1px dashed var(--line); }
.bubble .t { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }
.note { align-self: center; font-size: 12px; color: var(--muted); background: var(--soft); padding: 4px 10px; border-radius: 999px; text-align: center; max-width: 90%; }
.thread .who { font-size: 11px; color: var(--muted); margin: 6px 4px -4px; }
.thread .who.r { align-self: flex-end; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: var(--soft); border-radius: 10px; overflow: hidden; position: relative; }
.gallery img, .gallery video { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #000; }
.gallery figcaption { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; font-size: 12px; }
.gallery a { color: var(--muted); }

.posts { display: flex; flex-direction: column; gap: 14px; }
.post { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--panel); }
.post.posted { border-color: var(--ok); }
.post header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.post header b { font-size: 14px; }
.post textarea { min-height: 140px; }
.post .mn { font-size: 13px; color: var(--muted); margin: 8px 0; }
.post .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.post .publish { margin-top: 10px; padding: 12px; background: var(--soft); border-radius: 10px; display: grid; gap: 8px; }
.cc { font-size: 12px; color: var(--muted); margin-left: auto; }
.cc.over { color: var(--err); font-weight: 700; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: auto; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* team table */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.rate { font-weight: 700; }
.rate.low { color: var(--err); }
.tablewrap { overflow-x: auto; }
@media (max-width: 760px) {
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  td { border: 0; padding: 4px 0; }
}

/* simulator */
.sim { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
@media (max-width: 760px) { .sim { grid-template-columns: 1fr; } }
.people { display: flex; flex-direction: column; gap: 4px; }
.people button[data-id] { justify-content: space-between; text-align: left; border-color: transparent; background: transparent; }
.people button[data-id].on { background: var(--panel); border-color: var(--line); }
.phone { max-width: 420px; margin: 0 auto; width: 100%; border: 1px solid var(--line); border-radius: 28px; background: var(--panel); display: flex; flex-direction: column; height: min(720px, calc(100vh - 180px)); overflow: hidden; box-shadow: var(--shadow); }
.phone .ph-top { padding: 14px; text-align: center; border-bottom: 1px solid var(--line); font-weight: 700; }
.phone .ph-top span { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.phone .thread { flex: 1; overflow-y: auto; padding: 14px; background: var(--bg); }
/* in the simulator you ARE the contributor, so flip sides */
.phone .bubble.in { align-self: flex-end; background: #2f9e44; color: #fff; border: 0; border-bottom-right-radius: 4px; border-bottom-left-radius: 16px; }
.phone .bubble.out { align-self: flex-start; background: var(--bubble-in); color: var(--fg); border: 1px solid var(--line); border-bottom-left-radius: 4px; border-bottom-right-radius: 16px; }
.phone .bubble a { color: inherit; }
.phone form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.phone form input { border-radius: 999px; }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 4px 8px; }

/* login */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { margin-bottom: 18px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--err); color: #fff; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .top { padding: 0 12px; gap: 10px; }
  .brand { font-size: 0; } .brand::before { width: 14px; height: 14px; }
  nav { gap: 0; }
  nav a { padding: 8px 7px; font-size: 14px; }
  #logout { font-size: 13px; white-space: nowrap; }
}
