/* EquiFont — thème sombre, un seul accent (ambre), zéro webfont. */

:root {
  --bg: #101014;
  --surface: #18181f;
  --surface-2: #1f1f28;
  --border: #2a2a34;
  --text: #e6e6ec;
  --muted: #7a7a8c;
  --accent: #ffb627;
  --accent-ink: #1a1305;
  --warn: #ff8f5c;

  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, "Segoe UI", sans-serif;
  --radius: 4px;
}

* { box-sizing: border-box; }

/* Le navigateur applique [hidden] avec une spécificité de (0,1,0) : n'importe quelle
   règle par id la bat et laisse l'élément affiché — #output gardait ainsi son dernier
   rendu à l'écran une fois le texte vidé. On remet l'attribut au-dessus, une fois pour
   toutes les cibles de `hidden` de la page. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 40px 20px 64px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app,
#stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app {
  max-width: 880px;
  margin: 0 auto;
}

/* ── En-tête ─────────────────────────────────────────────────────────────── */

.head h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.head h1 span { color: var(--accent); }

.head p {
  margin: 4px 0 0;
  color: var(--muted);
}

/* ── Onglets ─────────────────────────────────────────────────────────────── */

/* Registre volontairement distinct de .segmented : celui-ci sert aux réglages,
   les onglets à la navigation. Un soulignement, pas un bouton plein. */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tabs button {
  padding: 8px 14px;
  margin-bottom: -1px; /* le soulignement actif recouvre la bordure de la barre */
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}

.tabs button:hover { color: var(--text); }

