:root {
  --bg: #faf6f3; --panel: #ffffff; --panel2: #f3ece7; --line: #e6d9d0; --text: #2a1d17; --muted: #6b5549;
  --accent: #c4532a; --accent-soft: #f6e1d6; --friend: #1b6b3a; --friend-soft: #e1f3e6; --owner-soft: #e2ecfb; --owner: #2257b5;
  --ok: #1d7040; --warn: #c98a12; --warn-text: #8f6000; --bad: #c0392b; --accent-text: #a5401c;
  --on-accent: #fff; --on-friend: #fff; --on-bad: #fff; --shadow: 0 1px 2px rgba(60, 30, 15, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14100e; --panel: #1c1613; --panel2: #251d19; --line: #382a24; --text: #f2e8e2; --muted: #b3a097;
    --accent: #ee7d4c; --accent-soft: #3a2219; --friend: #5fd38c; --friend-soft: #142a1c; --owner-soft: #18263d; --owner: #7db0ff;
    --ok: #4cc27b; --warn: #e6a92c; --warn-text: #f0b740; --bad: #ff7b6e; --accent-text: #f08a5d;
    --on-accent: #1a0d07; --on-friend: #06200f; --on-bad: #1a0605; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14100e; --panel: #1c1613; --panel2: #251d19; --line: #382a24; --text: #f2e8e2; --muted: #b3a097;
  --accent: #ee7d4c; --accent-soft: #3a2219; --friend: #5fd38c; --friend-soft: #142a1c; --owner-soft: #18263d; --owner: #7db0ff;
  --ok: #4cc27b; --warn: #e6a92c; --warn-text: #f0b740; --bad: #ff7b6e; --accent-text: #f08a5d;
  --on-accent: #1a0d07; --on-friend: #06200f; --on-bad: #1a0605; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
/* native controls (dropdowns, search boxes, audio players) take the page's colors, not the browser's black-on-white */
button, textarea, input, select { font: inherit; color: inherit; }
select option, select optgroup { background: var(--panel); color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--friend); outline-offset: 1px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.login input { width: 100%; padding: 11px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel2); outline: none; }
.login input:focus { border-color: var(--accent); }
.login button { width: 100%; margin-top: 12px; padding: 11px; border: 0; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.login .err { color: var(--bad); font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ---------- app layout ---------- */
#app { display: grid; grid-template-columns: 300px 1fr; height: 100%; }
#side { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.brand { padding: 16px 16px 4px; font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand .dotm { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#delivery { margin: 6px 12px 8px; font-size: 12.5px; padding: 7px 10px; border-radius: 8px; background: var(--panel2); color: var(--muted); }
#delivery.bad { background: var(--accent-soft); color: var(--text); }
#chats { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.chat { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 10px; padding: 9px 10px; margin: 2px 0; }
.chat:hover { background: var(--panel2); }
.chat.sel { background: var(--accent-soft); }
.chat .t { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13.5px; }
.chat .t span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat .meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.chat .rep { font-size: 12px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat.kid { padding-left: 22px; }
.chat.kid2 { padding-left: 34px; }
.sd { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.sd.work { background: var(--ok); animation: pulse 1.6s infinite; }
.sd.wait { background: var(--warn); }
@keyframes pulse { 50% { opacity: .35; } }
#logout { margin: 8px 12px 12px; padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: none; color: var(--muted); font-size: 13px; }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#top { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
#menu { display: none; border: 1px solid var(--line); background: none; border-radius: 8px; padding: 4px 10px; font-size: 16px; }
#chatTitle { font-weight: 650; font-size: 16px; }
#chatSub { font-size: 12.5px; color: var(--muted); }
#feed { flex: 1; overflow-y: auto; padding: 16px 18px 8px; }
#feedInner { max-width: 860px; margin: 0 auto; }
#older { display: block; margin: 0 auto 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 14px; font-size: 13px; color: var(--muted); }

/* ---------- feed items ---------- */
.msg { margin: 10px 0; padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.msg .who { font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 2px; display: flex; gap: 8px; align-items: baseline; }
.msg .who time { font-weight: 400; }
.msg.owner { background: var(--owner-soft); border-color: transparent; border-left: 4px solid var(--owner); }
.msg.owner .who { color: var(--owner); }
.msg.friend { background: var(--friend-soft); border-color: transparent; border-left: 4px solid var(--friend); }
.msg.friend .who { color: var(--friend); }
.msg.pending { opacity: .85; border-style: dashed; border-color: var(--friend); }
.st { font-weight: 500; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--panel); color: var(--muted); }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 6px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--panel2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--panel2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; margin: 8px 0; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; }
.md a { color: var(--accent-text); }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md h1, .md h2, .md h3 { font-size: 15px; margin: 10px 0 4px; }

details.steps { margin: 6px 2px; font-size: 13px; color: var(--muted); }
details.steps summary { cursor: pointer; list-style: none; padding: 3px 0; }
details.steps summary::-webkit-details-marker { display: none; }
details.steps summary::before { content: "▸ "; }
details.steps[open] summary::before { content: "▾ "; }
details.steps ul { margin: 4px 0 6px; padding-left: 18px; }
details.steps li { margin: 2px 0; }
details.steps li details summary::before { content: ""; }
details.steps li pre { white-space: pre-wrap; font-size: 12.5px; background: var(--panel2); padding: 8px; border-radius: 6px; color: var(--text); }

details.peer { margin: 8px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); font-size: 13.5px; }
details.peer summary { cursor: pointer; padding: 7px 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.peer summary b { color: var(--text); font-weight: 600; }
details.peer .md { padding: 0 12px 10px; }

.recap { margin: 10px 0; padding: 10px 14px; border-radius: 12px; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.recap .lbl { font-size: 12px; font-weight: 650; color: var(--accent-text); margin-bottom: 2px; }
.recap .ask { margin-top: 6px; font-weight: 600; }
.marker { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0; }
.media { margin: 10px 0; }
.media img, .media video { max-width: 100%; max-height: 520px; border-radius: 10px; border: 1px solid var(--line); display: block; margin: 6px 0; background: #000; }
.media .cap { font-size: 13px; color: var(--muted); }
.media .file { font-size: 13px; color: var(--muted); }

/* ---------- context, unread, plan ---------- */
.ctx { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--panel2); padding: 0 6px; border-radius: 999px; flex: none; }
.ctx.warm { color: #2a1d00; background: var(--warn); }
.ctx.hot { color: var(--on-bad); background: var(--bad); }
.chat .new { font-size: 10.5px; font-weight: 700; color: var(--on-friend); background: var(--friend); padding: 0 6px; border-radius: 999px; flex: none; }
.chat.unread .name { color: var(--text); }
.ctxbar { display: inline-block; vertical-align: middle; width: 70px; height: 5px; border-radius: 3px; background: var(--panel2); overflow: hidden; margin-left: 4px; }
.ctxbar i { display: block; height: 100%; background: var(--ok); }
.ctxbar.warm i { background: var(--warn); } .ctxbar.hot i { background: var(--bad); }
#plan { border-bottom: 1px solid var(--line); background: var(--panel); padding: 6px 18px; font-size: 13px; }
#plan[hidden] { display: none; }
#plan summary { cursor: pointer; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#plan ol { margin: 6px 0 4px; padding-left: 22px; }
#plan li.completed { color: var(--muted); text-decoration: line-through; }
#plan li.in_progress { font-weight: 650; color: var(--accent-text); }

/* ---------- edits, looks, step details ---------- */
.edit, .look { margin: 6px 0; font-size: 13.5px; }
.edit .line, .look .line { display: flex; align-items: baseline; gap: 8px; padding: 6px 10px; border-radius: 8px; background: var(--panel2); }
.edit.click .line { cursor: pointer; }
.edit.click .line:hover { outline: 1px solid var(--line); }
.edit time, .look time { margin-left: auto; font-size: 12px; color: var(--muted); }
.edit .ic, .look .ic { width: 18px; text-align: center; flex: none; }
.edit.priv .line { color: var(--muted); }
.cnt { font-size: 12px; margin-left: 4px; } .cnt .a { color: var(--ok); } .cnt .d { color: var(--bad); }
.look img { display: block; max-height: 170px; max-width: 100%; margin: 6px 0 0 28px; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; background: #000; }
li.step.click .lbl { cursor: pointer; border-bottom: 1px dotted var(--muted); }
.det { margin: 6px 0 8px; padding: 8px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.det pre, #modal pre { margin: 6px 0; white-space: pre-wrap; font: 12.5px/1.45 ui-monospace, Consolas, monospace; background: var(--panel2); padding: 8px 10px; border-radius: 6px; max-height: 420px; overflow: auto; }
.det pre.err { border-left: 3px solid var(--bad); }
.diff { font: 12.5px/1.45 ui-monospace, Consolas, monospace; border-radius: 6px; overflow: auto; max-height: 460px; margin: 6px 0; }
.diff div { white-space: pre-wrap; padding: 0 8px; }
.diff .del { background: rgba(212, 72, 59, .14); }
.diff .add { background: rgba(47, 158, 91, .14); }
.muted { color: var(--muted); font-size: 12.5px; }
button.link { border: 0; background: none; color: var(--accent-text); padding: 2px 0; font-size: 13px; text-decoration: underline; }
.media .who { font-size: 12px; color: var(--muted); }
.media img { cursor: zoom-in; }

/* ---------- assets ---------- */
.navbtn { display: block; margin: 0 12px 6px; padding: 9px 12px; text-align: left; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); font-weight: 650; font-size: 14px; }
.navbtn .muted { display: block; font-weight: 400; font-size: 11.5px; }
.navbtn.sel { background: var(--accent-soft); border-color: var(--accent); }
#assets { flex: 1; overflow-y: auto; padding: 14px 18px 24px; }
#assets[hidden], #feed[hidden], #composer[hidden] { display: none; }
.atools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tabs button { border: 0; background: var(--panel); padding: 7px 12px; font-size: 13px; }
.tabs button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
#aChat, #aQ { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; max-width: 100%; }
#aQ { flex: 1; min-width: 120px; }
.agrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.acard { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.acard:hover { border-color: var(--accent); }
.acard .thumb { aspect-ratio: 16 / 9; background: var(--panel2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.acard .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg { color: var(--muted); font-size: 13px; }
.ainfo { padding: 8px 10px 10px; }
.at { font-weight: 650; font-size: 14px; overflow-wrap: anywhere; }
.at.big { font-size: 18px; margin-top: 4px; }
.am, .aw { font-size: 12px; color: var(--muted); margin-top: 2px; }
.aw { color: var(--friend); }
.rs { font-weight: 600; } .rs.ok { color: var(--ok); } .rs.failed { color: var(--bad); } .rs.running { color: var(--warn-text); }
.ahead { margin-bottom: 10px; }
.agroup { margin: 16px 0; }
.agroup h4 { margin: 0 0 8px; font-size: 14px; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.atile { border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 0; overflow: hidden; position: relative; aspect-ratio: 16 / 9; }
.atile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.atile .tn { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.75)); padding: 10px 6px 3px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atile.audio { aspect-ratio: auto; background: var(--panel2); padding: 8px; grid-column: span 2; }
.atile.audio .an { font-size: 12.5px; margin-bottom: 4px; overflow-wrap: anywhere; }
.atile.audio audio { width: 100%; height: 34px; }
.agroup .more { margin-top: 8px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 14px; font-size: 13px; color: var(--muted); }
.lbnav { position: sticky; top: 0; display: flex; justify-content: space-between; pointer-events: none; height: 0; z-index: 2; }
.lbnav button { pointer-events: auto; margin-top: 30vh; border: 0; width: 42px; height: 64px; border-radius: 10px; background: rgba(0,0,0,.45); color: #fff; font-size: 30px; }
.mb video.full { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; background: #000; }

/* ---------- viewer ---------- */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal[hidden] { display: none; }
.mbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 980px; max-height: 100%; display: flex; flex-direction: column; }
.mh { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.mh > div { flex: 1; min-width: 0; }
.mt { font-weight: 650; overflow-wrap: anywhere; }
.ms { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.mx { border: 1px solid var(--line); background: none; border-radius: 8px; padding: 2px 10px; font-size: 15px; }
.mb { overflow: auto; padding: 12px 16px 16px; }
.mb pre.file { max-height: none; }
.mb img.full { max-width: 100%; display: block; margin: 0 auto; border-radius: 8px; }

/* ---------- composer ---------- */
#composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 18px 12px; }
#composerInner { max-width: 860px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#msg { resize: none; min-height: 46px; max-height: 220px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); outline: none; }
#msg:focus { border-color: var(--friend); }
#sendBtn { border: 0; border-radius: 10px; padding: 0 18px; background: var(--friend); color: var(--on-friend); font-weight: 600; }
#sendBtn:disabled { opacity: .5; cursor: default; }
#hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); min-height: 16px; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #side { position: fixed; inset: 0 auto 0 0; width: 86%; max-width: 330px; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.3); }
  #app.open #side { transform: none; }
  #menu { display: block; }
  #top, #feed, #composer { padding-left: 16px; padding-right: 16px; }
}

/* ---------- card slideshows ---------- */
.acard .thumb { position: relative; }
.acard .thumb img { position: absolute; inset: 0; opacity: 0; transition: opacity .6s ease; }
.acard .thumb img.on { opacity: 1; }
.acard .thumb img:not([src]) { display: none; }
.pc { position: absolute; right: 6px; bottom: 6px; font-size: 11px; color: #fff; background: rgba(0, 0, 0, .6); padding: 0 6px; border-radius: 999px; }

/* ---------- the "New" line (where he stopped reading) ---------- */
.newline { display: flex; align-items: center; gap: 8px; margin: 16px 0 10px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.newline::before { content: ''; flex: 1; height: 2px; background: var(--bad); border-radius: 1px; }
.newline span { background: var(--bad); color: var(--on-bad); padding: 1px 9px; border-radius: 999px; }

/* ---------- phones ---------- */
#app { height: 100dvh; }
@media (max-width: 760px) {
  #msg, #aQ, #aChat, .login input { font-size: 16px; } /* iOS zooms into any field under 16 px */
  .atools > .tabs { flex: 1 1 100%; }
  .tabs button { flex: 1; }
  #aChat { flex: 1 1 100%; }
  #assets { padding: 12px 12px 20px; }
  .agrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ainfo { padding: 6px 8px 8px; }
  .at { font-size: 13px; }
  .tgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .atile.audio { grid-column: 1 / -1; }
  #modal { padding: 8px; }
  .lbnav button { width: 36px; height: 54px; font-size: 26px; }
  .edit .line, .look .line { flex-wrap: wrap; }
  .look img { margin-left: 0; }
}

#menu { white-space: nowrap; }
.newline::after { content: ''; flex: 1; height: 2px; background: var(--bad); border-radius: 1px; } /* "NEW" sits in the middle */
.mb { position: relative; }
.lbnav { position: absolute; inset: 0; height: auto; display: flex; justify-content: space-between; align-items: center; padding: 0 6px; pointer-events: none; }
.lbnav button { margin-top: 0; }
#delivery.ok { display: none; }
