:root {
  color-scheme: dark;
  --bg: #0c1015;
  --panel: #121821;
  --panel-2: #161e29;
  --line: #263241;
  --line-strong: #3a4a5c;
  --text: #eef3f8;
  --muted: #9aa8b7;
  --accent: #7ed0ff;
  --accent-2: #a6e3a1;
  --danger: #ffb38a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  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 {
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #0f151d;
  padding: 18px 14px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 4px 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #17202b;
  color: var(--accent);
  font-weight: 800;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.tool-nav {
  display: grid;
  gap: 8px;
}

.tool-nav button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
  background: transparent;
  color: var(--text);
}

.tool-nav button:hover,
.tool-nav button.active {
  border-color: var(--line-strong);
  background: var(--panel);
}

.tool-nav strong {
  display: block;
  font-size: 13px;
}

.tool-nav span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.topbar {
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: #10161f;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
}

.active-tool-name {
  font-size: 17px;
  font-weight: 760;
}

.active-tool-description {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

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

.icon-button,
.primary-button {
  min-width: 40px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 750;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  position: relative;
}

.import-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.primary-button {
  padding: 0 14px;
  background: #173245;
  color: #d9f4ff;
}

.tool-host {
  position: relative;
  min-height: 0;
  padding: 18px;
}

.tool-host.dragging::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  pointer-events: none;
}

.tool-root {
  min-height: 100%;
}

.empty-state {
  position: absolute;
  inset: 18px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: rgba(18, 24, 33, 0.58);
  pointer-events: none;
}

.empty-state.hidden {
  display: none;
}

.empty-state-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
}

.empty-state h2 {
  margin: 0;
  font-size: 20px;
}

.empty-state p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  gap: 16px;
  min-height: calc(100vh - 108px);
}

.editor-pane,
.settings-pane,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor-pane {
  min-width: 0;
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.settings-pane {
  min-width: 0;
  padding: 14px;
  overflow: auto;
}

.pane-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.pane-title h2,
.panel h3 {
  margin: 0;
  font-size: 14px;
}

.pane-title span {
  color: var(--muted);
  font-size: 12px;
}

.canvas-stage {
  position: relative;
  min-height: 360px;
  overflow: auto;
  display: grid;
  place-items: center;
  background-color: #090d12;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.045) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.045) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.045) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.045) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.grid-zoom-popover {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(220px, calc(100% - 16px));
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(13, 19, 27, 0.94);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0);
  transition: opacity 140ms ease;
}

.canvas-stage:hover .grid-zoom-popover,
.grid-zoom-popover:focus-within {
  opacity: 1;
  pointer-events: auto;
}

.grid-zoom-popover label {
  color: #c8d4df;
  font-size: 12px;
  white-space: nowrap;
}

.grid-zoom-popover input {
  min-width: 0;
  flex: 1;
}

canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.control-group {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.control-group:first-child {
  padding-top: 0;
}

.control-group:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.control-group h3 {
  margin: 0 0 10px;
  font-size: 13px;
}

.field {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.field label,
.toggle {
  color: #c8d4df;
  font-size: 12px;
}

.field input,
.field select {
  width: 100%;
  min-height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #0d131b;
  color: var(--text);
  padding: 7px 9px;
}

.field input[type="range"] {
  padding: 0;
}

.field-help {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d131b;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  min-height: 32px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: #203040;
  color: var(--text);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.button-row button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}

.warning {
  display: none;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #75503c;
  border-radius: 8px;
  color: var(--danger);
  background: rgba(117, 80, 60, 0.18);
  font-size: 12px;
  line-height: 1.45;
}

.warning.visible {
  display: block;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.thumb {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d131b;
  padding: 9px;
}

.thumb-title {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: #c8d4df;
  font-size: 12px;
  margin-bottom: 7px;
}

.tag {
  color: var(--muted);
  white-space: nowrap;
}

.preview-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d131b;
  padding: 9px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 10px;
}

.size-list {
  display: grid;
  gap: 7px;
}

.size-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: #c8d4df;
  font-size: 12px;
}

.size-option input {
  width: auto;
  min-height: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #111a24;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.toast.visible {
  opacity: 1;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .tool-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

  .field-grid,
  .thumb-grid {
    grid-template-columns: 1fr;
  }

  .tool-host {
    padding: 12px;
  }
}
