:root {
  color-scheme: dark;
  --bg: #080a0d;
  --panel: #111720;
  --panel-strong: #171f2a;
  --panel-soft: #0d1219;
  --text: #eef3f8;
  --muted: #9aa8b7;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.24);
  --accent: #e2b84a;
  --accent-strong: #ffd66b;
  --green: #6fd0a9;
  --danger: #ef6f74;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  --chart-w: 1800px;
  --chart-h: 1100px;
  --chart-scale: 1;
  --control-scale: 1;
  --chart-display-w: 1800px;
  --chart-display-h: 1100px;
  --floor-bottom: 42px;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: 58px 1fr;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 26%),
    radial-gradient(circle at 76% 0%, rgba(226, 184, 74, 0.08), transparent 30%),
    var(--bg);
}

.topbar {
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 10, 13, 0.9);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  color: var(--text);
  font-weight: 720;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid rgba(226, 184, 74, 0.55);
  border-radius: 8px;
  background: rgba(226, 184, 74, 0.12);
  color: var(--accent-strong);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.text-button {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.075);
}

.icon-button:active,
.text-button:active {
  transform: translateY(1px);
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.36;
}

.icon-button.primary {
  border-color: rgba(226, 184, 74, 0.45);
  background: rgba(226, 184, 74, 0.13);
  color: var(--accent-strong);
}

.icon-button.accent {
  border-color: rgba(111, 208, 169, 0.45);
  background: rgba(111, 208, 169, 0.13);
  color: var(--green);
}

.icon-button.small {
  width: 34px;
  min-width: 34px;
  height: 34px;
}

.text-button {
  min-width: 96px;
  padding: 0 18px;
}

.text-button.primary {
  border-color: rgba(226, 184, 74, 0.55);
  background: rgba(226, 184, 74, 0.18);
  color: var(--accent-strong);
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.chart-viewport {
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  cursor: grab;
  scrollbar-color: #324252 #0b0f15;
  scrollbar-width: thin;
}

.chart-viewport.dragging {
  cursor: grabbing;
}

.chart-stage {
  position: relative;
  width: var(--chart-display-w);
  height: var(--chart-display-h);
  margin: 18px auto;
  flex: 0 0 auto;
}

.chart {
  position: relative;
  width: var(--chart-w);
  height: var(--chart-h);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 42%),
    linear-gradient(180deg, #141820 0%, #10151d 66%, #0a0d11 100%);
  box-shadow: var(--shadow);
  transform: scale(var(--chart-scale));
  transform-origin: top left;
}

.chart::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: var(--floor-bottom);
  left: 0;
  height: 5px;
  background: linear-gradient(90deg, #88713c, #d5ae48 45%, #7f6a3a);
  z-index: 5;
}

.guide-layer,
.items-layer {
  position: absolute;
  inset: 0;
}

.guide-band,
.guide-line,
.guide-label {
  position: absolute;
  pointer-events: none;
}

.guide-band {
  right: 0;
  left: 0;
  background: rgba(255, 255, 255, 0.018);
}

.guide-band:nth-child(odd) {
  background: rgba(226, 184, 74, 0.028);
}

.guide-line {
  right: 0;
  left: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.18);
}

.guide-label {
  right: 18px;
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(8, 10, 13, 0.62);
  color: #dce5ef;
  font-size: 14px;
  line-height: 1;
  transform: translateY(-50%);
  white-space: nowrap;
}

.animal-item {
  position: absolute;
  transform-origin: 50% 100%;
  user-select: none;
  touch-action: none;
}

.animal-shell {
  position: relative;
  display: grid;
  place-items: end center;
  width: 100%;
  height: 100%;
}

.animal-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.animal-item.selected .animal-shell {
  outline: 1px solid rgba(226, 184, 74, 0.82);
  outline-offset: 6px;
}

.animal-controls {
  position: absolute;
  z-index: 20;
  top: -20px;
  right: -20px;
  display: none;
  grid-auto-flow: column;
  gap: 8px;
  transform: scale(var(--control-scale));
  transform-origin: top right;
}

.animal-item.controls-below .animal-controls {
  top: auto;
  right: -20px;
  bottom: 18px;
  transform-origin: bottom right;
}

.animal-item.selected .animal-controls {
  display: grid;
}

.handle {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(17, 23, 32, 0.94);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.36);
  cursor: pointer;
}

.handle svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.handle-move {
  color: #dce5ef;
}

.handle-scale {
  color: var(--accent-strong);
  cursor: ns-resize;
}

.handle-delete {
  color: var(--danger);
}

.animals-panel {
  position: fixed;
  z-index: 30;
  top: 58px;
  bottom: 0;
  left: 0;
  width: min(360px, 92vw);
  padding: 16px;
  border-right: 1px solid var(--line);
  background: rgba(13, 18, 25, 0.96);
  box-shadow: var(--shadow);
  transform: translateX(-104%);
  transition: transform 220ms ease;
}

.animals-panel.open {
  transform: translateX(0);
}

.panel-head,
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2,
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.animal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  height: calc(100% - 48px);
  padding-top: 16px;
  overflow: auto;
}

.animal-card {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 154px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.animal-card.active {
  border-color: rgba(226, 184, 74, 0.76);
  background: rgba(226, 184, 74, 0.12);
}

.thumb-box {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  background: #0a0e13;
}

.thumb-box img {
  width: 92%;
  height: 92%;
  object-fit: contain;
}

.animal-card span {
  overflow: hidden;
  color: #dce5ef;
  font-size: 13px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 5, 8, 0.66);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.field,
.switch-row {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}

.settings-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.settings-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 160px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a0e14;
}

.segment-button {
  height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.segment-button:last-child {
  border-right: 0;
}

.segment-button.active {
  background: rgba(226, 184, 74, 0.18);
  color: var(--accent-strong);
}

.field input,
.field select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a0e14;
  color: var(--text);
  padding: 0 12px;
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  color: var(--text);
  font-size: 14px;
}

.switch-row input {
  width: 42px;
  height: 22px;
  accent-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 10px;
  }

  .brand span:last-child {
    display: none;
  }

  .toolbar {
    gap: 5px;
  }

  .icon-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
  }

  .chart-stage {
    margin: 12px 14px;
  }

  .animal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
