/* ===========================
   JewelSnap — Mobile-first CSS
   Max-width: 480px
   =========================== */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #1a1a1a;
  --color-surface: #252525;
  --color-surface-2: #2e2e2e;
  --color-border: #3a3a3a;
  --color-accent: #d4a574;
  --color-accent-dark: #b8884a;
  --color-text: #f0ece6;
  --color-text-muted: #9a9490;
  --color-gold: #d4a574;
  --color-silver: #c0c0c8;
  --color-rose-gold: #c8847a;
  --color-error: #e05a5a;
  --color-whatsapp: #25d366;
  --color-instagram: #e1306c;
  --color-selected-bg: #3a2e1a;
  --color-selected-border: #d4a574;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --touch-target: 48px;
  --spacing-xs: 8px;
  --spacing-sm: 12px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
}

html, body {
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Layout ---- */
.main {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--spacing-md);
  padding-bottom: env(safe-area-inset-bottom, 24px);
  min-height: calc(100vh - 56px);
}

/* ---- Header ---- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #111111;
  padding: 0 var(--spacing-md);
  height: 56px;
  border-bottom: 1px solid var(--color-border);
  max-width: 100%;
}

.header__logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: 0.5px;
}

.header__help-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 50%;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.header__help-btn:hover,
.header__help-btn:focus-visible {
  background: var(--color-surface-2);
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---- Sections (show/hide) ---- */
.section {
  display: none;
  animation: fadeIn 0.25s ease;
}

.section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Upload Section ---- */
.section--upload {
  padding-top: var(--spacing-xl);
  text-align: center;
}

.upload-hero {
  margin-bottom: var(--spacing-xl);
}

.upload-icon {
  font-size: 72px;
  margin-bottom: var(--spacing-md);
  line-height: 1;
}

.upload-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--spacing-sm);
}

.upload-subtitle {
  font-size: 14px;
  color: var(--color-text-muted);
  max-width: 320px;
  margin: 0 auto;
}

.upload-actions {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  min-height: var(--touch-target);
  padding: 0 var(--spacing-lg);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--color-accent);
  color: #1a1a1a;
}

.btn--secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn--accent {
  background: var(--color-accent);
  color: #1a1a1a;
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.btn--large {
  min-height: 56px;
  font-size: 17px;
}

.btn--small {
  min-height: 40px;
  font-size: 14px;
}

.btn--full {
  width: 100%;
}

.btn--half {
  flex: 1;
}

.btn--whatsapp {
  background: var(--color-whatsapp);
  color: #fff;
}

.btn--instagram {
  background: var(--color-instagram);
  color: #fff;
}

.btn__icon {
  font-size: 20px;
}

/* ---- Selection Section ---- */
.preview-thumb-wrap {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--spacing-sm);
  border: 1px solid var(--color-border);
}

.preview-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.change-photo-btn {
  margin-left: auto;
}

.selection-group {
  margin-bottom: var(--spacing-lg);
}

.selection-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-sm);
}

/* Piece grid: 2 columns × 3 rows */
.piece-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-xs);
}

.piece-btn {
  min-height: var(--touch-target);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: center;
}

.piece-btn:hover {
  background: var(--color-surface-2);
}

.piece-btn.selected {
  background: var(--color-selected-bg);
  border-color: var(--color-selected-border);
  color: var(--color-accent);
  font-weight: 700;
}

/* Metal row: 1 row × 3 columns */
.metal-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-xs);
}

.metal-btn {
  min-height: var(--touch-target);
  padding: var(--spacing-xs) var(--spacing-xs);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: background 0.15s, border-color 0.15s;
}

.metal-btn:hover {
  background: var(--color-surface-2);
}

.metal-btn.selected {
  background: var(--color-selected-bg);
  border-color: var(--color-selected-border);
  color: var(--color-accent);
  font-weight: 700;
}

.metal-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: block;
  border: 2px solid rgba(255,255,255,0.1);
}

.metal-swatch--gold     { background: linear-gradient(135deg, #f5d27a, #c8901a); }
.metal-swatch--silver   { background: linear-gradient(135deg, #e8e8f0, #8a8a9a); }
.metal-swatch--rose-gold { background: linear-gradient(135deg, #f0a898, #c06050); }

/* ---- Loading Section ---- */
.section--loading {
  padding-top: var(--spacing-xl);
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--spacing-lg);
}

.section--loading.active {
  display: flex;
}

.spinner {
  width: 64px;
  height: 64px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.loading-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}

.loading-subtext {
  font-size: 14px;
  color: var(--color-text-muted);
}

/* ---- Result Section ---- */
.result-image-wrap {
  width: 100%;
  margin-bottom: var(--spacing-lg);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.result-image {
  width: 100%;
  object-fit: contain;
  display: block;
  max-height: 400px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.share-row {
  display: flex;
  gap: var(--spacing-sm);
}

/* ---- Error Section ---- */
.section--error {
  padding-top: var(--spacing-xl);
  text-align: center;
  flex-direction: column;
  gap: var(--spacing-md);
  align-items: center;
}

.section--error.active {
  display: flex;
}

.error-icon {
  font-size: 56px;
}

.error-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-error);
}

.error-message {
  font-size: 15px;
  color: var(--color-text-muted);
  max-width: 320px;
}

/* ---- Help Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.modal__content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--spacing-xl) var(--spacing-lg);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal__close {
  position: absolute;
  top: var(--spacing-md);
  right: var(--spacing-md);
  width: var(--touch-target);
  height: var(--touch-target);
  background: var(--color-surface-2);
  border: none;
  border-radius: 50%;
  color: var(--color-text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: var(--spacing-lg);
  padding-right: var(--touch-target);
}

.tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-xl);
}

.tips-list li {
  font-size: 15px;
  color: var(--color-text);
  padding-left: var(--spacing-lg);
  position: relative;
}

.tips-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--color-accent);
  font-weight: 700;
}

/* ---- Focus styles ---- */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
