:root {
  --bg: #0a0a0c;
  --bg2: #121216;
  --bg3: #1a1a20;
  --line: #26262e;
  --text: #f2f0ea;
  --muted: #8d8b95;
  --orange: #f7931a;
  --orange2: #ffb347;
  --volt: #ffe14d;
  --red: #ff4d5e;
  --green: #3ddc84;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --pixel: "Silkscreen", var(--mono);
  --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
  --top: 64px;
  --left: 0px;
  --right: 310px;
}
body.light {
  --bg: #f6f4ef;
  --bg2: #ffffff;
  --bg3: #eceae4;
  --line: #dedbd3;
  --text: #16151a;
  --muted: #6b6974;
}
body.light .topbar { background: rgba(255, 255, 255, .92); }
body.light .hud { background: rgba(255,255,255,.95); }
body.light .btn.bomb { background: #fff0f1; color: #8a1020; border-color: #f2b8bf; }
body.light .editor-frame { background-color: #e9e7e1; background-image: linear-gradient(45deg, #dedbd3 25%, transparent 25%, transparent 75%, #dedbd3 75%), linear-gradient(45deg, #dedbd3 25%, transparent 25%, transparent 75%, #dedbd3 75%); }
body.light .bomb-ctl { background: #fff5f6; border-color: #f2b8bf; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top); z-index: 20;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 24px;
  padding: 0 18px; background: rgba(10, 10, 12, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bolt { width: 22px; height: 28px; fill: var(--orange); shape-rendering: crispEdges; flex: none; filter: drop-shadow(0 0 8px rgba(247,147,26,.55)); }
.brand h1 { font-family: var(--pixel); font-weight: 700; font-size: 17px; letter-spacing: .5px; margin: 0; white-space: nowrap; text-transform: uppercase; }
.tagline { margin: 2px 0 0; font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.actions { display: flex; gap: 10px; align-items: center; justify-self: end; }
.lang { background: none; border: 1px solid var(--line); color: var(--muted); padding: 7px 9px; font-family: var(--mono); font-size: 11px; cursor: pointer; }
.lang:hover { color: var(--text); border-color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--bg3); color: var(--text);
  padding: 10px 16px; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: transform .08s, background .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #140b00; box-shadow: 0 0 0 0 rgba(247,147,26,.0); }
.btn.primary:hover { background: var(--orange2); box-shadow: 0 0 24px rgba(247,147,26,.35); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { border-color: var(--muted); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.zap { filter: saturate(0) brightness(.2); }

/* ---------- Stage ---------- */
main#stage { position: fixed; top: var(--top); bottom: 0; left: var(--left); right: var(--right); background: #050506; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#view.dragging { cursor: grabbing; }
#view.selecting { cursor: crosshair; }
#view.link { cursor: pointer; }

.select-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 12px; align-items: center; padding: 8px 10px 8px 14px;
  background: var(--orange); color: #140b00; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: calc(100% - 24px);
}
.select-hint .btn { color: #140b00; border-color: rgba(0,0,0,.35); }


.close { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.close:hover { color: var(--text); }

.hud {
  position: absolute; left: 14px; bottom: 14px; z-index: 5; display: flex; align-items: center; gap: 4px;
  background: rgba(18,18,22,.9); border: 1px solid var(--line); padding: 4px; font-family: var(--mono); font-size: 11px; color: var(--muted);
}
.hud button { width: 30px; height: 30px; background: var(--bg3); border: 0; cursor: pointer; font-size: 16px; }
.hud button:hover { background: var(--line); }
.hud span { padding: 0 6px; white-space: nowrap; }
.hint-help { position: absolute; right: 14px; bottom: 16px; z-index: 4; font-size: 11px; color: var(--muted); font-family: var(--mono); pointer-events: none; }

/* ---------- Panel ---------- */
.panel {
  position: fixed; top: var(--top); right: 0; bottom: 0; width: 380px; z-index: 15;
  background: var(--bg2); border-left: 1px solid var(--line); overflow-y: auto; padding: 18px 20px 28px;
  box-shadow: -20px 0 60px rgba(0,0,0,.45);
}
.panel-head { position: relative; margin-bottom: 14px; }
.panel h2 { font-family: var(--pixel); font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: .5px; }
.panel .close { top: -4px; right: -4px; }
.rect-inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rect-inputs label { font-family: var(--mono); font-size: 10px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rect-inputs input { width: 100%; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); padding: 8px; min-width: 0; outline: none; color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--orange); }
.rect-inputs input { font-family: var(--mono); font-size: 13px; padding: 7px 6px; }
.price { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 4px; padding: 12px 14px; background: var(--bg); border: 1px solid var(--line); }
.price b { font-family: var(--mono); font-size: 26px; color: var(--orange); }
.price span { color: var(--muted); font-size: 13px; }
.price small { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.error { color: var(--red); font-size: 12px; margin: 6px 0; }

.editor { margin: 14px 0; }
.editor-frame {
  display: flex; align-items: center; justify-content: center; height: 230px; padding: 10px;
  background-color: #0e0e12;
  background-image: linear-gradient(45deg, #15151a 25%, transparent 25%, transparent 75%, #15151a 75%), linear-gradient(45deg, #15151a 25%, transparent 25%, transparent 75%, #15151a 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px; border: 1px solid var(--line);
}
#edCanvas { image-rendering: pixelated; image-rendering: crisp-edges; cursor: crosshair; touch-action: none; box-shadow: 0 0 0 1px rgba(255,255,255,.08); }
.tools { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.tools select { padding: 6px 8px; font-size: 12px; }
input[type="color"] { width: 38px; height: 32px; padding: 2px; cursor: pointer; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatches button { width: 20px; height: 20px; border: 1px solid rgba(255,255,255,.12); cursor: pointer; padding: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); }
.seg-btn { background: transparent; border: 0; padding: 6px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: var(--bg3); color: var(--text); box-shadow: inset 0 -2px 0 var(--orange); }
.brush { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 12px; color: var(--muted); }
.field input { font-size: 14px; color: var(--text); }
.fineprint { color: var(--muted); font-size: 11px; line-height: 1.45; margin: 10px 0 0; }
#payBtn { margin-top: 8px; }

/* ---------- Payment ---------- */
.paytabs { display: flex; border: 1px solid var(--line); margin-bottom: 14px; }
.paytabs .seg-btn { flex: 1; padding: 10px; font-size: 13px; }
.pay-amount { text-align: center; font-family: var(--mono); color: var(--muted); }
.pay-amount b { font-size: 28px; color: var(--orange); }
.qr { background: #fff; padding: 0; margin: 12px auto; width: 100%; max-width: 300px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr.empty { background: var(--bg); border: 1px dashed var(--line); color: var(--muted); font-size: 13px; padding: 20px; text-align: center; flex-direction: column; gap: 12px; }
.pay-info { font-size: 12px; color: var(--muted); line-height: 1.45; margin-bottom: 10px; }
.pay-info.warn { color: var(--volt); }
.pay-row { display: flex; gap: 6px; margin-bottom: 10px; }
.pay-row input { flex: 1; font-family: var(--mono); font-size: 11px; color: var(--muted); }
#walletLink { width: 100%; }
.pay-status { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 16px 0 4px; font-size: 13px; }
.spinner { width: 12px; height: 12px; background: var(--orange); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { background: var(--volt); transform: scale(.6); } }
.countdown { text-align: center; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 14px; }
#restartBtn { display: block; margin: 0 auto; }

.done { text-align: center; padding: 30px 6px; }
.done-burst { font-size: 54px; animation: pop .6s ease-out; filter: drop-shadow(0 0 20px rgba(255,225,77,.7)); }
@keyframes pop { from { transform: scale(.2); opacity: 0; } 70% { transform: scale(1.2); } to { transform: scale(1); } }
.done h3 { font-family: var(--pixel); font-size: 16px; text-transform: uppercase; }
.done p { color: var(--muted); font-size: 13px; line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); z-index: 40;
  background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.err { border-color: var(--red); color: #ffd6da; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .tagline { display: none; }
  .brand h1 { font-size: 13px; white-space: normal; line-height: 1.1; max-width: 150px; }
}
@media (max-width: 720px) {
  :root { --top: 96px; }
  .topbar { grid-template-columns: 1fr; grid-template-rows: 44px 48px; gap: 0; padding: 0 10px; }
  .brand { grid-row: 1; grid-column: 1; }
  .brand h1 { max-width: none; font-size: 14px; }
  .actions { grid-row: 2; grid-column: 1; display: flex; gap: 6px; width: 100%; }
  .actions .btn { flex: 1; padding: 8px 6px; font-size: 13px; }
  .actions select.lang { width: 58px; }
  .hint-help { display: none; }
  .panel { width: 100%; top: auto; height: 78vh; border-left: 0; border-top: 1px solid var(--line); }
  .editor-frame { height: 180px; }
}

body.panel-open .hint-help { display: none; }

/* ---------- Bombes ---------- */
.btn.bomb { background: #1d0f10; border-color: #5a1f26; color: #ffd6da; }
.btn.bomb:hover { background: #2a1215; border-color: var(--red); box-shadow: 0 0 22px rgba(255,77,94,.35); }
.select-hint.bomb-mode { background: var(--red); color: #1a0306; }
.select-hint.bomb-mode .btn { color: #1a0306; }
.sizes { display: flex; gap: 4px; flex-wrap: wrap; }
.sizes button { border: 1px solid rgba(0,0,0,.3); background: rgba(255,255,255,.18); color: inherit; font-family: var(--mono); font-size: 11px; padding: 4px 7px; cursor: pointer; }
.sizes button.active { background: #1a0306; color: #fff; border-color: #1a0306; }
.panel .sizes button { border-color: var(--line); background: var(--bg); color: var(--muted); }
.panel .sizes button.active { background: var(--red); color: #1a0306; border-color: var(--red); }
.bomb-ctl { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; padding: 10px 12px; border: 1px solid #5a1f26; background: #160b0c; }
.bomb-ctl small { color: var(--muted); font-size: 11px; line-height: 1.4; }
.bomb-ctl .btn { align-self: flex-start; }
.ed-wrap { position: relative; line-height: 0; }
#edMask { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; image-rendering: pixelated; }
.panel.bomb-mode #edCanvas { opacity: .28; }
.panel.bomb-mode .zone-only { display: none; }
.panel.bomb-mode .rect-inputs { grid-template-columns: repeat(2, 1fr); }
.panel.bomb-mode .price b { color: var(--red); }
.panel.bomb-mode #payBtn, .panel.bomb-mode #drawBtn { background: var(--red); border-color: var(--red); color: #1a0306; }
.select-hint .sizes { flex-wrap: nowrap; }
@media (max-width: 720px) { .select-hint { flex-wrap: wrap; justify-content: center; } }

/* ---------- Pixel War : colonnes latérales ---------- */
.sidebar { position: fixed; top: var(--top); bottom: 0; z-index: 12; display: flex; flex-direction: column; background: var(--bg2); border-color: var(--line); }
.sidebar.right { right: 0; width: var(--right); border-left: 1px solid var(--line); }
.side-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.side-head h2 { margin: 0; font-family: var(--pixel); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; }
.side-head small { color: var(--muted); font-size: 11px; }

.chat-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 13px; line-height: 1.4; word-break: break-word; position: relative; }
.msg .n { font-weight: 700; margin-right: 6px; }
.msg .x { color: var(--orange); font-family: var(--mono); font-size: 11px; margin-right: 6px; text-decoration: none; }
.msg .tm { color: var(--muted); font-size: 10px; font-family: var(--mono); }
.msg .del { position: absolute; right: 0; top: 0; background: none; border: 0; color: var(--red); cursor: pointer; }
.chat-form { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.chat-id { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chat-form input, .chat-form textarea { font-size: 13px; resize: none; color: var(--text); }
.chat-actions { display: flex; justify-content: flex-end; gap: 6px; }


.btn.xshare { background: #000; color: #fff; border-color: #000; margin: 0 6px 8px 0; }
body.light .btn.xshare { background: #111; }
.hud .tab { display: none; width: auto; padding: 0 10px; font-size: 12px; }

body.panel-open .sidebar.right { visibility: hidden; }

@media (max-width: 1100px) {
  :root { --left: 0px; --right: 0px; }
  .sidebar { display: none; width: min(340px, 88vw) !important; box-shadow: 0 0 40px rgba(0,0,0,.45); }
  .sidebar.open { display: flex; }
  .hud .tab { display: inline-block; }
  body.panel-open .sidebar.right { visibility: visible; }
}
.side-close { display: none; float: right; background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
@media (max-width: 1100px) { .side-close { display: block; } }
.chat-form textarea { font-family: var(--sans); }

/* ---------- Achat : tailles rapides, URL d'image, panneau mobile ---------- */
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0 2px; }
.presets button { border: 1px solid var(--line); background: var(--bg); color: var(--muted); padding: 7px 4px; cursor: pointer; font-family: var(--mono); font-size: 10px; line-height: 1.3; }
.presets button b { display: block; color: var(--text); font-size: 12px; }
.presets button.active { border-color: var(--orange); box-shadow: inset 0 -2px 0 var(--orange); }
.img-url { display: flex; gap: 6px; flex: 1 1 100%; }
.img-url input { flex: 1; font-size: 12px; padding: 6px 8px; }
.head-price { font-family: var(--mono); font-size: 12px; color: var(--orange); text-transform: none; margin-left: 6px; }
.grip { display: none; }
#view { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
@media (pointer: coarse) {
  .hud button { width: 42px; height: 42px; font-size: 20px; }
  .hud #coords { display: none; }
}
@media (max-width: 720px) {
  .panel { height: 58vh; padding-top: 10px; transition: height .2s ease; }
  .panel.collapsed { height: 64px; overflow: hidden; }
  .panel .grip { display: block; width: 100%; height: 18px; margin: -6px 0 4px; background: none; border: 0; cursor: pointer; position: relative; }
  .panel .grip::before { content: ""; position: absolute; left: 50%; top: 6px; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: var(--line); }
  .select-hint { display: none !important; }
  .actions .zap { display: none; }
  .presets button { padding: 9px 4px; }
}
body.light .swatches button { border-color: rgba(0,0,0,.25); }

/* ---------- Mobile : 2 temps bien séparés ----------
   1) placer : la toile est libre, une barre compacte en bas (taille, prix, « Dessiner »)
   2) dessiner : l'éditeur recouvre la toile ; « Déplacer la zone » ramène à l'étape 1 */
.place-only, .draw-only { display: none; }
@media (max-width: 720px) {
  .panel { transition: none; }
  .panel:not(.collapsed) { top: var(--top); height: auto; bottom: 0; z-index: 30; }
  .panel.collapsed { height: auto; max-height: 52vh; overflow-y: auto; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .panel.collapsed .place-only { display: block; }
  .panel:not(.collapsed) .draw-only { display: inline-flex; margin-bottom: 10px; }
  .panel.collapsed #stepEdit > :not(.place-only):not(#sizePresets):not(#bombCtl):not(#rectError) { display: none !important; }
  .panel.collapsed #bombExplain, .panel.collapsed #rerollBtn { display: none; }
  .panel.collapsed .bomb-ctl { margin: 6px 0; padding: 8px; }
  .panel.collapsed #drawBtn { width: 100%; margin-top: 10px; }
  .place-hint { margin: 0 0 6px; font-size: 12px; color: var(--muted); line-height: 1.35; }
  body.panel-open:not(.placing) .hud { visibility: hidden; }
}

[hidden] { display: none !important; }

/* ---------- Prix de lancement ---------- */
.promo { justify-self: center; display: flex; align-items: center; gap: 10px; padding: 6px 12px; border: 1px solid var(--orange);
  background: linear-gradient(135deg, rgba(247,147,26,.2), rgba(255,225,77,.08)); font-size: 13px; white-space: nowrap; }
.promo b { color: var(--orange); font-family: var(--mono); }
.promo-label { font-weight: 700; }
.promo-ends { color: var(--muted); font-size: 12px; }
.promo-left { font-family: var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.promo-pct { display: none; }
.price-old { color: var(--muted); font-size: 14px; margin-right: 4px; }
@media (max-width: 1180px) { .promo-label { display: none; } }
@media (max-width: 720px) {
  .promo { grid-row: 1; grid-column: 1; justify-self: end; padding: 3px 7px; gap: 6px; font-size: 11px; }
  .promo #promoDeal { display: none; }
  .promo-pct { display: inline; }
  .promo-ends > span:first-child { display: none; }
  .promo-ends { font-size: 11px; }
}
@media (max-width: 400px) { .brand h1 { font-size: 12px; } .bolt { width: 18px; height: 23px; } .brand { gap: 8px; } .promo { font-size: 10.5px; } }
