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

:root {
  --blue-50: #E6F1FB;
  --blue-400: #378ADD;
  --blue-600: #185FA5;
  --blue-800: #0C447C;
  --teal-50: #E1F5EE;
  --teal-400: #1D9E75;
  --teal-600: #0F6E56;
  --green-50: #EAF3DE;
  --green-600: #3B6D11;
  --amber-50: #FAEEDA;
  --amber-600: #854F0B;
  --red-50: #FCEBEB;
  --red-600: #A32D2D;
  --gray-0: #ffffff;
  --gray-10: #F5F5F3;
  --gray-20: #EEECEA;
  --gray-100: #D3D1C7;
  --gray-200: #B4B2A9;
  --gray-400: #888780;
  --gray-600: #5F5E5A;
  --gray-800: #444441;
  --gray-900: #2C2C2A;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-10);
  color: var(--gray-900);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.6;
}

/* Header */
header {
  background: var(--gray-0);
  border-bottom: 0.5px solid var(--gray-100);
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--gray-900);
  letter-spacing: -0.01em;
}

.badge {
  font-size: 12px;
  color: var(--gray-400);
  background: var(--gray-20);
  border: 0.5px solid var(--gray-100);
  padding: 4px 10px;
  border-radius: 20px;
}

/* Main */
main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 2rem 1.5rem;
}

/* API Section */
.api-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}

.api-card {
  background: var(--gray-0);
  border: 0.5px solid var(--gray-100);
  border-radius: 16px;
  padding: 2.5rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.api-icon { font-size: 2.5rem; margin-bottom: 1rem; }

.api-card h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--gray-900);
}

.api-card p {
  font-size: 14px;
  color: var(--gray-600);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
}

.input-row input {
  flex: 1;
  border: 0.5px solid var(--gray-100);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-family: monospace;
  background: var(--gray-10);
  color: var(--gray-900);
  outline: none;
  transition: border-color 0.15s;
}

.input-row input:focus {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px var(--blue-50);
}

.input-row input::placeholder { color: var(--gray-200); }

#saveKeyBtn {
  background: var(--blue-400);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

#saveKeyBtn:hover { background: var(--blue-600); }

.help-link {
  font-size: 13px;
  color: var(--blue-400);
  text-decoration: none;
}
.help-link:hover { text-decoration: underline; }

/* App Section */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-0);
  border: 0.5px solid var(--gray-100);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 1.25rem;
  font-size: 13px;
  color: var(--gray-600);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal-400);
  flex-shrink: 0;
}

.status-dot.busy { background: var(--amber-600); animation: pulse 1s infinite; }
.status-dot.error { background: var(--red-600); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#statusText { flex: 1; }

.disconnect-btn {
  background: none;
  border: 0.5px solid var(--gray-100);
  border-radius: var(--radius);
  padding: 4px 12px;
  font-size: 12px;
  color: var(--gray-600);
  cursor: pointer;
  transition: background 0.1s;
}
.disconnect-btn:hover { background: var(--gray-20); }

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
}

/* Camera Panel */
.camera-panel {
  background: var(--gray-0);
  border: 0.5px solid var(--gray-100);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.camera-container {
  position: relative;
  background: var(--gray-900);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

#videoEl {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
  transform: scaleX(-1);
}

#overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}

.camera-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--gray-400);
  font-size: 13px;
}

.camera-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.btn-primary, .btn-secondary, .btn-accent {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--gray-900);
  color: white;
}
.btn-primary:hover { background: var(--gray-800); }

.btn-secondary {
  background: var(--gray-10);
  color: var(--gray-900);
  border: 0.5px solid var(--gray-100);
}
.btn-secondary:hover { background: var(--gray-20); }

.btn-accent {
  background: var(--blue-400);
  color: white;
  flex: 1;
}
.btn-accent:hover { background: var(--blue-600); }
.btn-accent:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}

.tips-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tip {
  font-size: 12px;
  color: var(--gray-400);
  background: var(--gray-10);
  padding: 4px 10px;
  border-radius: 20px;
}

/* Results Panel */
.results-panel {
  background: var(--gray-0);
  border: 0.5px solid var(--gray-100);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  min-height: 400px;
}

.results-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 320px;
  color: var(--gray-600);
}

.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }

.results-empty h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--gray-800);
}

.results-empty p {
  font-size: 13px;
  max-width: 240px;
  line-height: 1.5;
}

/* Score Card */
.score-card {
  text-align: center;
  padding: 1.25rem;
  border-radius: 12px;
  background: var(--gray-10);
  margin-bottom: 1rem;
  border: 0.5px solid var(--gray-100);
}

.score-label {
  font-size: 12px;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.score-value {
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
  color: var(--gray-900);
}

.score-status {
  font-size: 14px;
  font-weight: 500;
}

.score-card.good { background: var(--green-50); border-color: #C0DD97; }
.score-card.good .score-value { color: var(--green-600); }
.score-card.good .score-status { color: var(--green-600); }

.score-card.warn { background: var(--amber-50); border-color: #FAC775; }
.score-card.warn .score-value { color: var(--amber-600); }
.score-card.warn .score-status { color: var(--amber-600); }

.score-card.bad { background: var(--red-50); border-color: #F7C1C1; }
.score-card.bad .score-value { color: var(--red-600); }
.score-card.bad .score-status { color: var(--red-600); }

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 1rem;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--gray-10);
  border: 0.5px solid var(--gray-100);
  border-radius: var(--radius);
}

.metric-icon { font-size: 18px; flex-shrink: 0; }

.metric-info { flex: 1; }

.metric-label {
  font-size: 12px;
  color: var(--gray-400);
  margin-bottom: 1px;
}

.metric-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-900);
}

.metric-target {
  font-size: 11px;
  color: var(--gray-200);
}

/* Feedback */
.feedback-box {
  background: var(--blue-50);
  border: 0.5px solid #B5D4F4;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 1rem;
}

.feedback-box h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue-800);
  margin-bottom: 8px;
}

#feedbackList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#feedbackList li {
  font-size: 13px;
  color: var(--blue-600);
  padding-left: 16px;
  position: relative;
  line-height: 1.4;
}

#feedbackList li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--blue-400);
}

/* Analyzed image */
.analyzed-image-container { margin-top: 1rem; }
.analyzed-image-container h4 {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 8px;
}
#resultCanvas {
  width: 100%;
  border-radius: var(--radius);
  border: 0.5px solid var(--gray-100);
}

/* Analyzing overlay */
.analyzing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-radius: 12px;
  font-size: 14px;
  color: var(--gray-600);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-100);
  border-top-color: var(--blue-400);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Footer */
footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 12px;
  color: var(--gray-200);
  display: flex;
  justify-content: center;
  gap: 8px;
  border-top: 0.5px solid var(--gray-100);
}

.hidden { display: none !important; }
