@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* ==========================================================================
   Palette — feuille de style unique
   ========================================================================== */

:root {
  --bg:          #0e0c16;
  --bg-2:        #15121f;
  --surface:     #1b1727;
  --surface-2:   #241f33;
  --line:        rgba(255, 255, 255, .09);
  --line-strong: rgba(255, 255, 255, .18);

  --text:        #f2eefb;
  --text-dim:    #a79fc0;

  --accent:      #7b61ff;
  --accent-2:    #ff4d6d;
  --accent-3:    #37d6c4;
  --gradient:    linear-gradient(120deg, #ff4d6d 0%, #7b61ff 52%, #37d6c4 100%);

  --danger:      #ff5a6e;
  --radius:      16px;
  --radius-sm:   10px;
  --shadow:      0 18px 48px rgba(0, 0, 0, .45);
  --ring:        0 0 0 3px rgba(123, 97, 255, .35);

  --bar-h:       60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(123, 97, 255, .18), transparent 60%),
    radial-gradient(900px 620px at 92% 8%, rgba(255, 77, 109, .13), transparent 62%),
    var(--bg);
  color: var(--text);
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0 0 .35em; line-height: 1.15; letter-spacing: -.02em; font-weight: 600; }
h1 { font-size: clamp(1.6rem, 3.4vw, 2.15rem); }
p  { margin: 0 0 1em; }
a  { color: inherit; text-decoration: none; }

.muted  { color: var(--text-dim); }
.center { text-align: center; }

/* -------------------------------------------------------------- icônes SVG */

.sprite { display: none; }

.ico {
  width: 1.25em;
  height: 1.25em;
  flex: 0 0 auto;
  vertical-align: -.22em;
  overflow: visible;
}
.ico-lg { width: 1.6em; height: 1.6em; }

/* ------------------------------------------------------------------ boutons */

.btn {
  --btn-bg: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .62rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease;
  white-space: nowrap;
}
.btn:hover  { transform: translateY(-1px); border-color: var(--line-strong); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--gradient);
  border-color: transparent;
  color: #14101f;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(123, 97, 255, .32);
}
.btn-primary:hover { box-shadow: 0 12px 30px rgba(123, 97, 255, .42); }

.btn-ghost  { background: rgba(255, 255, 255, .04); }
.btn-danger { background: rgba(255, 90, 110, .16); border-color: rgba(255, 90, 110, .4); color: #ffb7bf; }
.btn-sm     { padding: .45rem .9rem; font-size: .92rem; }
.btn-block  { width: 100%; padding: .8rem; margin-top: .4rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); transform: translateY(-1px); }
.icon-btn .ico { width: 20px; height: 20px; vertical-align: 0; }
.icon-btn[disabled] { opacity: .3; cursor: default; transform: none; }

/* ------------------------------------------------------------------ marque */

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 600;
  font-size: 1.12rem;
  letter-spacing: -.02em;
}
.brand-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gradient);
  box-shadow: 0 0 18px rgba(123, 97, 255, .6);
}
.brand-lg { font-size: 1.35rem; margin-bottom: 1.6rem; }

/* ------------------------------------------------------------ barre du haut */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: var(--bar-h);
  padding: 0 clamp(.9rem, 3vw, 2rem);
  background: rgba(14, 12, 22, .72);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.topnav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .42rem .85rem;
  border-radius: 999px;
  color: var(--text-dim);
  font-size: .95rem;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.topnav a:hover     { color: var(--text); background: rgba(255, 255, 255, .06); }
.topnav a.is-active { color: var(--text); background: rgba(255, 255, 255, .1); }

.topbar-right { display: flex; align-items: center; gap: .6rem; }

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient);
  color: #14101f;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.avatar::-webkit-details-marker { display: none; }

