:root {
  --bg: #f6f5fa;
  --card: #ffffff;
  --text: #1c1a24;
  --muted: #6b6778;
  --line: #e4e1ee;
  --accent: #7c3aed;
  --accent-soft: #efe7ff;
  --ok: #15803d;
  --ok-soft: #e3f6e9;
  --warn: #b45309;
  --warn-soft: #fff3dc;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --radius: 16px;
  --appbar-h: 56px;
  --tabbar-h: 64px;
  --rail-w: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bottom-chrome: calc(var(--tabbar-h) + var(--safe-bottom));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121018;
    --card: #1c1925;
    --text: #ece9f5;
    --muted: #a19bb3;
    --line: #2e2a3b;
    --accent: #a78bfa;
    --accent-soft: #2a2140;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #34280f;
    --bad: #f87171;
    --bad-soft: #3a1717;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { overscroll-behavior-y: none; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }

/* ---------- app chrome ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0 calc(var(--rail-w) + 8px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.appbar-title {
  flex: 1; min-width: 0; padding: 0 8px;
  font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; padding: 0; border-radius: 50%;
  background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--accent-soft); }
.install-btn { padding: 8px 14px; min-height: 38px; border-radius: 99px; font-size: .9rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; height: var(--bottom-chrome); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; user-select: none;
}
.tabbar svg { width: 26px; height: 26px; padding: 2px 14px; box-sizing: content-box; border-radius: 99px; transition: background .2s; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { background: var(--accent-soft); }

main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--bottom-chrome) + 24px);
}
main.has-actionbar { padding-bottom: calc(var(--bottom-chrome) + 110px); }
body.no-chrome main { padding-bottom: 24px; }

/* Wide screens & desktop app window: tab bar becomes a side rail */
@media (min-width: 820px) {
  :root { --rail-w: 92px; --bottom-chrome: 0px; }
  .tabbar {
    top: 0; right: auto; width: var(--rail-w); height: auto;
    flex-direction: column; justify-content: flex-start; gap: 8px; padding: calc(var(--safe-top) + 72px) 0 0;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tabbar a { flex: 0 0 auto; padding: 6px 0; }
  body:not(.no-chrome) main { margin-left: calc(var(--rail-w) + max(0px, (100vw - var(--rail-w) - 760px) / 2)); }
  main.has-actionbar { padding-bottom: 110px; }
}

/* ---------- content ---------- */
h1 { font-size: 1.45rem; margin: 4px 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
label.field { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
input, textarea, select {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 46px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 18px; min-height: 46px; cursor: pointer;
  background: var(--accent); color: #fff; text-decoration: none; user-select: none;
  transition: transform .08s, filter .15s;
}
button:active, .btn:active { transform: scale(.97); }
button.secondary, .btn.secondary { background: var(--accent-soft); color: var(--accent); }
button.ghost { background: transparent; color: var(--muted); padding: 6px 10px; min-height: 40px; }
button.danger { background: var(--bad-soft); color: var(--bad); }
button:disabled { opacity: .6; cursor: wait; }
button.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 160px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.small { font-size: .85rem; color: var(--muted); }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.notice { border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--accent-soft); color: var(--accent); display: flex; gap: 10px; align-items: flex-start; }
.notice.info button { margin-left: auto; }
.q { border-left: 4px solid transparent; }
.q.unknown { border-left-color: var(--warn); }
.q.filled { border-left-color: var(--ok); }
.q-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.q-title { font-weight: 600; }
.req { color: var(--bad); }
.opts label { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-weight: 400; min-height: 44px; }
.opts label + label { border-top: 1px solid var(--line); }
.opts input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); flex: none; }
.opts input:not([type=radio]):not([type=checkbox]) { width: auto; height: auto; min-height: 40px; }
.remember { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: .85rem; color: var(--muted); }
.remember input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }

.actionbar {
  position: fixed; left: var(--rail-w); right: 0; bottom: var(--bottom-chrome); z-index: 15;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding: 10px 12px;
}
.actionbar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; }
.actionbar .inner > * { flex: 1 1 0; padding-left: 10px; padding-right: 10px; }
.actionbar .inner > .primary { flex: 2 1 0; }
.actionbar .danger { flex: 0 0 52px; }

.list-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; text-decoration: none; color: inherit; transition: border-color .15s, transform .08s; }
.list-item:hover { border-color: var(--accent); }
.list-item:active { transform: scale(.99); }
.saved-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.saved-row:last-child { border-bottom: 0; }
@media (max-width: 560px) {
  .saved-row { grid-template-columns: 1fr auto; }
  .saved-row .val { grid-column: 1 / -1; grid-row: 2; }
}
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-chrome) + 90px); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; max-width: calc(100% - 32px);
  box-shadow: 0 8px 30px rgba(0,0,0,.2); animation: toastIn .2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }
.login { max-width: 380px; margin: calc(12vh + var(--safe-top)) auto 0; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 8px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.details dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 8px 0; }
.details dt { font-weight: 600; color: var(--muted); }
.details dd { margin: 0; }
.details pre { white-space: pre-wrap; font: inherit; font-size: 0.9em; color: var(--muted); background: var(--bg); padding: 10px; border-radius: 8px; }
@media (max-width: 520px) { .details dl { grid-template-columns: 1fr; } .details dd { margin-bottom: 6px; } }
.loading { display: flex; justify-content: center; padding: 60px 0; color: var(--muted); }
/* long links in questions/messages must wrap, or the whole page gets wider than the phone */
.card, .notice, h1 { overflow-wrap: anywhere; }
.q-head > div { min-width: 0; }
