/* Regudae web app — hand-written, no framework. Colours are tokens; no inline styles anywhere
   (CSP style-src 'self'). Layout lifted from Memoratu desk/web/css/app.css (the single-column shell:
   top bar, banners, bottom tab bar on phones / top tabs on wide screens); the palette is Regudae's
   (CONTRACT-CORE §7 and the icon kit's contact sheet): navy #14213D, gold #B8913F, page #F6F4EF,
   card #FFFFFF, ink #1D1D1B; dark: page #15161A, ink #E8E6E1, gold #C9A24C.

   Light and dark follow prefers-color-scheme. js/look.js mirrors the resolved scheme into
   data-scheme on <html> so a rule can key on it; the media query below is what paints the first frame. */
:root {
  --bg: #F6F4EF; --surface: #FFFFFF; --ink: #1D1D1B; --muted: #6B6A66; --line: #E3DFD5;
  --navy: #14213D; --gold: #B8913F; --accent: #14213D; --accent-ink: #FFFFFF; --accent-soft: #E9ECF3;
  --ok: #1F7A4D; --ok-bg: #E4F3EA; --danger: #B3261E; --danger-bg: #FBE9E7;
  --warn-bg: #FFF3D6; --warn-ink: #6A4A00; --info-bg: #E9ECF3; --info-ink: #14213D;
  --radius: 10px; --gap: 12px; --touch: 44px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161A; --surface: #1F2026; --ink: #E8E6E1; --muted: #A09E98; --line: #33343B;
    --navy: #14213D; --gold: #C9A24C; --accent: #C9A24C; --accent-ink: #15161A; --accent-soft: #2A2B33;
    --ok: #5FC48E; --ok-bg: #16301F; --danger: #FF8A80; --danger-bg: #3A1C1E;
    --warn-bg: #3A2E0A; --warn-ink: #FFD98A; --info-bg: #222A3D; --info-ink: #C9D3EA;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); padding-bottom: env(safe-area-inset-bottom); }
#app { min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px 96px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.4rem; margin: 20px 0 14px; }
h3 { font-size: 1.05rem; margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; word-break: break-all; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.ri-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ri { width: 1.25em; height: 1.25em; vertical-align: -.3em; flex: none; }
.ri.lg { width: 1.75em; height: 1.75em; }

/* top bar */
.top { display: flex; align-items: center; gap: var(--gap); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.brand .ri { width: 1.6em; height: 1.6em; color: var(--navy); }
@media (prefers-color-scheme: dark) { .brand .ri { color: var(--gold); } }
.top .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .85rem; text-align: right; }
.top .who b { color: var(--ink); font-weight: 600; }

/* nav: bottom tab bar on phones, top tabs on wide screens */
.nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 0; min-height: var(--touch);
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: .8rem; }
.nav a .ri { width: 1.4em; height: 1.4em; }
.nav a.on { color: var(--accent); }
@media (min-width: 720px) {
  .nav { position: static; border: 0; max-width: 720px; margin: 0 auto; width: 100%; order: 1; background: transparent; }
  .nav a { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 8px 18px; font-size: .95rem; }
  #app { display: flex; flex-direction: column; }
  .top { order: 0; } .banners { order: 0; } main { order: 2; padding-bottom: 48px; }
}

/* banners (the account states) */
.banners:empty { display: none; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px; font-size: .9rem; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.info { background: var(--info-bg); color: var(--info-ink); }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner > .text { flex: 1 1 220px; }
.banner .btn { min-height: 36px; }

/* buttons + inputs (16px font: iOS Safari will not zoom on focus) */
.btn { font: inherit; font-weight: 600; min-height: var(--touch); padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0; min-height: var(--touch); font-weight: 500; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea { font: inherit; width: 100%; min-height: var(--touch); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
textarea { padding: 10px 12px; line-height: 1.5; }
input[type=number].short { width: 6em; display: inline-block; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; margin: 0 10px 0 0; accent-color: var(--accent); }
.field { display: block; font-size: .85rem; color: var(--muted); margin: 14px 0 4px; }
.field.inline { display: flex; align-items: center; min-height: var(--touch); color: var(--ink); font-size: 1rem; margin: 8px 0; cursor: pointer; }
.choice { display: flex; align-items: flex-start; gap: 0; padding: 8px 0; cursor: pointer; }
.choice input { margin-top: 3px; }
.choice .what { display: block; }
.choice .why { display: block; color: var(--muted); font-size: .85rem; }
.form-actions { margin: 20px 0 8px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.error { color: var(--danger); margin: 10px 0 0; }
.ok { color: var(--ok); margin: 10px 0 0; }
.notice { background: var(--info-bg); color: var(--info-ink); padding: 10px 12px; border-radius: var(--radius); margin-top: 16px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice.danger { background: var(--danger-bg); color: var(--danger); }

/* auth pages */
.auth-page { max-width: 420px; padding-top: 6vh; }
.auth-page h2 { font-size: 1.6rem; }
.auth { display: flex; flex-direction: column; gap: 2px; margin-top: 16px; }
.auth .btn.primary { margin-top: 18px; }
.links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 18px; font-size: .95rem; }
.links a { min-height: var(--touch); display: inline-flex; align-items: center; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.card h3 { display: flex; align-items: center; gap: 8px; }
.card h3 .ri { color: var(--gold); }
.kv { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; gap: 6px 14px; margin: 6px 0; font-size: .95rem; }
.kv b { color: var(--muted); font-weight: 500; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: var(--touch); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .meta { color: var(--muted); font-size: .85rem; display: block; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .75rem; border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.chip.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.empty { color: var(--muted); padding: 16px 0; }
.state { text-align: center; padding: 48px 16px; color: var(--muted); }
.state .ri { width: 2.5em; height: 2.5em; color: var(--muted); }
.state h2 { color: var(--ink); margin-top: 10px; }

/* usage bars */
.usage { margin: 10px 0; }
.usage .l { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 4px; }
.usage .l span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.usage .bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: var(--navy); width: 0; }
@media (prefers-color-scheme: dark) { .usage .bar i { background: var(--gold); } }
.usage .bar i.p10 { width: 10%; } .usage .bar i.p20 { width: 20%; } .usage .bar i.p30 { width: 30%; } .usage .bar i.p40 { width: 40%; } .usage .bar i.p50 { width: 50%; }
.usage .bar i.p60 { width: 60%; } .usage .bar i.p70 { width: 70%; } .usage .bar i.p80 { width: 80%; } .usage .bar i.p90 { width: 90%; } .usage .bar i.p100 { width: 100%; }
.usage .bar i.hot { background: var(--danger); }

/* recovery codes */
.codes-box { font-family: ui-monospace, Menlo, monospace; font-size: 1rem; letter-spacing: .04em; min-height: 11em; }
.codes-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.codes-user { margin-bottom: 8px; }

/* the secret shown once */
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 1.05rem; background: var(--accent-soft); padding: 12px; border-radius: var(--radius); word-break: break-all; user-select: all; }

/* sheet: bottom sheet on phones, centred dialog on wide screens */
.sheet-host { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.4); }
.sheet { background: var(--surface); color: var(--ink); width: 100%; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet h3 { font-size: 1.2rem; margin-bottom: 8px; }
.sheet .form-actions { position: sticky; bottom: 0; background: var(--surface); padding: 10px 0 0; }
@media (min-width: 720px) {
  .sheet-host { align-items: center; }
  .sheet { max-width: 520px; border-radius: 16px; padding: 20px 24px; }
}
.ask { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--danger); border-radius: var(--radius); background: var(--danger-bg); color: var(--ink); }
.ask h3 { font-size: 1rem; }
.perm-group { margin: 10px 0; }
.perm-group .perm-head { font-weight: 600; margin: 6px 0; }
.perm-group .choice { padding: 4px 0 4px 8px; }

/* toast */
.toast-host { position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 0; right: 0; display: flex; justify-content: center; z-index: 30; pointer-events: none; }
.toast { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: .9rem; box-shadow: 0 2px 10px rgba(0,0,0,.2); transition: opacity .25s; }
.toast.tone-warn { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }

/* shortcuts sheet */
.keys-list { list-style: none; padding: 0; margin: 0; }
.keys-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
kbd { font-family: ui-monospace, Menlo, monospace; background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; font-size: .85rem; }

/* preview ribbon (the states preview route) */
.preview { background: var(--gold); color: #1D1D1B; font-size: .8rem; padding: 4px 16px; text-align: center; }
