/* Design tokens follow the reference mock: a pill-shaped bar on a plain
   ground, a solid Enter button, and a focus ring that appears on the whole
   bar rather than the input inside it. */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #0d0d0d;
  --muted: #8e8e93;
  --line: rgba(0, 0, 0, 0.1);
  --line-strong: rgba(0, 0, 0, 0.32);
  --ring: rgba(0, 0, 0, 0.06);
  --btn: #0d0d0d;
  --btn-hover: #282828;
  --btn-text: #ffffff;
  --warn-bg: #fdf3e6;
  --warn-line: #f0dcc0;
  --warn-text: #7a4a1e;
  --danger: #d62839;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 32px -16px rgba(0, 0, 0, 0.18);
  --shadow-focus: 0 1px 2px rgba(0, 0, 0, 0.04), 0 16px 40px -16px rgba(0, 0, 0, 0.22);
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --chip: #f8f9fa;
  --chip-hover: #f1f3f4;
  --chip-active: #e8eaed;
  --chip-text: #3c4043;
  --field-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0d;
    --surface: #171717;
    --text: #f5f5f5;
    --muted: #7d7d82;
    --line: rgba(255, 255, 255, 0.12);
    --line-strong: rgba(255, 255, 255, 0.4);
    --ring: rgba(255, 255, 255, 0.07);
    --btn: #f5f5f5;
    --btn-hover: #dcdcdc;
    --btn-text: #0d0d0d;
    --warn-bg: #2c2113;
    --warn-line: #4a3a20;
    --warn-text: #f0c99a;
    --danger: #ff6b70;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.7);
    --shadow-focus: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.8);
    --chip: #232323;
    --chip-hover: #2e2e2e;
    --chip-active: #383838;
    --chip-text: #e8eaed;
    --field-bg: #0d0d0d;
  }
}

* { box-sizing: border-box; }

/* An id selector with `display` set out-specifies the browser's built-in
   `[hidden] { display: none }`, so #gate and #vault would keep their layout
   box while hidden — the hidden gate pushed the note down the page. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh; /* dvh, not vh: mobile browser chrome changes the height */
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── the key gate ──────────────────────────────────────────────────── */

/* A drifting field of soft shapes behind the form. alpha:false in the
   context means it paints its own ground, so it needs a colour per theme
   rather than transparency. */
#field {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

#gate {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  transition: opacity 0.26s var(--ease);
}

#gate.fading { opacity: 0; }

#key-form { width: min(584px, 92vw); margin: 0; }

.search-shell {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  height: 52px;
  padding: 0 8px 0 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 1px 6px rgba(32, 33, 36, 0.08);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.search-shell:hover,
.search-shell:focus-within {
  border-color: transparent;
  box-shadow: 0 1px 6px rgba(32, 33, 36, 0.18);
}

@media (prefers-color-scheme: dark) {
  .search-shell { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5); }
  .search-shell:hover,
  .search-shell:focus-within {
    border-color: var(--line-strong);
    box-shadow: 0 1px 10px rgba(0, 0, 0, 0.7);
  }
}

.search-icon { flex: 0 0 auto; width: 20px; height: 20px; color: var(--muted); }

#key {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  /* Never below 16px: iOS Safari zooms the page when a focused field is
     smaller, which throws the whole layout off on a phone. */
  font-size: 16px;
}

#key::placeholder { color: var(--muted); }
#key::-webkit-search-decoration,
#key::-webkit-search-cancel-button { -webkit-appearance: none; }

.go {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 19px;
  background: var(--chip);
  color: var(--chip-text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}

.go:hover { background: var(--chip-hover); }
.go:active { background: var(--chip-active); }
.go:disabled { opacity: 0.5; cursor: default; }
.go:focus-visible { outline: 2px solid var(--line-strong); outline-offset: 2px; }

#status {
  min-height: 1.4em;
  margin: 16px 4px 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* ── the bar, used by the AI composer ──────────────────────────────── */

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 7px 7px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

.bar:focus-within {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-focus), 0 0 0 4px var(--ring);
}

.bar input,
.bar textarea {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  padding: 13px 0;
}

.bar input::placeholder,
.bar textarea::placeholder { color: var(--muted); }
.bar textarea { resize: none; max-height: 40vh; }

.solid,
#send,
#post-send {
  flex: 0 0 auto;
  border: 0;
  cursor: pointer;
  background: var(--btn);
  color: var(--btn-text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 12px 22px;
  border-radius: 12px;
  transition: background-color 0.25s var(--ease), transform 0.2s var(--ease);
}

