/* CipherMath — Midnight Violet with Graphite accent */
:root {
  color-scheme: dark;
  --bg: #0E0C14;
  --surface: #18151F;
  --surface-2: #1C1824;
  --bar: #141119;
  --line: #2A2535;
  --line-2: #3A3348;
  --text: #F2EFF8;
  --cipher: #D9D3E6;
  --muted: #A8A1B8;
  --dim: #8F88A0;
  --accent: #6D5DFC;
  --accent-press: #5B4BEB;
  --accent-text: #A99FFF;
  --indigo: #1E1B3A;
  --indigo-line: #2E2A55;
  --danger: #FF8A95;
  --danger-bg: #1F1418;
  --danger-line: #4A2530;
  --danger-ic: #3A1C24;
  --warn: #F5B76A;
  --warn-text: #F2E3D2;
  --warn-bg: #221A14;
  --warn-line: #4A3420;
  --ok: #8FE3B5;
  --ok-bg: #14261D;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
h1, h2, p { margin: 0; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i.xs { width: 14px; height: 14px; stroke-width: 2.2; }
.i.sm { width: 16px; height: 16px; }
.i.lg { width: 24px; height: 24px; }
.i.dim { color: var(--dim); }
.i.accent { color: var(--accent-text); }
.i.logo { color: #fff; }

/* ---------- layout ---------- */
#app { position: relative; max-width: 480px; margin: 0 auto; height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
#appbar { flex: none; display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 12px) 20px 4px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }

.screen { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 18px; padding: 14px 20px 32px; }
.screen.standalone { padding-top: calc(var(--safe-top) + 16px); }
.screen.centered { align-items: center; }
.self-stretch { align-self: stretch; }
.self-start { align-self: flex-start; }
.push-bottom { margin-top: auto; }
.center { text-align: center; align-items: center; }
.stack-8, .stack-10, .stack-12, .stack-14, .stack-18 { display: flex; flex-direction: column; }
.stack-8 { gap: 8px; } .stack-10 { gap: 10px; } .stack-12 { gap: 12px; } .stack-14 { gap: 14px; } .stack-18 { gap: 18px; }
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gap-12 { gap: 12px; }
.col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.grow { flex: 1; min-width: 0; text-align: left; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.topbar { display: flex; }

/* ---------- type ---------- */
.h-xl { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.h-lg { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.h-page { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
.h-md { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; text-align: center; }
.lead { font-size: 16px; line-height: 1.5; color: var(--muted); }
.sub { font-size: 14px; line-height: 1.5; color: var(--muted); }
.label { font-size: 13px; color: var(--muted); }
.hint { font-size: 12px; line-height: 1.5; color: var(--dim); }
.name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.note { display: flex; gap: 8px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.note .i { margin-top: 2px; }
.note-center { font-size: 13px; line-height: 1.5; color: var(--muted); text-align: center; }
.mono { font-family: var(--mono); }

/* ---------- logo ---------- */
.logo-tile { display: flex; align-items: center; justify-content: center; background: var(--indigo); border: 1px solid var(--indigo-line); flex: none; }
.logo-tile.xs { width: 26px; height: 26px; border-radius: 7px; }
.logo-tile.xs .i { width: 18px; height: 18px; }
.logo-tile.sm { width: 30px; height: 30px; border-radius: 9px; }
.logo-tile.sm .i { width: 22px; height: 22px; }
.logo-tile.lg { width: 64px; height: 64px; border-radius: 18px; }
.logo-tile.lg .i { width: 44px; height: 44px; }
.logo-tile.xl { width: 80px; height: 80px; border-radius: 22px; }
.logo-tile.xl .i { width: 56px; height: 56px; }
.mt-lock { margin-top: 6vh; }

/* ---------- buttons ---------- */
.btn { width: 100%; height: 54px; border-radius: 16px; border: 0; font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; flex: none; transition: background-color .15s, opacity .15s; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active:not(:disabled) { background: var(--accent-press); }
.btn.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--text); font-weight: 500; }
.btn.ghost:active:not(:disabled) { background: var(--surface-2); }
.btn.danger { background: #B4323F; color: #fff; }
.btn.sm { height: 48px; border-radius: 14px; font-size: 15px; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); display: flex; align-items: center; justify-content: center; flex: none; }
#cd-back, #ac-back, #about-back, #sp-back { color: var(--text); }
.round-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.link { background: none; border: 0; padding: 10px 4px; color: var(--accent-text); font-size: 14px; min-height: 44px; }
.pill { height: 32px; border-radius: 999px; border: 0; background: var(--indigo); color: var(--accent-text); font-size: 13px; font-weight: 600; padding: 0 12px; display: flex; align-items: center; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 500; color: var(--accent-text); background: var(--indigo); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.chip.ok { color: var(--ok); background: var(--ok-bg); font-size: 12px; padding: 5px 10px; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
input[type="text"], input[type="password"], textarea, select { font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; width: 100%; outline: none; }
input[type="text"], input[type="password"] { height: 54px; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; line-height: 1.45; min-height: 104px; }
input.mono { font-family: var(--mono); font-size: 17px; }
textarea.mono-sm { font-family: var(--mono); font-size: 16px; line-height: 1.5; word-break: break-all; }
::placeholder { color: #6E6880; }
.select-wrap { position: relative; display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.select-wrap select { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; padding: 0; border: 0; -webkit-appearance: none; appearance: none; }
.select-wrap .select-label { flex: 1; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-wrap:focus-within { border-color: var(--accent); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.empty p { font-size: 15px; line-height: 1.5; color: var(--muted); }
.card.empty strong { color: var(--text); font-weight: 600; }
.cipher { font-family: var(--mono); font-size: 13px; line-height: 1.55; color: var(--cipher); word-break: break-all; max-height: 10.5em; overflow-y: auto; -webkit-user-select: all; user-select: all; }
.plain { font-size: 18px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.card.error { background: var(--danger-bg); border-color: var(--danger-line); }
.err-ic { width: 40px; height: 40px; border-radius: 50%; background: var(--danger-ic); color: var(--danger); display: flex; align-items: center; justify-content: center; flex: none; }
.err-sub { font-size: 13px; line-height: 1.45; color: #C9B8BE; }
.cipher-preview { font-family: var(--mono); font-size: 12px; color: var(--dim); background: #160F12; border-radius: 10px; padding: 10px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reasons { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; line-height: 1.45; }

/* ---------- avatars ---------- */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--indigo); color: var(--accent-text); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex: none; }
.avatar.md { width: 40px; height: 40px; font-size: 16px; }
.avatar.xl { width: 72px; height: 72px; font-size: 28px; }
.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.profile .h-md { overflow-wrap: anywhere; }

/* ---------- paste zone ---------- */
.pastezone { height: 112px; border-radius: 20px; border: 1.5px dashed #3E3870; background: #131222; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; flex: none; }
.pastezone:active { background: #181630; }
.paste-ic { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.paste-t { font-size: 16px; font-weight: 600; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; flex: none; }
.list > * + * { border-top: 1px solid var(--line); }
.contact-row { width: 100%; min-height: 68px; background: none; border: 0; display: flex; align-items: center; gap: 14px; padding: 0 16px; text-align: left; }
.contact-row:active, .row-btn:active { background: var(--surface-2); }
.contact-row .sub { font-size: 13px; }
.row-btn { width: 100%; min-height: 52px; background: none; border: 0; display: flex; align-items: center; gap: 12px; padding: 0 16px; font-size: 15px; text-align: left; }
.row-btn.danger { color: var(--danger); font-weight: 500; }
.row-static { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; font-size: 15px; }
.group-t { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }

/* ---------- switch ---------- */
.switch { width: 51px; height: 31px; border-radius: 999px; border: 0; background: var(--line-2); position: relative; flex: none; padding: 0; transition: background-color .2s; }
.switch span { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #CFC9DA; transition: transform .2s, background-color .2s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(20px); background: #fff; }

/* ---------- key, words, meter ---------- */
.keytext { font-family: var(--mono); font-size: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.keytext.masked { letter-spacing: .15em; color: var(--dim); }
.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; flex: none; }
.segmented button { height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; }
.segmented button[aria-selected="true"] { background: var(--indigo); color: var(--text); font-weight: 600; }
.words { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.word { height: 64px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 16px; min-width: 0; }
.word .n { font-size: 12px; color: var(--dim); }
.word .w { font-family: var(--mono); font-size: 20px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.meter { display: flex; align-items: center; gap: 12px; }
.bars { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.bars span { height: 6px; border-radius: 999px; background: var(--line); }
.meter[data-level="1"] .bars span:nth-child(-n+1),
.meter[data-level="2"] .bars span:nth-child(-n+2) { background: var(--warn); }
.meter[data-level="3"] .bars span:nth-child(-n+3) { background: var(--accent-text); }
.meter[data-level="4"] .bars span { background: var(--ok); }
.meter-label { font-size: 13px; font-weight: 600; min-width: 52px; text-align: right; }
.meter[data-level="1"] .meter-label, .meter[data-level="2"] .meter-label { color: var(--warn); }
.meter[data-level="3"] .meter-label { color: var(--accent-text); }
.meter[data-level="4"] .meter-label { color: var(--ok); }
.warn { display: flex; gap: 12px; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 16px; padding: 14px 16px; }
.warn p { font-size: 13px; line-height: 1.5; color: var(--warn-text); }
.warn strong { font-weight: 600; }
.warn-ic { color: var(--warn); margin-top: 1px; }

/* ---------- install / welcome ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.steps li { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.step-n { width: 28px; height: 28px; border-radius: 50%; background: var(--indigo); color: var(--accent-text); font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none; }
.step-t { flex: 1; font-size: 15px; line-height: 1.4; }
.step-t strong { font-weight: 600; }
.perks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.perks li { display: flex; align-items: center; gap: 14px; font-size: 15px; }
.perk-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--indigo); color: var(--accent-text); display: flex; align-items: center; justify-content: center; flex: none; }

/* ---------- PIN pad ---------- */
.pad-host { display: flex; flex-direction: column; align-items: center; width: 100%; }
.pinpad { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.pin-dots { display: flex; gap: 16px; margin-top: 14px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #4A4259; transition: background-color .1s; }
.pin-dots span.on { background: var(--accent-text); border-color: var(--accent-text); }
.pad-msg { min-height: 20px; font-size: 13px; color: var(--muted); text-align: center; }
.pad-msg.err { color: var(--danger); }
.keypad { --k: min(76px, 19vw, 9.2dvh); display: grid; grid-template-columns: repeat(3, var(--k)); gap: min(16px, 2dvh) 28px; justify-content: center; margin-top: 4px; }
.key { width: var(--k); height: var(--k); border-radius: 50%; border: 0; background: var(--surface-2); font-size: 28px; font-weight: 500; display: flex; align-items: center; justify-content: center; transition: background-color .08s; }
.key:active { background: var(--line-2); }
.key-del { background: transparent; color: var(--muted); }
.pinpad.busy, .pinpad.disabled { opacity: .55; pointer-events: none; }
.passform { display: flex; flex-direction: column; gap: 12px; width: 100%; margin-top: 14px; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- about ---------- */
.prose { display: flex; flex-direction: column; gap: 10px; }
.prose h2 { font-size: 16px; font-weight: 600; margin-top: 10px; }
.prose p { font-size: 15px; line-height: 1.55; color: var(--muted); }

/* ---------- tab bar ---------- */
#tabbar { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--bar); border-top: 1px solid #262130; padding: 8px 8px calc(var(--safe-bottom) + 8px); }
#tabbar button { background: none; border: 0; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--dim); font-size: 11px; font-weight: 500; }
#tabbar button.active { color: var(--accent-text); font-weight: 600; }

/* ---------- sheet, toast, shield ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 4, 10, .65); }
.sheet-panel { position: relative; width: 100%; max-width: 480px; max-height: 92dvh; overflow-y: auto; background: var(--bar); border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0; padding: 22px 20px calc(var(--safe-bottom) + 20px); display: flex; flex-direction: column; gap: 14px; animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-title { font-size: 20px; font-weight: 600; text-align: center; }
.sheet-text { font-size: 14px; line-height: 1.5; color: var(--muted); text-align: center; }
#toast { position: fixed; left: 50%; top: calc(var(--safe-top) + 12px); transform: translate(-50%, -12px); max-width: calc(100% - 40px); background: #2A2440; color: var(--text); font-size: 14px; line-height: 1.4; padding: 12px 16px; border-radius: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, .4); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#shield { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; }

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