:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --line: #e2e0d8;
  --text: #1b1c1e;
  --muted: #6b6d72;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --danger: #b4412f;
  --ok: #2f7a4a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .04), 0 4px 16px rgba(20, 20, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #1a1b1e;
    --surface-2: #222327;
    --line: #2d2e33;
    --text: #ececea;
    --muted: #9a9ca2;
    --accent: #6fbfa6;
    --accent-ink: #0d1a16;
    --danger: #ef7d6a;
    --ok: #7ccf96;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

/* Light / dark switch (assets/theme.js) — overrides the phone setting when chosen */
:root[data-theme="dark"] {
    --bg: #111214;
    --surface: #1a1b1e;
    --surface-2: #222327;
    --line: #2d2e33;
    --text: #ececea;
    --muted: #9a9ca2;
    --accent: #6fbfa6;
    --accent-ink: #0d1a16;
    --danger: #ef7d6a;
    --ok: #7ccf96;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- Controls ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* stops iOS zooming */
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
input.code { letter-spacing: .35em; text-align: center; font-size: 22px; font-variant-numeric: tabular-nums; }

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
button:disabled { opacity: .55; cursor: default; }
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
button.link {
  background: none;
  color: var(--accent);
  padding: 4px 0;
  font-weight: 500;
}
button.full { width: 100%; margin-top: 20px; }
button.icon { padding: 7px 9px; font-size: 13px; }

.msg { margin-top: 14px; font-size: 14px; min-height: 1em; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---------- Homepage / sign-in ---------- */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 30px 26px 26px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-name { font-weight: 650; }
.stage h2 { font-size: 21px; margin-bottom: 4px; }
.qr { background: #fff; border-radius: 12px; padding: 12px; width: fit-content; margin: 16px auto 8px; }
.qr img { display: block; width: 184px; height: 184px; image-rendering: pixelated; }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; text-align: center; word-break: break-all;
  background: var(--surface-2); border-radius: 8px; padding: 8px; user-select: all;
}
.codes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px;
  background: var(--surface-2); border-radius: 10px; padding: 12px; margin-top: 14px; user-select: all;
}
.steps { padding-left: 18px; margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }
.foot { margin-top: 18px; text-align: center; }

/* ---------- Dashboard ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.top-inner { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.top .brand { margin: 0; }
.top .spacer { flex: 1; }
.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; min-width: 240px;
}
.menu-panel button {
  width: 100%; justify-content: flex-start; background: none; color: var(--text);
  font-weight: 500; padding: 9px 10px;
}
.menu-panel button:hover { background: var(--surface-2); }
.menu-panel .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu-panel .note { padding: 6px 10px; font-size: 12px; color: var(--muted); }

main.dash { max-width: 1240px; margin: 0 auto; padding: 20px 16px calc(40px + env(safe-area-inset-bottom)); }
.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-flow: dense;
  gap: 16px;
}
@media (max-width: 980px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 160px;
  overflow: hidden;
}
.block[data-size="s"] { grid-column: span 1; }
.block[data-size="m"] { grid-column: span 2; }
.block[data-size="l"] { grid-column: span 4; }
@media (max-width: 980px) { .block[data-size="l"] { grid-column: span 2; } }
@media (max-width: 600px) { .block[data-size] { grid-column: span 1; } }

.block-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px 0;
  font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.block-head .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.block-body { padding: 10px 14px 14px; flex: 1; min-height: 0; }
.block-tools { display: none; gap: 4px; }
body.editing .block-tools { display: flex; }
body.editing .block { outline: 2px dashed color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -2px; }
body.editing .block.is-hidden { opacity: .45; }
.block.is-hidden { display: none; }
body.editing .block.is-hidden { display: flex; }
.block-tools button { padding: 4px 8px; font-size: 12px; background: var(--surface-2); color: var(--text); font-weight: 500; }
.block-error { color: var(--danger); font-size: 14px; }

.editbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow); padding: 6px 6px 6px 16px;
  display: flex; align-items: center; gap: 10px; z-index: 6; font-size: 14px;
  max-width: calc(100vw - 32px);
}
.editbar button { border-radius: 999px; padding: 8px 14px; }

.banner {
  max-width: 1240px; margin: 14px auto 0; padding: 10px 14px;
  border-radius: 10px; font-size: 14px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
}
.editbar span { white-space: nowrap; }
body.editing main.dash { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }

/* Theme switch button (any page) */
.theme-btn { background: var(--surface-2); color: var(--text); padding: 7px 10px; font-size: 16px; line-height: 1; font-weight: 500; }
