/*
 * Porchlight, in a mix of Acre Design (Charcoal look) and Fulcrum Charcoal.
 *
 *   Grounds and lettering: Acre Charcoal (dark, and its light mode where the
 *   page turns to stone but every card and control stays charcoal).
 *   Accents, each with one job, from Fulcrum:
 *     gold  the porch light: the brand mark, your own messages, Send
 *     mist  servers and sync: server lights, focus rings
 *     sage  safe and OK: reassuring check-ins
 *     rose  needs attention: offline, not sent, errors, urgent check-ins
 *   Texture: Fulcrum's film grain. Type: Fraunces, Hanken Grotesk and
 *   JetBrains Mono when their files are in public/fonts/, else the phone's own.
 */
:root {
  color-scheme: dark;

  /* Charcoal: the same in both modes */
  --charcoal: #1c1d1b;   /* Acre ground */
  --surface: #232422;    /* Acre surface: received bubbles, inputs, chips */
  --raised: #2c2d2a;     /* Acre surface-sunk: sent bubbles, code */
  --pressed: #363733;    /* Acre ink-raised: pressed controls */
  --line: #3b3c38;       /* Acre line-on-surface: control borders */
  --line-soft: #2c3035;  /* Fulcrum line-soft: hairlines */
  --text-c: #efe8da;     /* Acre text on charcoal */
  --muted-c: #a8a296;    /* Acre muted on charcoal */
  --gold: #d8c296;       /* Fulcrum ore */
  --gold-ink: #2a2620;   /* Fulcrum ink, text on gold */
  --mist: #9fb4c6;       /* Fulcrum mist */
  --rose: #d6a9a2;       /* Fulcrum rose */
  --sage: #a9bda2;       /* Fulcrum sage */
  --gold-meta: #55493a;  /* secondary text on gold */
  --gold-alert: #7a2a25; /* "Not sent" on gold */
  --mist-tint: rgba(159, 180, 198, 0.15);
  --rose-tint: rgba(214, 169, 162, 0.10);
  --gold-tint: rgba(216, 194, 150, 0.16);

  /* The ground: these change with the mode */
  --ground: var(--charcoal);
  --text: var(--text-c);
  --muted: var(--muted-c);
  --line-ground: var(--line);
  --primary-bg: var(--gold);
  --primary-ink: var(--gold-ink);
  --link: var(--gold);
  --alert: var(--rose);
  --focus: var(--mist);

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.055'/%3E%3C/svg%3E");

  --font-display: "Fraunces", "Iowan Old Style", Charter, "Bitstream Charter", Georgia, serif;
  --font-body: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Shared radii: control 12, md 16, lg 22, sheet 28, pill */
  --radius-control: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-sheet: 28px;
  --radius-tail: 6px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --gutter: 16px;
}

/* Acre Charcoal light: a stone page, charcoal cards and controls */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --ground: #eeede8;
    --text: #1b1a17;
    --muted: #4b4740;
    --line-ground: #dcd5c8;
    --primary-bg: #2c2d2a;   /* an action on the light ground uses ink */
    --primary-ink: #efe8da;
    --link: #1b1a17;
    --alert: #843732;        /* Acre blush text, readable on stone */
    --focus: #15456e;        /* Acre sky text, readable on stone */
  }
}

/* Anything charcoal reads the charcoal values, whatever the mode */
.charcoal {
  --text: var(--text-c);
  --muted: var(--muted-c);
  --line-ground: var(--line);
  --primary-bg: var(--gold);
  --primary-ink: var(--gold-ink);
  --link: var(--gold);
  --alert: var(--rose);
  --focus: var(--mist);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground) var(--grain);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.fatal {
  max-width: 30rem;
  margin: 20vh auto 0;
  padding: 0 var(--gutter);
  font-size: 17px;
}

/* ------------------------------------------------------------ wordmark */

