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

:root {
  --black:      #111;
  --white:      #fff;
  --gray:       #666;
  --light-gray: #f5f5f5;
  --border:     #e0e0e0;
  --danger:     #c00;
  --success:    #1a7a1a;
  --radius:     12px;
  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--white);
  color: var(--black);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ─── Screens ────────────────────────────────────────── */

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

.screen-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  gap: 20px;
}

.screen-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.screen-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.screen-body {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

/* ─── Buttons ─────────────────────────────────────────── */

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  padding: 16px 24px;
  line-height: 1.2;
  transition: opacity .12s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:active {
  opacity: .7;
}

.btn-primary {
  background: var(--black);
  color: var(--white);
}

.btn-secondary {
  background: var(--light-gray);
  color: var(--black);
}

.btn-large {
  font-size: 20px;
  padding: 22px 32px;
  width: 100%;
  max-width: 320px;
}

.btn-full {
  width: 100%;
}

.btn-back {
  background: none;
  color: var(--gray);
  padding: 4px 0;
  font-size: 15px;
  font-weight: 500;
  flex-shrink: 0;
}

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

.btn-row button {
  flex: 1;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
}

/* ─── Home ────────────────────────────────────────────── */

h1 {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -1px;
}

.subtitle {
  color: var(--gray);
  font-size: 16px;
  line-height: 1.5;
  max-width: 280px;
}

/* ─── Camera area ─────────────────────────────────────── */

.camera-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.camera-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 4 / 3;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--gray);
  font-size: 15px;
  font-weight: 500;
  transition: border-color .2s, background .2s;
  -webkit-tap-highlight-color: transparent;
}

.camera-btn:active {
  background: var(--light-gray);
  border-color: var(--black);
}

.camera-icon {
  font-size: 52px;
  line-height: 1;
}

.camera-btn input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ─── Preview images ──────────────────────────────────── */

#label-preview-img,
#clothing-preview-img {
  width: 100%;
  border-radius: var(--radius);
  object-fit: cover;
  max-height: 280px;
  display: block;
}

/* ─── OCR status ──────────────────────────────────────── */

.ocr-status {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray);
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 20px;
}

.ocr-status.scanning::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--gray);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  flex-shrink: 0;
}

.ocr-status.found   { color: var(--success); }
.ocr-status.not-found { color: var(--gray); }

/* ─── Blur badge ──────────────────────────────────────── */

.blur-badge {
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 20px;
  display: inline-block;
}

.blur-badge.ok {
  background: #e6f4ea;
  color: var(--success);
}

.blur-badge.warn {
  background: #fff3cd;
  color: #856404;
}

/* ─── Crop ────────────────────────────────────────────── */

.crop-container {
  flex: 1;
  overflow: hidden;
  background: #000;
  position: relative;
  min-height: 0;
}

.crop-container img {
  display: block;
  max-width: 100%;
}

.hint {
  font-size: 13px;
  color: var(--gray);
  text-align: center;
  line-height: 1.4;
}

/* ─── Spinner ─────────────────────────────────────────── */

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--black);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

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

/* ─── AI result card ──────────────────────────────────── */

.result-card {
  background: var(--light-gray);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}

.result-label {
  font-size: 13px;
  color: var(--gray);
  flex-shrink: 0;
}

.result-value {
  font-size: 15px;
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

.result-value.empty {
  color: #aaa;
  font-weight: 400;
  font-style: italic;
}

.confidence-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.confidence-bar {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  background: var(--black);
  border-radius: 3px;
  transition: width .5s ease;
}

/* ─── Items list ──────────────────────────────────────── */

#items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
}

.item-thumb {
  width: 92px;
  height: 92px;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.item-thumb-placeholder {
  width: 92px;
  height: 92px;
  flex-shrink: 0;
  background: var(--light-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

.item-info {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.item-brand {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  font-size: 13px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-size-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.item-size-label {
  font-size: 13px;
  color: var(--gray);
  flex-shrink: 0;
}

.item-size-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--black);
  width: 80px;
  outline: none;
  -webkit-appearance: none;
}

.item-size-input:focus {
  border-color: var(--black);
}

/* ─── Contact form ────────────────────────────────────── */

#contact-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.field-label input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  font-size: 16px;
  font-family: var(--font);
  color: var(--black);
  background: var(--white);
  outline: none;
  -webkit-appearance: none;
  width: 100%;
}

.field-label input:focus {
  border-color: var(--black);
}

/* ─── Error box ───────────────────────────────────────── */

.error-box {
  background: #fff0f0;
  border: 1px solid #fcc;
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.error-box p {
  color: var(--danger);
  font-size: 14px;
  line-height: 1.4;
}

/* ─── Success ─────────────────────────────────────────── */

.success-icon {
  font-size: 72px;
  line-height: 1;
}

/* ─── Utility ─────────────────────────────────────────── */

.hidden {
  display: none !important;
}