.solid:hover, #send:hover, #post-send:hover { background: var(--btn-hover); }
.solid:active, #send:active, #post-send:active { transform: scale(0.97); }
#send:focus-visible, #post-send:focus-visible { outline: 2px solid var(--line-strong); outline-offset: 3px; }
#send:disabled, #post-send:disabled { opacity: 0.45; cursor: default; transform: none; }

.quiet {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
}

.quiet:hover { color: var(--text); border-color: var(--line-strong); }
.grow { flex: 1; }

/* ── shared pane chrome ────────────────────────────────────────────── */

#vault, #reader, #ai, #app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.26s var(--ease);
}

#vault.shown, #reader.shown, #ai.shown, #app.shown { opacity: 1; }

.pane-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 20px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.pane-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.pane-meta {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.pane-meta.warn { color: var(--danger); }

.sheet {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  justify-content: center;
}

.sheet > * {
  width: 100%;
  max-width: 680px;
  padding: 32px 24px max(48px, env(safe-area-inset-bottom));
}

/* ── note ──────────────────────────────────────────────────────────── */

#note {
  display: block;
  min-height: 100%;
  color: var(--text);
  background: none;
  border: 0;
  outline: none;
  resize: none;
  /* A writing surface, not a form field: generous line height and a measure
     that stops at a comfortable line length however wide the window is. */
  font: 17px/1.75 ui-serif, Georgia, Cambria, "Times New Roman", serif;
  letter-spacing: 0.002em;
}

#note::placeholder { color: var(--muted); font-style: italic; }

/* ── text ──────────────────────────────────────────────────────────── */

#doc {
  font: 17px/1.75 ui-serif, Georgia, Cambria, "Times New Roman", serif;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── ai ────────────────────────────────────────────────────────────── */

#ai { width: min(760px, 100%); margin: 0 auto; }

#model {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  max-width: 200px;
}

#ai-warning {
  flex: 0 0 auto;
  margin: 12px 20px 0;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 12px;
}

#chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg { display: flex; flex-direction: column; max-width: 88%; }

/* The person's own words sit right and filled, the model's left and plain —
   the shape every chat client has settled on, so it needs no explaining. */
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant, .msg.error { align-self: flex-start; }

.msg .who {
  margin-bottom: 5px;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.msg .body {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user .body {
  padding: 11px 15px;
  color: var(--btn-text);
  background: var(--btn);
  border-radius: 18px 18px 4px 18px;
}

.msg.assistant .body { padding: 0 2px; }

.msg.error .body {
  padding: 10px 14px;
  color: var(--danger);
  border: 1px solid var(--warn-line);
  border-radius: 14px;
}

#ask { flex: 0 0 auto; padding: 0 20px max(16px, env(safe-area-inset-bottom)); }

/* ── app ───────────────────────────────────────────────────────────── */

#app-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  background: var(--bg);
  display: block;
}

.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px max(16px, env(safe-area-inset-left))
    max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.dim { color: var(--muted); }

/* ── social: laid out like X ───────────────────────────────────────── */

:root {
  --rail: 275px;
  --column: 600px;
  --like: #f91880;
  --repost: #00ba7c;
  --save: #1d9bf0;
  --accent: #1d9bf0;
}

#social {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, var(--column));
  /* The implicit row is `auto`, which sizes to content and happily overflows
     a container with a definite height. Pinning it to the container's own
     height is what makes the inner scroller the thing that scrolls. */
  grid-template-rows: minmax(0, 100%);
  justify-content: center;
  opacity: 0;
  transition: opacity 0.26s var(--ease);
}

#social.shown { opacity: 1; }

/* ── left rail ─────────────────────────────────────────────────────── */

#rail {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 8px 12px max(12px, env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 11px 14px;
  font: inherit;
  font-size: 19px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s var(--ease);
}

.rail-item:hover { background: var(--ring); }
.rail-item.on { font-weight: 700; }
.rail-item svg { flex: 0 0 auto; width: 24px; height: 24px; }

#rail-post {
  width: calc(100% - 8px);
  margin: 12px 4px 0;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 999px;
}

#rail-me {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 999px;
  font-size: 14px;
  min-width: 0;
}

#rail-me .handle { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ── the timeline column ───────────────────────────────────────────── */

#timeline {
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* A grid item's automatic minimum size is its content, so without this the
     column grew to the full height of the feed, #social-scroll's `flex: 1`
     had unbounded space to fill, and the document scrolled instead of the
     column. Everything that sets scroll.scrollTop — returning to the top on
     a tab change, restoring your place on Back, scrolling a thread to the
     post you clicked — was writing to an element that never scrolled. */
  min-height: 0;
  border-right: 1px solid var(--line);
}

