:root {
  --bg0: #070709;
  --bg1: #0f1014;
  --card: #12131a;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8e8ec;
  --muted: #8b8c99;
  --accent: #f0b429;
  --accent-dim: rgba(240, 180, 41, 0.15);
  --ok: #3dd68c;
  --warn: #ffb020;
  --err: #ff6b6b;
  --radius: 14px;
  --font: "Noto Sans SC", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --display: "Bebas Neue", "Noto Sans SC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: relative;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  z-index: 0;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(1rem + env(safe-area-inset-top, 0)) 1.1rem 0.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand-mark {
  font-size: 1.75rem;
  color: var(--accent);
  line-height: 1;
  text-shadow: 0 0 24px rgba(240, 180, 41, 0.35);
}

.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.85rem;
  letter-spacing: 0.06em;
  font-weight: 400;
}

.sub {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.pill {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.layout {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.1rem calc(1.5rem + env(safe-area-inset-bottom, 0));
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .security-panel {
    grid-column: 1 / -1;
  }
}

.panel {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.03), transparent 40%),
    var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem 1.25rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.panel-head h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.qr-reader {
  position: relative;
  margin-top: 0.85rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  min-height: clamp(220px, 42vh, 380px);
  background: #000;
}

@media (max-width: 480px) {
  .qr-reader {
    min-height: min(48vh, 360px);
  }
}

.qr-video-el {
  display: block;
  width: 100%;
  height: 100%;
  min-height: clamp(220px, 42vh, 380px);
  object-fit: cover;
}

@media (max-width: 480px) {
  .qr-video-el {
    min-height: min(48vh, 360px);
  }
}

.qr-canvas-el {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
  left: 0;
  top: 0;
}

.scan-status {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.actions .file-picker {
  flex: 1 1 100%;
}

.btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.65rem 1rem;
  min-height: 2.75rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

@media (max-width: 600px) {
  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .actions .btn {
    width: 100%;
  }

  .file-picker {
    grid-column: 1 / -1;
  }
}

.file-picker {
  margin: 0;
  text-align: center;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:not(:disabled):active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(180deg, #ffd35a, var(--accent));
  color: #1a1203;
  border-color: rgba(0, 0, 0, 0.2);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-color: var(--border);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.manual {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}

.manual label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.manual-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.manual-row input {
  flex: 1 1 180px;
  min-width: 0;
  padding: 0.65rem 0.7rem;
  min-height: 2.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg1);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1rem;
}

.manual-row input:focus {
  outline: 2px solid var(--accent-dim);
  border-color: rgba(240, 180, 41, 0.45);
}

.link-btn {
  margin-top: 0.45rem;
  padding: 0.35rem 0;
  min-height: 2.25rem;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.result-empty {
  padding: 1.5rem 0;
  text-align: center;
  color: var(--muted);
}

.result-empty p {
  margin: 0.25rem 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

.kv {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 1rem;
  font-size: 0.88rem;
}

.kv dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

.kv dd {
  margin: 0;
  word-break: break-all;
}

.kv code {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--bg1);
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.mono {
  font-family: var(--mono);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.badge.ok {
  color: var(--ok);
  border-color: rgba(61, 214, 140, 0.35);
  background: rgba(61, 214, 140, 0.1);
}

.badge.pending {
  color: var(--warn);
  border-color: rgba(255, 176, 32, 0.35);
  background: rgba(255, 176, 32, 0.08);
}

.badge.err {
  color: var(--err);
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.08);
}

.log {
  margin-top: 1rem;
  max-height: 160px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg0);
  padding: 0.5rem 0.65rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

.log-line {
  padding: 0.15rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.log-line:last-child {
  border-bottom: none;
}

.security-panel summary {
  list-style: none;
}

.security-panel summary::-webkit-details-marker {
  display: none;
}

.sec-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.15rem 0;
  touch-action: manipulation;
  user-select: none;
}

.sec-summary-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.sec-summary-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.security-panel[open] .sec-summary-hint {
  opacity: 0.7;
}

.sec-list {
  margin: 0.75rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.sec-list li {
  margin-bottom: 0.65rem;
}

.sec-list strong {
  color: var(--text);
}

.foot {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 0.5rem 1.1rem calc(1.25rem + env(safe-area-inset-bottom, 0));
  font-size: 0.78rem;
  color: var(--muted);
}

.foot .dot {
  opacity: 0.4;
  margin: 0 0.35rem;
}
