:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1c1b1a;
  --muted: #6b6862;
  --border: #e2dfd8;
  --accent: #c8643b;
  --accent-text: #ffffff;
  --ok: #2f9e6a;
  --warn: #d08a17;
  --bad: #d4483b;
  --track: #e8e5de;
  --radius: 18px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b1a;
    --surface: #262523;
    --surface-2: #302e2b;
    --text: #f1efea;
    --muted: #a19d95;
    --border: #3a3834;
    --accent: #e0825a;
    --accent-text: #1c1b1a;
    --ok: #4cc18a;
    --warn: #e9a73b;
    --bad: #f0675a;
    --track: #3a3834;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.view {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 24px);
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.icon-btn {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--surface);
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn svg, .account-chip svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.account-chip {
  display: flex; align-items: center; gap: 8px;
  max-width: calc(100% - 56px);
  padding: 6px 12px 6px 6px;
  border: 0; border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}
.account-chip svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.acc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 15px; }
.avatar {
  flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; text-transform: uppercase;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; width: 100%; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 38px; font-size: 14px; padding: 0 14px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:not(:disabled):active { transform: scale(0.98); }

/* Login */
.login { display: flex; flex-direction: column; gap: 20px; padding-top: 8px; }
.lead { margin: 0; color: var(--muted); }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.steps > li {
  display: flex; gap: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  transition: opacity 0.2s;
}
.steps > li > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.steps > li.disabled { opacity: 0.5; }
.step-no {
  flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.step-title { margin: 2px 0 0; font-weight: 700; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
#form-code { display: flex; flex-direction: column; gap: 10px; }
.code-row { display: flex; gap: 8px; }
.code-row input {
  flex: 1; min-width: 0;
  min-height: 48px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg); color: var(--text);
  font: 15px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.error {
  margin: 0; padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  color: var(--bad);
  font-size: 14px;
}
.note { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; font-size: 14px; }
.note summary { cursor: pointer; font-weight: 600; }
.note p { color: var(--muted); }
.fineprint { margin: 0; color: var(--muted); font-size: 12px; text-align: center; }

/* Dashboard */
.cards { display: flex; flex-direction: column; gap: 14px; padding-top: 12px; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  --level: var(--ok);
}
.card[data-level="warn"] { --level: var(--warn); }
.card[data-level="bad"] { --level: var(--bad); }
.card[data-level="none"] { --level: var(--muted); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--muted); }
.pct { font-size: 44px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.bar {
  margin: 14px 0 12px;
  height: 12px; border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}
.bar > i {
  display: block; height: 100%; width: 0;
  border-radius: inherit;
  background: var(--level);
  transition: width 0.6s cubic-bezier(.2,.8,.2,1), background-color 0.3s;
}
.reset { margin: 0; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.reset-in { font-weight: 600; font-variant-numeric: tabular-nums; }
.reset-at { color: var(--muted); }

.status { margin-top: auto; padding-top: 24px; text-align: center; font-size: 13px; color: var(--muted); }
.status p { margin: 4px 0; }
.status-msg:empty { display: none; }
.status-msg.warn { color: var(--warn); }
.status-msg.bad { color: var(--bad); }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 0.45); animation: fade 0.2s; }
.sheet-panel {
  position: relative;
  width: 100%; max-width: 520px; margin: 0 auto;
  max-height: 85vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex; flex-direction: column; gap: 10px;
  animation: up 0.25s cubic-bezier(.2,.8,.2,1);
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 4px; }
.sheet-panel h2 { margin: 4px 0; font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }

.acc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.acc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 12px;
  background: var(--surface);
  border-radius: 16px;
  border: 2px solid transparent;
}
.acc-item.active { border-color: var(--accent); }
.acc-select {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  border: 0; background: none; padding: 0; text-align: left; cursor: pointer;
}
.acc-meta { min-width: 0; display: flex; flex-direction: column; }
.acc-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.acc-meta small { color: var(--muted); font-size: 13px; }
.acc-meta small.bad { color: var(--bad); }
.acc-logout { flex: none; min-height: 38px; font-size: 13px; padding: 0 12px; color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
