:root {
  color-scheme: dark;
  --bg: #141118;
  --surface: #1c1822;
  --surface-2: #252030;
  --surface-3: #2f2839;
  --border: #322a3d;
  --text: #ece9f2;
  --muted: #9a92a8;
  --accent: #a77cf0;
  --accent-strong: #7d4bc8;
  --accent-soft: rgba(167, 124, 240, .16);
  --danger: #ff6b6b;
  --ok: #4fd18b;
  --warn: #f2b84b;
  --bar-h: 54px;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); }
body { color: var(--text); font: 16px/1.45 var(--font); -webkit-text-size-adjust: 100%; -webkit-user-select: none; user-select: none; }
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 15px; margin: 14px 0 0; }

/* ---------- webbläsaren: låst app-skal, bara sidan scrollar ---------- */
.browser { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
body.is-locked .browser, body.is-locked .sheet, body.is-locked .menu,
body.is-locked .stage iframe, body.is-covered .browser, body.is-covered .sheet, body.is-covered .menu,
body.is-covered .stage iframe { visibility: hidden !important; }
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; background: #fff; }
.stage.show-start { background: var(--bg); }
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; visibility: hidden; }
.stage iframe.active { visibility: visible; z-index: 1; }

.progress { position: absolute; top: 0; left: 0; right: 0; height: 2.5px; z-index: 5; overflow: hidden; opacity: 0; transition: opacity .25s; pointer-events: none; }
.progress.on { opacity: 1; }
.progress i { position: absolute; top: 0; bottom: 0; width: 35%; background: var(--accent); border-radius: 2px; animation: slide 1.15s ease-in-out infinite; }
@keyframes slide { from { left: -35%; } to { left: 100%; } }

.bar { flex: none; display: flex; align-items: center; gap: 2px; height: calc(var(--bar-h) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--text); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn:disabled { color: #5a5266; }
.addr { flex: 1; min-width: 0; height: 38px; margin: 0 4px; display: flex; align-items: center; gap: 7px; padding: 0 12px; border-radius: 11px; background: var(--surface-2); color: var(--text); }
.addr:active { background: var(--surface-3); }
.addr-icon { display: flex; color: var(--muted); }
.addr-icon svg { width: 16px; height: 16px; }
.addr-icon.onion { color: var(--accent); }
.addr-icon.secure { color: var(--ok); }
.addr-icon.insecure { color: var(--warn); }
.addr-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; text-align: left; }
.addr-text.placeholder { color: var(--muted); }
.js-badge { font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--warn); border: 1px solid currentColor; border-radius: 5px; padding: 0 4px; line-height: 15px; }
.tab-count { min-width: 22px; height: 22px; padding: 0 4px; display: grid; place-items: center; border: 1.8px solid currentColor; border-radius: 6px; font-size: 12px; font-weight: 700; }

