:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #181c26;
  --surface-3: #202534;
  --line: #303746;
  --line-soft: #262c39;
  --text: #edf0f7;
  --muted: #9ba4b7;
  --accent: #d85cff;
  --accent-2: #8e5cff;
  --good: #65e5a7;
  --danger: #ff687d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f9;
  --line: #d4dbea;
  --line-soft: #e4e8f1;
  --text: #182030;
  --muted: #596579;
  --accent: #a83ce7;
  --accent-2: #6b45e6;
  --good: #108f63;
  --danger: #d93e58;
  --shadow: 0 16px 40px rgba(31, 42, 68, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden],
.workspace-panel,
.tool-page {
  display: none !important;
}

.workspace-panel.is-active,
.tool-page.is-active {
  display: block !important;
}

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

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(216, 92, 255, 0.12), transparent 34%),
    linear-gradient(180deg, var(--surface-2), var(--bg));
  color: var(--text);
  font-family: "Outfit", "Segoe UI", Arial, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

button:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--surface-3) 72%, var(--accent) 28%);
}

button:active {
  transform: translateY(1px);
}

input,
textarea,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input:focus,
textarea:focus,
select:focus,
button:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  outline-offset: 2px;
}

.admin-root {
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 13px;
  font-weight: 900;
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card p,
.message {
  color: var(--muted);
}

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

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 18px;
  padding: 18px;
  border-right: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand strong,
.sidebar-brand small {
  display: block;
}

.sidebar-brand small {
  color: var(--muted);
  margin-top: 2px;
}

.workspace-nav,
.sidebar-section,
.action-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  justify-content: flex-start;
  text-align: left;
  padding: 0 12px;
  background: transparent;
}

.nav-item.is-active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--surface-3)), var(--surface-3));
  color: white;
}

.primary-action {
  border-color: color-mix(in srgb, var(--accent) 80%, var(--line));
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

.soft-action {
  background: var(--surface-3);
}

.ghost-action {
  background: transparent;
}

.danger-action {
  border-color: color-mix(in srgb, var(--danger) 68%, var(--line));
  background: color-mix(in srgb, var(--danger) 18%, var(--surface-3));
  color: color-mix(in srgb, var(--danger) 74%, white);
}

.studio-shell {
  min-width: 0;
  padding: 18px;
}

.studio-topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow);
}

.studio-topbar h2,
.studio-topbar p {
  margin: 0;
}

.studio-topbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.viewport-switch,
.tool-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--surface);
}

.viewport-btn,
.tool-tab {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.viewport-btn.is-active,
.tool-tab.is-active {
  background: var(--surface-3);
  color: var(--text);
}

.message {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--good) 42%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--good) 12%, var(--surface));
}

.message.error {
  border-color: color-mix(in srgb, var(--danger) 50%, var(--line));
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  color: color-mix(in srgb, var(--danger) 45%, white);
}

.builder-grid {
  height: calc(100vh - 126px);
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(620px, 1fr) minmax(320px, 390px);
  gap: 12px;
  margin-top: 12px;
}

.tool-panel,
.inspector-panel,
.preview-frame,
.page-band {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
}

.tool-panel,
.inspector-panel {
  overflow: auto;
  padding: 12px;
}

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

.panel-head h3,
.tool-page h3,
.page-band h3 {
  margin: 0;
}

.icon-action {
  min-width: 34px;
  padding: 0;
}

.section-list,
.block-library,
.media-grid.compact {
  display: grid;
  gap: 8px;
}

.section-item,
.block-library button,
.media-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
}

.section-item {
  width: 100%;
  min-height: 52px;
  padding: 8px 10px;
  text-align: left;
}

.section-item strong,
.section-item small {
  display: block;
}

.section-item small {
  color: var(--muted);
  margin-top: 2px;
}

.section-item.is-active {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--line));
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
}

.preview-column {
  min-width: 0;
}

.preview-frame {
  height: 100%;
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr);
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}

.preview-head small {
  color: var(--muted);
}

#live-preview {
  width: 100%;
  height: 100%;
  border: 0;
  background: #080a10;
}

.preview-frame[data-viewport="tablet"] {
  width: min(820px, 100%);
  margin-inline: auto;
}

.preview-frame[data-viewport="mobile"] {
  width: min(430px, 100%);
  margin-inline: auto;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

.inspector-form,
.element-actions,
.field-grid,
.token-form {
  display: grid;
  gap: 10px;
}

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

.element-actions {
  margin-top: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.media-grid.compact {
  grid-template-columns: 1fr;
}

.media-card {
  overflow: hidden;
}

.media-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
  background: var(--surface-3);
}

.media-card-body {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.media-card-body strong {
  font-size: 12px;
  word-break: break-word;
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.media-actions button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.page-band {
  margin-top: 12px;
  padding: 16px;
}

.token-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
}

.code-workspace {
  height: calc(100vh - 126px);
  margin-top: 12px;
}

#page-editor {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #070910;
  color: #f4f7ff;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  padding: 14px;
}

@media (max-width: 1500px) {
  .builder-grid {
    grid-template-columns: 320px minmax(520px, 1fr) 340px;
  }
}

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

  .app-sidebar {
    position: static;
    height: auto;
    grid-template-rows: none;
  }

  .builder-grid {
    height: auto;
    grid-template-columns: 1fr;
  }

  .tool-panel,
  .inspector-panel {
    max-height: none;
  }

  .preview-frame {
    min-height: 76vh;
  }
}

@media (max-width: 760px) {
  .studio-shell {
    padding: 10px;
  }

  .studio-topbar,
  .field-grid,
  .token-form {
    grid-template-columns: 1fr;
  }

  .studio-topbar {
    display: grid;
  }

  .viewport-switch,
  .tool-tabs {
    width: 100%;
  }

  .viewport-btn,
  .tool-tab {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
