:root {
  --bg-deep: #0e081d;
  --bg-panel: #180f2e;
  --bg-card: #221540;
  --bg-input: #120a24;
  --border: #3a2368;
  --gold: #ffd43b;
  --gold-dark: #d98c00;
  --magenta: #e040fb;
  --cyan: #40e0ff;
  --green: #47e58e;
  --red: #ff5e78;
  --text: #f4eeff;
  --muted: #b6a6d8;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; }
.w-full { width: 100%; }

/* LOGIN */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #31175e, #0c0618);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-panel);
  border: 2px solid var(--gold-dark);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand h1 { margin: 0; font-size: 20px; color: var(--gold); }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.brand-orb {
  width: 44px; height: 44px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; background: linear-gradient(135deg, #7b2fff, #e040fb);
  border: 2px solid var(--gold);
}
.brand-orb.sm { width: 34px; height: 34px; font-size: 17px; border-radius: 10px; }

/* BUTTONS & INPUTS */
label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--gold); margin: 10px 0 4px; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text); font-size: 13px;
}
input[type="color"] {
  width: 100%; height: 32px; padding: 2px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-input); cursor: pointer;
}
input[type="range"] { accent-color: var(--gold); }

button, .upload-btn {
  border: none; border-radius: 10px; padding: 8px 14px;
  font-weight: 700; font-size: 13px; cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover, .upload-btn:hover { filter: brightness(1.08); }
button:active { transform: scale(0.97); }

.btn-gold { background: linear-gradient(180deg, #ffe066, #e59400); color: #1d0c35; }
.btn-secondary { background: #2f1d57; color: #fff; border: 1px solid #5a38a0; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-mini { padding: 5px 9px; font-size: 11.5px; border-radius: 8px; background: #29184d; color: var(--text); border: 1px solid var(--border); }
.btn-mini.danger, .brush-btn.danger { border-color: #8f2341; background: #3b1322; color: #ff9cb0; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* TOPBAR */
.studio-app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: 58px; flex: 0 0 58px;
  background: linear-gradient(90deg, #1b0f36, #251349, #1b0f36);
  border-bottom: 1px solid var(--border);
  padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.domain-pill {
  display: inline-block; margin-left: 6px; padding: 2px 8px; font-size: 11px;
  border-radius: 999px; background: rgba(255,212,59,0.14); color: var(--gold); border: 1px solid rgba(255,212,59,0.35);
}
.version-pill {
  padding: 4px 10px; border-radius: 999px; font-weight: 800; font-size: 12px;
  background: rgba(71,229,142,0.16); color: var(--green); border: 1px solid rgba(71,229,142,0.45);
}
.main-tabs { display: flex; gap: 6px; background: #120926; padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
.tab-btn { background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 9px; font-size: 13px; }
.tab-btn.active { background: linear-gradient(180deg, #5d2ec4, #3d1b8a); color: #fff; box-shadow: 0 2px 8px rgba(123,47,255,0.4); }

/* WORKSPACE 3-COLUMN GRID */
.workspace-grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 270px 1fr 310px;
}
.panel {
  background: var(--bg-panel);
  overflow-y: auto; padding: 12px;
}
.left-panel { border-right: 1px solid var(--border); }
.right-panel { border-left: 1px solid var(--border); }

.panel-section { margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h3 { margin: 0; font-size: 13px; color: var(--gold); letter-spacing: 0.3px; }

.item-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.item-list.compact { max-height: 190px; margin-top: 8px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 10px; background: var(--bg-card);
  border: 1px solid transparent; cursor: pointer; font-size: 12.5px;
}
.list-row:hover { border-color: #6b46c1; }
.list-row.active { background: #321d61; border-color: var(--gold); }
.list-row .sub { display: block; font-size: 10.5px; color: var(--muted); }
.badge-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* DRAGGABLE PALETTE */
.palette-grid, .brush-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette-chip {
  padding: 8px 7px; border-radius: 9px; background: var(--bg-card);
  border: 1px dashed #6441a8; font-size: 11.5px; font-weight: 600;
  cursor: grab; user-select: none; text-align: center;
}
.palette-chip:hover { border-color: var(--gold); background: #2c1b52; }
.palette-chip:active { cursor: grabbing; }
.palette-chip.wide { grid-column: span 2; }

/* STAGE AREA */
.stage-area {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: radial-gradient(circle at center, #1b1135, #0a0616);
}
.stage-toolbar, .stage-footer {
  flex: 0 0 auto; padding: 8px 14px; background: #140c29;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px;
}
.stage-footer { border-bottom: none; border-top: 1px solid var(--border); color: var(--muted); }
.tool-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-check { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-size: 12px; color: var(--text); text-transform: none; cursor: pointer; }
.inline-num { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-size: 11.5px; color: var(--gold); }
.inline-num input { width: 52px; padding: 4px 6px; text-align: center; }

/* MAP CANVAS 9:16 */
.map-viewport {
  flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 24px;
}
.map-stage {
  position: relative;
  width: 420px;
  height: 747px;
  border-radius: 22px;
  overflow: hidden;
  border: 3px solid var(--gold-dark);
  box-shadow: 0 24px 60px rgba(0,0,0,0.65);
  transform-origin: top center;
  user-select: none;
  flex-shrink: 0;
}
.map-stage.drop-hover { box-shadow: 0 0 0 4px var(--gold), 0 24px 60px rgba(0,0,0,0.7); }
.map-layer, .map-bg-img, .map-guide-grid, .map-fx-canvas, .map-trail-svg, .map-items-layer {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.map-bg-img { object-fit: fill; pointer-events: none; }
.map-layer, .map-fx-canvas, .map-trail-svg, .map-guide-grid { pointer-events: none; }
.map-guide-grid {
  background-image:
    linear-gradient(to right, rgba(255,212,59,0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,212,59,0.16) 1px, transparent 1px);
  background-size: 10% 10%;
}

/* DRAGGED MAP ITEMS */
.map-node-el, .map-effect-el {
  position: absolute; transform: translate(-50%, -50%);
  cursor: move; transition: box-shadow 0.12s;
}
.map-node-el {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  font-weight: 900; font-size: 14px; color: #fff;
  border: 2.5px solid var(--gold);
  box-shadow: 0 6px 14px rgba(0,0,0,0.55);
  text-shadow: 0 2px 3px rgba(0,0,0,0.85);
}
.map-node-el.style-normal { background: radial-gradient(circle at 30% 30%, #9b51ff, #4c1d95); }
.map-node-el.style-hard { background: radial-gradient(circle at 30% 30%, #ff5252, #9b111e); }
.map-node-el.style-superHard { background: radial-gradient(circle at 30% 30%, #e040fb, #4a148c); }
.map-node-el.style-boss { width: 56px; height: 56px; background: radial-gradient(circle at 30% 30%, #ff9800, #8c1d00); border-color: #fff176; }
.map-node-el.style-coinBonus { background: radial-gradient(circle at 30% 30%, #ffd43b, #b76e00); color: #2b1300; text-shadow: none; }
.map-node-el.style-rescue { background: radial-gradient(circle at 30% 30%, #ff6b35, #0077b6); }
.map-node-el img.node-custom-img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.map-node-el .node-tag {
  position: absolute; top: -13px; white-space: nowrap;
  padding: 1px 5px; border-radius: 6px; font-size: 8.5px; font-weight: 800;
  background: #140a27; color: var(--gold); border: 1px solid var(--gold);
}
.map-node-el.selected, .map-effect-el.selected {
  outline: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(255, 212, 59, 0.55);
  z-index: 999 !important;
}

.map-effect-el.fx-handle {
  padding: 4px 8px; border-radius: 999px;
  background: rgba(18, 9, 36, 0.78);
  border: 1.5px dashed rgba(255,212,59,0.75);
  font-size: 11px; white-space: nowrap; color: #fff;
}
.map-effect-el.fx-banner {
  padding: 5px 12px; border-radius: 12px;
  background: rgba(20, 11, 38, 0.9);
  border: 2px solid var(--gold);
  font-size: 11px; font-weight: 800; letter-spacing: 0.4px; white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.map-effect-el.fx-prop { background: transparent; padding: 2px; }
.map-effect-el.fx-prop img { display: block; max-width: 110px; max-height: 110px; pointer-events: none; }

/* BOARD EDITOR */
.brush-btn {
  padding: 7px 6px; border-radius: 9px; background: var(--bg-card);
  border: 1px solid var(--border); color: var(--text); font-size: 11.5px; justify-content: flex-start;
}
.brush-btn.active { background: #3b2273; border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.brush-options {
  margin-top: 8px; padding: 8px; border-radius: 10px; background: #130a26; border: 1px solid var(--border);
  font-size: 12px;
}
.template-row { display: flex; flex-wrap: wrap; gap: 5px; }

.board-canvas-shell {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto;
}
.board-frame {
  position: relative;
  padding: 14px; border-radius: 22px;
  background: linear-gradient(145deg, #2b1854, #140b29);
  border: 3px solid var(--gold-dark);
  box-shadow: 0 24px 60px rgba(0,0,0,0.65);
}
.board-grid {
  display: grid; gap: 4px; position: relative; z-index: 2; user-select: none;
}
.board-portal-svg {
  position: absolute; inset: 14px; width: calc(100% - 28px); height: calc(100% - 28px);
  pointer-events: none; z-index: 5;
}
.grid-cell {
  width: 56px; height: 56px; border-radius: 10px;
  position: relative; display: flex; align-items: center; justify-content: center;
  cursor: crosshair; transition: transform 0.08s;
  border: 1.5px solid rgba(255,255,255,0.12);
}
.grid-cell.light { background: #2d1b54; }
.grid-cell.dark { background: #211340; }
.grid-cell:hover { border-color: var(--gold); transform: scale(1.04); z-index: 4; }
.grid-cell.is-hole {
  background: repeating-linear-gradient(45deg, #0b0614, #0b0614 6px, #140b24 6px, #140b24 12px);
  border: 1.5px dashed rgba(255,255,255,0.14); opacity: 0.55;
}
.grid-cell.has-gold {
  background: linear-gradient(135deg, rgba(255,212,59,0.48), rgba(217,140,0,0.36));
  border-color: var(--gold);
  box-shadow: inset 0 0 10px rgba(255,212,59,0.55);
}
.grid-cell.portal-pending { outline: 3px solid var(--cyan); }
.cell-coord { position: absolute; top: 2px; left: 4px; font-size: 8.5px; color: rgba(255,255,255,0.35); pointer-events: none; }
.cell-main-icon { font-size: 23px; line-height: 1; pointer-events: none; }
.cell-hp {
  position: absolute; bottom: 2px; right: 3px; padding: 0 4px; border-radius: 5px;
  background: rgba(0,0,0,0.8); color: var(--gold); font-size: 10px; font-weight: 800; pointer-events: none;
}
.cell-sub-badge {
  position: absolute; top: 2px; right: 3px; font-size: 12px; pointer-events: none;
}
.cell-conveyor-bar {
  position: absolute; inset: 0; border-radius: 9px; pointer-events: none;
  border: 2px solid #ffb703; background: rgba(255, 183, 3, 0.16);
  display: flex; align-items: flex-end; justify-content: flex-start; padding: 2px 4px;
  font-size: 11px; font-weight: 900; color: #ffd43b;
}

/* INSPECTOR FORMS */
.inspector-card { display: flex; flex-direction: column; gap: 4px; }
.inspector-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.inspector-title h3 { margin: 0; font-size: 14px; color: var(--gold); }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.goal-row {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; margin-bottom: 6px; display: flex; flex-direction: column; gap: 6px;
}
.goal-row-top { display: flex; gap: 6px; align-items: center; }

/* MEDIA & API VIEWS */
.full-view { flex: 1; overflow-y: auto; padding: 20px 26px; }
.media-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.media-header h2 { margin: 0 0 4px; color: var(--gold); }
.upload-bar { display: flex; gap: 10px; align-items: center; }
.upload-bar select { width: 220px; }
.dropzone {
  border: 2px dashed #6b46c1; border-radius: 16px; padding: 24px; text-align: center;
  background: rgba(45, 27, 84, 0.35); margin-bottom: 18px; color: var(--muted);
}
.dropzone.over { border-color: var(--gold); background: rgba(255,212,59,0.12); color: #fff; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.media-card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column;
}
.media-thumb { height: 150px; background: #090512; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.media-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-meta { padding: 10px; font-size: 11.5px; display: flex; flex-direction: column; gap: 6px; }
.media-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-actions { display: flex; gap: 5px; flex-wrap: wrap; }

.api-cards { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
.api-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
.api-card h3 { margin: 0 0 8px; color: var(--gold); }
.endpoint-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 8px; font-size: 12px;
}
.api-actions { display: flex; gap: 10px; margin-top: 12px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { background: var(--bg-card); border-radius: 12px; padding: 12px; text-align: center; }
.stat-box strong { display: block; font-size: 24px; color: var(--gold); }
.json-preview {
  background: #0b0616; border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; overflow: auto; max-height: 460px; font-size: 12px; color: #a7ffce;
}

/* MODAL & TOAST */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(7, 3, 16, 0.78);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 20px;
}
.modal-box {
  width: 100%; max-width: 720px; max-height: 85vh; display: flex; flex-direction: column;
  background: var(--bg-panel); border: 2px solid var(--gold-dark); border-radius: 18px; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; color: var(--gold); font-size: 15px; }
.modal-body { padding: 16px; overflow-y: auto; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 3000; }
.toast {
  padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: #231445; border: 1px solid var(--gold); color: #fff; box-shadow: 0 10px 24px rgba(0,0,0,0.45);
}
.toast.err { border-color: var(--red); background: #3d1221; }
.toast-inline { padding: 10px; border-radius: 8px; background: #3d1221; border: 1px solid var(--red); margin-bottom: 12px; font-size: 12.5px; }

@media (max-width: 1120px) {
  .workspace-grid { grid-template-columns: 230px 1fr 270px; }
  .api-cards { grid-template-columns: 1fr; }
}