#tl-head {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 3;
  /* X's translucent header. The fallback matters: without a solid colour
     behind it, browsers without backdrop-filter show text through text. */
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

@supports (backdrop-filter: blur(12px)) {
  #tl-head {
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(12px);
  }
}

#tl-bar { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-left: 8px;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-btn:hover { background: var(--ring); }
.icon-btn svg { width: 20px; height: 20px; }

#tl-title {
  padding: 14px 16px 10px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#tl-title:empty { display: none; }

#tabs { display: flex; }

.tab {
  flex: 1;
  position: relative;
  padding: 16px 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}

.tab:hover { background: var(--ring); }
.tab.on { color: var(--text); font-weight: 700; }

/* The underline X puts under the active tab. */
.tab.on::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 56px;
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

#social-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── composer ──────────────────────────────────────────────────────── */

#composer { border-bottom: 1px solid var(--line); padding: 8px 16px; }
#composer[hidden] { display: none !important; }
#composer-row { display: flex; gap: 12px; }
#composer-main { flex: 1; min-width: 0; }

#post-body {
  width: 100%;
  padding: 12px 0 4px;
  font: inherit;
  font-size: 19px;
  line-height: 1.4;
  color: var(--text);
  background: none;
  border: 0;
  outline: none;
  resize: none;
  max-height: 45vh;
}

#post-body::placeholder { color: var(--muted); }

#composer-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

#post-send {
  padding: 9px 18px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 999px;
}

#post-count.near { color: #e0913a; }
#post-count.over { color: var(--like); }

/* ── posts ─────────────────────────────────────────────────────────── */

.post {
  display: block;
  padding: 12px 16px 4px;
  border-bottom: 1px solid var(--line);
  transition: background-color 0.15s var(--ease);
}

.post:hover { background: var(--ring); }
.post[data-post-id] { cursor: pointer; }

/* The post a thread is about: larger, and not a link to itself. */
.post.focus { cursor: default; padding-bottom: 8px; }
.post.focus:hover { background: transparent; }
.post.focus .post-body { font-size: 18px; line-height: 1.45; }
.post.focus .post-actions { max-width: none; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 12px; }

/* A thread reads as one column, so the ancestors above the focused post get
   a connecting line down the gutter the way X draws it.

   This used to be `.post.focus ~ .post { padding-left: 16px }`, which did
   nothing twice over: `~` selects the posts AFTER the focused one, which are
   the replies rather than the ancestors, and 16px is already `.post`'s own
   left padding on desktop. Ancestors now carry a class, so the rule can
   select the right elements and draw an actual line. */
.post.ancestor { border-bottom: 0; padding-bottom: 0; }
.post.ancestor .post-row { position: relative; }
.post.ancestor .post-row::before {
  content: "";
  position: absolute;
  /* Down the middle of the 40px avatar, from just under it to the next post. */
  left: 19px;
  top: 46px;
  bottom: -6px;
  width: 2px;
  border-radius: 1px;
  background: var(--line);
}
.post.ancestor .post-actions { margin-bottom: 4px; }

/* Keyboard reachability. Posts are focusable so a conversation can be opened
   without a mouse; the ring only shows for keyboard focus, never on click. */
.post:focus { outline: none; }
.post:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: -2px;
  border-radius: 4px;
}

/* The handle inside a repost banner or a "Replying to" line: a link to that
   profile, not a heading, and it must not inherit the banner's muted colour
   so weakly that it stops looking clickable. */
.who.plain { font-weight: 600; color: inherit; max-width: 100%; }

.repost-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px 52px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.repost-banner svg { width: 15px; height: 15px; }

.post-row { display: flex; gap: 12px; }
.post-main { flex: 1; min-width: 0; }

.post-head {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 2px;
  font-size: 15px;
  min-width: 0;
}

