:root {
  color-scheme: dark;
  --rsdw-bg: #0c0c0f;
  --rsdw-surface: rgba(20, 20, 24, 0.78);
  --rsdw-surface-2: rgba(30, 30, 35, 0.82);
  --rsdw-scroll-track: #15151a;
  --rsdw-scroll-thumb: #4a4133;
  --rsdw-scroll-thumb-hover: #6a5b46;
  --rsdw-text: #f5f1e8;
  --rsdw-muted: #cfc7b8;
  --rsdw-accent: #e0c896;
  --rsdw-accent-soft: rgba(224, 200, 150, 0.22);
  --rsdw-border: rgba(180, 164, 140, 0.55);
  --rsdw-border-strong: rgba(180, 164, 140, 0.9);
  --rsdw-danger: #ffb199;
  --stage-bg: rgba(8, 10, 12, 0.74);
}

@font-face {
  font-family: "SofiaSansCustom";
  src: url("https://fonts.gstatic.com/s/sofiasans/v20/Yq6T-LCVXSLy9uPBwlATrORKkzApcb8.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  min-width: 0;
  padding-top: 76px;
  background:
    linear-gradient(rgba(12, 12, 15, 0.62), rgba(12, 12, 15, 0.92)),
    url("./shared/assets/bg.jpg") center/cover no-repeat fixed,
    var(--rsdw-bg);
  color: var(--rsdw-text);
  font-family: "SofiaSansCustom", "Sofia Sans", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  scrollbar-color: var(--rsdw-scroll-thumb) var(--rsdw-scroll-track);
  scrollbar-width: thin;
}

body.is-dragging-asset {
  cursor: grabbing;
}

body.is-dragging-asset,
body.is-dragging-asset * {
  user-select: none;
}

::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

::-webkit-scrollbar-track {
  background: var(--rsdw-scroll-track);
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #344a65 0%, var(--rsdw-scroll-thumb) 100%);
  border: 2px solid var(--rsdw-scroll-track);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--rsdw-scroll-thumb-hover);
}

button,
input {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--rsdw-border);
  border-radius: 8px;
  background: rgba(18, 18, 22, 0.92);
  color: var(--rsdw-text);
  padding: 0 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

button:hover:not(:disabled),
button.is-active {
  border-color: var(--rsdw-border-strong);
  background: rgba(255, 255, 255, 0.08);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input {
  min-height: 36px;
  width: 100%;
  border: 1px solid var(--rsdw-border);
  border-radius: 8px;
  background: rgba(18, 18, 22, 0.94);
  color: var(--rsdw-text);
  padding: 0 10px;
  outline: none;
}

input:focus,
button:focus-visible {
  border-color: var(--rsdw-border-strong);
  box-shadow: 0 0 0 3px var(--rsdw-accent-soft);
  outline: 0;
}

.rsdw-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.rsdw-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 76px;
  padding: 0 1rem;
  border-bottom: 1px solid var(--rsdw-border);
  background: rgba(12, 12, 15, 0.88);
  backdrop-filter: blur(8px);
}

.rsdw-brand {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.rsdw-brand__logo,
.rsdw-iconbtn {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--rsdw-border);
  border-radius: 10px;
  background: rgba(20, 20, 24, 0.9);
}

