:root {
  --bg: #130f1c;
  --card: #1b1626;
  --raised: #251f33;
  --line: #31293f;
  --text: #f5f1fa;
  --muted: #a39bb3;
  --gold: #f2bd52;
  --gold-soft: #ffe7a8;
  --ok: #5fd39a;
  --bad: #ff7a7a;
  --progress: 0;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px calc(28px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
/* Light from the doorway, brighter while the door is open. */
body::before {
  content: "";
  position: fixed;
  inset: -20vh -30vw auto;
  height: 70vh;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(closest-side, var(--gold), transparent);
  opacity: 0.07;
  transition: opacity 0.8s;
}
body.door-open::before { opacity: 0.22; }
main { max-width: 460px; margin: 0 auto; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 2px 10px; }
h1 { margin: 0; font-size: 22px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h2 { margin: 0 0 14px; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h3 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
a { color: inherit; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.lead { margin-bottom: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.status { display: flex; flex: none; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #4d4560; transition: background 0.3s, box-shadow 0.3s; }
.dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.connecting { background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
.dot.problem { background: var(--bad); }

.card { margin: 12px 0; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); }
.banner { border-color: #5c4420; background: #2e2212; color: #ffd9a8; font-size: 15px; }
.banner a { color: #ffe7c4; }

/* Someone at the door. */
.ring { display: flex; align-items: center; gap: 14px; border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.ring strong { display: block; font-size: 17px; }
.ring-icon { display: grid; flex: none; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: color-mix(in srgb, var(--gold) 18%, var(--raised)); color: var(--gold); }
.ring-icon svg { width: 22px; height: 22px; }
.ring.now { box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 50%, transparent), 0 0 36px color-mix(in srgb, var(--gold) 25%, transparent); }
.ring.now .ring-icon svg { animation: shake 0.6s ease-in-out infinite; transform-origin: 50% 10%; }

/* The open button. */
.hero { display: flex; flex-direction: column; align-items: center; padding: 30px 18px 22px; text-align: center; }
.open {
  position: relative;
  display: grid;
  place-items: center;
  width: 176px;
  height: 176px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #2f2742, var(--raised));
  color: var(--gold);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.15s, box-shadow 0.4s, color 0.3s, border-color 0.3s, opacity 0.3s;
}
.open:disabled { cursor: default; opacity: 0.45; }
.open svg { grid-area: 1 / 1; width: 64px; height: 64px; }
.open .icon-check, .open .spinner { display: none; }
.open-ring {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--progress) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
}
.open[data-state="holding"] { transform: scale(0.97); box-shadow: 0 0 46px color-mix(in srgb, var(--gold) 28%, transparent); }
.open[data-state="sending"] .icon-door { opacity: 0.25; }
.open[data-state="sending"] .spinner {
  display: block;
  grid-area: 1 / 1;
  width: 92px;
  height: 92px;
  border: 3px solid color-mix(in srgb, var(--gold) 25%, transparent);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.open[data-state="open"] { border-color: color-mix(in srgb, var(--ok) 60%, transparent); color: var(--ok); box-shadow: 0 0 0 1px color-mix(in srgb, var(--ok) 50%, transparent), 0 0 60px color-mix(in srgb, var(--ok) 35%, transparent); }
.open[data-state="open"] .icon-door { display: none; }
.open[data-state="open"] .icon-check { display: block; }
.open[data-state="error"] { border-color: var(--bad); color: var(--bad); animation: nudge 0.35s; }
.open:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 4px; }
.open-title { font-size: 20px; font-weight: 650; }
.open-hint { margin-top: 4px; }

.field + .field { margin-top: 18px; }
.field-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 15px; border: 1px solid var(--line); border-radius: 999px; background: var(--raised); color: var(--text); font: inherit; font-size: 15px; text-decoration: none; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: color-mix(in srgb, var(--gold) 70%, transparent); background: color-mix(in srgb, var(--gold) 22%, var(--raised)); }
.chip:disabled { opacity: 0.45; cursor: default; }

.log { margin: 0; padding: 0; list-style: none; }
.log li { display: grid; grid-template-columns: 28px 1fr auto; align-items: baseline; gap: 4px 10px; padding: 9px 0; }
.log li + li { border-top: 1px solid var(--line); }
.log .what { min-width: 0; }
.log .when { font-size: 13px; color: var(--muted); white-space: nowrap; }
.log .icon { text-align: center; }
.log .detail { display: block; font-size: 13px; color: var(--muted); }
.log li.new { animation: glow 2s ease-out; }
.more { width: 100%; margin-top: 8px; }

details > summary { display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { margin: 0; }
details[open] > summary { margin-bottom: 8px; }
.group { display: grid; gap: 10px; padding: 16px 0; }
.group + .group, #admin .group:first-child { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; }
.row > span:last-child { text-align: right; overflow-wrap: anywhere; }
.label { margin-top: 6px; font-size: 14px; color: var(--muted); }
form { display: grid; gap: 10px; }
input[type="text"], input[type="password"], input[type="url"], select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raised);
  color: var(--text);
  font: inherit;
}
input[type="file"] { color: var(--muted); font: inherit; font-size: 14px; }
input[type="range"] { width: 100%; accent-color: var(--gold); }
progress { width: 100%; accent-color: var(--gold); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--gold); }
.btn { padding: 12px 16px; border: 0; border-radius: 12px; background: var(--text); color: var(--bg); font: inherit; font-weight: 600; cursor: pointer; }
.btn.subtle { border: 1px solid var(--line); background: transparent; color: var(--text); font-weight: 500; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.switch { position: relative; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; z-index: 1; margin: 0; opacity: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: #3d354d; transition: background 0.2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch input:checked + span { background: #34c77b; }
.switch input:checked + span::after { transform: translateX(20px); }

.keys { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.keys li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.keys .name { min-width: 0; overflow-wrap: anywhere; }
.keys .badge { margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: var(--raised); color: var(--muted); font-size: 12px; }
.keys button { flex: none; padding: 6px 12px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--bad); font: inherit; font-size: 14px; cursor: pointer; }
.new-key { display: grid; gap: 10px; padding: 12px; border: 1px dashed color-mix(in srgb, var(--gold) 45%, var(--line)); border-radius: 14px; }
.link { display: grid; gap: 8px; }
.link code { display: block; padding: 8px 10px; overflow: hidden; border-radius: 10px; background: var(--raised); color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.link .chips .chip { font-size: 14px; }

.code-editor { display: grid; gap: 10px; }
.code-view { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 64px; padding: 10px; border-radius: 14px; background: var(--raised); color: var(--gold); font-size: 15px; }
.code-view .short, .code-view .long { display: block; height: 14px; border-radius: 7px; background: var(--gold); }
.code-view .short { width: 14px; }
.code-view .long { width: 44px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #2b2439;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.45);
  font-size: 15px;
  transform: translateX(-50%);
}

@keyframes spin { to { transform: rotate(1turn); } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(14deg); } 75% { transform: rotate(-14deg); } }
@keyframes nudge { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes glow { from { background: color-mix(in srgb, var(--gold) 14%, transparent); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