.who {
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.who:hover { text-decoration: underline; }
.post-head .sep, .post-head time { color: var(--muted); font-weight: 400; }
.post-head time { flex: 0 0 auto; }

.post-body {
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.post-body a { color: var(--accent); text-decoration: none; }
.post-body a:hover { text-decoration: underline; }

/* X spreads the action row across the full width of the post body. */
.post-actions {
  display: flex;
  justify-content: space-between;
  max-width: 425px;
  margin: 10px 0 4px -8px;
}

.act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 6px 8px;
  cursor: pointer;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}

.act svg { width: 18px; height: 18px; }
.act .count { min-width: 1ch; }

.act[data-act="like"]:hover   { color: var(--like);   background: color-mix(in srgb, var(--like) 12%, transparent); }
.act[data-act="repost"]:hover { color: var(--repost); background: color-mix(in srgb, var(--repost) 12%, transparent); }
.act[data-act="save"]:hover,
.act[data-act="delete"]:hover { color: var(--save);   background: color-mix(in srgb, var(--save) 12%, transparent); }
.act[data-act="delete"]:hover { color: var(--like);   background: color-mix(in srgb, var(--like) 12%, transparent); }

.act[data-act="like"].on   { color: var(--like); }
.act[data-act="repost"].on { color: var(--repost); }
.act[data-act="save"].on   { color: var(--save); }
.act[data-act="like"].on svg,
.act[data-act="save"].on svg { fill: currentColor; }

/* ── avatars: a shape and a colour, never an upload ─────────────────── */

.avatar {
  flex: 0 0 auto;
  display: inline-block;
  width: var(--size, 40px);
  height: var(--size, 40px);
  background: var(--colour, #4f7cff);
}

.avatar.clickable { cursor: pointer; }
.avatar[data-shape="circle"]  { border-radius: 50%; }
.avatar[data-shape="square"]  { border-radius: 4px; }
.avatar[data-shape="rounded"] { border-radius: 30%; }
.avatar[data-shape="diamond"] { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.avatar[data-shape="hex"]     { clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.avatar[data-shape="flower"]  { border-radius: 62% 38% 55% 45% / 45% 58% 42% 55%; }

/* ── profile header ────────────────────────────────────────────────── */

#profile-head { padding: 16px; border-bottom: 1px solid var(--line); }
.profile-top { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.profile-meta { flex: 1; min-width: 0; }
.profile-meta h2 { margin: 0; font-size: 20px; font-weight: 800; }
.profile-meta p { margin: 2px 0 0; font-size: 14px; }
.profile-bio { margin-top: 10px !important; font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
.profile-actions { display: flex; gap: 8px; }
.profile-actions button { padding: 9px 18px; font-size: 14px; font-weight: 700; border-radius: 999px; }

/* ── settings ──────────────────────────────────────────────────────── */

#settings-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px max(24px, env(safe-area-inset-bottom));
}

#settings-panel h2 { font-size: 17px; font-weight: 800; margin: 24px 0 10px; }
#settings-panel h2:first-child { margin-top: 0; }

#settings-panel label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--muted);
}

#settings-panel input[type="text"],
#settings-panel textarea {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  resize: vertical;
}

#settings-panel input:focus,
#settings-panel textarea:focus { border-color: var(--accent); }

.hint { margin: 6px 2px 0; font-size: 13px; color: var(--muted); }

#shape-row, #colour-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.shape-pick, .colour-pick {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  padding: 0;
}

.shape-pick.on, .colour-pick.on { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.colour-pick { background: var(--colour); border-color: transparent; }

.settings-actions { display: flex; align-items: center; gap: 10px; margin-top: 22px; }
.settings-actions .solid { border-radius: 999px; padding: 10px 20px; font-weight: 700; }
#set-note { font-size: 13px; color: var(--muted); }

#feed-empty { padding: 32px 16px; text-align: center; font-size: 15px; }

/* ── bottom bar, mobile only ───────────────────────────────────────── */

#bottombar {
  display: none;
  position: sticky;
  bottom: 0;
  z-index: 3;
  justify-content: space-around;
  align-items: center;
  padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.bb-item {
  display: grid;
  place-items: center;
  min-width: 56px;
  min-height: 44px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.bb-item.on { color: var(--text); }
.bb-item svg { width: 25px; height: 25px; }

/* ── the drawer, mobile only ───────────────────────────────────────── */
/* Bookmarks and Settings do not fit in a five-slot bottom bar, so they
   live behind your own avatar in the top-left — the same place X keeps
   them on a phone. */

#drawer-open {
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-left: 12px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
}

#scrim {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(0, 0, 0, 0.4);
}

#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 9;
  width: min(288px, 80vw);
  padding: 20px 0 max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
}

#drawer-me {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-handle { font-size: 15px; color: var(--muted); }

.drawer-item {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 15px 20px;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
}

.drawer-item:hover { background: var(--ring); }
.drawer-item svg { width: 24px; height: 24px; flex: 0 0 auto; }

/* ── notifications ─────────────────────────────────────────────────── */

.notif {
  display: flex;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.notif:hover { background: var(--ring); }

/* Unread carries a tint rather than only a dot, so a glance down the list
   shows what is new without reading any of it. */
.notif.unread { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.notif.unread:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.notif-icon { flex: 0 0 auto; padding-top: 2px; }
.notif-icon svg { width: 21px; height: 21px; }
.notif-icon.like svg   { color: var(--like);   fill: currentColor; }
.notif-icon.repost svg { color: var(--repost); }
.notif-icon.reply svg  { color: var(--save); }
.notif-icon.follow svg { color: var(--accent); }

.notif-main { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.notif-head { display: flex; align-items: center; gap: 8px; font-size: 15px; flex-wrap: wrap; }
.notif-head time { font-size: 13px; }

.notif-snippet {
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The count on the nav item. Positioned against the rail item, which is
   already the click target. */
.rail-item, .bb-item { position: relative; }

.badge {
  position: absolute;
  top: 6px;
  left: 28px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
}

.bb-item .badge { left: 50%; top: 2px; transform: translateX(2px); }

/* ── search and replies ────────────────────────────────────────────── */

#search-bar { padding: 10px 16px; border-bottom: 1px solid var(--line); }

#search-input {
  width: 100%;
  padding: 11px 16px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--ring);
  border: 1px solid transparent;
  border-radius: 999px;
  outline: none;
}

#search-input:focus { background: var(--bg); border-color: var(--accent); }

#people { border-bottom: 1px solid var(--line); }

.person {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 16px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: none;
  border: 0;
  cursor: pointer;
}

.person:hover { background: var(--ring); }
.person-meta { display: flex; flex-direction: column; min-width: 0; }
.person-handle { font-weight: 700; font-size: 15px; }
.person-bio {
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#reply-context {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 16px 0;
  font-size: 14px;
  color: var(--muted);
}

.link-btn {
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.link-btn:hover { text-decoration: underline; }

.reply-line { font-size: 14px; color: var(--muted); margin-bottom: 3px; }
.reply-line .who.plain { font-size: 14px; vertical-align: baseline; }

.act[data-act="reply"]:hover { color: var(--save); background: color-mix(in srgb, var(--save) 12%, transparent); }

/* Red, and used for every failure the user can act on. */
.bad { color: var(--danger) !important; }

/* ── Small screens ─────────────────────────────────────────────────── */

@media (max-width: 480px) {
  #gate { padding: 20px; }
  .search-shell { height: 50px; padding-left: 16px; gap: 10px; }
  .go { padding: 0 14px; }

  .bar { padding: 6px 6px 6px 18px; border-radius: 16px; }

  .bar input,
  .bar textarea { font-size: 16px; padding: 13px 0; }

  /* 44px is the smallest comfortable touch target; the desktop padding
     alone lands just under it. */
  #enter,
  #send,
  #post-send { padding: 11px 18px; border-radius: 11px; font-size: 15px; min-height: 44px; }

  .quiet { min-height: 44px; }

  .sheet > * { padding: 22px 18px 40px; }
  .pane-head { padding-left: 16px; padding-right: 16px; }
  #note, #doc { font-size: 17px; }
  #chat { padding: 16px; gap: 14px; }
  #ask { padding-left: 14px; padding-right: 14px; }
  #ai-warning { margin-left: 14px; margin-right: 14px; }
  .msg { max-width: 92%; }

  #ai { padding: 0 14px max(12px, env(safe-area-inset-bottom)); }

  /* The spend line is the first thing to sacrifice when the row is tight;
     the caps are enforced server-side regardless of whether they are shown. */
  #spend { display: none; }

  #model { max-width: 50vw; }

  .post { padding: 10px 12px 2px; }
  .post-row { gap: 10px; }
  .repost-banner { margin-left: 46px; }
  #composer { padding: 6px 12px; }
  #post-body { font-size: 17px; }
  #tl-title { padding: 12px 14px 8px; font-size: 19px; }
  .post-actions { max-width: none; }
}

/* Between the two: keep the rail but drop the labels, as X does. */
@media (max-width: 1000px) {
  #social { grid-template-columns: 72px minmax(0, 1fr); }
  .rail-item .label, #rail-me .who, #rail-me .handle { display: none; }
  .rail-item { justify-content: center; padding: 12px; }
  #rail-post { padding: 13px 0; }
  #rail-post .label { display: none; }
  #rail-me { justify-content: center; }
}

/* Phone: no rail at all, a bottom bar instead — X's mobile shape. */
@media (max-width: 700px) {
  #social { grid-template-columns: minmax(0, 1fr); }
  #rail { display: none; }
  #timeline { border-right: 0; }
  #bottombar { display: flex; }
  #drawer-open { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