/* ---------- startsida ---------- */
.start { position: absolute; inset: 0; z-index: 2; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; background: var(--bg); }
.start-inner { max-width: 560px; margin: 0 auto; padding: 48px 18px 40px; }
.start-logo { width: 64px; height: 64px; margin: 0 auto 22px; border-radius: 20px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.start-logo svg { width: 36px; height: 36px; stroke-width: 1.6; }
.start-search { width: 100%; height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-radius: var(--radius); background: var(--surface-2); color: var(--muted); }
.start-search svg { width: 19px; height: 19px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 28px 4px 10px; }
.bm-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 8px; }
.bm-grid button { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 7px; }
.bm-grid .avatar { width: 56px; height: 56px; border-radius: 16px; font-size: 22px; }
.bm-grid .name { width: 100%; font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.avatar { display: grid; place-items: center; font-weight: 650; color: #fff; background: var(--accent-strong); flex: none; text-transform: uppercase; }

/* ---------- helskärmspaneler ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--bg); }
.sheet-head { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.sheet-head h1 { margin: 0; font-size: 17px; font-weight: 650; }
.sheet-head .text-btn:first-child { justify-self: start; }
.sheet-head .text-btn:last-child { justify-self: end; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; padding: 6px 14px calc(env(safe-area-inset-bottom) + 30px); }
.sheet-body > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.sheet-foot { flex: none; padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px); border-top: 1px solid var(--border); background: var(--surface); }
.text-btn { padding: 8px 4px; color: var(--accent); font-size: 16px; }
.text-btn.strong { font-weight: 650; }
.text-btn.danger-text { color: var(--danger); }

.addr-form { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.addr-field { flex: 1; min-width: 0; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 6px 0 12px; border-radius: 12px; background: var(--surface-2); color: var(--muted); }
.addr-field input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text); font: 17px var(--font); }
.addr-field input::placeholder { color: var(--muted); }
.addr-field svg { width: 18px; height: 18px; }
.clear-btn { width: 30px; height: 30px; display: grid; place-items: center; color: var(--muted); }
.clear-btn svg { width: 16px; height: 16px; }
.hint-search { margin-top: 22px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.list .row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 11px 0; text-align: left; }
.list .avatar { width: 36px; height: 36px; border-radius: 10px; font-size: 15px; }
.row-text { min-width: 0; flex: 1; }
.row-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.row-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.row-btn { width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); border-radius: 10px; }
.row-btn.danger { color: var(--danger); }
.row-input { flex: 1; min-width: 0; height: 38px; margin: 6px 0; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: 16px var(--font); }

.tab-list { list-style: none; margin: 0; padding: 6px 0 0; display: grid; gap: 10px; }
.tab-list li { display: flex; align-items: center; gap: 4px; border-radius: var(--radius); background: var(--surface); border: 1.5px solid transparent; }
.tab-list li.active { border-color: var(--accent); background: var(--surface-2); }
.tab-list .row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px 0 12px 12px; text-align: left; }
.tab-list .avatar { width: 34px; height: 34px; border-radius: 9px; font-size: 14px; }

/* ---------- meny (bottenark) ---------- */
.menu { position: fixed; inset: 0; z-index: 40; }
.menu-backdrop { position: absolute; inset: 0; background: rgba(5, 3, 8, .55); animation: fade .18s ease-out; }
.menu-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88%; overflow-y: auto; overscroll-behavior-y: contain; background: var(--surface); border-radius: 20px 20px 0 0; padding: 6px 14px calc(env(safe-area-inset-bottom) + 14px); animation: up .22s cubic-bezier(.2, .8, .2, 1); }
.menu-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 4px auto 10px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.menu-site { padding: 4px 4px 12px; }
.menu-host { font: 600 14px/1.35 ui-monospace, Menlo, monospace; word-break: break-all; }
.menu-group { background: var(--surface-2); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.menu-row { width: 100%; min-height: 50px; display: flex; align-items: center; gap: 13px; padding: 0 14px; text-align: left; font-size: 16px; color: var(--text); border-bottom: 1px solid var(--border); }
.menu-group > :last-child { border-bottom: 0; }
.menu-row:active { background: var(--surface-3); }
.menu-row svg { color: var(--accent); }
.menu-row span { flex: 1; }
.menu-row.danger, .menu-row.danger svg { color: var(--danger); }
.menu-row.is-on svg { fill: var(--accent); }
.menu-hint { margin: 0; padding: 0 14px 12px 49px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); }
.toggle-row { cursor: pointer; border-bottom: 0; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 46px; height: 28px; border-radius: 14px; background: var(--surface-3); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle-row input:checked + .switch { background: var(--warn); }
.toggle-row input:checked + .switch::after { transform: translateX(18px); }
.menu-tor { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 0 2px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

.confirm-panel { padding-top: 22px; text-align: center; }
.confirm-panel h2 { margin: 0 0 8px; font-size: 19px; }
.confirm-panel p { margin: 0 0 18px; }
.confirm-panel .btn { margin-top: 8px; }

/* ---------- knappar ---------- */
.btn { height: 50px; padding: 0 20px; border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center; gap: 10px; font-size: 17px; font-weight: 600; background: var(--surface-3); color: var(--text); }
.btn.primary { background: var(--accent-strong); color: #fff; }
.btn.danger { background: var(--danger); color: #1a0d0d; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }
.btn:active { filter: brightness(1.12); }

/* ---------- låsskärm ---------- */
.lock { position: fixed; inset: 0; z-index: 100; display: flex; overflow-y: auto; background: radial-gradient(120% 70% at 50% 0%, #2a1d3d 0%, var(--bg) 60%); }
body:not(.is-locked) .lock { display: none; }
.lock-inner { margin: auto; width: 100%; max-width: 380px; padding: 40px 26px calc(env(safe-area-inset-bottom) + 30px); text-align: center; }
.lock-logo { width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 26px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); box-shadow: 0 10px 40px rgba(125, 75, 200, .25); }
.lock-logo svg { width: 46px; height: 46px; stroke-width: 1.5; }
.lock h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.3px; }
.lock-inner > .muted { margin: 6px 0 28px; }
.setup p { margin: 0 0 14px; }
.code-input { width: 100%; height: 52px; margin-bottom: 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); text-align: center; font: 600 22px ui-monospace, Menlo, monospace; letter-spacing: 3px; text-transform: uppercase; outline: 0; }
.code-input:focus { border-color: var(--accent); }
.tor-line { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 34px; font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 12px; background: #3a3247; color: var(--text); font-size: 15px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4); animation: up .2s ease-out; }
