/*
 * Direction: Lamp
 *
 * One idea: the phone is a status lamp. The other person's state fills the whole first screen
 * with its colour, so it can be read from across a room before a word can: yellow when he
 * needs something, red when he must not be interrupted, plain paper when he is free, and a
 * dimmed grey when what he said is hours old. The words on the lamp lead with the one fact
 * that matters most (a need, then a don't-interrupt, then what he is doing). Your own state
 * is a strip at the bottom of that first screen, above the update bar: you know your own
 * state, so it stays small. On a laptop the two lamps sit side by side, half the screen each.
 *
 * Type, controls and the three colour jobs stay exactly as they are today; the colours are
 * spent on the whole screen instead of a band. One colour is added: the dim ground for a
 * stale status.
 *
 * Type: Atkinson Hyperlegible Next (OFL, OFL.txt).
 */

@font-face {
  font-family: 'Atkinson Next';
  src: url('atkinson-next-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Atkinson Next';
  src: url('atkinson-next-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f5f6f8;
  --surface: #ffffff;
  --ink: #15181c;
  --muted: #535a63;
  --rule: #cfd4db;
  --line: #8a929c;
  --soon: #1c4ea6;
  --need: #ffd21f;
  --need-ink: #15181c;
  --quiet: #b1221a;
  --quiet-ink: #ffffff;
  --dim: #dfe3e8;
  --focus: #1c4ea6;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --sign: clamp(2.5rem, 1.4rem + 5.5vw, 4.5rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.25rem;
  --space-7: 3.5rem;

  --tap: 2.75rem;
  /* The bar and your own strip, so the lamp can fill what is left of the first screen. */
  --bar: calc(var(--tap) + 2 * var(--space-3) + 1px);
  --mine: 6.75rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15181c;
    --surface: #1e2227;
    --ink: #eef0f3;
    --muted: #a7afb9;
    --rule: #363c44;
    --line: #6c747e;
    --soon: #93b6ff;
    --dim: #2a2f36;
    --focus: #93b6ff;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

input {
  caret-color: var(--soon);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Atkinson Next', system-ui, sans-serif;
  font-size: var(--step-0);
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.page {
  padding-bottom: calc(var(--bar) + var(--space-6));
}

/* --- The lamp ------------------------------------------------------------------------------- */

.lamp {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--mine) - var(--bar));
  min-height: calc(100dvh - var(--mine) - var(--bar));
  padding: var(--space-3) var(--space-4) var(--space-5);
  background: var(--paper);
  color: var(--ink);
  /* A lamp changes colour like a light switching, not like a page reloading. */
  transition: background-color 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

.lamp.is-need {
  background: var(--need);
  color: var(--need-ink);
}

.lamp.is-quiet {
  background: var(--quiet);
  color: var(--quiet-ink);
}

.lamp.is-dim {
  background: var(--dim);
}

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

/* Everything on a coloured lamp is set in the lamp's own foreground, never grey. */
.is-need .looked,
.is-need .meta,
.is-need .sync,
.is-quiet .looked,
.is-quiet .meta,
.is-quiet .sync,
.is-need .next-when,
.is-quiet .next-when {
  color: inherit;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-4);
}

.top h1 {
  font-size: var(--step-0);
  line-height: 1.5;
}

.sync {
  color: var(--muted);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

.bumped {
  margin: var(--space-3) calc(-1 * var(--space-4)) 0;
  padding: var(--space-2) var(--space-4) var(--space-3);
  background: var(--ink);
  color: var(--paper);
}

.bumped strong {
  display: block;
  font-size: var(--step-2);
  line-height: 1.2;
}

.bumped span {
  display: block;
  font-size: var(--step--1);
}

.who-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.who-block {
  min-width: 0;
}

.who {
  font-size: var(--step-1);
  line-height: 1.3;
}

.looked {
  color: var(--muted);
  font-size: var(--step--1);
}

.who-row form {
  flex: none;
}

.bump-reasons {
  margin-top: var(--space-2);
}

.bump-reasons summary {
  display: block;
  width: fit-content;
  margin-left: auto;
  padding: 0.55rem var(--space-3);
  border: 2px solid currentColor;
  border-radius: 999px;
  background: transparent;
  font-size: var(--step--1);
  line-height: 1.2;
  list-style: none;
  cursor: pointer;
}

.bump-reasons summary::-webkit-details-marker {
  display: none;
}

.bump-reasons summary:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.bump-reasons summary:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 2px;
}

.reasons {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* The one fact that matters most, set big. */
.lead {
  margin-top: var(--space-5);
}

.headline {
  font-size: var(--sign);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.012em;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.meta {
  margin-top: var(--space-2);
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.row > p {
  margin-top: 0;
  min-width: 0;
}

.row > form {
  flex: none;
}

.doing {
  margin-top: var(--space-6);
  font-size: var(--step-2);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.doing.is-empty {
  font-weight: 400;
  color: var(--muted);
}

.next-line {
  margin-top: var(--space-4);
  font-size: var(--step-1);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.next-when {
  color: var(--soon);
  font-weight: 700;
}

.next-text {
  font-weight: 700;
}

.sent {
  margin-top: var(--space-3);
}

/* Your own state: a strip at the bottom of the first screen on a phone. */
.mine {
  min-height: var(--mine);
  padding: var(--space-3) var(--space-4);
}

.mine .who-row {
  margin-top: 0;
}

.mine .lead {
  margin-top: 0;
}

.mine .headline {
  font-size: var(--step-1);
  line-height: 1.3;
}

.mine .row {
  margin-top: var(--space-1);
}

.mine .meta {
  margin-top: 0;
  font-size: var(--step--1);
}

/* Buttons take the lamp's colours: solid is the lamp's foreground, outlined is a line of it. */
.lamp button {
  background: transparent;
  border-color: currentColor;
  color: inherit;
}

.is-need button.solid {
  background: var(--need-ink);
  border-color: var(--need-ink);
  color: var(--need);
}

.is-quiet button.solid {
  background: var(--quiet-ink);
  border-color: var(--quiet-ink);
  color: var(--quiet);
}

.lamp :focus-visible {
  outline-color: currentColor;
}

.lamp input[type='text'] {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--surface);
}

/* --- The rest of the page: earlier, posting, this device ----------------------------------- */

.rest {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.earlier {
  padding: var(--space-4) 0 0;
  color: var(--muted);
}

.earlier summary {
  display: block;
  padding: 0.7rem 0;
  list-style: none;
  cursor: pointer;
}

.earlier summary::-webkit-details-marker {
  display: none;
}

.summary-label {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.earlier ol {
  margin: var(--space-2) 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-2);
}

.earlier li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: var(--space-3);
}

.earlier b {
  margin-right: var(--space-1);
}

.earlier time {
  font-variant-numeric: tabular-nums;
}

.earlier span {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.compose {
  padding-top: var(--space-6);
}

.compose h2 {
  font-size: var(--step-2);
  line-height: 1.2;
}

.compose h3 {
  font-size: var(--step-1);
  line-height: 1.3;
}

.compose-form {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.need-form {
  margin-top: var(--space-6);
}

.field-label,
legend {
  font-weight: 700;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

legend {
  padding: 0;
  margin-bottom: var(--space-2);
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.presets.lengths {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.presets.lengths button {
  padding: 0 var(--space-2);
}

.segmented {
  display: flex;
  border: 2px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

.segmented label {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 var(--space-1);
  font-size: var(--step--1);
  white-space: nowrap;
  cursor: pointer;
}

.segmented label:not(:first-of-type) {
  border-left: 1px solid var(--rule);
}

.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.segmented input:checked + label {
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
}

.segmented input:focus-visible + label {
  outline: 3px solid var(--focus);
  outline-offset: -5px;
}

.field-row {
  display: flex;
  gap: var(--space-2);
}

input[type='text'] {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: max(1rem, 16px);
}

input[type='text']::placeholder {
  color: var(--muted);
  opacity: 1;
}

input[type='text']:focus-visible {
  border-color: var(--ink);
}

button,
.bar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 120ms ease-out,
    border-color 120ms ease-out;
}

button:hover {
  border-color: var(--ink);
}

.lamp button:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

button.preset {
  border-color: var(--surface);
}

button.preset:hover {
  border-color: var(--ink);
}

button.need-preset {
  background: var(--need);
  border-color: var(--need);
  color: var(--need-ink);
}

button.need-preset:hover {
  border-color: var(--need-ink);
}

button.solid,
.bar-link.solid {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  font-weight: 700;
}

button.small {
  font-size: var(--step--1);
  padding: 0 var(--space-3);
}

button.plain {
  border: 0;
  padding: 0;
  background: none;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

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

.device {
  margin-top: var(--space-7);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
  color: var(--muted);
}

.device summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  cursor: pointer;
  color: var(--ink);
  font-weight: 700;
}

.device p {
  max-width: 40rem;
}

.device form + form {
  margin-top: var(--space-4);
}

.device button.plain {
  min-height: var(--tap);
  color: var(--ink);
}

/* --- Update bar (phones) ------------------------------------------------------------------- */

.update-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--rule);
}

.bar-link {
  width: 100%;
}

.bar-link:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* --- Wider screens: two lamps, half the screen each ----------------------------------------- */

@media (min-width: 52rem) {
  .page {
    padding-bottom: var(--space-7);
  }

  .lamps {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .lamp,
  .mine {
    min-height: 70vh;
    padding: var(--space-5) var(--space-6) var(--space-6);
  }

  .mine .who-row {
    margin-top: var(--space-4);
  }

  .mine .lead {
    margin-top: var(--space-5);
  }

  .mine .headline {
    font-size: var(--sign);
    line-height: 1.05;
  }

  .mine .row {
    margin-top: var(--space-2);
  }

  .mine .meta {
    font-size: var(--step-0);
  }

  /* The top line sits over Alex's lamp only; your lamp starts level with his name. */
  .mine .who-row {
    margin-top: calc(var(--space-4) + 1.5rem + var(--space-3));
  }

  .bumped {
    margin-left: 0;
    margin-right: 0;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .rest {
    padding: 0 var(--space-6);
  }

  .update-bar {
    display: none;
  }

  .compose-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: var(--space-7);
    align-items: start;
  }

  .need-form {
    margin-top: var(--space-4);
  }
}

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