:root {
  color-scheme: dark;
  --bg: #061520;
  --panel: rgba(255, 255, 255, .09);
  --panel-2: rgba(255, 255, 255, .14);
  --line: rgba(255, 255, 255, .16);
  --text: #f6fbff;
  --muted: #9bb1bf;
  --cyan: #43d9ff;
  --green: #63f0b4;
  --amber: #ffd166;
  --rose: #ff6b8a;
  --danger: #ff5876;
  --shadow: 0 22px 70px rgba(0, 0, 0, .36);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(130deg, rgba(67, 217, 255, .18), transparent 34%),
    linear-gradient(310deg, rgba(99, 240, 180, .13), transparent 38%),
    #061520;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: min(1120px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: 10px 10px calc(10px + var(--safe-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.app-top,
.scan-card,
.control-card,
.toast {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.app-top {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.brand > span {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--cyan), var(--green));
  color: #061520;
  font-weight: 950;
}

.brand div {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.brand strong,
.brand small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small,
.scan-copy span,
.meter-row span,
.result-pill,
label span,
.audit-item span,
.user-row span {
  color: var(--muted);
}

.live-chip {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(99, 240, 180, .36);
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(99, 240, 180, .1);
  color: var(--green);
  font-size: 13px;
  font-weight: 850;
}

.live-chip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.7s infinite;
}

.auth-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 44%) minmax(0, 1fr);
  gap: 10px;
}

.scan-card,
.control-card {
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 10px;
  padding: 10px;
}

.scan-card {
  grid-template-rows: minmax(0, 1fr) auto auto auto;
}

.video-box {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .1);
  background:
    radial-gradient(circle at 50% 28%, rgba(67, 217, 255, .2), transparent 33%),
    linear-gradient(160deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .02));
}

video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scaleX(-1);
}

.avatar-orbit {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.avatar-orbit span {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .25);
  background: linear-gradient(135deg, rgba(67, 217, 255, .55), rgba(99, 240, 180, .3));
  box-shadow: 0 0 20px rgba(67, 217, 255, .18);
  animation: floaty 4s ease-in-out infinite;
}

.avatar-orbit span:nth-child(1) {
  top: 11%;
  left: 14%;
}

.avatar-orbit span:nth-child(2) {
  right: 12%;
  top: 28%;
  animation-delay: .7s;
}

.avatar-orbit span:nth-child(3) {
  left: 22%;
  bottom: 13%;
  animation-delay: 1.2s;
}

.face-frame {
  position: absolute;
  inset: 13% 18%;
  border: 2px solid rgba(67, 217, 255, .58);
  border-radius: 50% 50% 45% 45%;
  box-shadow: inset 0 0 38px rgba(67, 217, 255, .12), 0 0 36px rgba(67, 217, 255, .14);
}

.face-frame.ready {
  border-color: rgba(99, 240, 180, .8);
  box-shadow: inset 0 0 38px rgba(99, 240, 180, .16), 0 0 38px rgba(99, 240, 180, .18);
}

.face-frame.warn {
  border-color: rgba(255, 209, 102, .82);
}

.face-frame.bad {
  border-color: rgba(255, 88, 118, .82);
}

.face-frame b {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: var(--green);
  border-style: solid;
}

.face-frame b:nth-child(1) { left: -2px; top: -2px; border-width: 3px 0 0 3px; }
.face-frame b:nth-child(2) { right: -2px; top: -2px; border-width: 3px 3px 0 0; }
.face-frame b:nth-child(3) { left: -2px; bottom: -2px; border-width: 0 0 3px 3px; }
.face-frame b:nth-child(4) { right: -2px; bottom: -2px; border-width: 0 3px 3px 0; }

.scan-line {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 12%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--green), var(--cyan), transparent);
  filter: drop-shadow(0 0 10px var(--green));
  animation: scan 2.4s linear infinite;
}

.scan-copy {
  min-height: 46px;
  display: grid;
  gap: 3px;
}

.scan-copy strong {
  font-size: 16px;
}

.scan-copy span {
  font-size: 13px;
  line-height: 1.35;
}

.meter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.meter-row div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .06);
}

.meter-row b {
  display: block;
  font-size: 20px;
}

.meter-row span {
  display: block;
  font-size: 12px;
  font-weight: 800;
}

.camera-actions,
.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn,
.mode-btn,
.icon-btn,
.mini-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.btn {
  min-height: 44px;
  padding: 0 12px;
  font-weight: 900;
}

.primary {
  border-color: transparent;
  color: #061520;
  background: linear-gradient(135deg, var(--cyan), var(--green));
}

.secondary {
  color: var(--text);
  background: rgba(67, 217, 255, .14);
}

.quiet,
.mode-btn,
.icon-btn,
.mini-btn {
  color: var(--text);
  background: rgba(255, 255, 255, .07);
}

.btn:hover,
.mode-btn:hover,
.icon-btn:hover,
.mini-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(67, 217, 255, .58);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .22);
}

.control-card {
  grid-template-rows: auto minmax(0, 1fr);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, .14);
}

.mode-btn {
  min-width: 0;
  min-height: 40px;
  font-weight: 900;
}

.mode-btn.active {
  border-color: transparent;
  color: #061520;
  background: linear-gradient(135deg, var(--cyan), var(--green));
}

.mode-panel {
  min-height: 0;
  display: none;
}

.mode-panel.active {
  display: grid;
  gap: 10px;
  align-content: start;
}

#panel-login,
#panel-register {
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
}

.challenge-box {
  min-height: 82px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .06);
}

