:root {
  color-scheme: light;
  --bg: #f3efe7;
  --panel: rgba(255, 255, 255, 0.88);
  --ink: #1a1f36;
  --muted: #677086;
  --line: rgba(26, 31, 54, 0.12);
  --line-strong: rgba(26, 31, 54, 0.2);
  --accent: #1f7a74;
  --accent-strong: #114d49;
  --accent-soft: rgba(31, 122, 116, 0.12);
  --warm: #f56f3a;
  --shadow: 0 28px 60px rgba(27, 33, 55, 0.14);
  --radius-xl: 28px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: Aptos, "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(245, 111, 58, 0.17), transparent 28%),
    radial-gradient(circle at bottom right, rgba(31, 122, 116, 0.18), transparent 34%),
    linear-gradient(180deg, #f7f3ec 0%, #efe8dd 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.studio-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 22px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 50%),
    linear-gradient(135deg, #13202b 0%, #1b2740 100%);
  box-shadow: var(--shadow);
  color: #f6f8fb;
}

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

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f56f3a 0%, #f4b13e 100%);
  color: #1b1f36;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.brand-copy h1,
.sidebar-header h2,
.inspector-head h3,
.section-head h3 {
  margin: 0;
}

.brand-copy h1 {
  font-size: clamp(24px, 4vw, 32px);
  letter-spacing: -0.04em;
}

.eyebrow {
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.72);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.compact-field {
  display: inline-grid;
  gap: 5px;
  min-width: 170px;
  color: rgba(255, 255, 255, 0.86);
}

.compact-field span {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.compact-field select {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
}

.workspace-layout {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 88px 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tool-rail,
.sidebar,
.stage-area,
.inspector {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: var(--panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.tool-rail {
  border-radius: var(--radius-xl);
  padding: 12px 10px;
  display: grid;
  gap: 10px;
  position: sticky;
  top: 20px;
}

.rail-button {
  border: 0;
  border-radius: 18px;
  padding: 12px 6px;
  display: grid;
  gap: 6px;
  place-items: center;
  background: transparent;
  color: var(--muted);
  transition: 160ms ease;
}

.rail-button:hover,
.rail-button.is-active {
  background: rgba(26, 31, 54, 0.07);
  color: var(--ink);
}

.rail-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: rgba(26, 31, 54, 0.07);
}

.rail-button.is-active .rail-icon {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.rail-button span:last-child {
  font-size: 11px;
  font-weight: 700;
}

.sidebar,
.inspector,
.stage-area {
  border-radius: var(--radius-xl);
}

.sidebar,
.inspector {
  overflow: hidden;
}

.sidebar-header,
.stage-topbar,
.inspector-card,
.section-block {
  padding: 20px;
}

.panel-header-row,
.mobile-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-header {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.3));
}

.sidebar-header .eyebrow,
.section-head p,
.inspector-head p,
.summary-label,
.stage-note,
.note-card {
  color: var(--muted);
}

.sidebar-scroll,
.inspector-scroll {
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.mobile-sheet-header,
.mobile-panel-actions,
.panel-dismiss,
.mobile-backdrop {
  display: none;
}

.mobile-sheet-header {
  padding: 18px 20px 0;
}

.sheet-eyebrow {
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.tool-panel {
  display: none;
}

.tool-panel.is-active {
  display: block;
}

.section-block + .section-block,
.inspector-card + .inspector-card {
  border-top: 1px solid var(--line);
}

.section-head {
  margin-bottom: 14px;
}

.section-head p,
.inspector-head p {
  margin: 6px 0 0;
  line-height: 1.5;
}

.template-grid,
.stack-actions,
.field-grid,
.mini-grid,
.swatch-grid {
  display: grid;
  gap: 10px;
}

.template-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.6);
  transition: 160ms ease;
}

.template-card:hover,
.chip-button:hover,
.swatch-button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.template-swatch {
  display: block;
  width: 100%;
  height: 88px;
  margin-bottom: 12px;
  border-radius: 14px;
}

.template-swatch.warm {
  background: linear-gradient(135deg, #f8e8d1 0%, #f56f3a 100%);
}

.template-swatch.deep {
  background: linear-gradient(135deg, #10272d 0%, #1f7a74 100%);
}

.template-swatch.crisp {
  background: linear-gradient(135deg, #f9fbff 0%, #f2c23d 45%, #f56f3a 100%);
}

.template-card strong,
.summary-row strong {
  display: block;
  font-size: 15px;
}

.template-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

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

.swatch-button {
  height: 54px;
  border: 1px solid rgba(26, 31, 54, 0.16);
  border-radius: 14px;
  background: var(--swatch);
}

.note-card {
  border: 1px dashed rgba(26, 31, 54, 0.2);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.5);
  line-height: 1.5;
}

.btn {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 16px;
  transition: 160ms ease;
}

.btn:disabled,
.chip-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #2b958c 100%);
  color: white;
}

.btn-soft {
  background: rgba(26, 31, 54, 0.06);
  border-color: rgba(26, 31, 54, 0.08);
  color: var(--ink);
}

.btn-soft.is-active {
  background: var(--accent-soft);
  border-color: rgba(31, 122, 116, 0.22);
  color: var(--accent-strong);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
  color: var(--ink);
  padding-inline: 13px;
}

.btn-wide {
  width: 100%;
}

.chip-button {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
}

.chip-button.is-active {
  background: var(--accent-soft);
  border-color: rgba(31, 122, 116, 0.24);
  color: var(--accent-strong);
}

.main-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  min-width: 0;
}

.stage-area {
  padding: 0;
  overflow: hidden;
}

.stage-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.meta-row,
.stage-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
  font-size: 13px;
}

.meta-pill strong {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.zoom-label {
  min-width: 48px;
  text-align: center;
  font-weight: 700;
}

.stage-board {
  min-height: calc(100vh - 290px);
  overflow: auto;
  padding: 28px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.44) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.44) 1px, transparent 1px),
    linear-gradient(180deg, #ddd7ce 0%, #d4cec4 100%);
  background-size: 24px 24px, 24px 24px, auto;
}

.stage-board.is-dragging {
  outline: 3px dashed rgba(31, 122, 116, 0.3);
  outline-offset: -14px;
}

.canvas-host {
  margin: 0 auto;
  width: 1200px;
  height: 1200px;
}

.canvas-host .canvas-container {
  box-shadow: 0 40px 90px rgba(17, 23, 38, 0.18);
  border-radius: 4px;
}

.stage-note {
  padding: 0 20px 20px;
  font-size: 13px;
}

.summary-row {
  display: grid;
  gap: 6px;
}

.summary-row + .summary-row {
  margin-top: 16px;
}

.summary-label,
.field span {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.field {
  display: grid;
  gap: 8px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field input[type="color"],
.field input[type="range"],
.field select {
  width: 100%;
}

.field input[type="color"] {
  height: 44px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
}

.field select,
.field input[type="range"] {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
  padding: 10px 12px;
}

.field input[type="range"] {
  padding-inline: 0;
}

.toast-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  gap: 10px;
  z-index: 30;
}

.toast {
  max-width: 320px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(20, 28, 46, 0.92);
  color: #f8fafc;
  box-shadow: 0 18px 40px rgba(10, 15, 26, 0.24);
}

.toast.is-warning {
  background: rgba(130, 64, 21, 0.94);
}

.toast.is-error {
  background: rgba(133, 31, 31, 0.94);
}

@media (max-width: 1380px) {
  .workspace-layout {
    grid-template-columns: 88px 300px minmax(0, 1fr);
  }

  .main-stack {
    grid-template-columns: 1fr;
  }

  .stage-board {
    min-height: 560px;
  }

  .sidebar-scroll,
  .inspector-scroll {
    max-height: none;
  }
}

@media (max-width: 980px) {
  .studio-shell {
    padding: 14px 14px 108px;
  }

  .topbar {
    position: sticky;
    top: 12px;
    z-index: 18;
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }

  .topbar-actions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .topbar-actions .btn,
  .compact-field {
    flex: 0 0 auto;
    width: auto;
  }

  .workspace-layout {
    display: flex;
    flex-direction: column;
  }

  .tool-rail {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: 14px;
    top: auto;
    z-index: 28;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    padding: 10px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.94);
  }

  .rail-button {
    padding: 10px 4px;
  }

  .sidebar,
  .inspector {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: 88px;
    max-height: min(72dvh, 680px);
    z-index: 26;
    transform: translateY(calc(100% + 28px));
    opacity: 0;
    pointer-events: none;
    transition: transform 180ms ease, opacity 180ms ease;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.97);
  }

  body.mobile-tools-open .sidebar,
  body.mobile-inspector-open .inspector {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-scroll,
  .inspector-scroll {
    max-height: calc(min(72dvh, 680px) - 92px);
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    display: block;
    background: rgba(18, 24, 38, 0.36);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 24;
  }

  body.mobile-tools-open .mobile-backdrop,
  body.mobile-inspector-open .mobile-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .panel-dismiss,
  .mobile-panel-actions,
  .mobile-sheet-header {
    display: flex;
  }

  .panel-dismiss {
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 14px;
    background: rgba(26, 31, 54, 0.05);
    color: var(--ink);
  }

  .mobile-panel-actions {
    width: 100%;
    gap: 10px;
  }

  .mobile-panel-actions .btn {
    flex: 1 1 0;
  }

  .main-stack {
    display: block;
    order: 1;
  }

  .stage-area {
    min-width: 0;
  }

  .sidebar {
    order: 2;
  }

  .stage-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .stage-board {
    min-height: clamp(360px, 56dvh, 620px);
    padding: 14px;
    overscroll-behavior: contain;
  }

  .meta-row,
  .stage-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .meta-pill {
    flex: 0 0 auto;
  }

  .stage-note {
    padding-bottom: 18px;
  }

  .toast-stack {
    bottom: 98px;
  }
}

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

  .tool-rail {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .tool-rail .rail-button span:last-child {
    font-size: 10px;
  }

  .sidebar,
  .inspector {
    left: 10px;
    right: 10px;
    bottom: 82px;
  }

  .meta-row,
  .stage-actions {
    justify-content: flex-start;
  }

  .field-grid,
  .swatch-grid {
    grid-template-columns: 1fr;
  }

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

  .canvas-host .canvas-container {
    box-shadow: 0 24px 56px rgba(17, 23, 38, 0.18);
  }

  .toast-stack {
    left: 14px;
    right: 14px;
    bottom: 92px;
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 430px) {
  .topbar {
    border-radius: 22px;
  }

  .brand-cluster {
    align-items: flex-start;
  }

  .brand-copy h1 {
    font-size: 22px;
  }

  .rail-icon {
    width: 38px;
    height: 38px;
  }

  .stage-board {
    padding: 10px;
  }

  .mini-grid {
    grid-template-columns: 1fr;
  }
}
