/* selfware design system — single source of truth.
   Any page in /ui/* should link this and add only its page-specific
   rules on top. Adding new tokens, buttons, pills, or panels? Add them
   here so the two live surfaces (/ui, /connections) can't drift.
*/

/* ── fonts ─────────────────────────────────────────────────────────── */
@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&family=Instrument+Serif:ital@0;1&display=swap");

/* ── tokens ────────────────────────────────────────────────────────── */
:root {
  --canvas:        #E4E4DF;
  --canvas-2:      #D6D5CE;
  --canvas-3:      #C1C0B7;
  --ink:           #1B1815;
  --ink-2:         #3B362F;
  --ink-3:         #6C6559;
  --ink-4:         #A09A8C;
  --ink-bg:        #14110D;
  --ink-bg-2:      #211D17;
  --ink-fg:        #F2F0EB;
  --ink-fg-2:      #BEB8A9;
  --rule:          #D1CFC6;
  --rule-strong:   #B1AFA4;
  --signal:        #C8341A;
  --signal-soft:   #E8B5A0;
  --signal-deep:   #8E1B05;
  --moss:          #1F9E63;
  --moss-soft:     #CBE8D5;
  --moss-deep:     #15774A;
  --sulfur-soft:   #DEDDA8;
  --amber:         #B8860B;
  --amber-soft:    #F0D775;
  --oxblood:       #5C2218;
  --oxblood-soft:  #C9A091;
  --iron:          #4A4036;
  --iron-soft:     #B5AC9F;

  --font-sans:     "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:     "Geist Mono", "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display:  "Instrument Serif", "Times New Roman", serif;

  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast:      120ms;
  --dur-base:      200ms;

  --radius-sm:     2px;
  --radius-md:     4px;
  --radius-lg:     8px;
  --radius-pill:   999px;

  --shadow-sm:  0 1px 2px rgba(26,23,20,.08);
  --shadow-pop: 0 18px 40px -12px rgba(26,23,20,.38), 0 6px 14px -4px rgba(26,23,20,.20), 0 0 0 1px rgba(26,23,20,.04);
}

/* ── base ──────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--canvas);
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; padding: 0; }
input, textarea { font: inherit; color: var(--ink); }
a { color: var(--signal-deep); text-decoration: underline; text-underline-offset: 2px; }
::selection { background: var(--signal-soft); color: var(--ink); }

/* ── wordmark s•elfware ────────────────────────────────────────────── */
.wm {
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  white-space: nowrap;
  display: inline-flex;
  align-items: baseline;
  font-size: 17px;
}
.wm__dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--signal);
  align-self: center;
  margin: 0 1px;
}

