:root {
  --bg: #fff8f0;
  --card: #ffffff;
  --ink: #2b2236;
  --muted: #7b7189;
  --line: #eadfd3;
  --primary: #ff6b4a;
  --primary-ink: #fff;
  --accent: #6c5ce7;
  --danger: #e0394a;
  --radius: 18px;
  --shadow: 0 4px 14px rgba(60, 30, 20, .08);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1925; --card: #2a2433; --ink: #f4eefb; --muted: #a99fb8; --line: #3a3245;
    --shadow: 0 4px 14px rgba(0,0,0,.35); color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .9rem; }
h2 { margin: .2rem 0 .3rem; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.pill { border: 0; border-radius: 999px; padding: 6px 12px; background: #e6f8ec; color: #137a3a; font-weight: 700; font-size: .8rem; }

main { max-width: 1100px; margin: 0 auto; padding: 12px 14px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ---------- chips / toolbar ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 2px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.chip.active { border-color: var(--c, var(--primary)); background: var(--c, var(--primary)); color: #fff; }
.chips.small .chip { padding: 5px 11px; font-size: .88rem; font-weight: 600; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--card);
}
.toolbar input:focus { outline: none; border-color: var(--primary); }

/* ---------- buttons ---------- */
.btn {
  border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 11px 16px;
  font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; transition: transform .08s;
}
.btn:active, .chip:active, .card:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 46px; height: 46px; flex: none; border-radius: 14px; border: 2px solid var(--line); background: var(--card);
  font-size: 1.3rem; font-weight: 700; cursor: pointer;
}

/* ---------- theme cards ---------- */
.theme-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
.theme-card {
  border: 0; border-radius: var(--radius); padding: 16px 12px; text-align: left; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 65%, #000));
  box-shadow: var(--shadow); font-weight: 800; font-size: 1.02rem; min-height: 78px;
}
.theme-card span { display: block; font-size: 1.7rem; margin-bottom: 4px; }
.theme-card.active { outline: 4px solid color-mix(in srgb, var(--c) 40%, transparent); outline-offset: 2px; }

/* ---------- grid / cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.card {
  position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; cursor: pointer; border: 0; padding: 0; text-align: left; display: flex; flex-direction: column;
}
.card .img { aspect-ratio: 3 / 4; background: #fff; display: grid; place-items: center; }
.card img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.card .meta { padding: 8px 10px 10px; font-weight: 700; font-size: .9rem; line-height: 1.2; }
.card .meta small { display: block; font-weight: 500; color: var(--muted); margin-top: 2px; }
.card .tag { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: .72rem;
  padding: 3px 8px; border-radius: 999px; font-weight: 700; }
.card .fav { position: absolute; top: 6px; right: 8px; font-size: 1.2rem; }
.card .check { position: absolute; top: 6px; right: 8px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 900; }
.card.added { outline: 3px solid #29b765; }
.card.appear { animation: pop .25s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.9); } }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty .big { font-size: 3.5rem; }

.status { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 12px; background: var(--card);
  border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin .8s linear infinite; flex: none; }
.status.done .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bottom nav ---------- */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav.bottom button { position: relative; flex: 1; border: 0; background: none; padding: 6px; font-size: .78rem;
  font-weight: 700; color: var(--muted); cursor: pointer; }
nav.bottom button span { display: block; font-size: 1.45rem; transition: transform .15s; }
nav.bottom button.active { color: var(--primary); }
nav.bottom button.active span { transform: translateY(-2px) scale(1.1); }
.badge { position: absolute; top: 2px; left: 55%; background: var(--primary); color: #fff; border-radius: 999px;
  font-size: .7rem; padding: 1px 6px; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: 100vw; }
dialog::backdrop { background: rgba(20, 10, 30, .5); backdrop-filter: blur(2px); }
.sheet[open] {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: min(560px, 100%); max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; animation: up .22s ease;
}
@media (min-width: 700px) { .sheet[open] { inset: 0; margin: auto; border-radius: 24px; height: fit-content; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; gap: 10px; align-items: center; }
.sheet-head h3 { flex: 1; margin: 0; }
.title-input { flex: 1; min-width: 0; font-weight: 800; font-size: 1.1rem; border: 0; border-bottom: 2px dashed var(--line);
  background: none; padding: 6px 2px; }
.title-input:focus { outline: none; border-color: var(--primary); }
.preview-wrap { background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 16px; padding: 12px;
  display: grid; place-items: center; min-height: 220px; }
.preview-wrap img { max-width: 100%; max-height: 38vh; box-shadow: 0 6px 20px rgba(0,0,0,.18); background: #fff; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.row.foot { font-size: .85rem; }
.row.foot a { color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: .9rem; }
.row label { flex-direction: row; align-items: center; gap: 8px; }
select, .sheet input[type=url], #addTitle {
  padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
}
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }
.or { text-align: center; color: var(--muted); font-weight: 700; }
.btn.file { flex-direction: row; }

/* ---------- options de mise en page ---------- */
.layout-opts { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 10px; }
.seg { display: flex; background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 10px; font-weight: 700; font-size: .85rem;
  cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--accent); color: #fff; }
.opt-line { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: .88rem; }
.opt-line input[type=range] { flex: 1; accent-color: var(--accent); }
.toggle { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .88rem; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.copies { display: flex; align-items: center; gap: 6px; }
.copies button { width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); font-weight: 800; }
.copies b { min-width: 22px; text-align: center; }

/* ---------- PIN ---------- */
.pin[open] { margin: auto; background: var(--bg); border-radius: 26px; padding: 22px 20px; width: min(340px, 92vw);
  text-align: center; animation: up .2s ease; }
.pin h3 { margin: 0 0 12px; }
.dots { display: flex; justify-content: center; gap: 12px; height: 22px; margin-bottom: 6px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.dots i.on { background: var(--primary); border-color: var(--primary); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.pad button { height: 60px; border-radius: 18px; border: 0; background: var(--card); box-shadow: var(--shadow);
  font-size: 1.4rem; font-weight: 800; cursor: pointer; }
.pad button:active { background: color-mix(in srgb, var(--primary) 20%, var(--card)); }
.pad button.ok { background: var(--primary); color: #fff; }
.pad[aria-disabled=true] { opacity: .4; pointer-events: none; }
#pinMsg.err { color: var(--danger); font-weight: 700; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 700; opacity: 0;
  transition: .25s; z-index: 100; max-width: 90vw; text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }
.sheet > * { flex-shrink: 0; }
.actions .btn { padding: 11px 8px; white-space: nowrap; }
