/*
 * One visual language carries the idea throughout:
 *   amber  (--server) marks what KeyBank sees or stores,
 *   teal   (--local)  marks what never leaves the browser.
 */
:root {
  color-scheme: light dark;
  --font-sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f2f1ec;
  --ink: #16181d;
  --ink-2: #4f535c;
  --ink-3: #7c7f88;
  --line: #e4e2da;
  --line-strong: #cfccc2;
  --focus: #2f6fed;
  --on-ink: #ffffff;

  --server: #b0560b;
  --server-soft: #fbefdf;
  --local: #0d7a6a;
  --local-soft: #e2f3ee;
  --danger: #b42318;
  --danger-soft: #fdeceb;

  --radius: 1rem;
  --radius-small: 0.75rem;
  --shadow: 0 1px 2px rgb(22 24 29 / 0.04), 0 8px 24px rgb(22 24 29 / 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #16191f;
    --surface-2: #1c2027;
    --ink: #ecebe6;
    --ink-2: #aeb2bb;
    --ink-3: #80858f;
    --line: #272c34;
    --line-strong: #373d47;
    --focus: #7aa7ff;
    --on-ink: #111317;

    --server: #f2a65a;
    --server-soft: rgb(242 166 90 / 0.12);
    --local: #52d1b4;
    --local-soft: rgb(82 209 180 / 0.1);
    --danger: #f5877d;
    --danger-soft: rgb(245 135 125 / 0.12);

    --shadow: none;
  }
}

/* Base */

*,
*::before,
*::after {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
}
h1, h2, h3, p, figure, dl, dd {
  margin: 0;
}
h1, h2, h3 {
  line-height: 1.2;
  letter-spacing: -0.015em;
}
a {
  color: inherit;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 0.2em;
}
a:hover {
  text-decoration-color: currentColor;
}
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
}
p code, li code {
  padding: 0.1em 0.35em;
  border-radius: 0.375rem;
  background: var(--surface-2);
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Page frame */

.topbar,
.shell,
.footer {
  width: min(100%, 72rem);
  margin-inline: auto;
  padding-inline: 1.5rem;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.25rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand-mark {
  width: 1.375rem;
  height: 1.375rem;
  color: var(--server);
}
.topbar-nav {
  display: flex;
  gap: 1.25rem;
  font-size: 0.9375rem;
}
.topbar-nav a {
  color: var(--ink-2);
  text-decoration: none;
}
.topbar-nav a:hover {
  color: var(--ink);
}

.shell {
  flex: 1;
  padding-bottom: 4rem;
}
.footer {
  display: grid;
  gap: 0.25rem;
  padding-block: 2rem 3rem;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 0.875rem;
}
.footer strong {
  color: var(--ink-2);
  font-weight: 600;
}

.hero {
  max-width: 44rem;
  margin: 1.5rem 0 2.25rem;
}
.eyebrow {
  margin-bottom: 0.625rem;
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
h1 {
  font-size: clamp(2rem, 4.5vw, 2.875rem);
  letter-spacing: -0.03em;
}
.lead {
  margin-top: 0.875rem;
  color: var(--ink-2);
  font-size: 1.0625rem;
}
.lead em {
  color: var(--server);
  font-style: normal;
  font-weight: 600;
}

.banner {
  margin-bottom: 1.5rem;
  padding: 0.875rem 1rem;
  border: 1px solid color-mix(in srgb, var(--server) 40%, transparent);
  border-radius: var(--radius-small);
  background: var(--server-soft);
}

/* Layout primitives */

.workspace {
  display: grid;
  gap: 1.5rem;
  align-items: start;
}
@media (min-width: 64rem) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 21rem;
  }
  .ledger-panel {
    position: sticky;
    top: 1.5rem;
  }
}
.stack {
  display: grid;
  gap: 1.25rem;
}
.stack-compact {
  gap: 0.375rem;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  align-items: center;
}
.card {
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 1.25rem;
}
.section-title:focus {
  outline: none;
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink-3);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hint {
  color: var(--ink-3);
  font-size: 0.875rem;
}

/* Forms */

.field {
  display: grid;
  gap: 0.625rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.field-label {
  padding: 0;
  font-weight: 600;
}
.field-meta {
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
}
.tag .icon {
  width: 0.9375rem;
  height: 0.9375rem;
}
.tag-local {
  background: var(--local-soft);
  color: var(--local);
}

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: inherit;
  font: inherit;
}
textarea {
  min-height: 11rem;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  line-height: 1.6;
}
textarea::placeholder {
  color: var(--ink-3);
  font-family: var(--font-sans);
}
textarea:focus,
input:focus {
  border-color: var(--focus);
  outline: 3px solid color-mix(in srgb, var(--focus) 20%, transparent);
  outline-offset: 0;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.segment {
  position: relative;
  display: inline-flex;
}
.segment input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.segment span {
  padding: 0.5rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.segment input:hover + span {
  border-color: var(--ink-3);
}
.segment input:checked + span {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--on-ink);
}
.segment input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.segment input:disabled {
  cursor: not-allowed;
}
.segment input:disabled + span {
  opacity: 0.4;
  text-decoration: line-through;
}
.custom-ttl {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.custom-ttl input {
  width: 6.5rem;
  padding: 0.4375rem 0.875rem;
  border-radius: 999px;
}

.submit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}
.submit-row .status {
  flex: 1 1 16rem;
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.625rem 1.125rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--on-ink);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.button:hover {
  background: color-mix(in srgb, var(--ink) 86%, var(--bg));
}
.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.button-secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}
.button-secondary:hover {
  background: var(--surface-2);
}
.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}
.button-quiet:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.button-small {
  min-height: 2.25rem;
  padding: 0.375rem 0.875rem;
  font-size: 0.875rem;
}
.button[data-copied] {
  border-color: var(--local);
  background: var(--local);
  color: var(--on-ink);
}

