:root {
    --bg: #14121a;
    --panel: #1f1c29;
    --line: #353044;
    --text: #ece8f4;
    --muted: #9d96b0;
    --accent: #d9a441;
    --ok: #5cc98b;
    --warn: #e0b354;
    --err: #ef7070;
    --info: #6fa8ff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .4rem; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 0; }
p { margin: .3rem 0; }
.muted { color: var(--muted); font-size: .88rem; font-weight: normal; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 1rem; }
[hidden] { display: none !important; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.2rem; color: var(--text); text-decoration: none; }
.logo img { width: 30px; height: 30px; }
.logo span { color: var(--accent); }
.top nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.top nav form { margin: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.auth { max-width: 400px; margin: 8vh auto; }

label { display: block; margin: .7rem 0; font-weight: 600; font-size: .9rem; }
label.check { font-weight: normal; display: flex; gap: .5rem; align-items: center; }
input:not([type=checkbox]), select, textarea {
    display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem; font: inherit;
    color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: .88rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.inline { display: flex; gap: .8rem; align-items: end; flex-wrap: wrap; margin: 0; }
.inline label { margin: 0; flex: 1 1 160px; }
.inline input[type=number] { width: 7rem; }

.btn, .tilebtns button, .filters button {
    font: inherit; font-size: .88rem; cursor: pointer; text-decoration: none; display: inline-block;
    padding: .5rem .85rem; color: var(--text); background: #2b2738; border: 1px solid var(--line); border-radius: 7px;
}
.btn:hover, .tilebtns button:hover, .filters button:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1c1503; font-weight: 700; }
.btn.danger { color: var(--err); margin-right: auto; }
.btn:disabled { opacity: .5; cursor: wait; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.notice { background: #26324a; border: 1px solid #3c5180; border-radius: 8px; padding: .6rem .8rem; margin: .6rem 0; }
.notice.err { background: #432529; border-color: #7c3b41; }
.notice .btn { margin-left: .6rem; }
.quota { color: var(--muted); margin: .4rem 0 .8rem; }
.quota strong { color: var(--text); }

.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin: .5rem 0; }
.bar span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .4s; }
.bar.big { height: 8px; background: var(--panel); margin-bottom: 1rem; }

.decks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.deck { color: inherit; text-decoration: none; margin: 0; }
.deck:hover { border-color: var(--accent); }
.deck h2 { margin: .6rem 0 0; }
.cover { aspect-ratio: 4 / 3; border-radius: 7px; background: var(--bg) center / cover; }

.deckhead { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: start; }
.filters { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.filters button.on { background: var(--accent); border-color: var(--accent); color: #1c1503; font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem; align-items: start; }
.grid.empty::after { content: "Aucune carte dans cette catégorie."; color: var(--muted); }
.grid[data-filter=todo] .tile:not(.todo),
.grid[data-filter=pending] .tile:not(.pending),
.grid[data-filter=done] .tile:not(.done),
.grid[data-filter=error] .tile:not(.error) { display: none; }
.tile { padding: 0; margin: 0; overflow: hidden; display: flex; flex-direction: column; }
.tile .art { position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; padding: 0; border: 0; background: var(--bg); cursor: zoom-in; }
.tile .art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .art.whole { aspect-ratio: 488 / 680; padding: .5rem .5rem 0; }
.tile .art.whole img { object-fit: contain; border-radius: 4.5% / 3.3%; }
.tile .art.original img { filter: grayscale(.7) brightness(.55); }
.noart { color: var(--muted); font-size: 2.5rem; }
.tile .meta { padding: .6rem .7rem .7rem; display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.qty { color: var(--accent); }
.errmsg { color: var(--err); font-size: .82rem; overflow-wrap: anywhere; }
.tilebtns { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: auto; padding-top: .4rem; }
.tilebtns button { padding: .3rem .55rem; font-size: .8rem; }

.tag { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: #353044; color: var(--muted); }
.tag.done { background: #1f3d2d; color: var(--ok); }
.tag.queued { background: #3d351f; color: var(--warn); }
.tag.generating { background: #1f2f4d; color: var(--info); animation: pulse 1.4s infinite; }
.tag.error { background: #432529; color: var(--err); }
.tag.stale { background: #3d351f; color: var(--warn); }
.tag.over { position: absolute; left: .4rem; bottom: .4rem; background: rgba(0, 0, 0, .7); color: #fff; }
.tag.over.ref { top: .4rem; bottom: auto; color: var(--accent); }
@keyframes pulse { 50% { opacity: .5; } }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem; width: min(560px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog .actions { justify-content: flex-end; margin-top: 1rem; }
dialog.view { width: min(1100px, 96vw); }
.close { position: absolute; top: .6rem; right: .6rem; background: none; border: 0; color: var(--text); font-size: 1.2rem; cursor: pointer; }
.compare { display: flex; gap: 1rem; align-items: start; justify-content: center; flex-wrap: wrap; }
.compare figure { margin: 0; flex: 1 1 400px; text-align: center; }
.compare figure.cardfig { flex: 0 1 420px; }
.compare figure.artfig, .compare figure.orig { flex: 0 1 280px; }
.compare img { max-width: 100%; max-height: 72vh; border-radius: 8px; }
.compare .cardfig img { border-radius: 4.5% / 3.3%; }
figcaption { color: var(--muted); font-size: .85rem; margin-top: .3rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); max-width: 90vw; background: #000; color: #fff; padding: .6rem 1rem; border-radius: 8px; border: 1px solid var(--line); z-index: 10; }

@media (max-width: 640px) {
    .cols { grid-template-columns: 1fr; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
