@font-face { font-family: UnderworldDisplay; src: url('/fonts/heading.ttf') format('truetype'); font-weight: 100 900; font-display: swap; }
:root {
  --bg: #0e0f0c; --s1: #16171a; --s2: #1d1e22; --line: #2c2d31; --text: #ecebe4; --muted: #a8a89f;
  --lime: #c3ff5c; --lav: #b9a7ff; --coral: #ff6b5c; --ink: #0e0f0c;
  --r: 10px; --tap: 44px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
.defs { position: absolute; }
svg { width: 20px; height: 20px; flex: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  height: 100dvh; display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: 'top' 'stage' 'panel' 'bar' 'credit';
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
}
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; min-height: var(--tap); }
.mark { width: 26px; height: 26px; image-rendering: pixelated; }
.word { font: 900 25px/1 UnderworldDisplay, Impact, sans-serif; letter-spacing: .02em; text-transform: uppercase; }
.pill { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--s1); font-weight: 600; font-size: 14px; }
.pill.holder { border-color: var(--lime); color: var(--lime); }

.stage { grid-area: stage; position: relative; padding: 0 12px; }
.canvas-wrap { position: relative; height: min(46dvh, calc(100vw - 24px)); display: flex; align-items: center; justify-content: center; }
#cv { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 6px; background: #0b0b0c; box-shadow: 0 0 0 1px var(--line); touch-action: none; cursor: grab; image-rendering: pixelated; }
#cv.dragging { cursor: grabbing; }
.loading { position: absolute; inset: auto 0 10px; margin: auto; width: max-content; padding: 6px 12px; border-radius: 999px; background: rgba(14, 15, 12, .9); color: var(--lime); font-size: 13px; font-weight: 600; }
.loading::after { content: ''; display: inline-block; width: 8px; height: 8px; margin-left: 8px; background: var(--lime); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }
.seltools { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: rgba(14, 15, 12, .92); border: 1px solid var(--line); z-index: 5; max-width: calc(100% - 16px); }
.seltools button { width: var(--tap); height: var(--tap); display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: var(--s1); }
.seltools button[aria-pressed='true'] { border-color: var(--lime); color: var(--lime); }
.seltools button[data-act='delete'] { color: var(--coral); }

.panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; margin-top: 8px; border-top: 1px solid var(--line); background: var(--s1); }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid var(--line); flex: none; }
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; padding: 4px 2px; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; border-bottom: 3px solid transparent; }
.tabs button[aria-selected='true'] { color: var(--lime); border-bottom-color: var(--lime); }
.pages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.page { padding: 12px; }
.sub { margin: 16px 0 8px; font: 800 13px/1.2 system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.hint.top { margin: 0 0 10px; }

.tpl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tpl { display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: var(--r); border: 1px solid var(--line); background: var(--s2); text-align: left; min-height: var(--tap); }
.tpl canvas { width: 100%; aspect-ratio: 1; border-radius: 6px; background: #0b0b0c; image-rendering: pixelated; }
.tpl b { font-size: 13px; line-height: 1.2; }
.tpl small { color: var(--muted); font-size: 12px; line-height: 1.25; }
.tpl[aria-pressed='true'] { border-color: var(--lime); box-shadow: inset 0 0 0 1px var(--lime); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 12px 0 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--s2); font-size: 13px; font-weight: 600; }
.sw i { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); }
.sw[aria-checked='true'] { border-color: var(--lime); color: var(--lime); }