.rsdw-brand__logo img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.rsdw-brand__title {
  overflow: hidden;
  font-size: 1.28rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-nav {
  display: flex;
  flex: 0 0 auto;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 1px solid var(--rsdw-border);
  border-radius: 10px;
  background: rgba(20, 20, 24, 0.88);
}

.mode-nav a {
  min-width: 78px;
  padding: 0.46rem 0.7rem;
  border-radius: 8px;
  color: var(--rsdw-muted);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.mode-nav a:hover,
.mode-nav a.is-active {
  color: var(--rsdw-text);
  background: rgba(255, 255, 255, 0.08);
}

.rsdw-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.rsdw-iconbtn {
  color: inherit;
  text-decoration: none;
}

.rsdw-iconbtn:hover {
  border-color: var(--rsdw-border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.rsdw-iconbtn img {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.rsdw-menu {
  position: relative;
}

.rsdw-menu__panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 1001;
  min-width: 180px;
  border: 1px solid var(--rsdw-border);
  border-radius: 10px;
  background: rgba(18, 18, 22, 0.98);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.rsdw-menu__panel[hidden] {
  display: none;
}

.rsdw-menu__panel a {
  display: block;
  padding: 0.62rem 0.8rem;
  color: var(--rsdw-text);
  font-size: 0.9rem;
  text-decoration: none;
}

.rsdw-menu__panel a:hover {
  background: rgba(255, 255, 255, 0.08);
}

.builder-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(460px, 1fr) minmax(285px, 340px);
  gap: 12px;
  width: 100%;
  height: calc(100vh - 76px);
  min-height: 640px;
  padding: 12px;
  overflow: hidden;
}

.asset-panel,
.workspace,
.inspector {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--rsdw-border);
  border-radius: 10px;
  background: var(--rsdw-surface);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.38);
  overflow: hidden;
}

.asset-panel,
.inspector {
  display: flex;
  flex-direction: column;
}

.asset-panel {
  user-select: none;
}

.panel-header {
  flex: 0 0 auto;
  padding: 0.9rem;
  border-bottom: 1px solid var(--rsdw-border);
  background: rgba(12, 12, 15, 0.5);
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.2;
}

.panel-header p {
  margin: 0.25rem 0 0;
  color: var(--rsdw-muted);
  font-size: 0.85rem;
}

.search-row,
.folder-row {
  flex: 0 0 auto;
}

.search-row {
  padding: 0.8rem 0.8rem 0.5rem;
}

.folder-row {
  padding: 0 0.8rem 0.15rem;
}

.folder-row select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--rsdw-border);
  border-radius: 8px;
  background: rgba(8, 8, 11, 0.78);
  color: var(--rsdw-text);
  font: inherit;
  font-size: 0.86rem;
}

.segmented {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.75rem 0.8rem 0.65rem;
}

.segmented button {
  min-width: 0;
  padding: 0 0.4rem;
  font-size: 0.84rem;
  font-weight: 800;
}

.favorites-panel {
  flex: 0 0 auto;
  padding: 0 0.8rem 0.65rem;
}

.favorite-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.4rem;
  min-height: 50px;
  max-height: 108px;
  overflow-y: auto;
  padding-bottom: 0.1rem;
  scrollbar-width: thin;
}

.favorite-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 48px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  padding: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

.favorite-tile:hover,
.favorite-tile.is-active {
  border-color: var(--rsdw-border);
  background: rgba(255, 255, 255, 0.08);
}

.favorite-tile .asset-thumb {
  width: 40px;
  height: 40px;
  border-radius: 7px;
}

.favorite-tile .asset-thumb img {
  width: 36px;
  height: 36px;
}

.favorite-empty {
  display: inline-flex;
  align-items: center;
  grid-column: 1 / -1;
  height: 48px;
  padding: 0 0.35rem;
  color: var(--rsdw-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.asset-list,
.placed-list {
  min-height: 0;
  overflow: auto;
}

.asset-list {
  display: grid;
  grid-auto-rows: minmax(68px, auto);
  gap: 0.45rem;
  padding: 0 0.55rem 0.8rem;
}

.asset-row,
.placed-row {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.asset-row {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 28px auto;
  gap: 0.65rem;
  align-items: center;
  min-height: 68px;
  padding: 0.45rem 0.55rem;
  touch-action: pan-y;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
}

.asset-row:hover,
.asset-row.is-active,
.asset-row:focus-visible,
.placed-row:hover,
.placed-row.is-active {
  border-color: var(--rsdw-border);
  background: rgba(255, 255, 255, 0.07);
}

.asset-row:active {
  cursor: grabbing;
}

.asset-favorite {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(236, 215, 158, 0.66);
  font-size: 1rem;
  line-height: 1;
  opacity: 0.34;
  padding: 0;
}

.asset-row:hover .asset-favorite,
.asset-favorite:focus-visible,
.asset-favorite.is-favorite {
  opacity: 1;
}

.asset-favorite:hover,
.asset-favorite.is-favorite {
  border-color: rgba(236, 215, 158, 0.35);
  background: rgba(236, 215, 158, 0.1);
  color: var(--rsdw-accent);
}

.asset-context-menu {
  position: fixed;
  z-index: 20;
  min-width: 138px;
  overflow: hidden;
  border: 1px solid var(--rsdw-border);
  border-radius: 8px;
  background: rgba(18, 18, 22, 0.98);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.44);
}

.asset-context-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--rsdw-text);
  padding: 0.62rem 0.8rem;
  text-align: left;
}

