:root {
  --paper: #f7f4ee;
  --card: #fffdf9;
  --ink: #1f1c18;
  --muted: #6d665c;
  --line: #e3ddd1;
  --wax: #8f2e20;          /* sealing wax */
  --wax-soft: #f3e3df;
  --on-wax: #ffffff;
  --good: #2e6b3d;
  --good-soft: #e4f0e6;
  --warn: #8a5a00;
  --warn-soft: #f6ecd6;
  --bad: #a52a1c;
  --bad-soft: #f7e1de;
  --shadow: 0 1px 2px rgba(31, 28, 24, .05), 0 6px 20px rgba(31, 28, 24, .05);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Cantarell", "Noto Sans", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161411;
    --card: #1f1c18;
    --ink: #ede7dc;
    --muted: #a59d90;
    --line: #353028;
    --wax: #cf5e46;
    --wax-soft: #3a211b;
    --good: #7cc98c;
    --good-soft: #1f3324;
    --warn: #e2a95a;
    --warn-soft: #3a2e1a;
    --bad: #f08576;
    --bad-soft: #3d201c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .88em; }
em { font-style: normal; font-weight: 600; }
.mt { margin-top: 18px; }

.wordmark {
  font-family: var(--serif);
  font-style: italic;
  font-size: 2.4rem;
  color: var(--wax);
  margin-bottom: 28px;
}
.wordmark.small { font-size: 1.45rem; margin: 0; }

/* ----- forms and buttons ----- */
.stack { display: grid; gap: .8rem; }
label { display: grid; gap: .35rem; font-size: .9rem; color: var(--muted); }
input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .65rem .8rem;
  width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--wax) 35%, transparent);
  outline-offset: 1px;
  border-color: var(--wax);
}
button {
  font: inherit;
  font-size: .95rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6rem 1.1rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button.primary { background: var(--wax); border-color: var(--wax); color: var(--on-wax); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--wax); }
button.link { background: none; border: none; color: var(--muted); padding: .6rem .4rem; }
button.link:hover { color: var(--ink); }
button.small { padding: .3rem .7rem; font-size: .84rem; }
button.danger { color: var(--bad); }
button.big { padding: .9rem 1.4rem; font-size: 1.02rem; }
button:disabled { opacity: .45; cursor: default; }
.actions { display: flex; justify-content: flex-end; gap: 10px; align-items: center; margin-top: 6px; }
.actions.left { justify-content: flex-start; }
.actions.center { justify-content: center; }
.hint { color: var(--muted); font-size: .88rem; margin: 0; }
.hint.good { color: var(--good); }
.hint.warn { color: var(--warn); }
.hint.bad { color: var(--bad); }
.lede { color: var(--muted); font-size: 1.02rem; margin-bottom: 24px; }

.handle-input {
  display: flex; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding-left: .8rem;
}
.handle-input span { color: var(--wax); font-family: var(--serif); font-size: 1.2rem; }
.handle-input input { border: none; font-size: 1.1rem; padding-left: .3rem; }
.handle-input:focus-within { outline: 3px solid color-mix(in srgb, var(--wax) 35%, transparent); border-color: var(--wax); }
.handle-input input:focus { outline: none; }

