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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
  border: none;
  background: transparent;
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2.5px solid var(--md-sys-color-secondary);
  outline-offset: 2px;
}

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

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  z-index: 20;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: var(--md-sys-shape-sm);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: var(--md-elevation-1);
}

.brand-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.brand-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.mode-switch-bar {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-full);
}

.mode-btn {
  padding: 8px 16px;
  border-radius: var(--md-sys-shape-xs);
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  transition: background-color 0.2s ease, color 0.2s ease, border-radius 0.42s var(--m3e-spring-spatial), transform 0.35s var(--m3e-spring-fast);
}

.mode-btn:first-child { border-top-left-radius: var(--md-sys-shape-full); border-bottom-left-radius: var(--md-sys-shape-full); }
.mode-btn:last-child { border-top-right-radius: var(--md-sys-shape-full); border-bottom-right-radius: var(--md-sys-shape-full); }

.mode-btn[aria-pressed="true"] {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-radius: var(--md-sys-shape-full);
  box-shadow: var(--md-elevation-1);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  min-inline-size: 40px;
  min-block-size: 40px;
  padding: 8px;
  border-radius: var(--md-sys-shape-full);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.3s var(--m3e-spring-fast);
}

@media (hover: hover) {
  .icon-btn:hover { background: var(--md-sys-color-surface-container-highest); transform: scale(1.04); }
  .mode-btn:not([aria-pressed="true"]):hover { background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface); }
}

.split-export {
  display: inline-flex;
  align-items: stretch;
  gap: 2px;
}

.split-main {
  padding: 10px 18px;
  border-radius: var(--md-sys-shape-full) var(--md-sys-shape-xs) var(--md-sys-shape-xs) var(--md-sys-shape-full);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: filter 0.2s ease, transform 0.32s var(--m3e-spring-fast);
}

.split-menu-btn {
  padding: 10px 12px;
  border-radius: var(--md-sys-shape-xs) var(--md-sys-shape-full) var(--md-sys-shape-full) var(--md-sys-shape-xs);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.2s ease, border-radius 0.35s var(--m3e-spring-spatial);
}

.split-menu-btn[aria-expanded="true"] {
  border-radius: var(--md-sys-shape-full);
}

@media (hover: hover) {
  .split-main:hover, .split-menu-btn:hover { filter: brightness(1.08); }
}

.workspace-grid {
  display: grid;
  grid-template-columns: 300px 1fr 316px;
  min-height: 0;
  overflow: hidden;
}

.side-panel {
  background: var(--md-sys-color-surface-container-low);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-panel.right-panel {
  border-right: none;
  border-left: 1px solid var(--md-sys-color-outline-variant);
}

.m3-card {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.preset-card {
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--md-sys-shape-md);
  background: var(--md-sys-color-surface-container);
  border: 1.5px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.32s var(--m3e-spring-fast), border-color 0.2s ease, background-color 0.2s ease, border-radius 0.35s var(--m3e-spring-spatial);
}

.preset-thumb {
  height: 36px;
  border-radius: var(--md-sys-shape-xs);
  display: grid;
  place-items: center;
  padding: 4px 6px;
  overflow: hidden;
}

.preset-thumb.bg-checker {
  background-color: #f4f6f9;
  background-image: linear-gradient(45deg, #e1e6ee 25%, transparent 25%), linear-gradient(-45deg, #e1e6ee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e1e6ee 75%), linear-gradient(-45deg, transparent 75%, #e1e6ee 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.preset-thumb.bg-dark { background: #161d26; }
.preset-thumb.bg-navy { background: #0A2946; }
.preset-thumb.bg-light { background: #FFFFFF; border: 1px solid var(--md-sys-color-outline-variant); }

.preset-card[aria-pressed="true"] {
  border-color: var(--md-sys-color-secondary);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-radius: var(--md-sys-shape-lg);
}

@media (hover: hover) {
  .preset-card:hover { transform: translateY(-1px); background: var(--md-sys-color-surface-container-high); }
}

.preset-name { font-size: 12px; font-weight: 700; line-height: 1.25; }
.preset-desc { font-size: 11px; color: var(--md-sys-color-on-surface-variant); line-height: 1.2; }

.add-chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.m3-chip-btn {
  padding: 8px 10px;
  border-radius: var(--md-sys-shape-sm);
  background: var(--md-sys-color-surface-container);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background-color 0.2s ease, transform 0.28s var(--m3e-spring-fast), border-radius 0.3s var(--m3e-spring-spatial);
}

@media (hover: hover) {
  .m3-chip-btn:hover { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); transform: translateY(-1px); }
}

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: var(--md-sys-shape-sm);
  background: var(--md-sys-color-surface-container);
  border: 1.5px solid transparent;
  font-size: 12px;
}

.layer-row.selected {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-secondary);
}

.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  text-align: left;
}

.layer-mini-btn {
  min-inline-size: 26px;
  min-block-size: 26px;
  border-radius: var(--md-sys-shape-full);
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

@media (hover: hover) {
  .layer-mini-btn:hover { background: var(--md-sys-color-surface-container-highest); color: var(--md-sys-color-on-surface); }
}

.stage-column {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--md-sys-color-surface);
  padding: 16px 20px 84px;
}

.stage-viewport {
  flex: 1;
  min-height: 0;
  border-radius: var(--md-sys-shape-xl);
  border: 1px solid var(--md-sys-color-outline-variant);
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.06);
}

.stage-viewport.bg-checker {
  background-color: #edf1f7;
  background-image: linear-gradient(45deg, #dce2ec 25%, transparent 25%), linear-gradient(-45deg, #dce2ec 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #dce2ec 75%), linear-gradient(-45deg, transparent 75%, #dce2ec 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}

.stage-viewport.bg-dark { background: #141a22; }
.stage-viewport.bg-light { background: #FFFFFF; }
.stage-viewport.bg-navy { background: #0A2946; }

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .stage-viewport.bg-checker {
    background-color: #19202a;
    background-image: linear-gradient(45deg, #222b38 25%, transparent 25%), linear-gradient(-45deg, #222b38 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #222b38 75%), linear-gradient(-45deg, transparent 75%, #222b38 75%);
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .stage-viewport.bg-checker {
  background-color: #19202a;
  background-image: linear-gradient(45deg, #222b38 25%, transparent 25%), linear-gradient(-45deg, #222b38 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #222b38 75%), linear-gradient(-45deg, transparent 75%, #222b38 75%);
}

@media (max-width: 1120px) {
  .workspace-grid { grid-template-columns: 260px 1fr 275px; }
}

@media (max-width: 900px) {
  .app-shell { height: auto; overflow: auto; }
  .workspace-grid { grid-template-columns: 1fr; overflow: visible; }
  .stage-column { min-height: 460px; }
}