.wordmark {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 400;
  font-variation-settings: "SOFT" 100, "opsz" 96;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.wordmark.small {
  gap: 0;
  font-size: 23px;
  font-variation-settings: "SOFT" 100, "opsz" 36;
  letter-spacing: -0.015em;
}

/* The porch light: the one place the brand glows */
.glow {
  width: 20px;
  height: 20px;
  margin-left: 7px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 7px var(--gold-tint);
  flex: none;
}

@media (prefers-color-scheme: light) {
  .glow { box-shadow: 0 0 0 7px var(--raised); }
}

.charcoal .glow.small,
.glow.small {
  width: 11px;
  height: 11px;
  margin: 0 12px 0 4px;
  box-shadow: 0 0 0 4px var(--gold-tint);
  align-self: center;
}

.empty .glow { display: block; margin: 0 auto 24px; }

::selection { background: var(--gold); color: var(--gold-ink); }

/* ------------------------------------------------------------ server lights */

.lamp {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  border: 1.5px solid var(--muted);
  background: transparent;
}

.lamp-ok {
  background: var(--mist);
  border-color: var(--mist);
  box-shadow: 0 0 0 3px var(--mist-tint);
}

.lamp-down { border-color: var(--alert); box-shadow: 0 0 0 3px var(--rose-tint); }

.lamp-refused { border-color: var(--alert); border-style: dashed; }

.lamp-unknown { border-style: dotted; opacity: 0.7; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.legend span { display: inline-flex; align-items: center; gap: 8px; }

/* ------------------------------------------------------------ gate (setup, unlock) */

.gate {
  min-height: 100%;
  display: flex;
  justify-content: center;
  padding: max(9vh, env(safe-area-inset-top)) var(--gutter) 48px;
}

.gate-inner { width: 100%; max-width: 26rem; }

.lede {
  margin: 18px 0 32px;
  max-width: 36ch;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
}

.lede strong { color: var(--text); font-weight: 600; }

.form { display: grid; gap: 22px; }

.field { display: grid; gap: 8px; }

label, .label {
  font-size: 15px;
  font-weight: 600;
}

.aside {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 400;
}

.aside.block { display: block; margin: 2px 0 0; }

/* Controls stay charcoal in both modes, with light lettering */
input[type="text"], input[type="password"], input:not([type]), textarea {
  width: 100%;
  min-height: 50px;
  padding: 12px 15px;
  background: var(--surface);
  color: var(--text-c);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 17px;
}

input::placeholder, textarea::placeholder { color: var(--muted-c); opacity: 1; }

input:not([type="checkbox"]):focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.pass-row { display: flex; gap: 8px; }

.pass-row input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 16px;
  letter-spacing: 0.01em;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.hint code { font-family: var(--font-mono); font-size: 0.88em; }

.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 17px;
  font-weight: 400;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  accent-color: var(--primary-bg);
  flex: none;
}

.check .aside { font-size: 15px; }

.error {
  margin: 0;
  color: var(--alert);
  font-weight: 600;
}

/* ------------------------------------------------------------ buttons */

button { cursor: pointer; }

button:disabled { cursor: progress; opacity: 0.7; }

.primary {
  min-height: 54px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--primary-bg);
  color: var(--primary-ink);
  font-size: 16px;
  font-weight: 600;
}

/* Secondary buttons are charcoal controls in both modes */
.quiet {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text-c);
  font-weight: 600;
  font-size: 15px;
}

.quiet:active { background: var(--pressed); }

.quiet.wide { width: 100%; }

.danger {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--alert);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--alert);
  font-weight: 600;
  font-size: 15px;
}

.textlink {
  justify-self: start;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ------------------------------------------------------------ chat layout */

.chat {
  height: 100%;
  height: 100dvh;
  max-width: 44rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--charcoal) var(--grain);
  border-bottom: 1px solid var(--line-soft);
}

.bar-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.room-label {
  color: var(--muted);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lamps {
  min-height: 44px;
  padding: 0 4px 0 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  flex: none;
}

.lamp-set { display: flex; gap: 14px; }

.lamp-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
}

.banner {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin: 0;
  padding: 11px var(--gutter);
  background: var(--charcoal) linear-gradient(var(--rose-tint), var(--rose-tint));
  border-bottom: 1px solid var(--line-soft);
  font-size: 15px;
}

.banner::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--rose);
  border-radius: 50%;
  transform: translateY(1px);
}

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px var(--gutter) 20px;
  display: flex;
  flex-direction: column;
}

.messages:focus { outline: none; }

.empty {
  margin: auto;
  max-width: 26ch;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

.empty p { margin: 0; }

.empty .empty-title {
  margin-bottom: 8px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 24px;
  font-variation-settings: "SOFT" 100, "opsz" 36;
  letter-spacing: -0.015em;
}

.earlier { align-self: center; margin: 4px 0 12px; }

.day {
  align-self: center;
  margin: 20px 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted-c);
  font-size: 12.5px;
  font-weight: 600;
}

