:root {
  --bg: #0b0d10;
  --panel: rgba(28, 31, 36, .72);
  --panel-solid: #16191e;
  --line: rgba(255, 255, 255, .1);
  --text: #f4f5f7;
  --muted: #9aa1ab;
  --accent: #2f8cff;
  --accent-2: #4fd1a5;
  --chip: rgba(255, 255, 255, .1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
input { font: inherit; color: inherit; }

main { position: fixed; inset: 0 0 calc(var(--tab-h) + var(--safe-b)) 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.page { overflow-y: auto; padding: calc(var(--safe-t) + 20px) 16px 24px; user-select: text; }
.page h1 { font-size: 28px; margin: 0 0 16px; letter-spacing: -.02em; }
.page h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 24px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- сканер ---------- */
#view-scan { background: #000; overflow: hidden; }
#video, #still { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#still.contain { object-fit: contain; }
#bubbles { position: absolute; inset: 0; pointer-events: none; }
.bubble {
  position: absolute; transform: translate(-50%, -50%);
  pointer-events: auto; white-space: nowrap;
  background: rgba(20, 22, 26, .82); color: #fff;
  border: 1px solid rgba(255, 255, 255, .25);
  padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 15px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  animation: pop .18s ease-out;
}
.bubble.sel { background: var(--accent); border-color: transparent; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.7); opacity: 0; } }

.viewfinder {
  position: absolute; left: 50%; top: 38%;
  width: min(78vw, 420px); height: min(24vw, 130px);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.viewfinder .c { position: absolute; width: 26px; height: 26px; border: 3px solid var(--accent); }
.viewfinder .tl { left: 0; top: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.viewfinder .tr { right: 0; top: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 8px; }
.viewfinder .bl { left: 0; bottom: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 8px; }
.viewfinder .br { right: 0; bottom: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }
.viewfinder.hit .c { border-color: var(--accent-2); }
.vf-label {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(20, 22, 26, .78); color: #fff; font-weight: 700; font-size: 20px;
  padding: 6px 16px; border-radius: 999px; white-space: nowrap;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#view-scan.snap .viewfinder { display: none; }

.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-t) + 12px) 16px 0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.seg { display: flex; background: var(--panel); border-radius: 999px; padding: 4px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.seg button { padding: 7px 16px; border-radius: 999px; font-weight: 600; font-size: 15px; color: #d6d9de; }
.seg button.on { background: rgba(255, 255, 255, .18); color: #fff; }
.tools { display: flex; gap: 10px; }
.round { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.round.on { background: #fff; color: #000; }

.cam-msg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; gap: 16px; background: #000; }
.cam-msg p { margin: 0; color: var(--muted); max-width: 320px; }
.btn { background: var(--accent); color: #fff; font-weight: 600; padding: 12px 20px; border-radius: 14px; }

.status {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 70px); transform: translateX(-50%);
  background: var(--panel); padding: 6px 14px; border-radius: 999px; font-size: 13px; color: #dfe3e8;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); white-space: nowrap;
}

.shutter {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 236px; width: 70px; height: 70px; border-radius: 50%;
  border: 4px solid #fff; display: grid; place-items: center;
}
.shutter span { width: 54px; height: 54px; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.shutter.retake span { background: var(--accent); }

/* ---------- карточка конвертации ---------- */
.card {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 26px;
  padding: 14px 14px 16px; text-align: center;
  backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3);
}
.card.static { position: static; background: var(--panel-solid); }
.pair { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cur { flex: 1; max-width: 150px; display: flex; align-items: center; gap: 8px; background: var(--chip); padding: 10px 12px; border-radius: 999px; font-size: 18px; }
.cur b { flex: 1; text-align: left; letter-spacing: .02em; }
.cur svg { width: 16px; height: 16px; opacity: .6; }
.flag { font-size: 22px; line-height: 1; }
.swap { width: 46px; height: 46px; border-radius: 50%; background: var(--chip); display: grid; place-items: center; transition: transform .2s; }
.swap:active { transform: rotate(180deg); }
.src { margin-top: 12px; color: var(--muted); font-size: 16px; min-height: 22px; }
.dst { font-size: clamp(30px, 10vw, 44px); font-weight: 750; letter-spacing: -.02em; margin: 2px 0 8px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rate-pill { display: inline-block; background: var(--chip); color: #d9dde3; font-size: 14px; padding: 6px 14px; border-radius: 999px; }
.rate-pill.stale { color: #ffcf7a; }
.amount {
  width: 100%; margin-top: 14px; text-align: center; background: transparent; border: 0; outline: 0;
  font-size: 22px; color: var(--muted); font-variant-numeric: tabular-nums; user-select: text;
}

/* ---------- конвертер / история / настройки ---------- */
.cheat { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cheat td { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.cheat td:last-child { text-align: right; font-weight: 600; }
.cheat tr { cursor: pointer; }

.row-head { display: flex; justify-content: space-between; align-items: baseline; }
.link { color: var(--accent); font-weight: 600; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.hist .a { color: var(--muted); }
.hist .b { font-weight: 700; text-align: right; }
.hist time { display: block; font-size: 12px; color: var(--muted); }

.field { display: block; margin-bottom: 22px; }
.field > span { display: block; font-weight: 600; margin-bottom: 8px; }
.field input:not([type]), .field input[inputmode] {
  width: 100%; max-width: 200px; padding: 12px 14px; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 12px; outline: 0;
}
.field small { display: block; margin-top: 6px; color: var(--muted); }
.field.check { display: flex; align-items: center; gap: 12px; }
.field.check > span { margin: 0; }
.field.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- таббар ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: rgba(11, 13, 16, .94); border-top: 1px solid var(--line);
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); }
.tabbar button.on { color: var(--accent); }

/* ---------- выбор валюты ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 82vh;
  background: var(--panel-solid); border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; padding-bottom: var(--safe-b);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
.sheet-head { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head input { flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 0; outline: 0; background: rgba(255, 255, 255, .08); }
.picker-list { list-style: none; margin: 0; padding: 0 0 8px; overflow-y: auto; }
.picker-list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; }
.picker-list li.sel { background: rgba(47, 140, 255, .16); }
.picker-list li .flag { width: 28px; text-align: center; }
.picker-list li b { width: 46px; }
.picker-list li span:last-child { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-list .sep { padding: 10px 16px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; cursor: default; }

@media (min-width: 640px) {
  .card { left: 50%; right: auto; width: 460px; transform: translateX(-50%); }
  .page { max-width: 560px; margin: 0 auto; }
}
@media (max-height: 640px) {
  .shutter { bottom: 214px; width: 60px; height: 60px; }
  .shutter span { width: 46px; height: 46px; }
}