.asset-context-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.asset-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(180, 164, 140, 0.38);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 38%, rgba(224, 200, 150, 0.14), transparent 62%),
    rgba(10, 10, 12, 0.48);
  color: var(--rsdw-accent);
  font-size: 0.72rem;
  font-weight: 800;
  overflow: hidden;
}

.asset-thumb img {
  display: block;
  width: 46px;
  height: 46px;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.asset-thumb.is-generated {
  letter-spacing: 0.04em;
}

.asset-copy {
  display: grid;
  gap: 0.18rem;
  min-width: 0;
}

.asset-name,
.placed-name {
  overflow: hidden;
  font-weight: 800;
  line-height: 1.22;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-path,
.placed-meta {
  overflow: hidden;
  color: var(--rsdw-muted);
  font-size: 0.78rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-kind {
  align-self: center;
  min-width: 44px;
  border: 1px solid var(--rsdw-border);
  border-radius: 999px;
  color: var(--rsdw-accent);
  padding: 0.13rem 0.38rem;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  padding: 0.6rem;
  border-bottom: 1px solid var(--rsdw-border);
  background: rgba(12, 12, 15, 0.5);
}

.toolbar-group {
  display: flex;
  flex: 0 0 auto;
  gap: 0.35rem;
  min-width: 0;
}

.toolbar-meta {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
  color: var(--rsdw-muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.builder-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(224, 200, 150, 0.12), transparent 38%),
    linear-gradient(180deg, rgba(28, 32, 34, 0.62), rgba(8, 10, 12, 0.88)),
    var(--stage-bg);
  outline: 0 solid transparent;
  transition: outline-color 0.12s ease, outline-width 0.12s ease;
}

.builder-stage.is-drag-target {
  outline: 2px solid rgba(224, 200, 150, 0.34);
  outline-offset: -2px;
}

.builder-stage.is-drop-ready {
  outline-color: var(--rsdw-accent);
}

.selection-marquee {
  position: absolute;
  z-index: 4;
  border: 1px solid rgba(243, 207, 137, 0.95);
  background: rgba(243, 207, 137, 0.16);
  box-shadow: inset 0 0 0 1px rgba(12, 12, 15, 0.42);
  pointer-events: none;
}

.builder-stage canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.stage-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--rsdw-border);
  border-radius: 8px;
  background: rgba(18, 18, 22, 0.92);
  color: var(--rsdw-muted);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.controls-hud {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.26rem;
  width: min(520px, calc(100% - 24px));
  max-height: none;
  padding: 0.45rem;
  overflow: visible;
  border: 1px solid rgba(243, 207, 137, 0.22);
  border-radius: 8px;
  background: rgba(8, 8, 11, 0.72);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}

.controls-hud.is-preview {
  grid-template-columns: 1fr;
  width: min(280px, calc(100% - 24px));
}

.controls-hud[hidden] {
  display: none;
}

.controls-hud.is-collapsed {
  grid-template-columns: 1fr;
  width: auto;
  min-width: 96px;
  max-height: none;
  overflow: hidden;
  padding: 0.48rem 0.7rem;
}

.controls-hud:focus-visible {
  outline: 2px solid var(--rsdw-accent);
  outline-offset: 2px;
}

.orientation-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 4;
  padding: 0.5rem 0.72rem;
  border: 1px solid rgba(243, 207, 137, 0.22);
  border-radius: 8px;
  background: rgba(8, 8, 11, 0.72);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
  color: rgba(245, 239, 224, 0.96);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  cursor: pointer;
  user-select: none;
  backdrop-filter: blur(16px);
}

.orientation-toggle:hover {
  border-color: rgba(243, 207, 137, 0.46);
  color: #fff9ec;
}

.orientation-toggle:focus-visible {
  outline: 2px solid var(--rsdw-accent);
  outline-offset: 2px;
}

.nudge-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.nudge-overlay[hidden] {
  display: none;
}

.nudge-arrow {
  position: absolute;
  width: 38px;
  height: 38px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  filter:
    drop-shadow(0 3px 8px rgba(0, 0, 0, 0.62))
    drop-shadow(0 0 10px rgba(243, 207, 137, 0.28));
  opacity: 0.96;
}

.nudge-mode {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 0.22rem 0.42rem;
  border: 1px solid rgba(243, 207, 137, 0.24);
  border-radius: 8px;
  background: rgba(8, 8, 11, 0.7);
  color: rgba(245, 239, 224, 0.94);
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.hud-collapsed-row {
  color: rgba(245, 239, 224, 0.95);
  font-size: 0.8rem;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
}

.hud-row {
  display: grid;
  grid-template-columns: minmax(74px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 0.48rem;
  min-height: 24px;
  color: rgba(245, 239, 224, 0.92);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
}

.hud-icons {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.18rem;
  min-width: 0;
}

.hud-icon {
  display: block;
  width: auto;
  height: 20px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.hud-plus {
  color: var(--rsdw-muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.hud-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.viewport-notice {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 5;
  max-width: min(420px, calc(100% - 32px));
  padding: 0.58rem 0.9rem;
  border: 1px solid rgba(243, 207, 137, 0.28);
  border-radius: 8px;
  background: rgba(8, 8, 11, 0.78);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
  color: rgba(245, 239, 224, 0.96);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.viewport-notice.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  padding: 0.8rem;
}

.field-grid label {
  display: grid;
  gap: 0.3rem;
  color: var(--rsdw-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.field-grid input {
  color: var(--rsdw-text);
}

.inline-action {
  border: 0;
  background: transparent;
  color: var(--rsdw-accent);
  font: inherit;
  font-weight: 800;
  padding: 0;
  text-decoration: underline;
}

.inline-action:hover {
  color: #fff1c3;
}

.placed-section {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  border-top: 1px solid var(--rsdw-border);
}

.placed-section h2 {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.75rem 0.8rem 0.45rem;
  font-size: 0.92rem;
}

.placed-list {
  display: grid;
  gap: 0.4rem;
  padding: 0 0.55rem 0.8rem;
}

.placed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
  min-height: 52px;
  padding: 0.5rem 0.55rem;
}

.placed-summary {
  min-height: 38px;
  border-color: rgba(243, 207, 137, 0.16);
  color: var(--rsdw-muted);
  font-size: 0.78rem;
  font-weight: 800;
  justify-content: center;
  text-align: center;
}

@media (max-width: 1120px) {
  .builder-shell {
    grid-template-columns: minmax(285px, 340px) minmax(420px, 1fr);
  }

  .inspector {
    position: absolute;
    top: 88px;
    right: 12px;
    bottom: 12px;
    z-index: 4;
    width: min(340px, 38vw);
  }

  .orientation-toggle {
    left: 14px;
    right: auto;
  }
}

@media (max-width: 760px) {
  body {
    padding-top: 126px;
  }

  .rsdw-header {
    height: 126px;
    flex-wrap: wrap;
    align-content: center;
    gap: 0.65rem;
  }

  .mode-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .mode-nav a {
    flex: 1 0 82px;
  }

  .builder-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 360px minmax(420px, 1fr) 310px;
    height: auto;
    min-height: calc(100vh - 126px);
    overflow: visible;
  }

  .asset-panel,
  .workspace,
  .inspector {
    position: static;
    width: auto;
  }

  .orientation-toggle {
    left: auto;
    right: 14px;
  }

  .asset-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
  }

  .asset-row {
    grid-template-columns: 42px minmax(0, 1fr) 28px;
    min-height: 58px;
  }

  .asset-thumb {
    width: 42px;
    height: 42px;
  }

  .asset-thumb img {
    width: 38px;
    height: 38px;
  }

  .asset-kind {
    display: none;
  }

  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .toolbar-group,
  .toolbar-meta {
    flex: 0 0 auto;
  }
}
