:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #607080;
  --line: #d8e2ea;
  --brand: #175cd3;
  --brand-strong: #0b46b2;
  --ok: #14855f;
  --warn: #be6b00;
  --danger: #c93535;
  --shadow: 0 20px 60px rgba(17, 31, 44, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(238, 243, 247, 0.94)),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  border: 0;
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.phone-frame {
  width: min(100%, 430px);
  min-height: min(860px, calc(100vh - 48px));
  background: var(--panel);
  border: 1px solid rgba(140, 157, 173, 0.32);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-header {
  display: grid;
  gap: 8px;
}

.step-label {
  margin: 0;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

.description {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.notice {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid #f1d08d;
  border-radius: 8px;
  background: #fff8e8;
  color: #6d4700;
  font-size: 13px;
  line-height: 1.45;
}

.notice strong {
  font-size: 14px;
}

.camera-card,
.gate-panel,
.result-panel {
  display: grid;
  gap: 16px;
}

.gate-panel,
.result-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.gate-panel ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
}

.camera-stage {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 5;
  border-radius: 8px;
  background: #101820;
  border: 1px solid #111d28;
}

.camera-stage video,
.camera-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.camera-stage video {
  transform: scaleX(-1);
}

.camera-stage canvas {
  display: none;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.78);
  background: linear-gradient(180deg, rgba(9, 18, 28, 0.25), rgba(9, 18, 28, 0.72));
  font-size: 14px;
}

.face-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.guide-ring {
  width: min(78%, 380px);
  height: min(74%, 540px);
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  box-shadow:
    0 0 0 999px rgba(7, 15, 23, 0.28),
    inset 0 0 18px rgba(255, 255, 255, 0.1);
}

.camera-stage.adjusting .guide-ring {
  border-color: #f6c453;
}

.camera-stage.aligned .guide-ring {
  border-color: #30b07b;
}

.camera-stage.failed .guide-ring {
  border-color: #e35d5d;
}

.guide-cross {
  position: absolute;
  background: rgba(255, 255, 255, 0.42);
}

.guide-cross-x {
  width: 36px;
  height: 1px;
}

.guide-cross-y {
  width: 1px;
  height: 36px;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #edf6ff;
  color: #123b63;
  font-weight: 700;
}

#status-text {
  font-size: 16px;
  line-height: 1.35;
}

#timer-text {
  flex: 0 0 auto;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #dde8f1;
}

.progress-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 220ms ease;
}

#progress-text {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.challenge-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.challenge-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.challenge-list li.active {
  border-color: #9fc4f5;
  background: #f0f7ff;
  color: var(--ink);
}

.challenge-list li.done {
  border-color: #a7dccb;
  background: #effaf6;
  color: var(--ok);
}

.debug-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  padding: 10px;
  border: 1px dashed #b9c7d3;
  border-radius: 8px;
  background: #f8fafc;
  color: #425466;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
}

.debug-panel div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.debug-panel strong {
  color: #15202b;
  font-weight: 800;
}

.challenge-index {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #eef3f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.challenge-state {
  font-size: 12px;
  font-weight: 800;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 52px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:enabled:hover {
  background: var(--brand-strong);
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #aab8c4;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.permission-error {
  color: var(--danger);
  font-size: 14px;
  line-height: 1.45;
}

.result-panel dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.result-panel dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.result-panel dt {
  color: var(--muted);
}

.result-panel dd {
  margin: 0;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.admin-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.admin-refresh {
  min-width: 120px;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.admin-summary article,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(17, 31, 44, 0.07);
}

.admin-summary article {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.admin-summary span,
.admin-card dt {
  color: var(--muted);
  font-size: 13px;
}

.admin-summary strong {
  font-size: 22px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.admin-card {
  padding: 16px;
}

.admin-card h2 {
  margin-bottom: 12px;
}

.admin-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.admin-card dl div {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.admin-card dd {
  margin: 0;
  font-weight: 800;
}

.admin-image-wrap,
.admin-video-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #101820;
}

.admin-video-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
}

.admin-image-wrap img,
.admin-video-wrap video {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.admin-video-wrap video {
  position: absolute;
  inset: 0;
  height: 100%;
  max-height: none;
  background: #101820;
}

.admin-video-wrap .admin-empty {
  min-height: 100%;
  display: grid;
  place-items: center;
}

.admin-empty {
  margin: 0;
  padding: 28px 16px;
  color: #d7e2ed;
  text-align: center;
}

.action-frame-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.action-frame-grid figure {
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
}

.action-frame-grid img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.action-frame-grid figcaption {
  padding: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.admin-json-card {
  grid-column: 1 / -1;
}

.admin-json-card pre {
  overflow: auto;
  max-height: 520px;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #0f1720;
  color: #d7e2ed;
  font-size: 12px;
}

@media (max-width: 520px) {
  .app-shell {
    display: block;
    padding: 0;
    background: #fff;
  }

  .phone-frame {
    width: 100%;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 25px;
  }

  .admin-shell {
    width: 100%;
    padding: 18px;
  }

  .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .action-frame-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-json-card {
    grid-column: auto;
  }
}