/* menu déroulant */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  min-width: 200px;
  padding: .4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 50;
}
.menu-panel a,
.menu-panel button {
  display: block;
  width: 100%;
  padding: .55rem .7rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-panel a, .menu-panel button { display: flex; align-items: center; gap: .6rem; }
.menu-panel a:hover, .menu-panel button:hover { background: rgba(255, 255, 255, .08); }
.menu-panel .ico { width: 18px; height: 18px; opacity: .75; }
.menu-album {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .45rem .7rem;
  font-size: .9rem;
  color: var(--text-dim);
}
.menu-album select { flex: 1; padding: .35rem .5rem; font-size: .88rem; }
.menu-panel .danger { color: #ffa1ac; }
.menu-user { padding: .5rem .7rem .3rem; margin: 0; color: var(--text-dim); font-size: .85rem; }

/* ------------------------------------------------------- pages / conteneurs */

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(1.4rem, 4vw, 2.6rem) clamp(.9rem, 3vw, 2rem) 5rem;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.6rem;
}
.page-head-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

.section { margin-bottom: 2.6rem; }
.section-title {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .12em;
  margin-bottom: .9rem;
}

/* filtres */
.filters { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.search-box { position: relative; flex: 1 1 240px; display: flex; }
.search-box .ico {
  position: absolute;
  left: .8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--text-dim);
  pointer-events: none;
}
.search-box input[type="search"] { width: 100%; padding-left: 2.4rem; }

input[type="text"],
input[type="search"],
input[type="password"],
select {
  padding: .68rem .9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
select { cursor: pointer; }
option { background: var(--surface); color: var(--text); }

/* ------------------------------------------------------------------ grille */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: clamp(.8rem, 2vw, 1.3rem);
}

.card, .album-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.card:hover, .album-card:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.card-thumb, .album-cover {
  display: block;
  aspect-ratio: 4 / 3;
  background:
    repeating-conic-gradient(rgba(255, 255, 255, .04) 0 25%, transparent 0 50%) 0 0 / 22px 22px,
    var(--bg-2);
}
.card-thumb img, .album-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-thumb-light { background: #fff; }
.card-thumb-light img { object-fit: contain; padding: 10%; }

.album-cover-empty {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--text-dim);
  opacity: .55;
}
.album-cover-empty .ico { width: 42px; height: 42px; }

.card-body { padding: .8rem .9rem 1rem; }
.card-title {
  margin: 0 0 .15rem;
  font-size: 1rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-meta { margin: 0; color: var(--text-dim); font-size: .82rem; }

.card-actions {
  display: flex;
  gap: .2rem;
  padding: 0 .55rem .6rem;
  opacity: .35;
  transition: opacity .18s ease;
}
.card:hover .card-actions,
.album-card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }
@media (hover: none) { .card-actions { opacity: 1; } }

.album-card-loose { border-style: dashed; background: rgba(255, 255, 255, .02); }

/* état vide */
.empty {
  padding: clamp(2.5rem, 8vw, 5rem) 1.5rem;
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 24px;
  background: rgba(255, 255, 255, .02);
}
.empty-icon { display: block; margin: 0 auto .8rem; color: var(--accent); }
.empty-icon .ico { width: 56px; height: 56px; }
.empty-actions { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; margin-top: 1.2rem; }

/* ============================ authentification ============================ */

.auth {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  min-height: 100vh;
}

.auth-art {
  position: relative;
  overflow: hidden;
  display: grid;
  align-items: center;
  padding: clamp(2rem, 6vw, 5rem);
  background: linear-gradient(160deg, #191233, #0e0c16 70%);
}
.auth-art-text { position: relative; z-index: 2; max-width: 440px; }
.auth-art-text h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); font-weight: 600; }
.auth-art-text p  { color: var(--text-dim); font-size: 1.05rem; }

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .55;
  animation: float 18s ease-in-out infinite;
}
.blob-1 { width: 380px; height: 380px; background: #ff4d6d; top: -60px; left: -80px; }
.blob-2 { width: 420px; height: 420px; background: #7b61ff; bottom: -120px; left: 26%; animation-delay: -6s; }
.blob-3 { width: 300px; height: 300px; background: #37d6c4; top: 22%; right: -60px; animation-delay: -12s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(30px, -28px) scale(1.08); }
  66%      { transform: translate(-24px, 22px) scale(.94); }
}
@media (prefers-reduced-motion: reduce) { .blob { animation: none; } }

.auth-form { display: grid; place-items: center; padding: clamp(1.5rem, 5vw, 3rem); }
.auth-card {
  width: min(400px, 100%);
  padding: clamp(1.6rem, 4vw, 2.4rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.auth-card h2 { font-size: 1.5rem; }

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; margin-bottom: .35rem; font-size: .88rem; color: var(--text-dim); }
.field input { width: 100%; }

.auth-switch { margin: 1.3rem 0 0; text-align: center; color: var(--text-dim); font-size: .93rem; }
.auth-switch a { color: var(--text); border-bottom: 1px solid var(--accent); padding-bottom: 1px; }

.alert {
  padding: .7rem .9rem;
  border-radius: 12px;
  font-size: .92rem;
  margin-bottom: .9rem;
}
.alert-error { background: rgba(255, 90, 110, .14); border: 1px solid rgba(255, 90, 110, .35); color: #ffc0c7; }

@media (max-width: 880px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { min-height: 220px; padding: 2rem 1.4rem; }
  .auth-art-text h1 { font-size: 1.9rem; }
  .auth-art-text p  { display: none; }
}

/* ================================ éditeur ================================= */

.editor {
  display: grid;
  grid-template-rows: var(--bar-h) 1fr auto;
  height: 100dvh;
  overflow: hidden;
}

.ed-bar {
  position: relative;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .7rem;
  background: rgba(14, 12, 22, .85);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.ed-bar-spacer { flex: 1; }
.ed-history { display: flex; gap: .2rem; }

.ed-title {
  width: min(260px, 34vw);
  padding: .42rem .7rem;
  background: transparent;
  border-color: transparent;
  font-weight: 500;
}
.ed-title:hover { background: rgba(255, 255, 255, .05); }
.ed-select { padding: .42rem .7rem; font-size: .9rem; max-width: 160px; }

.ed-stage {
  position: relative;
  z-index: 1;
  overflow: hidden;
  background:
    repeating-conic-gradient(rgba(255, 255, 255, .022) 0 25%, transparent 0 50%) 0 0 / 28px 28px,
    var(--bg-2);
  touch-action: none;
}
.ed-stage[data-cursor="grab"]      { cursor: grab; }
.ed-stage[data-cursor="crosshair"] { cursor: crosshair; }

.ed-canvas-wrap {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
  border-radius: 2px;
}
.ed-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#bgCanvas { background: #fff; }

.ed-zoom {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .5rem;
  background: rgba(20, 17, 32, .82);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  font-size: .82rem;
  color: var(--text-dim);
  z-index: 5;
}

/* palette d'outils */
.ed-tools {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
  padding: .7rem clamp(.7rem, 2vw, 1.4rem);
  background: rgba(20, 17, 32, .92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}

.tool-row { display: flex; gap: .25rem; flex-wrap: wrap; }
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, border-color .15s ease;
}
.tool .ico { width: 22px; height: 22px; }
.tool i { display: none; font-style: normal; font-size: .58rem; letter-spacing: .01em; }
.tool.is-active { color: #191330; }
.tool:hover { background: rgba(255, 255, 255, .12); transform: translateY(-2px); }
.tool.is-active {
  background: var(--gradient);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(123, 97, 255, .38);
}

.tool-settings { display: flex; gap: 1.1rem; flex-wrap: wrap; flex: 1 1 260px; min-width: 200px; }
.slider { flex: 1 1 150px; min-width: 130px; font-size: .78rem; color: var(--text-dim); }
.slider span { display: block; margin-bottom: .1rem; }
.slider b { color: var(--text); font-weight: 500; }

input[type="range"] {
  width: 100%;
  height: 4px;
  appearance: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gradient);
  border: 2px solid #0e0c16;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #7b61ff; border: 2px solid #0e0c16;
}

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem; }
.swatch, .recent {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  min-width: 0;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease;
}
.swatch:hover, .recent:hover { transform: scale(1.12); }
.swatch.is-active { border-color: #fff; }

.color-row { display: flex; align-items: center; gap: .7rem; }
.color-picker {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .25rem .6rem .25rem .25rem;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: .8rem;
  color: var(--text-dim);
  cursor: pointer;
}
.color-picker input[type="color"] {
  width: 30px; height: 30px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.color-picker input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
.color-picker input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }

.recents { display: flex; gap: .25rem; flex-wrap: wrap; max-width: 180px; }

.ed-tools-toggle, .ed-tools-close { display: none; }

/* mobile : la palette devient un tiroir */
@media (max-width: 820px) {
  /* Barre du haut : rien ne doit sortir de l'écran, encoche comprise. */
  .editor { min-width: 0; --peek: 142px; }
  .ed-bar {
    gap: .3rem;
    padding-left:  max(.45rem, env(safe-area-inset-left));
    padding-right: max(.45rem, env(safe-area-inset-right));
    min-width: 0;
    overflow: hidden;
  }
  .ed-bar > *, .ed-history > * { flex-shrink: 0; }
  .ed-bar .icon-btn { width: 36px; height: 36px; }
  .ed-bar .icon-btn .ico { width: 19px; height: 19px; }
  .ed-history { gap: .1rem; }
  .ed-bar-spacer { display: none; }

  .ed-title {
    flex: 1 1 0;
    width: auto;
    min-width: 40px;
    padding: .4rem .5rem;
    font-size: .95rem;
    text-overflow: ellipsis;
  }
  .ed-select { display: none; }
  #edSave span { display: none; }
  #edSave { width: 40px; height: 36px; padding: 0; }
  #edSave .ico { width: 20px; height: 20px; }

  .ed-tools {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    flex-direction: column;
    align-items: stretch;
    gap: .85rem;
    padding: .9rem 1rem calc(1rem + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -14px 40px rgba(0, 0, 0, .5);
    /* tiroir fermé : la grille d'outils complète reste visible */
    transform: translateY(calc(100% - var(--peek)));
    transition: transform .3s cubic-bezier(.3, .85, .3, 1);
    z-index: 30;
  }
  .ed-tools::before {
    content: '';
    position: absolute;
    top: 7px; left: 50%;
    width: 42px; height: 4px;
    margin-left: -21px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .25);
  }
  .ed-tools.is-open { transform: translateY(0); }

  /* Bouton de repli, visible seulement tiroir ouvert. */
  .ed-tools.is-open .ed-tools-close {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    order: -2;
    width: 100%;
    margin: -.2rem 0 -.35rem;
    padding: .45rem;
    border: 0;
    border-radius: 12px;
    background: none;
    color: var(--text-dim);
    font: inherit;
    font-size: .82rem;
    cursor: pointer;
  }
  .ed-tools.is-open .ed-tools-close:active { background: rgba(255, 255, 255, .07); }
  .ed-tools-close .ico { width: 18px; height: 18px; }

  /* le bouton palette laisse la place au tiroir ouvert */
  .ed-tools.is-open ~ .ed-tools-toggle { opacity: 0; pointer-events: none; }
  .ed-tools-toggle { transition: opacity .2s ease; }

  /* Les 9 outils tiennent sur deux rangées : plus rien à faire défiler. */
  .tool-row {
    order: -1;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: .35rem;
    margin-top: .4rem;
  }
  .tool {
    width: auto;
    height: 52px;
    gap: 3px;
    padding: 0 2px;
  }
  .tool .ico { width: 22px; height: 22px; }
  .tool i {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .56rem;
  }

  .tool-settings { gap: .9rem; }
  .slider { flex: 1 1 100%; }
  input[type="range"] { height: 6px; }
  input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; }

  /* Une seule rangée de pastilles, qui s'étire sans jamais déborder.
     Le width:100% ne concerne que la grille : dans .recents (flex),
     il ferait grossir chaque pastille à la largeur du conteneur. */
  .swatches { grid-template-columns: repeat(6, 1fr); gap: .4rem; }
  .swatches .swatch { width: 100%; height: 34px; aspect-ratio: auto; }

  .color-row { justify-content: space-between; gap: .5rem; }
  .recents { max-width: none; flex: 0 1 auto; justify-content: flex-end; gap: .3rem; }
  .recents .recent { width: 30px; height: 30px; }

  .ed-tools-toggle {
    display: grid;
    place-items: center;
    position: fixed;
    right: 1rem;
    bottom: calc(var(--peek) + 14px + env(safe-area-inset-bottom));
    width: 52px; height: 52px;
    border: none;
    border-radius: 50%;
    background: var(--gradient);
    color: #191330;
    box-shadow: 0 10px 26px rgba(0, 0, 0, .5);
    z-index: 31;
    cursor: pointer;
  }
  .ed-tools-toggle .ico { width: 24px; height: 24px; }
  .ed-zoom { bottom: calc(var(--peek) + 16px + env(safe-area-inset-bottom)); left: 1rem; right: auto; }
}

/* ============================ modales & toasts ============================ */

.modal-back {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(6, 5, 12, .68);
  backdrop-filter: blur(6px);
  z-index: 100;
  animation: fade .16s ease;
}
.modal {
  width: min(400px, 100%);
  padding: 1.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: pop .2s cubic-bezier(.2, .9, .3, 1.2);
}
.modal h3 { font-size: 1.15rem; }
.modal-field { margin: 1rem 0; }
.modal-field input, .modal-field select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop  { from { opacity: 0; transform: translateY(8px) scale(.97); } }

.ed-toast, .app-toast {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  padding: .65rem 1.1rem;
  background: rgba(30, 26, 46, .96);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: .92rem;
  z-index: 200;
}
.app-toast { opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.app-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.ed-toast.success, .app-toast.success { border-color: rgba(55, 214, 196, .5); }
.ed-toast.error,   .app-toast.error   { border-color: rgba(255, 90, 110, .55); color: #ffc0c7; }


/* ==========================================================================
   Adaptations mobile (pages hors éditeur)
   ========================================================================== */

@media (max-width: 760px) {
  :root { --bar-h: 56px; }

  body.has-tabbar { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  .topbar { gap: .6rem; padding: 0 .9rem; }
  .brand-name { display: none; }
  .brand-dot { width: 22px; height: 22px; }

  /* la navigation devient une barre d'onglets en bas d'écran */
  .topnav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 45;
    display: flex;
    justify-content: space-around;
    gap: 0;
    padding: .35rem .4rem calc(.35rem + env(safe-area-inset-bottom));
    background: rgba(17, 14, 27, .93);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
    overflow: visible;
  }
  .topnav a {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: .35rem .2rem;
    border-radius: 12px;
    font-size: .68rem;
    letter-spacing: .01em;
  }
  .topnav a .ico { width: 22px; height: 22px; }
  .topnav a.is-active { color: var(--text); background: none; }
  .topnav a.is-active .ico { color: var(--accent-2); }

  .btn-new span { display: none; }
  .btn-new { width: 38px; height: 38px; padding: 0; border-radius: 50%; }
  .btn-new .ico { width: 20px; height: 20px; }

  .page { padding: 1.2rem .9rem 2rem; }
  .page-head { align-items: flex-start; flex-direction: column; gap: .7rem; margin-bottom: 1.1rem; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 1; }

  .filters { gap: .5rem; }
  .search-box { flex: 1 1 100%; }
  .filters select { flex: 1; }
  .filters .btn { flex: 0 0 auto; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
  .card-body { padding: .6rem .7rem .7rem; }
  .card-title { font-size: .92rem; }
  .card-meta { font-size: .74rem; }
  .card-actions { justify-content: space-between; padding: 0 .4rem .5rem; }
  .icon-btn { width: 34px; height: 34px; }

  .section { margin-bottom: 1.8rem; }
  .empty { padding: 2.4rem 1rem; border-radius: 20px; }
  .empty-actions .btn { flex: 1 1 100%; }

  /* les boîtes de dialogue remontent du bas, à portée de pouce */
  .modal-back { align-items: end; padding: 0; }
  .modal {
    width: 100%;
    border-radius: 22px 22px 0 0;
    padding: 1.3rem 1.1rem calc(1.3rem + env(safe-area-inset-bottom));
    animation: sheet .24s cubic-bezier(.2, .9, .3, 1);
  }
  .modal-actions .btn { flex: 1; }
  @keyframes sheet { from { transform: translateY(100%); } }

  .app-toast, .ed-toast { bottom: calc(88px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 2rem); }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .tool { height: 48px; }
  .tool i { font-size: .52rem; }
}

/* Confort tactile : cibles plus grandes là où le survol n'existe pas */
@media (hover: none) {
  .icon-btn { width: 40px; height: 40px; }
  .btn:not(.btn-sm):not(.btn-new) { padding: .7rem 1.15rem; }
}
