:root {
  --bg: #f5f4fb; --card: #ffffff; --text: #1c1a2b; --muted: #6a6780; --line: #dcd9ec;
  --accent: #5b3fd6; --accent-text: #ffffff; --danger: #c0392b; --warn: #b7791f;
  --s1: #d9534f; --s2: #e0a31a; --s3: #5aa469; --s4: #2f9e6a;
}
:root[data-theme="dark"] {
  --bg: #11101a; --card: #1b1a29; --text: #ece9fb; --muted: #a09db8; --line: #2d2b42;
  --accent: #9a86ff; --accent-text: #12101f; --danger: #ef6b5b; --warn: #e0b04a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11101a; --card: #1b1a29; --text: #ece9fb; --muted: #a09db8; --line: #2d2b42;
    --accent: #9a86ff; --accent-text: #12101f; --danger: #ef6b5b; --warn: #e0b04a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 40px; }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.icon { padding: 0; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
button.wide { width: 100%; }
button.linkish { background: none; border: 0; padding: 6px 0; min-height: 0; color: var(--accent); text-decoration: underline; text-align: left; }
button.linkish.danger-text { color: var(--danger); }
a { color: var(--accent); }
a.btnlike { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-height: 40px; width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 5px; }
label.chk { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; margin: 10px 0; }
label.chk input { width: auto; min-height: 0; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.note { color: var(--muted); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; } .gap { gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.pad { padding: 8px 16px 24px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }

/* Layout */
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
html:not(.unlocked) #app { padding-bottom: 0; }
html:not(.ready) body > :not(script):not(style):not(link) { visibility: hidden; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 5; background: var(--bg); }
.bar h1 { margin: 0; font-size: 22px; }
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs[hidden] { display: none; }
#tabs button { flex: 1; max-width: 144px; border: 0; background: none; border-radius: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 8px 2px; color: var(--muted); min-height: 56px; }
#tabs button.on { color: var(--accent); font-weight: 600; }

/* Auth cards */
.card.auth { margin: 7vh 16px 24px; padding: 24px 20px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; max-width: 440px; }
@media (min-width: 480px) { .card.auth { margin-left: auto; margin-right: auto; } }
.card.auth h1 { margin: 6px 0 4px; font-size: 24px; text-align: center; }
.card.auth .lead { text-align: center; color: var(--muted); margin: 0 0 8px; }
.logo { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; background: var(--accent); color: var(--accent-text); display: flex; align-items: center; justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; align-items: flex-start; }
.card.auth button.primary { margin-top: 14px; }
.inp { display: flex; align-items: center; gap: 4px; position: relative; }
.inp input { flex: 1; min-width: 0; }
.inp.grow { flex: 1 1 100%; }
.toolbar select { flex: 1; }
.inp .ico { position: absolute; left: 11px; color: var(--muted); display: flex; pointer-events: none; }
.inp .ico + input { padding-left: 36px; }
.meter-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; min-height: 22px; }
.meter { display: flex; gap: 3px; width: 96px; flex: none; }
.meter i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.meter i.s1 { background: var(--s1); } .meter i.s2 { background: var(--s2); } .meter i.s3 { background: var(--s3); } .meter i.s4 { background: var(--s4); }
.rk { font: 600 17px/1.6 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .5px; text-align: center; background: var(--bg); border: 1px dashed var(--line); border-radius: 12px; padding: 14px 8px; margin: 12px 0; word-break: break-all; user-select: all; }

/* Vault list */
.toolbar { display: flex; gap: 8px; padding: 0 16px 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; padding: 0 16px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border-radius: 999px; padding: 6px 14px; min-height: 34px; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.banner { margin: 4px 16px 10px; padding: 10px 12px; border: 1px solid var(--warn); border-radius: 10px; background: var(--card); font-size: 14px; }
.banner button { margin-top: 8px; display: block; }
.list { padding: 0 8px; min-height: 120px; }
.row-item { display: flex; align-items: center; }
.row-main { flex: 1; display: flex; align-items: center; gap: 12px; text-align: left; border: 0; background: none; border-radius: 12px; padding: 10px 8px; width: 100%; min-width: 0; }
.row-main:active { background: var(--card); }
.rt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.rt b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av { width: 40px; height: 40px; border-radius: 12px; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; flex: none; }
.fav { color: var(--s2); display: flex; }
.empty { text-align: center; padding: 48px 24px; color: var(--text); }
.fab { position: fixed; right: max(16px, calc(50vw - 344px)); bottom: calc(72px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 18px; padding: 0; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.28); z-index: 9; }
.codes-row .code { font-size: 22px; font-weight: 700; letter-spacing: 1px; color: var(--accent); }
.tbar { height: 4px; border-radius: 2px; background: var(--line); margin-top: 6px; overflow: hidden; }
.tbar i { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }
.tbar i.low { background: var(--s1); }

/* Sheets (dialogs) */
dialog.sheet { border: 0; padding: 0; background: transparent; color: var(--text); max-width: none; max-height: none; width: 100%; height: 100%; margin: 0; }
dialog.sheet::backdrop { background: rgba(10, 8, 24, .55); }
.sheet-box { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 520px; max-height: 92dvh; background: var(--card); border: 1px solid var(--line); border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
dialog.sheet.wide .sheet-box { max-width: 600px; }
@media (min-width: 600px) { .sheet-box { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 18px; max-height: 88vh; } }
.sheet-head { display: flex; align-items: center; padding: 12px 8px 4px 18px; }
.sheet-head h2 { margin: 0; font-size: 18px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 4px 18px 12px; overflow-y: auto; overscroll-behavior: contain; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.sheet-foot button.primary { min-width: 96px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 20px 8px; }

/* Detail */
.frow { display: flex; align-items: center; gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.fl { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fl small { color: var(--muted); }
.fl a, .fl span { overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.code { font-size: 26px; font-weight: 700; letter-spacing: 2px; color: var(--accent); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tag { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 13px; color: var(--muted); }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--muted); }
.pill.s1 { background: var(--s1); } .pill.s2 { background: var(--s2); color: #231a00; } .pill.s3 { background: var(--s3); } .pill.s4 { background: var(--s4); }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 6px; }
.preview { max-width: 100%; border-radius: 10px; display: block; margin: 0 auto; }
video.scan { width: 100%; border-radius: 12px; background: #000; aspect-ratio: 1; object-fit: cover; }

/* Generator */
.gen-out { font: 600 18px/1.5 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; padding: 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); margin: 12px 0; min-height: 64px; border-left: 6px solid var(--muted); }
.gen-out[data-s="4"] { border-left-color: var(--s4); } .gen-out[data-s="3"] { border-left-color: var(--s3); } .gen-out[data-s="2"] { border-left-color: var(--s2); } .gen-out[data-s="1"] { border-left-color: var(--s1); }
.seg { display: flex; } .seg button { flex: 1; border-radius: 0; } .seg button:first-child { border-radius: 10px 0 0 10px; } .seg button:last-child { border-radius: 0 10px 10px 0; border-left: 0; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.rng { display: block; color: var(--text); margin: 14px 0 6px; font-size: 14px; } .rng input { padding: 0; min-height: 32px; border: 0; background: none; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.sel { margin: 10px 0; font-size: 14px; color: var(--text); }

/* Security and settings */
.score { display: flex; flex-direction: column; align-items: center; padding: 18px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); margin-bottom: 8px; }
.score b { font-size: 40px; } .score.s4 b { color: var(--s4); } .score.s3 b { color: var(--s3); } .score.s1 b { color: var(--s1); }
details.sec { border-bottom: 1px solid var(--line); padding: 8px 0; }
details.sec summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-weight: 600; min-height: 36px; }
.kv .kvr { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); margin: 0; color: var(--text); font-size: 15px; width: 100%; }
.setrow > span { display: flex; flex-direction: column; min-width: 0; }
.setrow select { width: auto; max-width: 52%; flex: none; }
.setrow.btn { background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; min-height: 56px; }
.setrow.btn.danger b { color: var(--danger); }
.setrow.static button { flex: none; }

/* Toast and update bar */
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; z-index: 2147483000; text-align: center; font-size: 14px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.updbar { position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 2147483000; max-width: 92vw; background: #222; color: #fff; padding: 9px 12px; border-radius: 10px; font: 14px system-ui, sans-serif; display: flex; gap: 10px; align-items: center; }
.updbar button { min-height: 0; padding: 4px 10px; background: #fff; color: #222; border: 0; border-radius: 6px; }
.updbar button.x { background: none; color: #fff; padding: 0 4px; }

/* About text (for search engines and first-time visitors) */
.about { max-width: 720px; margin: 8px auto 0; padding: 16px 16px 48px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
.about h2 { font-size: 18px; color: var(--text); margin: 8px 0; }
.about h3 { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); margin: 18px 0 6px; }
.about details { border-bottom: 1px solid var(--line); padding: 8px 0; }
.about summary { cursor: pointer; color: var(--text); font-weight: 600; }
.about p, .about li { margin: 6px 0; }
html.unlocked .about { display: none; }
html:not(.ready) .about { display: none; }
@media (display-mode: standalone) { .about { display: none; } }
@media print { .about, #tabs, .fab { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