/* ── keycap buttons ────────────────────────────────────────────────── */
/*
   Variants:
     .btn                — the ink-black keycap default (never used bare
                            outside .btn--primary/outline/ghost; combining
                            with a modifier is the norm)
     .btn--primary       — rust-red, use for hero "commit" moments
                            (Save, Confirm, Accept, first-time Connect on
                            an unauth wall). Reserve for one CTA per view.
     .btn--outline       — paper-toned, use for repeated / secondary
                            actions: Reconnect, Reject, "connect" links
                            once the user has already been oriented.
     .btn--ghost         — transparent, tertiary nav (Cancel, Back,
                            Disconnect, in-nav links).
     .btn--sm            — size modifier; compose with any variant.
*/
.btn {
  --bg: #1A1611; --side: #000; --fg: #EDE7D8; --depth: 3px;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 14px; font-weight: 600; letter-spacing: -0.005em;
  padding: 11px 18px;
  color: var(--fg);
  background: var(--bg);
  border: 0;
  border-radius: 7px;
  text-decoration: none;
  box-shadow:
    0 var(--depth) 0 0 var(--side),
    0 calc(var(--depth) + 6px) 14px -6px rgba(26,23,20,.25);
  transform: translateY(0);
  cursor: pointer;
  transition: transform 80ms var(--ease-standard),
              box-shadow 80ms var(--ease-standard),
              background 120ms var(--ease-standard);
  white-space: nowrap;
}
.btn:hover { background: color-mix(in oklab, var(--bg) 88%, white); }
.btn:active { transform: translateY(var(--depth)); box-shadow: 0 0 0 0 var(--side); }
.btn:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.btn--primary { --bg: #C8341A; --side: #6E1605; --fg: #FAEAD4; }
.btn--outline { --bg: var(--canvas); --side: #B8AE93; --fg: var(--ink); }
.btn--outline:hover { background: var(--canvas-2); }
.btn--ghost   { --depth: 0px; --side: transparent; background: transparent; color: var(--ink); box-shadow: none; padding: 9px 12px; }
.btn--ghost:hover { background: var(--canvas-2); }
.btn--sm      { font-size: 13px; padding: 7px 12px; --depth: 2px; border-radius: 5px; }
.btn[disabled] { opacity: .4; pointer-events: none; }

/* ── top nav (shared) ──────────────────────────────────────────────── */
.nav {
  border-bottom: 1px solid var(--rule);
  background: var(--canvas);
  position: sticky; top: 0; z-index: 20;
}
.nav__in {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 28px;
  display: flex; align-items: center; gap: 20px;
}
.nav__spacer { flex: 1; }
.nav__crumb {
  color: var(--ink-3); font-family: var(--font-mono); font-size: 12px;
}
.nav a.nav__link {
  color: var(--ink-2); font-size: 13px; text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-md);
}
.nav a.nav__link:hover { background: var(--canvas-2); }
.nav a.nav__link[aria-current="page"] { color: var(--ink); font-weight: 600; }

/* ── touch pointers ────────────────────────────────────────────────── */
/* Keyed on pointer type, not width: a 44px control is about fingers, not
   about how narrow the window is, and keying it to width would coarsen a
   small desktop window that has a mouse. */
@media (pointer: coarse) {
  /* iOS zooms the whole page when a focused control's text is under 16px.
     The design's 12–13px controls read correctly on a desktop and make an
     iPhone lurch and re-centre on every tap into a field, which is the
     single worst thing about this UI on a phone. Raise the font on touch
     only; desktop density is untouched.

     Specificity rather than !important: pages legitimately style their own
     fields (`.search input` is 13px, at (0,1,1)), so a bare `input`
     selector loses. `:not()` carries its argument's specificity, lifting
     this to (0,2,1) — enough to win, while leaving a page free to set
     something deliberately larger. The excluded types have no text to
     zoom into. */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea { font-size: 16px; }

  /* Apple's 44pt minimum. These land at 26–34px today. */
  .btn, .nav__link, .tab, .wm, input, select { min-height: 44px; }
  .btn { padding-top: 10px; padding-bottom: 10px; }
  .nav__link { display: inline-flex; align-items: center; }
}


/* ── small screens ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* The nav is why every page scrolled sideways on a phone: a single
     non-wrapping flex row of wordmark + chip + spacer + actions measures
     ~457px against a 393px viewport. The spacer exists to push actions
     right on a wide screen and has nothing to do on a narrow one. */
  .nav__in {
    /* Two rows of 44px touch targets is already 88px of sticky chrome on
       an 852px screen; the padding is what keeps it from being more. */
    padding: 6px max(16px, env(safe-area-inset-left)) 6px max(16px, env(safe-area-inset-right));
    gap: 2px 10px;
    flex-wrap: wrap;
  }
  /* The spacer pushes actions right on a wide screen. On a narrow one,
     giving it the full row turns it into a line break — brand and schema
     on the first row, actions together on the second — instead of letting
     the actions strand one per line wherever they happen to fall. */
  .nav__spacer { flex-basis: 100%; height: 0; margin: 0; }
  .nav__crumb, .nav__schema { font-size: 11px; }

  /* Real data here is machine-generated: message ids, tokens, and
     addresses like donotreply+9abb17fd-458c-55fb-9ff4-…@parentsquare.com.
     Without this one of them silently sets the width of the page. */
  body { overflow-wrap: anywhere; }

  /* Keep the last row of content clear of the home indicator. */
  .shell { padding-bottom: env(safe-area-inset-bottom); }
}

/* A contested merge, answered on screen.
   The reviewer was previously shown "contested" and nothing else — the
   question without the evidence. These carry the reason each candidate
   might be the right one, drawn from the rows on every side. */
.contest { margin-top: .6rem; padding: .6rem .7rem; border-radius: 6px;
           background: var(--surface-2, #f3f2ee); border: 1px solid var(--line, #ddd); }
.contest__q { margin: 0 0 .45rem; font-weight: 600; }
.contest__opts { list-style: none; margin: 0; padding: 0; }
.contest__opt { display: flex; align-items: baseline; gap: .5rem;
                padding: .25rem 0; flex-wrap: wrap; }
.contest__why { font-size: .86em; opacity: .8; }
.contest__terms { font-family: var(--mono, ui-monospace, monospace); opacity: .9; }
.contest__meta, .contest__none { margin: .45rem 0 0; font-size: .82em; opacity: .65; }
