:root {
  --bg: #0b1319;
  --panel: #111b24;
  --panel-2: #16222d;
  --panel-3: #1c2b38;
  --line: #24343f;
  --line-soft: #1a2934;
  --text: #e6ecf2;
  --muted: #7d8d9c;
  --muted-2: #55656f;
  --accent: #ff4655;
  --accent-dim: #b32e3c;
  --cyan: #21e6b4;
  --radius: 6px;
  --panel-w-l: 238px;
  --panel-w-r: 262px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", -apple-system, system-ui, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; font-size: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  position: relative;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .11em;
  font-size: 13px;
  padding-right: 6px;
}

.strat-name {
  width: 210px;
  padding: 7px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  outline: none;
}
.strat-name:focus { border-color: var(--accent-dim); }

.map-picker { position: relative; }

.map-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
}
.map-btn:hover { border-color: var(--muted-2); }
.map-label { color: var(--muted); font-size: 11px; letter-spacing: .06em; }
.chev { color: var(--muted); }

.map-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 268px;
  max-height: 62vh;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  z-index: 50;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .55);
}
.map-menu[hidden] { display: none; }

.map-item {
  padding: 7px 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  text-align: left;
  color: var(--text);
}
.map-item:hover { background: var(--panel-3); }
.map-item.active { border-color: var(--accent); color: #fff; }

.topbar-spacer { flex: 1; }

.zoom-group {
  display: flex;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.zoom-val {
  min-width: 54px;
  padding: 6px 4px;
  background: transparent;
  border: none;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.zoom-val:hover { color: var(--text); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted-2); }
.zoom-group .icon-btn { border: none; border-radius: 0; background: transparent; }
.icon-btn:disabled { opacity: .35; cursor: default; }

.btn {
  padding: 7px 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted-2); }
.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.btn-accent:hover { background: #ff5563; border-color: #ff5563; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- workspace ---------- */

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  flex: 0 0 auto;
  min-height: 0;
}
.panel-left { width: var(--panel-w-l); border-right: 1px solid var(--line); }
.panel-right { width: var(--panel-w-r); border-left: 1px solid var(--line); }

.panel-block {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
  min-height: 0;
}
.panel-block.grow {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.count {
  font-variant-numeric: tabular-nums;
  color: var(--muted-2);
}

/* tools */

.tool-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.tool {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  padding: 0;
}
.tool:hover { color: var(--text); border-color: var(--muted-2); }
.tool.active {
  background: rgba(255, 70, 85, .14);
  border-color: var(--accent);
  color: var(--accent);
}
.tool svg { pointer-events: none; }

/* tabs */

.tabs { display: flex; gap: 2px; }
.tab {
  padding: 3px 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted-2);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}
.tab:hover { color: var(--muted); }
.tab.active { background: var(--panel-3); color: var(--text); }

.search {
  width: 100%;
  padding: 6px 9px;
  margin-bottom: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  outline: none;
}
.search:focus { border-color: var(--accent-dim); }
.search::placeholder { color: var(--muted-2); }

.asset-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.asset {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 2px 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.asset:hover { border-color: var(--muted-2); background: var(--panel-3); }
.asset:active { cursor: grabbing; }
.asset img { width: 34px; height: 34px; object-fit: contain; pointer-events: none; }
.asset span {
  font-size: 10px;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.asset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.role-group { margin-bottom: 10px; }
.role-title {
  font-size: 10px;
  color: var(--muted-2);
  letter-spacing: .08em;
  margin: 0 0 5px 1px;
}

/* swatches */

.swatches { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, .16);
  padding: 0;
}
.swatch.active { outline: 2px solid var(--text); outline-offset: 1px; }

.style-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}
.mini-label { color: var(--muted); font-size: 11px; width: 30px; flex: 0 0 auto; }
.range {
  flex: 1;
  min-width: 0;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--line);
  border-radius: 2px;
  outline: none;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}
.range-val {
  width: 34px;
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

/* canvas */

.canvas-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(circle at 50% 42%, #16232e 0%, #0a1117 72%);
  overflow: hidden;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 13px;
  background: rgba(10, 17, 23, .82);
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
  transition: opacity .35s;
  white-space: nowrap;
}
.hint.hide { opacity: 0; }

/* inspector */

.inspector .empty-note {
  margin: 0;
  color: var(--muted-2);
  font-size: 12px;
}

.insp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.insp-row > span { color: var(--muted); font-size: 11px; }
.insp-row > b { font-weight: 500; font-size: 12px; }

.insp-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; margin-top: 10px; }
.insp-actions .btn { padding: 5px 8px; font-size: 12px; }

.text-input {
  width: 100%;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 54px;
}
.text-input:focus { border-color: var(--accent-dim); }

/* layers */

.layers { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }

.layer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 2px;
}
.layer:hover { background: var(--panel-2); }
.layer.active { background: var(--panel-3); border-color: var(--accent-dim); }
.layer img { width: 18px; height: 18px; object-fit: contain; flex: 0 0 auto; }
.layer .dot {
  width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.3);
}
.layer .layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text);
}
.layer .eye {
  width: 20px; height: 20px; border: none; background: transparent;
  color: var(--muted-2); font-size: 12px; padding: 0; border-radius: 3px;
}
.layer .eye:hover { color: var(--text); background: var(--panel-3); }

/* meta */

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 12px;
}
.meta-row span { color: var(--muted); }
.meta-row b { font-weight: 500; }
.meta-actions { display: grid; gap: 5px; margin-top: 10px; }

/* modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 12, .76);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }

.modal-box {
  width: 640px;
  max-width: calc(100vw - 40px);
  max-height: 76vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 14px; font-weight: 500; letter-spacing: .04em; }
.modal-head-actions { display: flex; align-items: center; gap: 6px; }

.library-list { flex: 1; overflow-y: auto; padding: 8px; }

.strat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 6px;
  background: var(--panel-2);
}
.strat-card.current { border-color: var(--accent); }
.strat-card .thumb {
  width: 52px; height: 52px;
  border-radius: 5px;
  object-fit: cover;
  background: #0a1117;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.strat-card .info { flex: 1; min-width: 0; }
.strat-card .info h3 {
  margin: 0 0 3px;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.strat-card .info p { margin: 0; font-size: 11px; color: var(--muted); }
.strat-card .ops { display: flex; gap: 4px; }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

/* toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 9px 18px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  font-size: 12px;
  z-index: 200;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
}
.toast[hidden] { display: none; }

.muted { color: var(--muted); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #22323e;
  border-radius: 5px;
  border: 2px solid var(--panel);
}
::-webkit-scrollbar-thumb:hover { background: #2e4150; }
