/* === VARIABLES === */
:root {
  --cream:   #FAF6EE;
  --ink:     #2C1A0E;
  --brown:   #7A5030;
  --gold:    #C8920A;
  --divider: #DDD0B8;
  --white:   #FFFFFF;
  --light:   #F0E8D8;
  --radius-card: 12px;
  --radius-el:   8px;
  --radius-badge:4px;
  --nav-h:   64px;
  --header-h:56px;
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* === LAYOUT === */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* === HEADER === */
.app-header {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.app-header h1 {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 18px;
  color: var(--gold);
}

.btn-prefs {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-badge);
  transition: background 0.15s;
}
.btn-prefs:hover { background: var(--light); }

/* === SECTIONS === */
.sections-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.section {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 80px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.section.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* === BOTTOM NAV === */
.bottom-nav {
  height: var(--nav-h);
  background: var(--white);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--brown);
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--gold); }
.nav-btn:active { background: var(--light); }

/* === GUIDE — SEARCH & FILTERS === */
.guide-controls {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 10px 40px 10px 14px;
  border: 1.5px solid var(--divider);
  border-radius: var(--radius-el);
  background: var(--white);
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.search-input:focus { border-color: var(--gold); }
.search-input::placeholder { color: var(--brown); opacity: 0.6; }

.btn-search-reset {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--divider);
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 11px;
  color: var(--brown);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  line-height: 1;
  transition: opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-search-reset:active { background: var(--gold); color: var(--white); }
.search-wrap.has-value .btn-search-reset { opacity: 1; pointer-events: auto; }

.famille-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.famille-chips::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--divider);
  background: var(--white);
  font-size: 12px;
  color: var(--brown);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.chip.active, .chip:active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--white);
}

/* === GUIDE — GRID === */
.famille-group { margin-bottom: 20px; }

.famille-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 8px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.famille-header h2 {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 16px;
  color: var(--gold);
}

.famille-toggle {
  font-size: 12px;
  color: var(--brown);
  transition: transform 0.2s;
}
.famille-group.collapsed .famille-toggle { transform: rotate(-90deg); }

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.famille-group.collapsed .color-grid { display: none; }

/* === COLOR CARD === */
.color-card {
  background: var(--white);
  border-radius: var(--radius-card);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(44,26,14,0.08);
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.color-card:active { transform: scale(0.97); }

.card-swatch {
  width: 100%;
  height: 80px;
}

.card-body {
  padding: 10px;
}

.card-name {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 4px;
  line-height: 1.3;
}

.card-pigments {
  font-size: 11px;
  color: var(--brown);
  font-family: 'Courier New', monospace;
  margin-bottom: 6px;
  display: none;
}

body[data-name-mode="B"] .card-pigments { display: block; }

.card-famille {
  display: inline-block;
  padding: 2px 7px;
  background: var(--gold);
  color: var(--white);
  font-size: 10px;
  border-radius: var(--radius-badge);
  margin-bottom: 8px;
}

.recipe-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.recipe-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.recipe-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}

.recipe-label {
  font-size: 11px;
  color: var(--brown);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recipe-num {
  font-size: 10px;
  color: var(--gold);
  font-weight: 600;
  font-style: normal;
  font-family: 'Courier New', monospace;
}

.detail-recipe-num {
  font-size: 11px;
  color: var(--gold);
  font-weight: 600;
  font-family: 'Courier New', monospace;
  margin-left: 2px;
}

.recipe-bar-wrap {
  width: 60px;
  flex-shrink: 0;
  height: 6px;
  background: var(--light);
  border-radius: 3px;
  overflow: hidden;
}

.recipe-bar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 3px;
  transition: width 0.3s;
}