/* ----- welcome and unlock ----- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; }
.sheet { width: min(520px, 100%); }
.sheet.narrow { width: min(380px, 100%); }
.choices { display: grid; gap: 12px; }
.options { display: grid; gap: 12px; margin-bottom: 12px; }
.option {
  display: grid; gap: 4px; text-align: left;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
.option span { color: var(--muted); font-size: .9rem; font-weight: 400; }

/* ----- app ----- */
.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 28px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.bar select { width: auto; padding: .4rem .7rem; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav button { border: none; background: none; color: var(--muted); padding: .45rem .85rem; }
.nav button[aria-current] { color: var(--ink); background: var(--card); box-shadow: var(--shadow); }
.page { max-width: 760px; margin: 0 auto; padding: 28px 24px 64px; display: grid; gap: 16px; }
.page > section { display: grid; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}
.card.empty { text-align: center; padding: 40px 24px; }
.card.alert { border-color: var(--warn); background: var(--warn-soft); }
.card.alert h3 { margin-top: 0; color: var(--warn); }
.code-box {
  font-family: var(--mono); font-size: 1.05rem; letter-spacing: .04em; line-height: 1.7;
  text-align: center; word-spacing: .2em; user-select: all;
  background: var(--paper); border: 1px dashed var(--line); border-radius: 10px; padding: .8rem 1rem;
}
.balance { margin: 4px 0 10px; font-size: 1.05rem; }
.soft { background: var(--paper); border-radius: 10px; padding: .7rem 1rem; }
textarea.mono { font-family: var(--mono); text-transform: uppercase; }

.hero { padding: 8px 4px 4px; }
.handle-big { font-family: var(--serif); font-size: 2.2rem; font-weight: 600; line-height: 1.15; }
.handle-big::before { content: "@"; color: var(--wax); }
.status { margin: 6px 0 0; font-size: .95rem; color: var(--muted); }
.status::before { content: "● "; }
.status.good { color: var(--good); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }
.seals { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.seal { background: var(--good-soft); color: var(--good); border-radius: 99px; padding: .25rem .75rem; font-size: .85rem; font-weight: 500; }

.devices { list-style: none; padding: 0; margin: 12px 0 14px; display: grid; gap: 8px; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.devices li.hint { border-style: dashed; }

details.sub { margin-top: 14px; }
details > summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
details.tech > summary, details.advanced > summary { font-weight: 600; color: var(--ink); font-size: 1rem; }
details[open] > summary { margin-bottom: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 0; }
legend { color: var(--muted); font-size: .85rem; padding: 0 4px; }

.mono-box {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  font-family: var(--mono); font-size: .8rem; word-break: break-all;
  background: var(--paper); border: 1px dashed var(--line); border-radius: 10px; padding: .5rem .7rem;
}
.mono-box span { user-select: all; }

/* ----- activity ----- */
.activity { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.activity li {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px;
}
.activity .meta { display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.pill { font-size: .78rem; font-weight: 600; border-radius: 99px; padding: .15rem .6rem; background: var(--line); color: var(--muted); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* ----- dialogs ----- */
dialog {
  width: min(560px, calc(100% - 32px));
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--ink);
  padding: 26px 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(20, 16, 12, .45); }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink); font-size: .95rem; }
.check input { width: auto; margin-top: .3rem; }
.steps { padding-left: 1.2rem; margin: 6px 0; display: grid; gap: 12px; }
.cmd-box { display: grid; gap: 6px; margin-top: 8px; justify-items: start; }
pre.cmd {
  margin: 0; width: 100%;
  font-family: var(--mono); font-size: .76rem; white-space: pre-wrap; word-break: break-all;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem;
}

/* ----- toast ----- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 10;
  max-width: min(600px, calc(100% - 32px));
  background: var(--ink); color: var(--paper);
  padding: .8rem 1.1rem; border-radius: 12px; box-shadow: var(--shadow); font-size: .95rem;
}
.toast.error { background: var(--bad); color: #fff; }

.display-name { font-size: 1.2rem; margin-top: 2px; }
.verified { color: var(--good); font-weight: 700; }
#use-verified { justify-self: start; }

.good { color: var(--good); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border-radius: 99px; padding: .35rem .9rem; }
.chip[aria-pressed="true"] { background: var(--wax); border-color: var(--wax); color: var(--on-wax); }
.chip:disabled { opacity: 1; cursor: default; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress .bar { height: 100%; width: 4%; background: var(--wax); transition: width .6s ease; }

.help-btn {
  display: inline-grid; place-items: center;
  width: 1.35rem; height: 1.35rem; padding: 0; margin-left: 4px; vertical-align: middle;
  border-radius: 50%; font: 600 .78rem var(--sans); color: var(--muted);
  background: transparent; border: 1px solid var(--line);
}
.help-btn:hover, .help-btn[aria-expanded="true"] { color: var(--wax); border-color: var(--wax); }
.help {
  background: var(--wax-soft); border-radius: 10px; padding: 12px 14px; margin: 4px 0 10px;
  font-size: .9rem; font-family: var(--sans); font-weight: 400; color: var(--ink);
}
.help p { margin: 0 0 .5rem; }
.help p:last-child { margin: 0; }

details.stage { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
details.stage > summary { color: var(--ink); font-size: 1rem; }
details.stage > summary .badge { margin-left: 4px; }
.row-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row-item:last-child { border-bottom: none; }
.row select { width: auto; flex: 1; }
