:root {
  color-scheme: light;
  --yellow: #ffd21f;
  --yellow-strong: #f2bd00;
  --black: #111111;
  --white: #ffffff;
  --ink: #171717;
  --muted: #706f68;
  --surface: #f5f4ef;
  --surface-2: #ebe9df;
  --line: #dedbd1;
  --shadow: 0 20px 60px rgba(17, 17, 17, 0.14);
  font-family: Inter, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  background: var(--surface);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: 72px 1fr;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  color: var(--white);
  background: var(--black);
  border-bottom: 4px solid var(--yellow);
}

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

.brand strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: #ccc8b9;
  font-size: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 5px;
  background: var(--yellow);
}

.brand-mark span {
  background: var(--black);
}

.project-title {
  width: 100%;
  height: 42px;
  border: 1px solid #393939;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--white);
  background: #202020;
  outline: none;
}

.project-title:focus {
  border-color: var(--yellow);
}

.topbar-actions,
.export-controls,
.status-chips {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  justify-content: flex-end;
  min-width: 0;
}

.primary-btn,
.ghost-btn,
.wide-btn,
.button-grid button,
.layout-card,
.mini-btn {
  min-height: 38px;
  border-radius: 7px;
  padding: 0 14px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border 160ms ease;
}

.primary-btn {
  color: var(--black);
  background: var(--yellow);
}

.primary-btn:hover,
.wide-btn:hover,
.button-grid button:hover,
.layout-card:hover,
.mini-btn:hover {
  transform: translateY(-1px);
}

.wide-btn:disabled,
.button-grid button:disabled,
.layout-card:disabled,
.mini-btn:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

.ghost-btn {
  color: var(--white);
  border: 1px solid #454545;
  background: #222;
}

.ghost-btn:hover {
  border-color: var(--yellow);
}

.editor-layout {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(260px, 17vw, 320px);
}

.panel {
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 18px;
  background: var(--white);
}

.left-panel {
  position: fixed;
  top: 84px;
  left: 16px;
  z-index: 40;
  width: min(360px, calc(100vw - 32px));
  height: calc(100dvh - 100px);
  max-height: calc(100dvh - 100px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px) scale(0.98);
  visibility: hidden;
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.menu-open .left-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.menu-backdrop {
  position: fixed;
  inset: 72px 0 0;
  z-index: 30;
  background: rgba(17, 17, 17, 0.18);
}

.menu-backdrop[hidden] {
  display: none;
}

.menu-panel-title {
  position: sticky;
  top: -18px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -18px -18px 16px;
  padding: 14px 18px;
  color: var(--white);
  background: var(--black);
  border-bottom: 4px solid var(--yellow);
}

.menu-title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-pinned #menuPinBtn {
  color: var(--black);
  background: var(--yellow);
}

.menu-panel-title strong {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.right-panel {
  border-left: 1px solid var(--line);
}

.panel section + section {
  margin-top: 22px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0;
}

.layout-list,
.project-list,
.field-stack,
.control-stack {
  display: grid;
  gap: 10px;
}

.layout-card {
  width: 100%;
  min-height: 74px;
  padding: 12px;
  text-align: left;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--surface);
}

.layout-card strong,
.project-item strong {
  display: block;
  font-size: 13px;
}

.layout-card small,
.project-item small,
.file-drop small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.layout-card.active {
  border-color: var(--black);
  background: var(--yellow);
}

.grid-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-controls label,
.field-stack label,
.export-controls label,
.inspector-content label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.grid-controls input,
.field-stack input,
.inspector-content input,
.inspector-content textarea,
.inspector-content select,
.export-controls select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  color: var(--ink);
  background: var(--white);
}

.inspector-content textarea {
  min-height: 92px;
  padding: 9px;
  resize: vertical;
}

.wide-btn,
.button-grid button,
.mini-btn {
  color: var(--black);
  background: var(--yellow);
}

.button-grid button[aria-pressed="true"],
.mini-btn.active {
  color: var(--white);
  background: var(--black);
}

.wide-btn {
  width: 100%;
}

.file-drop {
  display: grid;
  gap: 5px;
  min-height: 88px;
  padding: 18px;
  place-items: center;
  text-align: center;
  border: 1px dashed #b8b09d;
  border-radius: 8px;
  background: #fffaf0;
  cursor: pointer;
}

.file-drop input {
  display: none;
}