/* === DETAIL OVERLAY === */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: rgba(44,26,14,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.overlay-backdrop {
  flex: 1;
  cursor: pointer;
}

.overlay-sheet {
  background: var(--cream);
  border-radius: 20px 20px 0 0;
  max-height: 90dvh;
  overflow-y: auto;
  transform: translateY(30px);
  transition: transform 0.25s ease;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}
.overlay.open .overlay-sheet { transform: translateY(0); }

.detail-swatch {
  width: 100%;
  height: 140px;
  border-radius: 20px 20px 0 0;
}

.detail-body {
  padding: 20px 20px 24px;
}

.detail-name {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 4px;
}

.detail-pigments {
  font-size: 12px;
  color: var(--brown);
  font-family: 'Courier New', monospace;
  margin-bottom: 8px;
  display: none;
}
body[data-name-mode="B"] .detail-pigments { display: block; }

.detail-hex {
  font-family: 'Courier New', monospace;
  font-size: 14px;
  color: var(--gold);
  margin-bottom: 8px;
}

.detail-famille {
  display: inline-block;
  padding: 3px 10px;
  background: var(--gold);
  color: var(--white);
  border-radius: var(--radius-badge);
  font-size: 12px;
  margin-bottom: 16px;
}

.detail-section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brown);
  margin-bottom: 10px;
  font-weight: 600;
}

.detail-recipe { margin-bottom: 16px; }

.detail-recipe-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--divider);
}
.detail-recipe-row:last-child { border-bottom: none; }

.detail-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}

.detail-recipe-info { flex: 1; }

.detail-recipe-name {
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
}

.detail-recipe-parts {
  font-size: 12px;
  color: var(--brown);
}

.detail-bar-wrap {
  width: 80px;
  height: 8px;
  background: var(--light);
  border-radius: 4px;
  overflow: hidden;
}

.detail-bar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 4px;
}

.detail-note {
  background: var(--light);
  border-radius: var(--radius-el);
  padding: 12px;
  font-size: 13px;
  color: var(--brown);
  line-height: 1.5;
  margin-bottom: 16px;
  font-style: italic;
}

.btn-see-guide {
  width: 100%;
  padding: 13px;
  background: var(--gold);
  color: var(--white);
  border: none;
  border-radius: var(--radius-el);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-bottom: 8px;
}
.btn-see-guide:active { opacity: 0.8; }

/* === BOITE === */
.boite-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.boite-title {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 20px;
  color: var(--gold);
  text-align: center;
}

.boite-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 440px;
}

.godet {
  aspect-ratio: 1;
  border-radius: var(--radius-el);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.3);
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.godet:active { transform: scale(0.92); }

.godet-num {
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 2px;
}

.godet-short {
  font-size: 7px;
  text-align: center;
  line-height: 1.2;
  padding: 0 2px;
}

.godet-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-el);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}
.godet.tooltip-visible .godet-tooltip { opacity: 1; }

.boite-legende {
  width: 100%;
  max-width: 440px;
}

.legende-title {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 15px;
  color: var(--gold);
  margin-bottom: 12px;
}

.legende-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--divider);
}
.legende-item:last-child { border-bottom: none; }

.legende-dot {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}

.legende-info { flex: 1; }

.legende-name {
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}

.legende-hex {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--brown);
}

.btn-legende-guide {
  padding: 6px 12px;
  background: var(--light);
  border: 1px solid var(--divider);
  border-radius: var(--radius-badge);
  font-size: 11px;
  color: var(--brown);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-legende-guide:active { background: var(--gold); color: var(--white); }

/* === PIPETTE === */
.pipette-tabs {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--divider);
  border-radius: var(--radius-el);
  overflow: hidden;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.pipette-tab {
  flex: 1;
  padding: 10px;
  background: var(--white);
  border: none;
  font-size: 14px;
  color: var(--brown);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.pipette-tab.active {
  background: var(--gold);
  color: var(--white);
  font-weight: 600;
}

.pipette-panel { display: none; }
.pipette-panel.active { display: flex; flex-direction: column; gap: 16px; }

/* Mode caméra */
.camera-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #111;
  border-radius: var(--radius-card);
  overflow: hidden;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-viewfinder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  pointer-events: none;
}

.viewfinder-corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: #fff;
  border-style: solid;
  border-width: 0;
}
.viewfinder-corner.tl { top:0; left:0; border-top-width:2px; border-left-width:2px; }
.viewfinder-corner.tr { top:0; right:0; border-top-width:2px; border-right-width:2px; }
.viewfinder-corner.bl { bottom:0; left:0; border-bottom-width:2px; border-left-width:2px; }
.viewfinder-corner.br { bottom:0; right:0; border-bottom-width:2px; border-right-width:2px; }

