/* ==================== DESIGN SYSTEM (V1 Style) ==================== */
:root {
  --bg: #0f1115;
  --card: #161a22;
  --muted: #8a93a6;
  --text: #e8edf7;
  --accent: #4da3ff;
  --accent-ghost: #2a3550;
  --ok: #4ad295;
  --warn: #ffb34d;
  --err: #ff6b6b;
  --radius: 16px;
  --phase-1: #4da3ff;
  --phase-2: #ffb34d;
  --phase-complete: #4ad295;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
}

/* ==================== HEADER ==================== */
.app-header {
  padding: clamp(16px, 4vw, 28px);
  text-align: center;
  background: linear-gradient(180deg, rgba(77, 163, 255, 0.05) 0%, transparent 100%);
}

h1 {
  margin: 0 0 6px;
  font-size: clamp(1.25rem, 4vw, 1.8rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent) 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.9rem, 2.5vw, 1rem);
}

/* ==================== LAYOUT ==================== */
.container {
  width: min(1000px, 96vw);
  margin: 0 auto 40px;
  display: grid;
  gap: 18px;
}

@media (min-width: 960px) {
  .container {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
  .camera-card {
    position: sticky;
    top: 18px;
  }
}

/* ==================== CARDS ==================== */
.camera-card,
.result-card,
.help {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* ==================== VIDEO SECTION ==================== */
.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  background: #0b0e13;
  border-radius: 12px;
  overflow: hidden;
  border: 3px solid transparent;
  transition: border-color 0.3s ease;
}

.video-wrapper.phase-1 {
  border-color: var(--phase-1);
}

.video-wrapper.phase-2 {
  border-color: var(--phase-2);
}

.video-wrapper.phase-complete {
  border-color: var(--phase-complete);
  animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ==================== OVERLAY PHASE INDICATOR ==================== */
.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 12px;
  gap: 8px;
}

#phaseLabel {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 2px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
}

#phaseLabel.phase-1 {
  background: rgba(77, 163, 255, 0.15);
  border-color: var(--phase-1);
  color: var(--phase-1);
}

#phaseLabel.phase-2 {
  background: rgba(255, 179, 77, 0.15);
  border-color: var(--phase-2);
  color: var(--phase-2);
}

#phaseLabel.phase-complete {
  background: rgba(74, 210, 149, 0.15);
  border-color: var(--phase-complete);
  color: var(--phase-complete);
}

/* ==================== PROGRESS BAR ==================== */
.progress-container {
  width: 80%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #764ba2);
  width: 0%;
  transition: width 0.5s ease;
  box-shadow: 0 0 10px rgba(77, 163, 255, 0.5);
}

.progress-fill.step-1 { width: 50%; }
.progress-fill.step-2 { width: 100%; }

/* ==================== PAUSE OVERLAY ==================== */
.pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 20;
}

.pause-overlay.active {
  display: flex;
}

.pause-icon {
  font-size: 48px;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.pause-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.pause-countdown {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--warn);
}

/* ==================== CONTROLS ==================== */
.controls {
  margin-top: 16px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

label {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
}

select,
input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #273044;
  background: #0f141d;
  color: var(--text);
  outline: none;
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

select:focus,
input:focus {
  border-color: var(--accent);
}

input[readonly] {
  cursor: not-allowed;
  opacity: 0.8;
}

/* ==================== BUTTONS ==================== */
.buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

button {
  appearance: none;
  border: none;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
  min-width: 120px;
}

button.primary {
  background: var(--accent);
  color: #0b0f16;
}

button.primary:hover:not(:disabled) {
  background: #6bb3ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(77, 163, 255, 0.3);
}

button.ghost {
  background: var(--accent-ghost);
  color: var(--text);
}

button.ghost:hover:not(:disabled) {
  background: #3a4560;
  transform: translateY(-2px);
}

button.success {
  background: var(--ok);
  color: #0b0f16;
}

button.success:hover:not(:disabled) {
  background: #5ddba8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74, 210, 149, 0.3);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ==================== STATUS ==================== */
.status {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
  background: rgba(138, 147, 166, 0.1);
  color: var(--muted);
  font-weight: 500;
}

.status.ok {
  background: rgba(74, 210, 149, 0.1);
  color: var(--ok);
}

.status.warn {
  background: rgba(255, 179, 77, 0.1);
  color: var(--warn);
}

.status.err {
  background: rgba(255, 107, 107, 0.1);
  color: var(--err);
}

.status.phase-1 {
  background: rgba(77, 163, 255, 0.1);
  color: var(--phase-1);
}

.status.phase-2 {
  background: rgba(255, 179, 77, 0.1);
  color: var(--phase-2);
}

/* ==================== HELP SECTION ==================== */
.help {
  grid-column: 1 / -1;
}

details {
  cursor: pointer;
}

summary {
  padding: 8px 0;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: '▶';
  display: inline-block;
  transition: transform 0.2s ease;
}

details[open] summary::before {
  transform: rotate(90deg);
}

details[open] summary {
  margin-bottom: 12px;
}

.help ol {
  padding-left: 24px;
  color: var(--muted);
}

.help li {
  margin-bottom: 8px;
  line-height: 1.6;
}

.help strong {
  color: var(--text);
}

/* ==================== FOOTER ==================== */
.app-footer {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  border-top: 1px solid #1e2535;
  font-size: 0.85rem;
}

/* ==================== RESPONSIVE ==================== */
@media (min-width: 960px) {
  .video-wrapper {
    aspect-ratio: 16/10;
  }
}

@media (max-width: 600px) {
  .buttons {
    flex-direction: column;
  }
  
  button {
    width: 100%;
  }
}