:root {
  color-scheme: light;
  --ink: #18211b;
  --muted: #667068;
  --paper: #f4f1e8;
  --panel: #fffdf8;
  --green: #237a42;
  --green-dark: #16582e;
  --lime: #b9db45;
  --line: #d8d9ce;
  --shadow: 0 24px 70px rgb(31 49 35 / 14%);
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 300px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% 4%, rgb(185 219 69 / 24%), transparent 24rem),
    linear-gradient(120deg, transparent 0 72%, rgb(35 122 66 / 5%) 72% 73%, transparent 73%),
    var(--paper);
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #1b6ea8;
  outline-offset: 3px;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(420px, 0.75fr);
  gap: 5rem;
  align-items: end;
  max-width: 1480px;
  margin: 0 auto;
  padding: 3.5rem clamp(1.25rem, 4vw, 4.5rem) 2.75rem;
  border-bottom: 1px solid rgb(24 33 27 / 14%);
}

.eyebrow,
.section-label {
  margin: 0 0 0.55rem;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 700px;
  margin-bottom: 0.75rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.2rem, 7vw, 7.25rem);
  font-weight: 400;
  letter-spacing: -0.065em;
  line-height: 0.83;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2vw, 1.8rem);
  letter-spacing: -0.035em;
}

.intro {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.35vw, 1.25rem);
  line-height: 1.55;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--ink);
}

.steps li {
  display: grid;
  gap: 1.25rem;
  padding: 0.8rem 0.65rem 0;
  border-right: 1px solid rgb(24 33 27 / 18%);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
}

.steps li:last-child {
  border-right: 0;
}

.steps span {
  color: var(--green);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(440px, 1.35fr) minmax(220px, 0.75fr);
  gap: clamp(1rem, 2vw, 2rem);
  max-width: 1680px;
  margin: 0 auto;
  padding: clamp(2rem, 4vw, 4.5rem);
}

.library-panel,
.stage {
  min-width: 0;
}

.library-panel {
  display: flex;
  max-height: calc(100vh - 3rem);
  flex-direction: column;
  align-self: start;
  padding: clamp(1.25rem, 2.5vw, 2.25rem);
  border: 1px solid rgb(24 33 27 / 12%);
  border-radius: 4px 34px 4px 4px;
  background: rgb(255 253 248 / 87%);
  box-shadow: 0 12px 40px rgb(31 49 35 / 7%);
  backdrop-filter: blur(12px);
}

.library-panel--right {
  border-radius: 34px 4px 4px 4px;
}

.library-panel.is-drop-target {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgb(35 122 66 / 18%);
}

.panel-heading,
.stage-heading {
  display: flex;
  flex: 0 0 auto;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
}

