:root {
  --bg: #f4f2ec;
  --surface: #fffdf8;
  --surface-2: #f8f6ef;
  --ink: #171717;
  --muted: #74706a;
  --line: #e4dfd2;
  --accent: #235cff;
  --accent-soft: #e8eeff;
  --accent-2: #111827;
  --danger: #d92d20;
  --ok: #079455;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(31, 35, 51, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button, input, textarea { font: inherit; }

#topbar {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 18px;
  background: rgba(255, 253, 248, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  user-select: none;
  min-width: 190px;
}

.brand .logo {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  background: linear-gradient(135deg, #111827 0%, var(--accent) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 850;
  box-shadow: 0 9px 22px rgba(35, 92, 255, 0.24);
}

.brand .name { font-weight: 800; font-size: 16px; letter-spacing: -0.03em; }
.brand .dot { color: var(--muted); font-weight: 700; }

.project {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#projectName {
  width: 190px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.save-state {
  min-width: 86px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
  border: 1px solid var(--line);
}
.save-state.saved { color: var(--ok); background: #ecfdf3; border-color: #abefc6; }
.save-state.dirty { color: #b54708; background: #fffaeb; border-color: #fedf89; }

.actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-group { display: flex; gap: 8px; }

.btn {
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #c7c1b4; box-shadow: 0 8px 22px rgba(31, 35, 51, 0.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 10px 26px rgba(35, 92, 255, 0.22); }
.btn-primary:hover { background: #164cff; border-color: #164cff; }
.btn-small { height: 32px; padding: 0 11px; font-size: 12px; }
.btn-big { height: 48px; padding: 0 20px; font-size: 15px; }

#studio {
  height: calc(100% - 68px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 310px;
  gap: 16px;
  padding: 16px;
}

.studio-sidebar,
.workspace {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

.studio-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.intro-card,
.selected-card { background: linear-gradient(180deg, #fffdf8 0%, #f8f6ef 100%); }
.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.sidebar-section h2,
.workspace-head h1 {
  margin: 0;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.15;
  letter-spacing: -0.04em;
}
.sidebar-section p,
#selectedHelp {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  font-weight: 850;
  letter-spacing: -0.02em;
}
.section-title small { color: var(--muted); font-size: 12px; font-weight: 650; }

#blocksPanel {
  overflow: auto;
  max-height: calc(100vh - 272px);
  padding-right: 4px;
}

.workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #fbfaf5 0%, #eeece5 100%);
}
.workspace-head {
  height: 72px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}
.device-switcher {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: #e9e5da;
}
.device-btn {
  border: none;
  border-radius: 999px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}
.device-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 4px 14px rgba(31, 35, 51, 0.12); }

.canvas-shell {
  min-height: 0;
  flex: 1;
  padding: 16px;
  background:
    radial-gradient(circle at 20px 20px, rgba(31, 35, 51, 0.06) 1px, transparent 1px) 0 0 / 22px 22px,
    #eeece5;
}

#gjs { height: 100% !important; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.tab {
  height: 34px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
}
.tab.active { background: #fff; color: var(--ink); border-color: var(--line); box-shadow: 0 6px 16px rgba(31, 35, 51, 0.06); }
.panel-host { display: none; min-height: 0; flex: 1; overflow: auto; padding: 8px 10px 14px; }
.panel-host.active { display: block; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 1000;
  background: rgba(23, 23, 23, 0.38);
  backdrop-filter: blur(7px);
}
.hidden { display: none !important; }
.modal-box {
  width: min(640px, 94vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 32px 90px rgba(31, 35, 51, 0.24);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 18px; letter-spacing: -0.03em; }
.modal-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.modal-close:hover { color: var(--ink); }

.projects-list { padding: 14px; overflow-y: auto; }
.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.p-name { font-weight: 850; letter-spacing: -0.02em; }
.p-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.p-actions { display: flex; gap: 7px; }
.p-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.p-btn.danger:hover { color: var(--danger); border-color: #fecdca; background: #fffbfa; }
.empty-state { color: var(--muted); text-align: center; padding: 34px 12px; font-size: 14px; line-height: 1.45; }

.asset-box { width: min(800px, 94vw); }
.modal-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.url-add { display: flex; min-width: 260px; }
#assetUrl {
  min-width: 220px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 10px 0 0 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 0 10px;
  font-size: 12px;
}
.url-add .btn { border-radius: 0 10px 10px 0; }
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  overflow-y: auto;
  max-height: 52vh;
}
.asset-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-2);
  cursor: pointer;
}
.asset-item:hover { border-color: var(--accent); box-shadow: 0 12px 26px rgba(35, 92, 255, 0.12); }
.asset-item img,
.asset-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: none;
  background: rgba(17, 24, 39, 0.78);
  color: #fff;
  opacity: 0;
  cursor: pointer;
}
.asset-item:hover .asset-del { opacity: 1; }
.asset-kind {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 3px 8px;
  background: rgba(17, 24, 39, 0.78);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 850;
}
.hint { margin: 0; padding: 0 20px 18px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.export-body { padding: 20px; overflow-y: auto; font-size: 14px; line-height: 1.62; color: #312f2b; }
.export-body p { margin-top: 0; }
.export-body ol { padding-left: 20px; }
.export-body li { margin-bottom: 8px; }
.export-body code { background: #f0eee6; border: 1px solid var(--line); padding: 2px 6px; border-radius: 7px; }
.export-body hr { border: none; border-top: 1px solid var(--line); margin: 22px 0; }
.export-body h4 { margin: 0 0 12px; }

.code-box { width: min(920px, 94vw); }
.code-tabs { display: flex; gap: 6px; padding: 12px 16px 0; }
.code-tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 12px 12px 0 0;
  padding: 8px 14px;
  font-weight: 850;
  cursor: pointer;
}
.code-tab.active { color: var(--ink); background: var(--surface-2); }
#codeArea {
  margin: 0 16px 14px;
  min-height: 340px;
  width: calc(100% - 32px);
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 0 14px 14px 14px;
  background: #111827;
  color: #e5e7eb;
  padding: 14px;
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}
.code-foot { display: flex; gap: 8px; padding: 0 16px 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 2000;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent-2);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

/* GrapesJS: transform technical UI into simple studio controls */
.gjs-one-bg { background-color: var(--surface); }
.gjs-two-color { color: var(--ink); }
.gjs-three-bg { background-color: var(--surface-2); }
.gjs-four-color, .gjs-four-color-h:hover { color: var(--accent); }
.gjs-pn-panels { display: none !important; }
.gjs-cv-canvas { top: 0 !important; width: 100% !important; height: 100% !important; background: #d8d3c6; }
.gjs-cv-canvas__frames { padding: 28px; }
.gjs-frame-wrapper { border-radius: 14px; overflow: hidden; box-shadow: 0 20px 54px rgba(31, 35, 51, 0.22); }
.gjs-blocks-c { padding: 0; }
.gjs-block-category { border: 0; margin-bottom: 12px; }
.gjs-block-category .gjs-title {
  padding: 10px 2px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.gjs-blocks-cs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gjs-block {
  width: 100% !important;
  min-height: 84px;
  margin: 0 !important;
  padding: 12px 10px !important;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  box-shadow: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.gjs-block:hover { border-color: var(--accent); box-shadow: 0 12px 28px rgba(35, 92, 255, 0.12); transform: translateY(-1px); }
.gjs-block__media { display: none; }
.gjs-block-label { color: var(--ink); font-size: 12px; font-weight: 850; text-align: left; }
.gjs-sm-sector,
.gjs-trt-trait,
.gjs-layer { background: transparent; border: 0; }
.gjs-sm-sector .gjs-sm-title,
.gjs-sm-sector .gjs-title,
.gjs-trt-header,
.gjs-layer-title {
  background: transparent !important;
  color: var(--ink) !important;
  border-bottom: 1px solid var(--line) !important;
  font-weight: 850;
}
.gjs-field,
.gjs-field input,
.gjs-field select,
.gjs-input-holder input {
  background: #fff !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
.gjs-sm-label,
.gjs-trt-trait__label,
.gjs-label { color: var(--muted) !important; }
.gjs-layer { border-radius: 10px; }
.gjs-layer.gjs-selected { background: var(--accent-soft); }
.gjs-resizer-h { border-color: var(--accent); }
.gjs-toolbar { border-radius: 999px; background: var(--accent-2); box-shadow: var(--shadow); }
.gjs-toolbar-item { color: #fff; }

@media (max-width: 1100px) {
  #studio { grid-template-columns: 260px minmax(0, 1fr); }
  .right-sidebar { display: none; }
  .actions .btn { padding: 0 10px; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  #topbar { height: auto; min-height: 68px; flex-wrap: wrap; padding: 12px; }
  .actions { width: 100%; margin-left: 0; overflow-x: auto; }
  #studio { height: calc(100vh - 122px); grid-template-columns: 1fr; padding: 10px; }
  .left-sidebar { display: none; }
}
