/* ─────────────────────────── Page ─────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 30% 0%, #2a3550 0%, #0f1424 60%, #060812 100%);
  min-height: 100vh;
  color: #e8eaed;
  -webkit-font-smoothing: antialiased;
}
.stage {
  display: flex; gap: 48px; align-items: center; justify-content: center;
  padding: 48px 24px; min-height: 100vh; flex-wrap: wrap;
}

/* ─────────────────────── iPhone frame ─────────────────────── */
.phone {
  width: 390px; height: 844px;
  border-radius: 56px;
  background: linear-gradient(160deg, #1f2230 0%, #0a0c14 100%);
  padding: 14px;
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,.7),
    0 0 0 2px #2a2e3d,
    inset 0 0 0 2px #0a0c14;
  position: relative;
}
.bezel {
  width: 100%; height: 100%;
  border-radius: 44px;
  background: #000;
  overflow: hidden;
  position: relative;
}
.dynamic-island {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 120px; height: 34px; background: #000;
  border-radius: 20px; z-index: 30;
}
.screen {
  position: absolute; inset: 0;
  background: #11141d;
  color: #fff;
  display: flex;
}

/* ───────────────────────── Views ───────────────────────────── */
.view {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: 56px 18px 24px;
}
.view.active { display: flex; }

.topbar {
  position: absolute; top: 18px; left: 24px; right: 24px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: #cfd2db;
  letter-spacing: 0.3px;
}
.topbar .indicators { font-size: 10px; opacity: .7; }
.topbar .time { font-variant-numeric: tabular-nums; }

.title { margin: 4px 0 2px; font-size: 26px; font-weight: 700; }
.subtitle { margin: 0 0 14px; font-size: 13px; color: #9aa1b3; }

.iconbtn.back {
  background: none; border: none; color: #5fa9ff;
  font-size: 26px; line-height: 1; cursor: pointer; padding: 0 6px;
}

/* ───────────────────────── Camera ──────────────────────────── */
.camera-wrap {
  position: relative;
  flex: 1;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}
#video, .overlay-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.overlay-canvas { pointer-events: none; }
.camera-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #1a1d28; color: #9aa1b3; padding: 16px; text-align: center;
  font-size: 14px;
}
.camera-fallback.hidden { display: none; }

.ar-status {
  position: absolute;
  top: 10px; left: 50%; transform: translateX(-50%);
  padding: 6px 12px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: 0.2px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s ease;
}
.ar-status.searching { background: rgba(0,0,0,0.55); }
.ar-status.tracking  { background: rgba(255, 165, 0, 0.85); }
.ar-status.solved    { background: rgba(48, 175, 90, 0.9); }
.ar-status.error     { background: rgba(220, 60, 60, 0.9); }

.viewfinder {
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 78%; aspect-ratio: 1 / 1;
  pointer-events: none;
  opacity: 0.55;
}
.corner {
  position: absolute; width: 26px; height: 26px;
  border: 3px solid #5fa9ff;
  border-radius: 4px;
}
.corner.tl { top: 0;    left: 0;  border-right: none; border-bottom: none; border-top-left-radius: 12px; }
.corner.tr { top: 0;    right: 0; border-left:  none; border-bottom: none; border-top-right-radius: 12px; }
.corner.bl { bottom: 0; left: 0;  border-right: none; border-top:    none; border-bottom-left-radius: 12px; }
.corner.br { bottom: 0; right: 0; border-left:  none; border-top:    none; border-bottom-right-radius: 12px; }

