:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #13201d;
  --muted: #5b6b67;
  --border: #d9e1de;
  --accent: #0f5c4d;
  --accent-text: #ffffff;
  --accent-soft: #e2f0ec;
  --ok: #1d7a3e;
  --ok-bg: #e5f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --error: #b42318;
  --error-bg: #fdecea;
  --info-bg: #e9eef6;
  --info: #23466e;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1412;
    --surface: #13201d;
    --text: #e8f0ed;
    --muted: #9db0aa;
    --border: #26372f;
    --accent: #3fb59a;
    --accent-text: #04140f;
    --accent-soft: #173229;
    --ok: #5fd08a;
    --ok-bg: #12301f;
    --warn: #f2c35b;
    --warn-bg: #33280c;
    --error: #ff8a7a;
    --error-bg: #3a1714;
    --info-bg: #182436;
    --info: #a9c4ea;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app { min-height: 100dvh; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 16px);
}

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 56px;
}

.topbar h1 { margin: 0; font-size: 1.15rem; text-align: center; outline: none; }
.topbar-actions { display: flex; gap: 4px; justify-content: flex-end; min-width: 48px; }
.back, .icon-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 0 8px;
  color: var(--accent); text-decoration: none; font-size: 1.05rem; border-radius: 10px;
}
.back { font-size: 2rem; line-height: 1; }
.icon-link[hidden] { display: none; }

.content { display: flex; flex-direction: column; gap: 16px; padding-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

h2 { font-size: 1.1rem; margin: 4px 0; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.center { text-align: center; }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; word-break: break-all; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}

button, .button {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: var(--surface); color: var(--accent); border-color: var(--border); }
.danger { background: var(--surface); color: var(--error); border-color: var(--error); }
button.small, .button.small { min-height: 40px; font-size: 0.9rem; padding: 0 12px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.row-buttons > * { flex: 1 1 140px; }

label, .label { font-weight: 600; font-size: 0.95rem; }
input[type="text"], select {
  width: 100%; min-height: 48px; padding: 0 12px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
}
#recovery-code { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.04em; text-transform: uppercase; }

.checks { display: flex; flex-direction: column; gap: 8px; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; font-weight: 400; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); }

.notice { padding: 12px 14px; border-radius: 12px; background: var(--info-bg); color: var(--info); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.error { background: var(--error-bg); color: var(--error); }

.big-name { font-size: 1.4rem; font-weight: 700; }
.verification-code {
  font: 700 2.6rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em; text-align: center; margin: 8px 0;
}

/* gate screen */
.gate { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 0; text-align: center; }
.site-name { font-size: 2rem; font-weight: 800; letter-spacing: 0.12em; }
.gate-name { font-size: 1.1rem; color: var(--muted); }
.gate-state { font-size: 1.1rem; font-weight: 600; }
.gate-state[hidden] { display: none; }
.gate-button {
  width: min(68vw, 260px); aspect-ratio: 1; border-radius: 50%;
  margin: 20px 0 8px; display: flex; flex-direction: column; gap: 4px;
  background: var(--accent); color: var(--accent-text);
  font-size: 1.5rem; font-weight: 800; letter-spacing: 0.06em;
  box-shadow: 0 10px 30px rgb(15 92 77 / 30%);
  transition: transform 0.08s ease;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.gate-button:active:not(:disabled) { transform: scale(0.97); }
.gate-button:disabled { opacity: 0.6; }
.feedback { min-height: 3em; font-weight: 600; padding: 4px 8px; border-radius: 10px; }
.feedback.ok { color: var(--ok); }
.feedback.warn { color: var(--warn); }
.feedback.error { color: var(--error); }
.feedback.info { color: var(--info); }
.connection { font-size: 0.95rem; }
.connection.ok { color: var(--ok); }
.connection.warn { color: var(--warn); }
.connection.error { color: var(--error); }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 14px; min-height: 56px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); text-decoration: none;
}
.list-item .title { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: 0.85rem; }
.list-item.inactive { opacity: 0.6; }
.list-item.denied, .list-item.failure, .list-item.not_executed { border-left: 4px solid var(--error); }
.list-item.unknown { border-left: 4px solid var(--warn); }
.list-item.dispatched { border-left: 4px solid var(--ok); }
.list-item button { margin-top: 8px; align-self: flex-start; }

.details { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.details .row { display: grid; grid-template-columns: 130px 1fr; gap: 8px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }

.qr-block { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.qr-block[hidden] { display: none; }
.qr { width: min(80vw, 300px); height: auto; background: #fff; padding: 12px; border-radius: 12px; image-rendering: pixelated; }
.invite-status { font-weight: 700; font-size: 1.1rem; text-align: center; }
.invite-status.approved { color: var(--ok); }
.invite-status.rejected, .invite-status.expired, .invite-status.cancelled { color: var(--error); }

[hidden] { display: none !important; }