.piece-count {
  flex: 0 0 auto;
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.filters {
  display: flex;
  flex: 0 0 auto;
  gap: 0.45rem;
  margin: 1.75rem 0 1.4rem;
  padding-bottom: 0.25rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.filter,
.export-button,
.reset-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.filter {
  flex: 0 0 auto;
  padding: 0.52rem 0.85rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.filter:hover,
.filter.is-active {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.piece-grid {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: max-content;
  gap: 1rem;
  align-content: start;
  min-height: 0;
  padding: 0.15rem 0.45rem 0.3rem 0.15rem;
  overflow-y: scroll;
  overscroll-behavior: contain;
  scrollbar-color: #9aa398 transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.piece-grid::-webkit-scrollbar {
  width: 9px;
}

.piece-grid::-webkit-scrollbar-track {
  background: #ecece5;
  border-radius: 999px;
}

.piece-grid::-webkit-scrollbar-thumb {
  border: 2px solid #ecece5;
  border-radius: 999px;
  background: #8d988d;
}

.library-piece {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #ddded7;
  border-radius: 14px;
  background: #f4f3f0;
  cursor: grab;
  touch-action: pan-y;
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.library-piece:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 26px rgb(30 52 36 / 12%);
}

.library-piece:focus-visible {
  outline: 3px solid #1b6ea8;
  outline-offset: 3px;
}

.library-piece.is-source {
  opacity: 0.35;
}

.piece-preview {
  display: grid;
  min-height: 135px;
  place-items: center;
  padding: 0.55rem;
  border-bottom: 1px solid #ddded7;
  background:
    linear-gradient(45deg, #edeee9 25%, transparent 25%) 0 0 / 12px 12px,
    linear-gradient(-45deg, #edeee9 25%, transparent 25%) 0 6px / 12px 12px,
    linear-gradient(45deg, transparent 75%, #edeee9 75%) 6px -6px / 12px 12px,
    linear-gradient(-45deg, transparent 75%, #edeee9 75%) -6px 0 / 12px 12px,
    #f8f8f5;
}

.piece-preview img {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  box-shadow: 0 3px 10px rgb(24 33 27 / 10%);
}

.piece-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--panel);
}

.piece-category {
  display: block;
  margin-bottom: 0.12rem;
  color: var(--green);
  font-size: 0.59rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.piece-name {
  display: block;
  overflow: hidden;
  font-size: 0.82rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drag-cue {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  padding: 0.42rem 0.58rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  cursor: grab;
  touch-action: none;
}

.drag-cue:active {
  cursor: grabbing;
}

.library-empty {
  margin: 2rem 0 0;
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}

.stage {
  align-self: start;
}

.stage-heading {
  max-width: 520px;
  margin: 0 auto 1.5rem;
}

.stage-actions {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.reset-button {
  padding: 0.48rem 0.8rem;
  color: var(--green-dark);
  font-size: 0.72rem;
  font-weight: 800;
}

.export-button {
  padding: 0.48rem 0.8rem;
  border-color: var(--green);
  color: #fff;
  background: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
}

.export-button:hover:not(:disabled) {
  background: var(--green-dark);
}

.export-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.reset-button:hover:not(:disabled) {
  border-color: var(--green);
  background: rgb(255 255 255 / 70%);
}

.reset-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.phone-area {
  position: relative;
  width: min(100%, 520px);
  margin: 0 auto;
}

.phone-shell {
  position: relative;
  box-sizing: content-box;
  width: min(70%, 340px);
  margin: 0 auto;
  aspect-ratio: 720 / 1604;
  overflow: hidden;
  border: 7px solid #191d1a;
  border-radius: 32px;
  background: #f3f2ef;
  box-shadow: var(--shadow), 0 0 0 1px rgb(255 255 255 / 70%) inset;
}

.phone-screen,
.screen-fill,
.template-layer {
  position: absolute;
  inset: 0;
}

.screen-fill {
  background: #f4f3f0;
}

.template-layer {
  z-index: 5;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.header-layer,
.footer-layer {
  position: absolute;
  z-index: 6;
  left: 0;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.header-layer {
  top: 5.24%;
}

.footer-layer {
  bottom: 3.74%;
}

.design-canvas {
  position: absolute;
  z-index: 3;
  top: 12.41%;
  right: 0;
  bottom: 11.04%;
  left: 0;
  overflow: hidden;
  background: #f4f3f0;
  touch-action: none;
  transition: background 140ms ease, box-shadow 140ms ease;
}

.design-canvas.is-drop-target {
  background: #edf3e6;
  box-shadow: inset 0 0 0 4px rgb(35 122 66 / 42%);
}

.design-canvas.is-drop-target .empty-state {
  display: none;
}

.empty-state {
  display: grid;
  min-height: 100%;
  padding: 2.5rem 1.2rem;
  place-content: center;
  color: #6e766f;
  text-align: center;
}

.empty-state__number {
  display: grid;
  width: 4.2rem;
  height: 4.2rem;
  margin: 0 auto 1.2rem;
  place-items: center;
  border: 1px solid #b9c9b6;
  border-radius: 50%;
  color: var(--green);
  font-family: Georgia, serif;
  font-size: 2rem;
  background: #fff;
}

.empty-state strong {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--ink);
  font-size: 0.95rem;
}

.empty-state span:last-child {
  font-size: 0.75rem;
  line-height: 1.5;
}

.canvas-piece {
  position: absolute;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.canvas-piece:focus {
  outline: 0;
}

.canvas-piece.is-selected {
  z-index: 1;
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--green), 0 7px 18px rgb(23 50 30 / 18%);
}

.canvas-piece.is-editing {
  cursor: grabbing;
}

.canvas-piece img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.canvas-piece__remove,
.canvas-piece__resize {
  position: absolute;
  z-index: 2;
  width: 1.65rem;
  height: 1.65rem;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  box-shadow: 0 2px 7px rgb(22 48 28 / 30%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms ease;
}

.canvas-piece__remove {
  top: 0.2rem;
  left: 50%;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transform: translateX(-50%);
}

.canvas-piece__resize {
  display: grid;
  padding: 0;
  place-items: center;
}

.canvas-piece__resize::before {
  width: 0.55rem;
  height: 0.55rem;
  content: "";
}

.canvas-piece__resize--nw {
  top: 0.2rem;
  left: 0.2rem;
  cursor: nwse-resize;
}

.canvas-piece__resize--nw::before {
  border-top: 2px solid #fff;
  border-left: 2px solid #fff;
}

.canvas-piece__resize--ne {
  top: 0.2rem;
  right: 0.2rem;
  cursor: nesw-resize;
}

.canvas-piece__resize--ne::before {
  border-top: 2px solid #fff;
  border-right: 2px solid #fff;
}

.canvas-piece__resize--sw {
  bottom: 0.2rem;
  left: 0.2rem;
  cursor: nesw-resize;
}

.canvas-piece__resize--sw::before {
  border-bottom: 2px solid #fff;
  border-left: 2px solid #fff;
}

.canvas-piece__resize--se {
  right: 0.2rem;
  bottom: 0.2rem;
  cursor: nwse-resize;
}

.canvas-piece__resize--se::before {
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
}

.canvas-piece.is-selected .canvas-piece__remove,
.canvas-piece.is-selected .canvas-piece__resize,
.canvas-piece:focus-within .canvas-piece__remove,
.canvas-piece:focus-within .canvas-piece__resize {
  opacity: 1;
  pointer-events: auto;
}

.stage-hint {
  max-width: 430px;
  margin: 1.3rem auto 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
  text-align: center;
}

.drag-ghost {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  width: min(290px, 70vw);
  overflow: hidden;
  border: 2px solid var(--green);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 20px 50px rgb(21 42 27 / 28%);
  opacity: 0.92;
  pointer-events: none;
  transform: translate(-9999px, -9999px) rotate(2deg);
}

.drag-ghost span {
  display: block;
  padding: 0.45rem 0.65rem;
  color: #fff;
  background: var(--green);
  font-size: 0.7rem;
  font-weight: 800;
}

.drag-ghost img {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
}

body.is-dragging,
body.is-dragging * {
  cursor: grabbing !important;
  user-select: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

noscript {
  display: block;
  padding: 1rem;
  color: #fff;
  background: #8b3131;
  text-align: center;
}

@media (min-width: 1100px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    display: grid;
    grid-template-rows: minmax(0, 1fr);
  }

  .workspace {
    grid-template-rows: minmax(0, 1fr);
    width: 100%;
    height: 100%;
    min-height: 0;
    padding-top: 0.9rem;
    padding-right: clamp(1rem, 2vw, 2rem);
    padding-bottom: 0.35rem;
    padding-left: clamp(1rem, 2vw, 2rem);
    overflow: hidden;
  }

  .library-panel {
    position: static;
    width: 100%;
    height: 100%;
    max-height: none;
    align-self: stretch;
    padding: clamp(1rem, 1.7vw, 1.6rem);
  }

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

  .stage {
    display: flex;
    height: 100%;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  .stage-heading {
    display: flex;
    width: 100%;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.45rem;
    text-align: left;
  }

  .stage-heading .section-label {
    margin-bottom: 0;
  }

  .stage-actions {
    justify-content: flex-end;
  }

  .phone-area {
    flex: 1 1 auto;
    min-height: 0;
  }

  .phone-shell {
    width: auto;
    height: calc(100% - 0.9rem);
    max-width: 92%;
  }

  .stage-hint {
    display: none;
  }
}

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

  .stage {
    order: -1;
  }
}

@media (max-width: 980px) {
  .masthead {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .phone-shell {
    width: min(70%, 320px);
  }
}

@media (max-width: 620px) {
  .masthead {
    padding-top: 2.25rem;
  }

  .steps {
    gap: 0.5rem;
  }

  .steps li {
    gap: 0.7rem;
    padding-right: 0.3rem;
    padding-left: 0.3rem;
    font-size: 0.68rem;
  }

  .workspace {
    padding: 1.5rem 0.85rem 3rem;
  }

  .library-panel {
    max-height: calc(100vh - 2rem);
    padding: 1.1rem;
    border-radius: 3px 24px 3px 3px;
  }

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

  .piece-preview img {
    max-height: 220px;
  }

  .stage-heading {
    align-items: flex-start;
  }

  .stage-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  .phone-shell {
    width: min(82%, 300px);
    border-width: 5px;
    border-radius: 26px;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
