:root {
  color-scheme: dark;
  --bg: #080d12;
  --panel: #111a23;
  --panel-2: #17232e;
  --line: #2b3b47;
  --text: #eef4f7;
  --muted: #8fa2af;
  --gold: #d4a84f;
  --gold-2: #f2cf76;
  --green: #55d88a;
  --red: #ff6b68;
  --blue: #62b5ff;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px; padding: 8px 14px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(8, 13, 18, .94); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px);
}
.topbar h1 { margin: 0; font: 700 17px/1.1 Georgia, serif; letter-spacing: .02em; }
.eyebrow { color: var(--gold); font-size: 9px; letter-spacing: .22em; font-weight: 800; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 22px; }

#app { max-width: 900px; margin: 0 auto; padding: 10px 10px 24px; }
.boot-card { min-height: 65vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bottom-nav {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  height: calc(66px + env(safe-area-inset-bottom)); padding: 5px 5px env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
  background: rgba(9, 14, 19, .97); border-top: 1px solid var(--line); backdrop-filter: blur(16px);
}
.bottom-nav button { border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 700; }
.bottom-nav span { display: block; font-size: 20px; line-height: 25px; }
.bottom-nav button.active { color: var(--gold-2); background: rgba(212, 168, 79, .12); }

#offline-progress {
  position: fixed; z-index: 60; left: 10px; right: 10px; top: calc(72px + env(safe-area-inset-top));
  padding: 12px; border: 1px solid #7c622f; border-radius: 14px; background: #191811;
  box-shadow: 0 14px 40px #000a; font-size: 12px;
}
#offline-progress strong, #offline-progress span { display: block; }
#offline-progress span { color: var(--muted); margin-top: 3px; }
#offline-progress progress { width: 100%; height: 7px; margin-top: 9px; accent-color: var(--gold); }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 2px 9px; }
.section-title h2 { margin: 0; font: 700 18px Georgia, serif; }
.status-pill { padding: 5px 9px; border-radius: 999px; background: #22303a; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.status-pill.ready { color: var(--green); background: #143225; }
.status-pill.pending { color: var(--gold-2); background: #332918; }

.panel { margin-bottom: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.control-grid.three { grid-template-columns: repeat(3, 1fr); }
label.control { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
select, input[type="text"], input[type="number"], textarea {
  width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 10px;
  background: #0c141b; color: var(--text); padding: 8px 10px; outline: none;
}
textarea { min-height: 82px; resize: vertical; }
select:focus, input:focus, textarea:focus { border-color: var(--gold); }

.item-strip { display: flex; gap: 7px; overflow-x: auto; padding: 2px 1px 8px; scroll-snap-type: x proximity; }
.item-card { flex: 0 0 78px; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: #0d151c; text-align: center; scroll-snap-align: start; }
.item-card.active { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.item-card.ready::after { content: "✓"; position: absolute; margin: -4px 0 0 -13px; color: var(--green); font-weight: 900; }
.item-card img { width: 64px; height: 64px; object-fit: contain; display: block; }
.item-card small { display: block; height: 26px; overflow: hidden; color: #cbd6dc; font-size: 9px; line-height: 13px; }

.stage-shell { position: relative; overflow: hidden; border: 1px solid #3a4b58; border-radius: 16px; background: radial-gradient(circle at 50% 42%, #26343f, #111820 63%, #090d11); touch-action: none; }
.stage-shell::before { content: ""; display: block; padding-top: 150%; }
.stage-shell canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage-hint { position: absolute; left: 8px; bottom: 8px; padding: 5px 8px; border-radius: 8px; background: #000a; color: #b6c3cb; font-size: 9px; pointer-events: none; }

.tool-row, .button-row { display: flex; gap: 7px; overflow-x: auto; padding-top: 8px; }
.tool-row button, .button, .button-row button {
  min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--panel-2); white-space: nowrap; font-size: 11px; font-weight: 800;
}
.tool-row button.active { border-color: var(--gold); color: var(--gold-2); }
.button.primary { background: #8c692d; border-color: #c69b4b; color: #fff7df; }
.button.success { background: #1d5638; border-color: #3b9867; }
.button.danger { background: #512323; border-color: #a64a48; }

.sliders { display: grid; gap: 7px; }
.range-row { display: grid; grid-template-columns: 72px 1fr 54px; align-items: center; gap: 6px; font-size: 10px; color: var(--muted); }
.range-row output { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--gold); }

.catalog-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.catalog-list .item-card { width: auto; min-width: 0; flex-basis: auto; position: relative; }
.catalog-list .item-card img { width: 100%; aspect-ratio: 1; height: auto; }

.outfit-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot { min-height: 56px; border: 1px dashed #455763; border-radius: 11px; padding: 5px; text-align: center; color: var(--muted); font-size: 9px; }
.slot img { display: block; width: 42px; height: 42px; margin: auto; object-fit: contain; }

.editor-form { display: grid; gap: 8px; }
.editor-form .group { padding: 9px; border-radius: 12px; background: #0d151c; }
.editor-form h3 { margin: 0 0 8px; font-size: 12px; color: var(--gold-2); }

.motion-preview { position: relative; height: 360px; overflow: hidden; border-radius: 15px; background: center/cover url('/studio-assets/arena-background.png'), #111; }
.motion-preview canvas { width: 100%; height: 100%; }
.arena-phone { position: relative; width: min(100%, 390px); aspect-ratio: 393/852; margin: auto; overflow: hidden; border: 2px solid #586875; border-radius: 28px; background: center/cover url('/studio-assets/arena-background.png'), #111; }
.arena-element { position: absolute; display: grid; place-items: center; border: 1px dashed transparent; color: white; touch-action: none; text-align: center; font-size: 10px; }
.arena-element.selected { border-color: var(--gold); background: #d4a84f18; }
.arena-element img { width: 100%; height: 100%; object-fit: contain; }

.sheet-backdrop { position: fixed; z-index: 70; inset: 0; background: #000a; display: flex; align-items: flex-end; }
.sheet { width: 100%; max-height: 84dvh; overflow: auto; padding: 16px 14px calc(18px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; background: #111a23; border-top: 1px solid #40515d; }
.sheet h2 { margin: 0 0 12px; font: 700 20px Georgia, serif; }
.sheet button { width: 100%; margin-top: 7px; }
.notice { padding: 10px; border-radius: 11px; background: #1a2630; color: var(--muted); font-size: 11px; line-height: 1.45; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: 88%; padding: 10px 14px; border-radius: 12px; background: #edf4f7; color: #101820; box-shadow: 0 10px 30px #0008; font-size: 12px; font-weight: 700; }

@media (min-width: 700px) {
  #app { padding: 16px 18px 30px; }
  .fit-layout { display: grid; grid-template-columns: minmax(320px, 1fr) 350px; gap: 12px; align-items: start; }
  .stage-shell::before { padding-top: 150%; }
  .catalog-list { grid-template-columns: repeat(5, 1fr); }
  .bottom-nav { left: 50%; width: 640px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; }
}