.camera-actions {
  position: absolute;
  bottom: 12px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
}

.btn-capture {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  border: 3px solid var(--gold);
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-capture:active { transform: scale(0.9); background: var(--gold); }

.btn-flip {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
  border: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-camera-start {
  width: 100%;
  padding: 14px;
  background: var(--gold);
  color: var(--white);
  border: none;
  border-radius: var(--radius-el);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-camera-start:active { opacity: 0.8; }

/* Photo mode */
.photo-drop-zone {
  width: 100%;
  padding: 32px;
  border: 2px dashed var(--divider);
  border-radius: var(--radius-card);
  text-align: center;
  cursor: pointer;
  color: var(--brown);
  font-size: 14px;
  line-height: 1.6;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.photo-drop-zone:active { border-color: var(--gold); }
.photo-drop-zone .drop-icon { font-size: 32px; margin-bottom: 8px; }

.photo-canvas-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: #111;
  touch-action: none;
}

#photo-canvas {
  width: 100%;
  display: block;
  cursor: crosshair;
}

.photo-viewfinder {
  position: absolute;
  width: 60px;
  height: 60px;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.btn-analyze {
  width: 100%;
  padding: 14px;
  background: var(--gold);
  color: var(--white);
  border: none;
  border-radius: var(--radius-el);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-analyze:active { opacity: 0.8; }

/* Résultats pipette */
.pipette-result {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: 0 1px 4px rgba(44,26,14,0.08);
}

.result-detected {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--divider);
}

.result-swatch {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-el);
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.1);
}

.result-detected-label {
  font-size: 13px;
  color: var(--brown);
}

.result-hex {
  font-family: 'Courier New', monospace;
  font-size: 16px;
  color: var(--ink);
  font-weight: 600;
}

.result-matches-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brown);
  font-weight: 600;
  margin-bottom: 10px;
}

.result-match {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.result-match:last-child { border-bottom: none; }
.result-match:active { opacity: 0.7; }

.match-rank {
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
  width: 24px;
  flex-shrink: 0;
  text-align: center;
}

.match-dot {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-badge);
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.match-info { flex: 1; min-width: 0; }

.match-name {
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
}

.match-recipe {
  font-size: 11px;
  color: var(--brown);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.match-score {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
  flex-shrink: 0;
}

/* Color live preview */
.color-live {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--light);
  border-radius: var(--radius-el);
}

.color-live-swatch {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-el);
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.color-live-info {
  flex: 1;
}

.color-live-label {
  font-size: 12px;
  color: var(--brown);
}

.color-live-hex {
  font-family: 'Courier New', monospace;
  font-size: 16px;
  color: var(--ink);
  font-weight: 600;
}

/* === PREFS OVERLAY === */
.prefs-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  background: rgba(44,26,14,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.prefs-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.prefs-sheet {
  background: var(--cream);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom, 32px));
  width: 100%;
  transform: translateY(20px);
  transition: transform 0.22s ease;
}
.prefs-overlay.open .prefs-sheet { transform: translateY(0); }

.prefs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.prefs-title {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 20px;
  color: var(--gold);
}

.btn-close-prefs {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--brown);
  padding: 4px 8px;
}

.prefs-section { margin-bottom: 24px; }

.prefs-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--brown);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.prefs-radio-group {
  display: flex;
  gap: 8px;
}

.prefs-radio-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--divider);
  border-radius: var(--radius-el);
  background: var(--white);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.prefs-radio-btn.selected {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--white);
}

.prefs-radio-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.prefs-radio-desc {
  font-size: 11px;
  opacity: 0.7;
  line-height: 1.3;
}

/* Hidden canvas for camera pixel reading */
#pixel-canvas { display: none; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--brown);
  font-style: italic;
  font-family: Georgia, serif;
  font-size: 15px;
}

/* Section header */
.section-title {
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 20px;
  color: var(--gold);
  margin-bottom: 16px;
}

/* Scrollbar global */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 2px; }

/* Safe area support */
.bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