.file-drop span {
  font-weight: 900;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button-grid button {
  min-height: 42px;
  padding: 0 8px;
}

.canvas-workspace {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: 56px 1fr;
  background:
    linear-gradient(90deg, rgba(17, 17, 17, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(17, 17, 17, 0.04) 1px, transparent 1px),
    var(--surface-2);
  background-size: 24px 24px;
}

.workspace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
}

.status-chips span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--white);
  font-size: 12px;
  font-weight: 800;
}

.canvas-viewport {
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vw, 28px);
  overflow: auto;
}

#collageCanvas {
  display: block;
  background: var(--white);
  box-shadow: var(--shadow);
  touch-action: none;
}

.inspector-content {
  display: grid;
  gap: 12px;
}

.inspector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inspector-row {
  display: flex;
  gap: 8px;
}

.inspector-row button {
  flex: 1;
}

.project-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

.icon-btn {
  min-width: 42px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  color: var(--white);
  background: var(--black);
  font-size: 11px;
  font-weight: 800;
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.checkbox-line {
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
}

.checkbox-line input {
  width: 18px;
  min-height: 18px;
}

.empty-state {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}

.empty-state.compact {
  padding: 9px 10px;
  font-size: 11px;
}

@media (min-width: 1180px) {
  .menu-pinned .editor-layout {
    grid-template-columns:
      clamp(286px, 19vw, 370px)
      minmax(0, 1fr)
      clamp(260px, 17vw, 320px);
  }

  .menu-pinned .left-panel {
    position: static;
    z-index: auto;
    width: auto;
    height: 100%;
    max-height: none;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
    opacity: 1;
    pointer-events: auto;
    transform: none;
    visibility: visible;
    transition: none;
  }

  .menu-pinned .menu-backdrop {
    display: none;
  }

  .menu-pinned #menuCloseBtn {
    display: none;
  }

  .menu-pinned .menu-panel-title {
    top: -18px;
  }
}

@media (max-width: 980px) {
  html,
  body {
    min-width: 0;
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    grid-template-rows: auto 1fr;
    overflow: hidden;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand small {
    display: none;
  }

  .brand strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
  }

  .project-title {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 38px;
  }

  .topbar-actions {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .topbar-actions .ghost-btn,
  .topbar-actions .primary-btn {
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  .editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(168px, 32dvh);
    overflow: hidden;
  }

  .right-panel {
    border: 0;
    border-top: 1px solid var(--line);
    min-height: 0;
  }

  .left-panel {
    top: 116px;
    left: 10px;
    width: calc(100vw - 20px);
    height: calc(100dvh - 128px);
    max-height: calc(100dvh - 128px);
  }

  .menu-backdrop {
    inset: 108px 0 0;
  }

  .panel {
    height: 100%;
    max-height: none;
  }

  .left-panel.panel {
    max-height: calc(100dvh - 128px);
  }
}

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .project-title {
    grid-column: auto;
    grid-row: auto;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }

  .topbar-actions .ghost-btn,
  .topbar-actions .primary-btn {
    min-width: 0;
    padding: 0 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .left-panel {
    top: 164px;
    height: calc(100dvh - 176px);
    max-height: calc(100dvh - 176px);
  }

  .left-panel.panel {
    max-height: calc(100dvh - 176px);
  }

  .menu-backdrop {
    inset: 152px 0 0;
  }

  .workspace-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .canvas-workspace {
    grid-template-rows: auto 1fr;
  }

  .status-chips,
  .export-controls {
    justify-content: space-between;
  }
}

@media (max-width: 430px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand strong {
    font-size: 13px;
  }

  .project-title {
    height: 34px;
    font-size: 13px;
  }

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

  .topbar-actions .ghost-btn,
  .topbar-actions .primary-btn {
    min-height: 34px;
  }

  .left-panel {
    top: 192px;
    height: calc(100dvh - 202px);
    max-height: calc(100dvh - 202px);
  }

  .left-panel.panel {
    max-height: calc(100dvh - 202px);
  }

  .menu-backdrop {
    inset: 180px 0 0;
  }

  .editor-layout {
    grid-template-rows: minmax(0, 1fr) minmax(150px, 30dvh);
  }

  .workspace-toolbar {
    padding: 8px 10px;
  }

  .status-chips span {
    min-height: 28px;
    font-size: 11px;
  }
}