/* Status line */

.status {
  display: flex;
  gap: 0.625rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.status::before {
  content: "";
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  margin-top: 0.5em;
  border-radius: 50%;
  background: var(--ink-3);
}
.status[data-state="working"]::before {
  background: var(--server);
  animation: pulse 1s ease-in-out infinite alternate;
}
.status[data-state="success"] {
  color: var(--local);
}
.status[data-state="success"]::before {
  background: var(--local);
}
.status[data-state="error"] {
  color: var(--danger);
}
.status[data-state="error"]::before {
  background: var(--danger);
}

/* Generated link */

.link-row {
  display: flex;
  gap: 0.5rem;
}
.link-row input.link-input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  text-overflow: ellipsis;
}
.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.5rem;
  align-items: start;
}

.anatomy .panel-title {
  margin-bottom: 0.875rem;
}
.anatomy {
  min-width: 0;
}
.anatomy-parts {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.875rem;
}
.anatomy-part {
  padding-left: 0.875rem;
  border-left: 3px solid;
}
.anatomy-part dt code {
  display: block;
  overflow: hidden;
  font-size: 0.8125rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.anatomy-part dd {
  margin-top: 0.25rem;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.anatomy-part strong {
  color: var(--ink);
}
.anatomy-server {
  border-color: var(--server);
}
.anatomy-server dt {
  color: var(--server);
}
.anatomy-local {
  border-color: var(--local);
}
.anatomy-local dt {
  color: var(--local);
}

.qr {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
}
.qr-code {
  display: grid;
  place-items: center;
  min-width: 11.75rem;
  min-height: 11.75rem;
  max-width: 13rem;
  padding: 0.625rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: #ffffff;
  color: #4f535c;
  font-size: 0.8125rem;
  text-align: center;
}
.qr-code img,
.qr-code canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* "What KeyBank sees" ledger */

.ledger-panel {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-top: 3px solid var(--server);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.ledger-head {
  display: grid;
  gap: 0.25rem;
}
.ledger-head .panel-title {
  color: var(--server);
}
.ledger {
  display: grid;
  gap: 0.625rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ledger-entry {
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface-2);
  font-size: 0.8125rem;
  animation: arrive 0.3s ease-out;
}
.ledger-request {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.625ch;
  font-family: var(--font-mono);
  font-weight: 600;
}
.ledger-path {
  min-width: 0;
  overflow-wrap: anywhere;
}
.ledger-method {
  color: var(--server);
}
.ledger-io {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.25rem 0.75rem;
  margin-top: 0.5rem;
}
.ledger-io dt {
  color: var(--ink-3);
}
.ledger-io dd {
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.ledger-literal {
  font-family: var(--font-mono);
}
.ledger-foot {
  display: flex;
  gap: 0.5rem;
  color: var(--ink-2);
  font-size: 0.8125rem;
}
.ledger-foot .icon {
  margin-top: 0.1em;
  color: var(--local);
}

/* How it works */

.how {
  margin-top: 4.5rem;
  padding-top: 3rem;
  border-top: 1px solid var(--line);
}
.how-intro {
  max-width: 44rem;
}
.how-intro .section-title {
  font-size: clamp(1.5rem, 3vw, 2rem);
}
.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  margin: 2rem 0 1rem;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.step {
  position: relative;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  counter-increment: step;
}
.step::after {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}
.step h3 {
  margin: 0.875rem 0 0.375rem;
  font-size: 1rem;
}
.step p {
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.step-icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
}
.step-server {
  background: var(--server-soft);
  color: var(--server);
}
.step-local {
  background: var(--local-soft);
  color: var(--local);
}
.step-burn {
  background: var(--danger-soft);
  color: var(--danger);
}

.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
}
.compare-col {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.compare-col h3 {
  font-size: 1rem;
}
.compare-col ul {
  display: grid;
  gap: 0.375rem;
  margin: 0.75rem 0 0;
  padding-left: 1.125rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.compare-keybank {
  border-color: color-mix(in srgb, var(--local) 45%, transparent);
  background: var(--local-soft);
}
.compare-keybank h3 {
  color: var(--local);
}

/* Share page */

.envelope-head {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.seal {
  display: grid;
  place-items: center;
  flex: none;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--local-soft);
  color: var(--local);
  transition: background-color 0.3s, color 0.3s;
}
.seal .icon {
  width: 1.375rem;
  height: 1.375rem;
}
.record-id {
  overflow-wrap: anywhere;
}
.callout {
  display: flex;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-small);
  background: var(--server-soft);
  font-size: 0.9375rem;
}
.callout .icon {
  margin-top: 0.15em;
  color: var(--server);
}

/* Once the key is spent, the warning and the button have done their job. */
.envelope:is([data-state="open"], [data-state="spent"]) :is(.callout, [data-decrypt-actions]) {
  display: none;
}
.envelope[data-state="spent"] .seal,
.envelope[data-state="invalid"] .seal {
  background: var(--danger-soft);
  color: var(--danger);
}

.plaintext-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.plaintext-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.plaintext-toolbar .hint {
  margin-right: 0.25rem;
}
.countdown-value {
  display: inline-block;
  min-width: 1.25rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: center;
}
.countdown-value[data-infinite="true"] {
  font-size: 1.2em;
  line-height: 1;
}
.countdown-bar {
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}
.countdown-bar::after {
  content: "";
  display: block;
  height: 100%;
  background: var(--local);
  transform-origin: left;
}
.countdown-bar[data-state="running"]::after {
  animation: drain var(--autohide-duration, 60s) linear forwards;
}
.countdown-bar[data-state="stopped"] {
  display: none;
}
.plaintext {
  max-height: 60vh;
  margin: 0;
  padding: 1rem 1.125rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Dialog */

.modal {
  width: min(32rem, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 48px rgb(0 0 0 / 0.2);
}
.modal::backdrop {
  background: rgb(14 16 20 / 0.5);
}
.modal form {
  padding: 1.5rem;
}

/* Motion */

@keyframes pulse {
  to {
    opacity: 0.3;
  }
}
@keyframes arrive {
  from {
    opacity: 0;
    transform: translateY(-0.25rem);
  }
}
@keyframes drain {
  to {
    transform: scaleX(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
  .countdown-bar {
    display: none;
  }
}

/* Small screens */

@media (max-width: 40rem) {
  .topbar,
  .shell,
  .footer {
    padding-inline: 1rem;
  }
  .hero {
    margin: 0.75rem 0 1.5rem;
  }
  .card {
    padding: 1.125rem;
  }
  .submit-row > .button,
  .link-row > .button {
    width: 100%;
  }
  .link-row {
    flex-direction: column;
  }
  .result-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .qr {
    justify-self: center;
  }
  .how {
    margin-top: 3rem;
    padding-top: 2rem;
  }
}

/* API demo options use the same controls as the note form. */
select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  background: var(--surface, #fff);
  color: var(--ink);
  font: inherit;
}