.challenge-box span {
  grid-column: 1 / -1;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.challenge-box b {
  min-width: 0;
  line-height: 1.3;
}

.icon-btn {
  width: 42px;
  height: 42px;
  font-size: 20px;
  font-weight: 900;
}

.result-pill {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  line-height: 1.35;
  background: rgba(255, 255, 255, .06);
}

.result-pill.ok {
  border-color: rgba(99, 240, 180, .55);
  color: var(--green);
}

.result-pill.fail {
  border-color: rgba(255, 88, 118, .55);
  color: #ffc1cb;
}

.mini-flow {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mini-flow div {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .05);
}

.mini-flow i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(99, 240, 180, .42);
  animation: pulse 1.8s infinite;
}

.mini-flow b,
.mini-flow span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-flow span {
  color: var(--muted);
  font-size: 12px;
}

.form-grid {
  display: grid;
  gap: 8px;
}

.enroll-guide {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(67, 217, 255, .24);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(67, 217, 255, .11), rgba(99, 240, 180, .07));
}

.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.guide-head span {
  color: var(--green);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.guide-head b {
  font-size: 18px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, .22);
}

.progress-track i {
  width: 0%;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  box-shadow: 0 0 18px rgba(99, 240, 180, .28);
  transition: width .22s ease;
}

.enroll-guide p {
  margin: 0;
  color: var(--text);
  line-height: 1.35;
  font-weight: 750;
  overflow-wrap: anywhere;
}

label {
  min-width: 0;
  display: grid;
  gap: 5px;
  font-size: 13px;
  font-weight: 850;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  padding: 0 10px;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
}

input:focus {
  border-color: rgba(67, 217, 255, .64);
  box-shadow: 0 0 0 4px rgba(67, 217, 255, .12);
}

.admin-tools {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 8px;
}

.admin-scroll {
  min-height: 0;
  max-height: 100%;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 8px;
  overflow: hidden;
}

.list-block {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .05);
}

.users-list,
.audit-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 7px;
  padding-right: 2px;
}

.user-row,
.audit-item,
.empty-state {
  border: 1px solid rgba(255, 255, 255, .11);
  border-radius: var(--radius);
  padding: 8px;
  background: rgba(0, 0, 0, .12);
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
}

.user-row b,
.user-row span,
.audit-item b,
.audit-item span {
  display: block;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  gap: 5px;
}

.mini-btn {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 850;
}

.audit-item {
  display: grid;
  gap: 3px;
}

.audit-item span {
  font-size: 12px;
}

.empty-state {
  color: var(--muted);
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 40;
  width: min(420px, calc(100vw - 24px));
  padding: 11px 12px;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, 16px);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 12px rgba(99, 240, 180, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 240, 180, 0); }
}

@keyframes scan {
  0% { top: 10%; opacity: .35; }
  50% { opacity: 1; }
  100% { top: 90%; opacity: .35; }
}

@keyframes floaty {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); opacity: .55; }
  50% { transform: translate3d(8px, -10px, 0) scale(1.08); opacity: .85; }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 8px 8px calc(8px + var(--safe-bottom));
    gap: 8px;
  }

  .app-top {
    min-height: 54px;
  }

  .brand > span {
    width: 38px;
    height: 38px;
  }

  .live-chip {
    max-width: 42%;
    min-height: 32px;
  }

  .live-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .auth-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(292px, 45%) minmax(0, 1fr);
    gap: 8px;
  }

  .scan-card,
  .control-card {
    padding: 8px;
    gap: 7px;
  }

  .scan-card {
    grid-template-rows: minmax(0, 1fr) auto auto auto;
  }

  .scan-copy {
    min-height: 38px;
  }

  .meter-row div {
    padding: 6px 7px;
  }

  .meter-row b {
    font-size: 18px;
  }

  .mode-btn {
    min-height: 38px;
    font-size: 13px;
  }

  .btn {
    min-height: 42px;
  }

  .challenge-box {
    min-height: 72px;
    padding: 8px;
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }

  .enroll-guide {
    padding: 8px;
    gap: 6px;
  }

  .enroll-guide p {
    font-size: 13px;
  }

  .mini-flow {
    grid-template-columns: 1fr;
  }

  .mini-flow div {
    grid-template-columns: auto 72px minmax(0, 1fr);
    align-items: center;
    min-height: 36px;
    padding: 7px 8px;
  }

  .form-grid label:last-child {
    grid-column: 1 / -1;
  }

  input {
    min-height: 40px;
  }

  .admin-tools,
  .admin-scroll {
    grid-template-columns: 1fr;
  }

  .admin-scroll {
    overflow: auto;
  }

  .list-block {
    min-height: 96px;
  }
}

@media (max-width: 370px), (max-height: 700px) {
  .app-shell {
    padding: 6px 6px calc(6px + var(--safe-bottom));
    gap: 6px;
  }

  .app-top {
    min-height: 50px;
    padding: 6px;
  }

  .auth-workspace {
    grid-template-rows: minmax(268px, 43%) minmax(0, 1fr);
    gap: 6px;
  }

  .scan-copy span,
  .meter-row span,
  label span,
  .result-pill {
    font-size: 12px;
  }

  .challenge-box {
    min-height: 64px;
  }

  .result-pill {
    min-height: 38px;
  }

  .enroll-guide {
    padding: 7px;
  }

  .guide-head b {
    font-size: 16px;
  }

  .camera-actions .btn {
    min-height: 38px;
  }

  .mini-flow div {
    min-height: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