.tabs button[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── Panneaux ────────────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

textarea {
  display: block;
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 0.04em;
}

textarea::placeholder { color: #43434f; }

textarea:focus-visible,
select:focus-visible,
input:focus-visible,
button:focus-visible,
.cp-sv:focus-visible,
.cp-hue:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Contrôles ───────────────────────────────────────────────────────────── */

/* 220px : 3 colonnes sur desktop — les six réglages d'image occupent deux rangées
   pleines, le zoom d'aperçu (purement visuel) reste seul sur la troisième. */
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

select,
input[type="number"] {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

/* ── Sélecteur de couleur (colorpicker.js) ───────────────────────────────── */

/* --cp-color : la couleur courante. --cp-hue : la même teinte à saturation et
   luminosité pleines, qui sert de fond au carré. Toutes deux posées par le script. */
.cp {
  position: relative;
  flex: none;
}

.cp-swatch {
  display: block;
  width: 48px;
  height: 32px;
  padding: 0;
  background: var(--cp-color);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.cp-swatch:hover:not(:disabled) { border-color: var(--muted); }
.cp-swatch:disabled { opacity: 0.35; cursor: not-allowed; }

/* 248 px : le panneau tient dans la colonne de contrôles (271 px) sur desktop. En
   fenêtre étroite les colonnes rétrécissent et le panneau sortirait de l'écran :
   colorpicker.js mesure à l'ouverture et bascule sur .cp-pop-right le cas échéant. */
.cp-pop {
  position: absolute;
  z-index: 10;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  gap: 12px;
  width: 248px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}

.cp-pop-right {
  left: auto;
  right: 0;
}

/* Saturation en x, luminosité en y : deux dégradés suffisent, aucun canvas. */
.cp-sv {
  position: relative;
  height: 168px;
  border-radius: 2px;
  background:
    linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #fff, var(--cp-hue));
  cursor: crosshair;
  touch-action: none; /* sinon le navigateur fait défiler la page au lieu de suivre le doigt */
}

.cp-hue {
  position: relative;
  height: 16px;
  border-radius: 2px;
  background: linear-gradient(to right,
    #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  cursor: ew-resize;
  touch-action: none;
}

.cp-dot {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7);
  pointer-events: none; /* le glisser vise la zone, jamais la pastille */
}

.cp-hue .cp-dot { top: 50%; }

.cp-hex {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cp-hex.is-invalid {
  border-color: var(--warn);
  color: var(--warn);
}

/* ── Palettes dans le popover ────────────────────────────────────────────── */

.cp-palettes,
.cp-recent {
  display: grid;
  gap: 6px;
}

/* Sépare les couleurs rangées (au-dessus) des couleurs récentes (en dessous) :
   deux rangées de pastilles identiques seraient indistinctes sans ça. */
.cp-recent {
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.cp-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.cp-palette-head {
  display: flex;
  gap: 6px;
}

/* min-width: 0 — sans ça un nom de palette long force la largeur du popover. */
.cp-palette-select {
  flex: 1;
  min-width: 0;
  height: 28px;
  font-size: 12px;
}

.cp-palette-new {
  flex: 1;
  height: 28px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}

.cp-palette-toggle {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.cp-palette-new:hover,
.cp-palette-toggle:hover:not(:disabled) { border-color: var(--muted); }

.cp-palette-toggle:not(.is-remove) { color: var(--accent); }
.cp-palette-toggle.is-remove { color: var(--warn); }
.cp-palette-toggle:disabled { opacity: 0.4; cursor: not-allowed; }

/* Historique des couleurs choisies — masqué tant que rien n'a été retenu. */
.cp-memory,
.cp-palette-colors {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.cp-memory-swatch {
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
}

.cp-memory-swatch:hover { border-color: var(--text); }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.check input { accent-color: var(--accent); }

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented button {
  flex: 1;
  height: 32px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}

.segmented button:last-child { border-right: 0; }
.segmented button:hover { color: var(--text); }

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* ── Aperçu ──────────────────────────────────────────────────────────────── */

.preview-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  padding: 24px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Damier : rend la transparence visible sans image de fond. */
  background-color: #14141a;
  background-image:
    linear-gradient(45deg, #1c1c24 25%, transparent 25%, transparent 75%, #1c1c24 75%),
    linear-gradient(45deg, #1c1c24 25%, transparent 25%, transparent 75%, #1c1c24 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}

#output {
  display: block;
  image-rendering: pixelated;
  flex: none;
}

.placeholder {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

.meta {
  display: flex;
  gap: 12px;
  margin: 10px 0 0;
  min-height: 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.warn { color: var(--warn); }

/* ── Actions ─────────────────────────────────────────────────────────────── */

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.actions button {
  height: 38px;
  padding: 0 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}

.actions button:hover:not(:disabled) { border-color: var(--muted); }

.actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.actions .primary:hover:not(:disabled) { background: #ffc555; }

.actions button:disabled { opacity: 0.4; cursor: not-allowed; }

.actions button.is-flash {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.hint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

/* ── Vue des palettes (onglet, monté par palettes.js) ────────────────────── */

/* La section porte déjà .panel : marges, fond et bordure viennent de là. */
#view-palettes {
  display: grid;
  gap: 12px;
}

/* La couleur se choisit une fois, en haut, et chaque « + » de la liste la range. */
.pal-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pal-toolbar .field-label { margin-bottom: 0; }

.pal-list {
  display: grid;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pal-row {
  display: grid;
  grid-template-columns: auto 180px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.pal-row:last-child { border-bottom: 0; }

.pal-order { display: flex; gap: 2px; }

.pal-order button {
  width: 22px;
  height: 26px;
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.pal-order button:disabled { opacity: 0.25; cursor: not-allowed; }

.pal-name {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}

.pal-swatches {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

/* Le × de retrait n'apparaît qu'au survol : au repos la rangée reste une simple
   bande de couleurs, lisible d'un coup d'œil. */
.pal-chip {
  position: relative;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
}

.pal-chip::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
}

.pal-chip:hover::after,
.pal-chip:focus-visible::after { opacity: 1; }

/* Bordure pointillée : l'emplacement où viendra la prochaine couleur, pas une couleur. */
.pal-add {
  width: 22px;
  height: 22px;
  padding: 0;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 2px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.pal-add:hover:not(:disabled) { border-color: var(--accent); }
.pal-add:disabled { opacity: 0.3; cursor: not-allowed; }

.pal-empty,
.pal-none {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.pal-none { margin: 0; padding: 14px 12px; }

.pal-drop {
  height: 28px;
  padding: 0 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}

.pal-drop:hover { border-color: var(--warn); color: var(--warn); }

.pal-status {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.pal-status.is-warn { color: var(--warn); }

.pal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pal-spacer { flex: 1; }

.pal-actions button {
  height: 32px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
}

.pal-actions button:hover { border-color: var(--muted); }

.pal-actions .pal-new {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.pal-actions .pal-new:hover { background: #ffc555; }

@media (max-width: 560px) {
  .pal-row {
    grid-template-columns: auto 1fr;
    row-gap: 8px;
  }
  .pal-swatches,
  .pal-drop { grid-column: 1 / -1; }
}

/* ── Pied de page & erreurs ──────────────────────────────────────────────── */

.foot {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.foot p { margin: 0 0 6px; }
.foot strong { color: var(--text); font-weight: 600; }

.error {
  margin: 0;
  padding: 12px 14px;
  background: #2a1512;
  border: 1px solid #5c2a20;
  border-radius: var(--radius);
  color: #ffb3a0;
  font-family: var(--mono);
  font-size: 13px;
}

@media (max-width: 640px) {
  body { padding: 24px 14px 40px; }
  .actions { flex-wrap: wrap; }
}