.slots { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.slot { display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; align-items: center; padding: 8px; border-radius: var(--r); border: 1px solid var(--line); background: var(--s2); }
.slot.sel { border-color: var(--lime); }
.slot canvas { width: 56px; height: 56px; border-radius: 6px; background: #0b0b0c; image-rendering: pixelated; }
.slot .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-width: 0; }
.slot input[type='number'] { width: 92px; min-height: var(--tap); padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.slot select { min-height: var(--tap); max-width: 100%; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; }
.slot .meta { grid-column: 2 / 4; color: var(--muted); font-size: 12px; min-height: 16px; }
.icon { width: var(--tap); height: var(--tap); display: inline-grid; place-items: center; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.icon.danger { color: var(--coral); }
.own { display: flex; flex-wrap: wrap; gap: 6px; }
.own button { width: 56px; height: 56px; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: #0b0b0c; }
.own canvas { width: 100%; height: 100%; image-rendering: pixelated; border-radius: 7px; }

.texts { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.field input { min-height: var(--tap); padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }

.stk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.stk { position: relative; display: grid; place-items: center; aspect-ratio: 1; min-height: 56px; border-radius: var(--r); border: 1px solid var(--line); background: var(--s2); padding: 8px; }
.stk canvas { width: 100%; height: 100%; image-rendering: pixelated; object-fit: contain; }
.stk.locked { opacity: .55; }
.stk.locked::after { content: ''; position: absolute; right: 4px; top: 4px; width: 16px; height: 16px; background: var(--lime); -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="5" y="10.5" width="14" height="10" rx="2.5"/><path d="M8 10.5V8a4 4 0 0 1 8 0v2.5" fill="none" stroke="black" stroke-width="2.2"/></svg>') center/contain no-repeat; mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="5" y="10.5" width="14" height="10" rx="2.5"/><path d="M8 10.5V8a4 4 0 0 1 8 0v2.5" fill="none" stroke="black" stroke-width="2.2"/></svg>') center/contain no-repeat; }

.shelf { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.shelf .empty { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 13px; }
.mine, .review { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mine li, .review li { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; padding: 8px; border-radius: var(--r); border: 1px solid var(--line); background: var(--s2); font-size: 13px; }
.mine canvas, .review canvas { width: 64px; height: 64px; border-radius: 6px; background: #0b0b0c; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--line); }
.badge.approved { background: var(--lime); color: var(--ink); }
.badge.pending { background: var(--lav); color: var(--ink); }
.badge.rejected, .badge.unpublished { background: #3a2422; color: var(--coral); }
.review .acts { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.review .acts button { min-height: var(--tap); padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-size: 14px; }
.review .acts .ok { border-color: var(--lime); color: var(--lime); }
.review .acts .no { color: var(--coral); }
.status { min-height: 18px; margin: 8px 0 0; font-size: 13px; color: var(--lime); }

.primary, .ghost { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 16px; border-radius: 10px; font-weight: 700; font-size: 15px; }
.primary { border: 0; background: var(--lime); color: var(--ink); }
.primary:disabled { opacity: .5; }
.ghost { border: 1px solid var(--line); background: var(--s2); }
.wide { width: 100%; margin-top: 10px; }
.bar { grid-area: bar; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--bg); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; min-width: 0; }
.seg button { min-height: var(--tap); padding: 0 10px; border: 0; background: var(--s1); font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked='true'] { background: var(--s2); color: var(--lime); }
.exports { display: flex; gap: 6px; flex: none; }
.credit { grid-area: credit; margin: 0; padding: 4px 12px calc(6px + var(--safe-b)); display: flex; gap: 8px; justify-content: center; font-size: 12px; color: var(--muted); background: var(--bg); }
.credit a { color: var(--muted); text-decoration: none; min-height: 24px; display: inline-flex; align-items: center; }
.credit a:hover { color: var(--lime); }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(12px); padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--ink); font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 30; }
.toast.on { opacity: 1; transform: translateX(-50%); }

.sheet { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--s1); color: var(--text); }
.sheet::backdrop { background: rgba(0, 0, 0, .7); }
.sheet .x { position: absolute; right: 8px; top: 8px; width: var(--tap); height: var(--tap); display: grid; place-items: center; border: 0; background: none; border-radius: 8px; }
.sheet-head { text-align: center; }
.sheet-seal { width: 40px; height: 40px; }
.sheet h2 { margin: 6px 0 4px; font: 900 26px/1.1 UnderworldDisplay, Impact, sans-serif; text-transform: uppercase; }
.sheet-head p { margin: 0; color: var(--muted); font-size: 14px; }
.perks { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.perks li { display: flex; gap: 8px; align-items: center; }
.perks svg { color: var(--lime); }
.wallets { display: grid; gap: 8px; }
.wbtn { display: grid; grid-template-columns: 36px 1fr auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center; min-height: 56px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--s2); text-align: left; }
.wico { grid-row: 1 / 3; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--bg); }
.wname { font-weight: 700; }
.wsub { grid-column: 2; color: var(--muted); font-size: 12px; }
.wbtn .chev { grid-row: 1 / 3; grid-column: 3; color: var(--muted); }
.who { text-align: center; color: var(--muted); font-size: 14px; }

/* phone landscape and short screens: canvas left, editor right */
@media (orientation: landscape) and (max-height: 560px) {
  .app { grid-template-columns: minmax(0, 1fr) minmax(300px, 46%); grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: 'top top' 'stage panel' 'stage bar' 'credit credit'; }
  .canvas-wrap { height: calc(100dvh - var(--safe-t) - var(--safe-b) - 150px); }
  .panel { margin-top: 0; border-left: 1px solid var(--line); }
  .top { padding-top: 2px; padding-bottom: 2px; }
  .tabs button { min-height: 46px; }
  .bar { border-left: 1px solid var(--line); }
}
/* desktop */
@media (min-width: 900px) and (min-height: 561px) {
  .app { grid-template-columns: minmax(0, 1fr) 420px; grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: 'top top' 'stage panel' 'stage bar' 'stage credit'; }
  .stage { padding: 12px 24px 24px; display: flex; flex-direction: column; }
  .canvas-wrap { flex: 1; height: auto; min-height: 0; }
  .panel { margin-top: 0; border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; margin-right: 16px; }
  .bar { margin-right: 16px; border: 1px solid var(--line); border-top: 0; background: var(--s1); }
  .credit { margin-right: 16px; }
  .tpl-grid, .shelf { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .loading::after { animation: none; }
  .toast { transition: none; }
}
