/* Two layers, per the repo's CSS convention: `components` owns structure,
   `theme` owns colour, so a palette change never has to touch layout.

   Colour tokens are defined per theme with attribute selectors rather than
   light-dark() inside the custom property, because light-dark() in a token
   definition breaks session-replay tooling. */

@layer components, theme;

@layer theme {
  :root {
    --bg: #fbfaf8;
    --surface: #ffffff;
    --ink: #1c1b19;
    --ink-soft: #5d5a55;
    --line: #e3e0da;
    --accent: #2f5d50;
    --accent-ink: #ffffff;
    --danger: #8a3324;
    --notice-bg: #fdf6e3;
    --notice-line: #e0d5b0;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #16181a;
      --surface: #1e2124;
      --ink: #eceae6;
      --ink-soft: #a5a29c;
      --line: #33383d;
      --accent: #7fbfa8;
      --accent-ink: #10231d;
      --danger: #e0836f;
      --notice-bg: #2a2519;
      --notice-line: #4a4130;
    }
  }

  body {
    background: var(--bg);
    color: var(--ink);
  }

  section {
    background: var(--surface);
    border: 1px solid var(--line);
  }

  h1,
  h2 {
    color: var(--ink);
  }

  .note,
  .tagline,
  .state,
  .fingerprint {
    color: var(--ink-soft);
  }

  button {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
  }

  button.primary {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
  }

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

  button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: var(--accent);
  }

  input,
  textarea {
    background: var(--bg);
    color: var(--ink);
    border: 1px solid var(--line);
  }

  blockquote {
    background: var(--bg);
    border-left: 3px solid var(--accent);
  }

  .error {
    color: var(--danger);
  }

  .exchange li.them {
    background: var(--bg);
    border: 1px solid var(--line);
  }

  .exchange li.you {
    background: var(--accent);
    color: var(--accent-ink);
  }

  .exchange .who {
    color: var(--ink-soft);
  }

  .exchange li.you .who {
    color: var(--accent-ink);
    opacity: 0.75;
  }

  .notice {
    background: var(--notice-bg);
    border: 1px solid var(--notice-line);
  }

  code {
    color: var(--ink-soft);
  }
}

@layer components {
  * {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  }

  main {
    max-width: 44rem;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .masthead {
    padding-bottom: 0.5rem;
  }

  h1 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
  }

  .tagline {
    margin: 0.25rem 0 0;
    font-size: 0.95rem;
  }

  section {
    border-radius: 10px;
    padding: 1.25rem;
  }

  h2 {
    margin: 0 0 0.35rem;
    font-size: 1.05rem;
  }

  .note {
    margin: 0 0 1rem;
    font-size: 0.9rem;
  }

  form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  label {
    font-size: 0.85rem;
    font-weight: 600;
  }

  input,
  textarea {
    padding: 0.6rem 0.7rem;
    border-radius: 7px;
    font: inherit;
    width: 100%;
  }

  textarea {
    resize: vertical;
  }

  button {
    padding: 0.6rem 1rem;
    border-radius: 7px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    align-self: flex-start;
  }

  button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
  }

  .state {
    font-size: 0.85rem;
  }

  meter {
    width: 7rem;
    height: 0.5rem;
  }

  ul {
    margin: 0;
    padding-left: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.92rem;
  }

  .exchange {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    font-size: 0.92rem;
  }

  .exchange li {
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    max-width: 90%;
  }

  .exchange li.them {
    align-self: flex-start;
  }

  .exchange li.you {
    align-self: flex-end;
  }

  .exchange .who {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.15rem;
  }

  blockquote {
    margin: 0 0 1rem;
    padding: 0.9rem 1rem;
    border-radius: 0 7px 7px 0;
    white-space: pre-wrap;
    min-height: 3rem;
  }

  .fingerprint {
    margin: 0.9rem 0 0;
    font-size: 0.8rem;
    word-break: break-all;
  }

  code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
  }

  .notice {
    margin: 0.9rem 0 0;
    padding: 0.7rem 0.85rem;
    border-radius: 7px;
    font-size: 0.88rem;
  }

  .error {
    margin: 0.75rem 0 0;
    font-size: 0.9rem;
    font-weight: 600;
  }

  [hidden] {
    display: none !important;
  }
}

@layer components {
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.75rem;
  }

  .grid > div {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }

  select {
    padding: 0.6rem 0.7rem;
    border-radius: 7px;
    font: inherit;
    width: 100%;
  }

  details {
    font-size: 0.9rem;
  }

  summary {
    cursor: pointer;
    padding: 0.35rem 0;
  }

  .keys {
    max-height: 15rem;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    padding-left: 2rem;
  }

  .keys li {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.3rem 0;
  }

  .keys code {
    flex: 1;
    word-break: break-all;
  }

  .keys button {
    flex: none;
    align-self: center;
    padding: 0.25rem 0.6rem;
    font-size: 0.72rem;
  }

  .counters {
    display: flex;
    gap: 2rem;
    margin: 0 0 1rem;
  }

  .counters div {
    display: flex;
    flex-direction: column;
  }

  .counters dt {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .counters dd {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
  }
}

@layer theme {
  select {
    background: var(--bg);
    color: var(--ink);
    border: 1px solid var(--line);
  }

  .counters dt {
    color: var(--ink-soft);
  }

  summary {
    color: var(--accent);
  }
}
