/* ===== Variables ===== */
:root {
  --bg: #0f0f12;
  --surface: #1a1a1f;
  --border: #2a2a32;
  --text: #e8e8ec;
  --muted: #8888a0;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.25);
  --danger: #ff6b6b;
  --warn: #ffc857;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ===== Header & Toggle ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}

.header-credit {
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  flex: 0 0 auto;
  text-align: center;
}

.header-back {
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
  flex: 0 0 auto;
}
.header-back:hover {
  text-decoration: underline;
}

/* Back to home as small link/button on camera/image pages */
body[data-page="camera"] .header-back,
body[data-page="image"] .header-back {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: nowrap;
  justify-self: start;
  align-self: center;
}
body[data-page="camera"] .header-back:hover,
body[data-page="image"] .header-back:hover {
  background: var(--border);
  text-decoration: none;
}

/* Center h1 on camera/image pages: same single-row layout and size as home */
body[data-page="camera"] .header,
body[data-page="image"] .header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}
body[data-page="camera"] .header-back,
body[data-page="image"] .header-back {
  grid-column: 1;
  justify-self: start;
}
body[data-page="camera"] .header h1,
body[data-page="image"] .header h1 {
  grid-column: 2;
  justify-self: center;
  flex: none;
  font-size: 1.25rem;
}
body[data-page="camera"] .header .mode-toggle,
body[data-page="image"] .header .mode-toggle {
  grid-column: 3;
  justify-self: end;
}

.header .mode-toggle {
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mode-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.mode-label[data-mode="frontal"] { margin-right: 0; }
.mode-label[data-mode="side"] { margin-left: 0; }
.mode-label.active { color: var(--accent); font-weight: 600; }

/* Toggle switch */
.switch {
  position: relative;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 28px;
  transition: 0.3s;
}

.slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked + .slider {
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(24px);
  background: var(--accent);
}

/* ===== Two-column layout: only metrics column scrolls ===== */
.app {
  display: grid;
  grid-template-columns: 1fr 380px;
  grid-template-rows: 1fr;
  gap: 0;
  height: calc(100vh - 60px);
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

/* ===== Camera section ===== */
.camera-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.video-container {
  width: 100%;
  max-width: 780px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.video-wrapper {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #000;
}

/* Subtle flash when auto-capture triggers */
.video-container.capture-flash .video-wrapper {
  animation: captureFlash 0.4s ease-out;
}

@keyframes captureFlash {
  0% { filter: brightness(1); }
  30% { filter: brightness(1.4); }
  100% { filter: brightness(1); }
}

.video-wrapper::before {
  content: '';
  display: block;
  padding-bottom: 75%;
}

.video-wrapper.mirror {
  transform: scaleX(-1);
}

#video,
#overlay,
.frozen-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.frozen-frame {
  display: none;
  pointer-events: none;
}

.frozen-frame.visible {
  display: block;
}

#overlay {
  pointer-events: none;
}

/* Uploaded/pasted image: show full image and align overlay */
.video-wrapper.image-source #video {
  display: none;
}

.video-wrapper.image-source .frozen-frame.visible,
.video-wrapper.image-source #overlay {
  object-fit: contain;
  object-position: center;
}

/* Overlay message (profile prompt, etc.) */
.overlay-message {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2rem;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.85);
  color: var(--warn);
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
  display: none;
}

.overlay-message.visible {
  display: block;
}

/* Retake in controls bar: shown only after capture */
.ctrl-btn.retake-in-bar {
  display: none;
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.ctrl-btn.retake-in-bar.visible {
  display: inline-flex;
}
.ctrl-btn.retake-in-bar:hover {
  background: var(--border);
  color: var(--text);
}

/* Control bar */
.controls-bar {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.ctrl-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.ctrl-btn:hover {
  background: var(--border);
}

/* Fullscreen: make the video wrapper the fullscreen element so video+canvas fill the screen */
.video-wrapper:fullscreen,
.video-wrapper:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  border-radius: 0;
  background: #000;
}

.video-wrapper:fullscreen::before,
.video-wrapper:-webkit-full-screen::before {
  display: none;
}

.video-wrapper:fullscreen #video,
.video-wrapper:fullscreen .frozen-frame,
.video-wrapper:fullscreen #overlay,
.video-wrapper:-webkit-full-screen #video,
.video-wrapper:-webkit-full-screen .frozen-frame,
.video-wrapper:-webkit-full-screen #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.hint-block {
  margin-top: 0.75rem;
  width: 100%;
  max-width: 780px;
  text-align: center;
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.hint-main {
  font-weight: 500;
  color: var(--text);
}

.hint-sub {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.hint-sub.empty {
  display: none;
}

/* ===== Dashboard: only this column scrolls ===== */
.dashboard {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1rem 1.25rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  min-width: 0;
}

.dashboard h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

/* ===== Metric cards (legend system: left border = canvas color) ===== */
.metric-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--metric-color, var(--muted));
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.6rem;
  cursor: default;
  transition: background 0.15s ease, border-left-width 0.15s ease;
}

.metric-card:hover {
  background: rgba(255, 255, 255, 0.03);
  border-left-width: 4px;
}

.metric-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.metric-value.warn { color: var(--warn); }
.metric-value.danger { color: var(--danger); }

.metric-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.metric-label + .metric-label { margin-top: 0.1rem; }

.section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.25rem;
}

.dashboard .metric-card:first-of-type { margin-top: 0; }

/* ===== Home page ===== */
body.page-home .header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
body.page-home .header-credit {
  justify-self: start;
}
body.page-home .header h1 {
  grid-column: 2;
  justify-self: center;
  text-align: center;
  flex: none;
}

.home-main {
  padding: 2rem 1.5rem;
  max-width: 720px;
  margin: 0 auto;
  overflow-y: auto;
  height: calc(100vh - 60px);
}

.home-intro {
  margin-bottom: 2.5rem;
}

.home-intro h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.home-intro p {
  margin: 0 0 1.25rem;
  line-height: 1.6;
  color: var(--muted);
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

.home-card {
  display: block;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.home-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.home-card-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.75rem;
}

.home-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.home-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ===== Image page: drop zone & source image ===== */
.image-section .video-container {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.image-wrapper {
  position: relative;
  min-height: 320px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: var(--radius);
}

.image-drop-zone {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  pointer-events: auto;
}

.image-drop-text {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
  max-width: 100%;
  width: 100%;
}

.source-image {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

body[data-page="image"] .video-wrapper.image-wrapper #overlay {
  object-fit: contain;
  object-position: center;
  z-index: 2;
}

body[data-page="image"] #clearBtn {
  display: none;
}

body[data-page="image"] #clearBtn.visible {
  display: inline-block;
}
