:root {
  --bg: #0b0f14;
  --ok: #22c55e;
  --ng: #ef4444;
  --warn: #f59e0b;
  --idle: #94a3b8;
  --frame: rgba(255, 255, 255, 0.9);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: #e5e7eb;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app { position: fixed; inset: 0; }

#video, #demoCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
#demoCanvas[hidden] { display: none; }

/* ---- ガイド枠 ---- */
#overlay { position: absolute; inset: 0; pointer-events: none; }

#guideFrame {
  position: absolute;
  left: 50%;
  top: 46%;
  width: min(78vmin, 480px); /* 実寸はJS(applyFrame)が項目ごとに上書き */
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  border-radius: 28px;
  /* 枠外を暗く落とす */
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.55);
  transition: width 0.35s, aspect-ratio 0.35s;
}

#frameLabel {
  position: absolute;
  top: -42px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: #e5e7eb;
  background: rgba(15, 23, 42, 0.85);
  padding: 6px 14px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

#guideFrame .corner {
  position: absolute;
  width: 42px;
  height: 42px;
  border: 5px solid var(--frame);
  transition: border-color 0.25s;
}
#guideFrame .tl { top: -3px; left: -3px; border-right: none; border-bottom: none; border-top-left-radius: 28px; }
#guideFrame .tr { top: -3px; right: -3px; border-left: none; border-bottom: none; border-top-right-radius: 28px; }
#guideFrame .bl { bottom: -3px; left: -3px; border-right: none; border-top: none; border-bottom-left-radius: 28px; }
#guideFrame .br { bottom: -3px; right: -3px; border-left: none; border-top: none; border-bottom-right-radius: 28px; }

#guideFrame[data-state="ok"] .corner { border-color: var(--ok); }
#guideFrame[data-state="ng"] .corner { border-color: var(--ng); }
#guideFrame[data-state="warn"] .corner { border-color: var(--warn); }

/* ---- 上部状態ピル ---- */
#topBar {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

#statusPill {
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(15, 23, 42, 0.85);
  border: 1.5px solid var(--idle);
  color: var(--idle);
  backdrop-filter: blur(6px);
  transition: all 0.25s;
}
#statusPill[data-state="ok"]   { border-color: var(--ok);   color: var(--ok); }
#statusPill[data-state="ng"]   { border-color: var(--ng);   color: var(--ng); }
#statusPill[data-state="warn"] { border-color: var(--warn); color: var(--warn); }

/* ---- 下部ガイダンス ---- */
#bottomBar {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  text-align: center;
}

#guidance {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  background: rgba(15, 23, 42, 0.8);
  padding: 12px 18px;
  border-radius: 14px;
  backdrop-filter: blur(6px);
  max-width: 560px;
}

#confirmDots {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 60, 35, 0.85);
  border: 1px solid var(--ok);
  padding: 10px 16px;
  border-radius: 14px;
}
#confirmDots[hidden] { display: none; }
#confirmDots .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}
#confirmDots .dot.filled { background: var(--ok); }
#confirmLabel { font-size: 13px; color: #bbf7d0; margin-left: 6px; }

/* ---- デモ操作 ---- */
#demoControls {
  display: flex;
  align-items: center;
  gap: 10px;
}
#demoControls[hidden] { display: none; }
.demo-badge {
  font-size: 12px;
  color: #fbbf24;
  border: 1px solid #fbbf24;
  border-radius: 6px;
  padding: 3px 8px;
}
#demoControls button {
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: rgba(30, 41, 59, 0.9);
  color: #e5e7eb;
}
#demoControls button.active { border-color: #38bdf8; color: #38bdf8; }

/* ---- 開始 / 結果 画面 ---- */
#startScreen, #resultScreen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 14, 0.92);
  z-index: 10;
  padding: 24px;
}
#startScreen[hidden], #resultScreen[hidden] { display: none; }

.start-card, .result-card {
  width: 100%;
  max-width: 420px;
  background: #101826;
  border: 1px solid #1f2c40;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
}

.start-card h1 { font-size: 24px; margin-bottom: 14px; }
.start-card p { font-size: 14px; line-height: 1.8; color: #9fb0c3; margin-bottom: 22px; }

#btnStart, #btnRestart {
  width: 100%;
  font-size: 17px;
  font-weight: 700;
  padding: 15px;
  border: none;
  border-radius: 12px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}
#btnStart:active, #btnRestart:active { opacity: 0.85; }

.error { color: var(--ng); margin-top: 14px; font-size: 13px; }
.error[hidden] { display: none; }

.result-ok { font-size: 30px; font-weight: 800; color: var(--ok); margin-bottom: 6px; }
.result-ok.fail { color: var(--warn); }
.result-sub { font-size: 14px; color: #9fb0c3; margin-bottom: 16px; }

#btnRetrySave {
  width: 100%;
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  border: 1px solid var(--warn);
  border-radius: 12px;
  background: transparent;
  color: var(--warn);
  cursor: pointer;
  margin-bottom: 10px;
}
#btnRetrySave[hidden] { display: none; }

#resultItems {
  list-style: none;
  text-align: left;
  margin-bottom: 14px;
  border: 1px solid #1a2536;
  border-radius: 10px;
  overflow: hidden;
}
#resultItems li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: 14px;
  border-bottom: 1px solid #1a2536;
}
#resultItems li:last-child { border-bottom: none; }
#resultItems .item-ok { color: var(--ok); font-weight: 800; }
#resultItems .item-conf { margin-left: auto; color: #8195ab; font-size: 12px; }

#resultPhoto {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 16px;
  border: 1px solid #1f2c40;
}

.result-meta {
  text-align: left;
  margin-bottom: 20px;
  font-size: 14px;
}
.result-meta > div {
  display: flex;
  justify-content: space-between;
  padding: 7px 4px;
  border-bottom: 1px solid #1a2536;
}
.result-meta dt { color: #8195ab; }
.result-meta dd { font-variant-numeric: tabular-nums; }
