:root {
  --bg: #05070d;
  --panel: rgba(16, 23, 40, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8ecf8;
  --muted: #8b97b5;
  --accent: #22d3a6;
  --indigo: #7c6cff;
  --danger: #ff6b6b;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(124, 108, 255, 0.22), transparent 60%),
    radial-gradient(700px 500px at 100% 110%, rgba(34, 211, 166, 0.14), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 18px 22px 22px;
  gap: 16px;
}

/* ------------------------------- 顶栏 ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 6px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 240px;
}

.brand-mark {
  position: relative;
  width: 42px;
  height: 42px;
  flex: none;
}

.corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(148, 163, 255, 0.95);
}

.corner.tl {
  left: 0;
  top: 0;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 4px;
}

.corner.tr {
  right: 0;
  top: 0;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 4px;
}

.corner.bl {
  left: 0;
  bottom: 0;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 4px;
}

.corner.br {
  right: 0;
  bottom: 0;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 4px;
}

.dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(34, 211, 166, 0.9);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand-text strong {
  font-size: 17px;
  letter-spacing: 2px;
}

.brand-text span {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

.clock {
  text-align: center;
}

#clock-time {
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 3px;
  line-height: 1.1;
}

#clock-date {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 2px;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--muted);
}

.net-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.7);
}

.net-dot.online {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(34, 211, 166, 0.8);
}

.net-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.8);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.09);
}

/* ------------------------------- 主区域 ------------------------------- */

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
}

.camera-shell {
  position: relative;
  border-radius: 26px;
  overflow: hidden;
  background: #0a0f1c;
  border: 1px solid var(--line);
  min-height: 0;
}

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

.frame {
  position: absolute;
  inset: 12%;
  pointer-events: none;
}

.fc {
  position: absolute;
  width: 54px;
  height: 54px;
  border: 3px solid rgba(124, 108, 255, 0.9);
}

.fc.tl {
  left: 0;
  top: 0;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 14px;
}

.fc.tr {
  right: 0;
  top: 0;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 14px;
}

.fc.bl {
  left: 0;
  bottom: 0;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 14px;
}

.fc.br {
  right: 0;
  bottom: 0;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 14px;
}

.scanline {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 166, 0.9), transparent);
  box-shadow: 0 0 18px rgba(34, 211, 166, 0.8);
  animation: scan 2.6s ease-in-out infinite;
}

@keyframes scan {
  0% {
    top: 2%;
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  85% {
    opacity: 1;
  }
  100% {
    top: 98%;
    opacity: 0;
  }
}

.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 9px 20px;
  border-radius: 999px;
  background: rgba(5, 7, 13, 0.6);
  border: 1px solid var(--line);
  color: rgba(232, 236, 248, 0.82);
  font-size: 12.5px;
  letter-spacing: 1px;
}

.camera-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(5, 7, 13, 0.88);
  text-align: center;
  padding: 30px;
}

.cam-error-title {
  font-size: 18px;
  font-weight: 600;
}

.cam-error-text {
  max-width: 460px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

/* ------------------------------- 侧栏 ------------------------------- */

.side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.side-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 16px 14px;
  backdrop-filter: blur(10px);
}

.side-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 12px;
}

.side-metrics {
  display: flex;
  gap: 26px;
}

.side-metrics div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-metrics strong {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
}

.side-metrics span {
  font-size: 11px;
  color: var(--muted);
}

.recent {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.recent li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  padding: 7px 9px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.03);
}

.recent .r-name {
  font-weight: 600;
}

.recent .r-time {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 11px;
}

.recent-empty {
  color: var(--muted);
  justify-content: center !important;
}

.recent .ok {
  color: var(--accent);
}

.recent .bad {
  color: var(--danger);
}

.manual {
  margin-top: auto;
}

.manual input {
  width: 100%;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0 12px;
  font-size: 12.5px;
  font-family: var(--mono);
  outline: none;
}

.manual input:focus {
  border-color: rgba(124, 108, 255, 0.7);
}

.ghost-btn {
  height: 36px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ghost-btn.wide {
  width: 100%;
  margin-top: 10px;
}

.primary-btn {
  height: 38px;
  padding: 0 22px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #4f46e5, #8b5cf6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.side-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  padding: 0 4px;
}

.side-foot b {
  font-family: var(--mono);
  color: #c7d0ee;
}

.side-foot a {
  color: #9aa6ff;
  text-decoration: none;
}

/* ------------------------------- 结果 ------------------------------- */

.result {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 6, 12, 0.78);
  backdrop-filter: blur(14px);
  z-index: 20;
  animation: fade 0.18s ease-out;
}

.result-card {
  width: min(520px, 88vw);
  border-radius: 28px;
  padding: 38px 40px 30px;
  background: linear-gradient(180deg, rgba(20, 28, 48, 0.98), rgba(10, 15, 26, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6);
  animation: pop 0.22s ease-out;
}

.result-icon {
  width: 86px;
  height: 86px;
  margin: 0 auto 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  color: #05231b;
  background: linear-gradient(140deg, #34e2b0, #06b6d4);
  box-shadow: 0 0 60px rgba(34, 211, 166, 0.4);
}

.result.bad .result-icon {
  color: #2b0507;
  background: linear-gradient(140deg, #ff9a9a, #ff5a5f);
  box-shadow: 0 0 60px rgba(255, 107, 107, 0.35);
}

.result-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
}

.result-sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

.student {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 26px 0 8px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  text-align: left;
}

.student img {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  object-fit: cover;
  background: #1b2540;
  flex: none;
}

.student-info {
  min-width: 0;
}

.student-name {
  font-size: 19px;
  font-weight: 700;
}

.student-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  word-break: break-all;
}

.result-time {
  margin-top: 16px;
  font-family: var(--mono);
  font-size: 24px;
  letter-spacing: 2px;
}

.result-hint {
  margin-top: 18px;
  font-size: 11.5px;
  color: var(--muted);
}

.result.bad .result-hint {
  visibility: hidden;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pop {
  from {
    transform: scale(0.94);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ------------------------------- Modal / Toast ------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 6, 12, 0.7);
  backdrop-filter: blur(8px);
  z-index: 30;
}

.modal-card {
  width: min(420px, 90vw);
  background: #0d1322;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px;
}

.modal-card h2 {
  font-size: 18px;
  margin-bottom: 18px;
}

.modal-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.modal-card input {
  display: block;
  width: 100%;
  height: 40px;
  margin-top: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0 12px;
  font-size: 13px;
  outline: none;
}

.modal-tip {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.7;
  margin: 6px 0 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 999px;
  background: rgba(13, 19, 34, 0.95);
  border: 1px solid var(--line);
  font-size: 13px;
  z-index: 40;
}

@media (max-width: 980px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .side {
    display: none;
  }
  .clock {
    display: none;
  }
}