/* ───────────────────────── Buttons ─────────────────────────── */
.actions {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.btn {
  flex: 0 1 auto; padding: 12px 14px; border: none; border-radius: 14px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
  font-family: inherit; color: inherit;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: #2f7bff; color: white;
  box-shadow: 0 6px 18px -8px rgba(47,123,255,.7);
}
.btn.primary.wide { flex: 1; padding: 14px 18px; font-size: 15px; }
.btn.ghost {
  background: rgba(255,255,255,0.08);
  color: #d6dae5;
  backdrop-filter: blur(10px);
}
.btn.ghost:hover { background: rgba(255,255,255,0.12); }

/* shutter */
#capture-btn {
  width: 64px; height: 64px; border-radius: 50%;
  padding: 0; background: white;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.12);
}
#capture-btn .shutter {
  width: 50px; height: 50px; border-radius: 50%;
  border: 2px solid #11141d; background: white;
}

/* ───────────────────────── Grid ────────────────────────────── */
.grid-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 354px);
  aspect-ratio: 1 / 1;
  background: #1a1d28;
  border: 2px solid #5fa9ff;
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
}
.cell {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 600;
  background: #11141d;
  color: #fff;
  border: 0;
  border-right: 1px solid #2a2e3d;
  border-bottom: 1px solid #2a2e3d;
  cursor: pointer;
  transition: background .15s ease;
  font-variant-numeric: tabular-nums;
  padding: 0;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }
/* thicker borders between 3×3 boxes */
.cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid #5fa9ff; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid #5fa9ff; }
.cell.empty { color: #4a5066; }
.cell.solved { color: #5fa9ff; font-weight: 700; }
.cell.given  { color: #ffffff; }
.cell.selected { background: rgba(95,169,255,0.18); outline: 2px solid #5fa9ff; outline-offset: -2px; z-index: 2; }
.cell.error    { background: rgba(255, 90, 90, 0.18); }
.cell.empty::before { content: "·"; color: #2a2e3d; }
.cell.solved.empty::before { content: ""; }

/* ─────────────── Detection thumbnail (review) ─────────────── */
.detect-thumb-host {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 10px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  font-size: 12px;
  color: #b8bdcc;
}
.detect-thumb {
  width: 56px; height: 56px;
  border-radius: 6px;
  background: #000;
  flex: 0 0 auto;
}
.detect-thumb-label { line-height: 1.3; }

/* ───────────────────────── Keypad ──────────────────────────── */
.keypad {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 6px; margin-bottom: 12px;
}
.keypad button {
  padding: 10px 0; font-size: 18px; font-weight: 600;
  border: none; border-radius: 10px;
  background: rgba(255,255,255,0.08); color: #fff;
  cursor: pointer; font-family: inherit;
}
.keypad button:active { background: rgba(95,169,255,0.4); }

/* ───────────────────────── Legend ──────────────────────────── */
.legend {
  max-width: 360px; color: #cfd2db; font-size: 14px; line-height: 1.55;
}
.legend h2 { font-size: 18px; margin: 0 0 12px; color: #fff; }
.legend ol { padding-left: 18px; margin: 0 0 14px; }
.legend ol li { margin-bottom: 6px; }
.legend .note { color: #8990a3; font-size: 12.5px; }
.legend code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px; border-radius: 4px;
  font-size: 12px;
}

/* ─────────────────── Debug modal ──────────────────────────── */
.debug-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  overflow: auto;
}
.debug-modal.hidden { display: none; }
.debug-modal-inner {
  background: #11141d;
  border-radius: 16px;
  padding: 16px;
  max-width: 100%;
  max-height: 100%;
  display: flex; flex-direction: column; gap: 10px;
}
.debug-modal header {
  display: flex; justify-content: space-between; align-items: center;
}
.debug-modal h2 { margin: 0; font-size: 18px; }
.debug-stats {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.05);
  padding: 8px 10px;
  border-radius: 8px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfd2db;
}
.debug-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  background: #000;
  touch-action: pinch-zoom;
}
.debug-hint { font-size: 11px; color: #888; margin: 0; text-align: center; }

/* ─────────────────── Mobile (no side-by-side) ──────────────── */
@media (max-width: 900px) {
  .stage { flex-direction: column; gap: 24px; padding: 24px 12px; }
  .phone { transform: scale(0.95); transform-origin: top center; }
  .legend { max-width: 92%; }
}