/* ------------------------------------------------------------ messages */

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(84%, 34rem);
  margin-top: 6px;
}

.msg.mine { align-self: flex-end; align-items: flex-end; }

.msg.theirs { align-self: flex-start; align-items: flex-start; }

.who {
  margin: 12px 0 5px 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.bubble {
  padding: 10px 14px 7px;
  border-radius: var(--radius-lg);
  color: var(--text-c);
}

/* Your own messages carry the porch light */
.mine .bubble {
  background: var(--gold);
  border: 1px solid var(--gold);
  border-bottom-right-radius: var(--radius-tail);
  color: var(--gold-ink);
}

.mine .meta { color: var(--gold-meta); }

.mine .dot { border-color: var(--gold-meta); }

.mine .dot.on { background: var(--gold-ink); border-color: var(--gold-ink); }

.mine .delivery.failed { color: var(--gold-alert); }

.theirs .bubble {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: var(--radius-tail);
}

.text {
  margin: 0;
  font-size: 17px;
  line-height: 1.42;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.meta {
  margin: 3px 0 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  color: var(--muted-c);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.delivery { display: inline-flex; gap: 4px; align-items: center; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--muted-c);
}

.dot.on { background: var(--mist); border-color: var(--mist); }

.delivery.waiting { font-style: italic; }

.delivery.failed { color: var(--rose); font-weight: 600; }

/* ------------------------------------------------------------ composer */

.dock {
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: var(--charcoal) var(--grain);
  border-top: 1px solid var(--line-soft);
}

.checkins {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 var(--gutter) 10px;
  scrollbar-width: none;
}

.checkins::-webkit-scrollbar { display: none; }

/* Check-ins are tinted by meaning: sage for OK, rose for attention, mist for switching line */
.checkin {
  --tone: var(--muted-c);
  --tone-tint: rgba(168, 162, 150, 0.10);
  --tone-line: var(--line);
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 15px 0 13px;
  border: 1px solid var(--tone-line);
  border-radius: 999px;
  background: var(--surface) linear-gradient(var(--tone-tint), var(--tone-tint));
  color: var(--text-c);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.checkin::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tone);
  flex: none;
}

.checkin[data-tone="sage"] {
  --tone: var(--sage);
  --tone-tint: rgba(169, 189, 162, 0.14);
  --tone-line: rgba(169, 189, 162, 0.34);
}

.checkin[data-tone="rose"] {
  --tone: var(--rose);
  --tone-tint: rgba(214, 169, 162, 0.14);
  --tone-line: rgba(214, 169, 162, 0.34);
}

.checkin[data-tone="mist"] {
  --tone: var(--mist);
  --tone-tint: rgba(159, 180, 198, 0.14);
  --tone-line: rgba(159, 180, 198, 0.34);
}

.checkin:active { background: var(--pressed); }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 0 var(--gutter);
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  padding: 12px 15px;
  line-height: 1.35;
}

.send {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--gold);
  color: var(--gold-ink);
  font-size: 16px;
  font-weight: 600;
}

/* ------------------------------------------------------------ settings sheet */

.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: 0 20px calc(24px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--charcoal) var(--grain);
  overflow-y: auto;
}

.sheet::backdrop { background: rgba(10, 10, 9, 0.62); }

@media (min-width: 40rem) {
  .sheet {
    max-width: 32rem;
    margin: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sheet);
  }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 -20px;
  padding: 18px 20px 14px;
  background: var(--charcoal) var(--grain);
  border-bottom: 1px solid var(--line-soft);
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  font-variation-settings: "SOFT" 100, "opsz" 96;
  letter-spacing: -0.015em;
}

.sheet-section {
  display: grid;
  gap: 14px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line-soft);
}

.sheet-section:last-child { border-bottom: 0; }

.sheet-section h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  font-variation-settings: "SOFT" 100, "opsz" 36;
}

.host-list, .room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.host { display: grid; gap: 2px; }

.host-head {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
}

.host-head strong { font-weight: 600; }

.host-status, .host-url {
  margin: 0 0 0 20px;
  color: var(--muted);
}

.host-url {
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.code {
  display: block;
  padding: 11px 13px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
  user-select: all;
}

.row { display: flex; flex-wrap: wrap; gap: 10px; }

.room-current { font-weight: 600; }

.room-switch { width: 100%; text-align: left; }

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: rise 0.4s var(--ease); }
  @keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}
