:root {
  --ink: #2d2723;
  --muted: #766c65;
  --paper: #f6efe4;
  --panel: #fffdf8;
  --line: #d9cec0;
  --coral: #ff786b;
  --yellow: #f4c84d;
  --mint: #bfe2cf;
  --lilac: #d8c9f2;
  --sky: #c7e2f1;
  --shadow: 0 18px 45px rgba(70, 51, 39, 0.1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.95), transparent 32%),
    linear-gradient(145deg, #f8f2e9, #efe5d9);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 120, 107, 0.45);
  outline-offset: 3px;
}

.page-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: 0.12;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.25'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1760px, calc(100% - 32px));
  margin: 16px auto;
  border: 2px solid var(--ink);
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(360px, 0.8fr) auto;
  align-items: center;
  gap: 32px;
  padding: 24px 28px;
  border-bottom: 2px solid var(--ink);
  background: rgba(255, 253, 248, 0.92);
}

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

.brand-mark {
  position: relative;
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border: 3px solid var(--ink);
  border-radius: 19px 19px 24px 24px;
  background: var(--yellow);
  transform: rotate(-3deg);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  top: -10px;
  width: 22px;
  height: 24px;
  border: 3px solid var(--ink);
  background: var(--yellow);
  z-index: -1;
}

.brand-mark::before {
  left: 2px;
  border-radius: 18px 5px 8px 5px;
  transform: rotate(-22deg);
}

.brand-mark::after {
  right: 2px;
  border-radius: 5px 18px 5px 8px;
  transform: rotate(22deg);
}

.brand-mark span {
  position: absolute;
  display: block;
  background: var(--ink);
}

.brand-mark span:nth-child(1),
.brand-mark span:nth-child(2) {
  top: 21px;
  width: 6px;
  height: 9px;
  border-radius: 999px;
}

.brand-mark span:nth-child(1) { left: 14px; }
.brand-mark span:nth-child(2) { right: 14px; }

.brand-mark span:nth-child(3) {
  left: 50%;
  bottom: 12px;
  width: 14px;
  height: 7px;
  border-radius: 2px 2px 10px 10px;
  transform: translateX(-50%);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 3vw, 56px);
  line-height: 0.9;
  letter-spacing: -0.055em;
}

h1 em {
  display: inline-block;
  margin-left: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  color: var(--coral);
}

h2 {
  margin-bottom: 0;
  font-size: 23px;
  line-height: 1;
  letter-spacing: -0.035em;
}

.header-copy {
  max-width: 620px;
  margin-bottom: 0;
  font-size: 15px;
  line-height: 1.5;
  color: #655b55;
}

.header-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.button {
  min-height: 44px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 rgba(45, 39, 35, 0.12);
}

.button:active {
  transform: translateY(0);
  box-shadow: none;
}

.button-primary {
  background: var(--coral);
}

.button-ghost {
  background: var(--panel);
}

.button-ghost.is-active {
  background: var(--coral);
}

.button-dark {
  background: var(--ink);
  color: white;
}

.button-full {
  width: 100%;
  min-height: 50px;
}

.button:disabled,
.button[disabled] {
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
}

.button:disabled:hover,
.button[disabled]:hover {
  transform: none;
  box-shadow: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 0.77fr) minmax(500px, 1.54fr) minmax(270px, 0.77fr);
  min-height: 720px;
}

.panel {
  min-width: 0;
  padding: 22px;
  background: rgba(255, 253, 248, 0.76);
}

.library-panel {
  border-right: 2px solid var(--ink);
}

.controls-panel {
  border-left: 2px solid var(--ink);
}

.panel-heading,
.stage-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: #f4ecdf;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin: 18px 0;
  padding: 5px;
  border: 1.5px solid var(--ink);
  border-radius: 14px;
  background: #eee4d6;
}

.mode-tab {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.mode-tab.is-active {
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(50, 38, 30, 0.12);
}

.recipe-library {
  display: grid;
  gap: 10px;
}

.recipe-card {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 82px;
  padding: 9px;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.42);
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.recipe-card:hover {
  transform: translateX(3px);
  border-color: var(--ink);
}

.recipe-card.is-active {
  border: 2px solid var(--ink);
  background: #fff7e8;
  box-shadow: 4px 5px 0 rgba(45, 39, 35, 0.12);
}

.recipe-thumb {
  display: grid;
  place-items: center;
  width: 66px;
  height: 62px;
  border: 1.5px solid var(--ink);
  border-radius: 15px;
  overflow: hidden;
}

.recipe-thumb svg {
  width: 76px;
  height: 76px;
}

.recipe-meta strong,
.recipe-meta span {
  display: block;
}

.recipe-meta strong {
  margin-bottom: 4px;
  font-size: 13px;
}

.recipe-meta span {
  overflow: hidden;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe-arrow {
  font-size: 19px;
  color: var(--muted);
}

.category-tabs {
  display: flex;
  gap: 7px;
  margin-bottom: 13px;
  padding-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar { display: none; }

.category-button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fffdf8;
  font-size: 10px;
  font-weight: 850;
  cursor: pointer;
}

.category-button.is-active {
  border-color: var(--ink);
  background: var(--yellow);
}

.part-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.part-card {
  min-height: 96px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.48);
  cursor: pointer;
}

.part-card:hover,
.part-card.is-active {
  border-color: var(--ink);
  background: #fff5dc;
}

.part-preview {
  display: grid;
  place-items: center;
  height: 56px;
  margin-bottom: 7px;
  border-radius: 11px;
  background: #f1e8db;
  overflow: hidden;
}

.part-preview svg {
  width: 92px;
  height: 78px;
}

.part-name {
  display: block;
  overflow: hidden;
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-rule {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  margin-top: 18px;
  padding: 13px;
  border: 1.5px dashed #b7a99b;
  border-radius: 16px;
  background: #f4ecdf;
}

.source-rule p {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  color: #6b615a;
}

.source-rule strong {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
}

.source-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--lilac);
}

.stage-column {
  min-width: 0;
  padding: 22px 26px 18px;
  background: linear-gradient(180deg, #efe4d6, #eadccc);
}

.stage-toolbar {
  border-bottom-color: rgba(45, 39, 35, 0.24);
}

.stage-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1.5px solid rgba(45, 39, 35, 0.35);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.55);
  font-size: 10px;
  font-weight: 800;
}

.status-dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: #73bd83;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  width: min(100%, 670px);
  margin: 24px auto 18px;
  border: 3px solid var(--ink);
  border-radius: 34px;
  background: #ffe9bd;
  box-shadow: 10px 12px 0 rgba(45, 39, 35, 0.12);
  overflow: hidden;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.15;
  background-image: radial-gradient(circle at 4px 4px, var(--ink) 1.4px, transparent 1.6px);
  background-size: 18px 18px;
  pointer-events: none;
}

#faceCanvas {
  position: relative;
  z-index: 1;
  width: 94%;
  height: 94%;
  overflow: visible;
}

.stage-sticker {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 2;
  padding: 8px 11px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: rotate(-3deg);
}

.canvas-action {
  position: absolute;
  bottom: 17px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fffdf8;
  font-size: 21px;
  cursor: pointer;
}

.canvas-action:hover {
  background: var(--yellow);
}

.canvas-action-left { left: 17px; }
.canvas-action-right { right: 17px; }
.canvas-action-right.is-active { background: var(--coral); }

.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding-top: 14px;
  border-top: 1px solid rgba(45, 39, 35, 0.24);
}

.recipe-code {
  overflow: hidden;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Stage action toolbar */

.stage-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  width: min(100%, 670px);
  margin: 0 auto 10px;
  padding: 5px 8px;
  border: 1.5px solid rgba(45, 39, 35, 0.18);
  border-radius: 12px;
  background: rgba(255, 253, 248, 0.7);
}

.stage-btn {
  min-height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease;
}

.stage-btn:hover:not(:disabled) {
  background: rgba(45, 39, 35, 0.09);
}

.stage-btn:active:not(:disabled) {
  background: rgba(45, 39, 35, 0.15);
}

.stage-btn:focus-visible {
  outline: 3px solid rgba(255, 120, 107, 0.45);
  outline-offset: 2px;
}

.stage-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.stage-sep {
  width: 1px;
  height: 22px;
  flex: 0 0 1px;
  background: var(--line);
  margin: 0 5px;
}

/* Expression pills */

.expression-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.pill-button {
  min-height: 32px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: #fffdf8;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.pill-button:hover:not(:disabled) {
  border-color: var(--ink);
}

.pill-button.is-active,
.pill-button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--yellow);
}

.pill-button:focus-visible {
  outline: 3px solid rgba(255, 120, 107, 0.45);
  outline-offset: 3px;
}

.pill-button:disabled {
  opacity: 0.42;
  cursor: default;
}

/* Toggle switch */

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  user-select: none;
}

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

.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  flex: 0 0 36px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--line);
  transition: background 160ms ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 160ms ease;
}

.toggle-input:checked + .toggle-track {
  background: var(--coral);
}

.toggle-input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.toggle-input:focus-visible + .toggle-track {
  outline: 3px solid rgba(255, 120, 107, 0.45);
  outline-offset: 3px;
}

.control-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 850;
}

.control-heading.stacked {
  display: grid;
  gap: 2px;
}

.control-heading small {
  font-size: 10px;
  font-weight: 650;
  color: var(--muted);
}

.control-heading output {
  padding: 4px 7px;
  border-radius: 7px;
  background: #eee4d6;
  font-size: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--coral);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.palette-button {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
}

.palette-button::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(45, 39, 35, 0.28);
  border-radius: inherit;
}

.palette-button.is-active {
  border-color: var(--ink);
  transform: scale(1.08);
}

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

.finish-button {
  min-height: 42px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fffdf8;
  font-size: 10px;
  font-weight: 850;
  cursor: pointer;
}

.finish-button.is-active {
  border: 2px solid var(--ink);
  background: #fff1c9;
}

.text-input {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  padding: 0 12px;
  background: #fffdf8;
  font-size: 13px;
  font-weight: 750;
}

.control-note {
  margin: 14px 0 0;
  font-size: 10px;
  line-height: 1.55;
  color: var(--muted);
}

.saved-strip {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 150px;
  gap: 16px;
  align-items: stretch;
  padding: 18px 24px;
  border-top: 2px solid var(--ink);
  background: #f3eadf;
}

.saved-heading {
  align-self: center;
}

.saved-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(92px, 1fr));
  gap: 10px;
  min-width: 0;
}

.saved-card,
.save-card {
  min-height: 108px;
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  background: #fffdf8;
  overflow: hidden;
}

.saved-card {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.saved-card svg {
  width: 100%;
  height: 100%;
}

.saved-card span {
  position: absolute;
  right: 7px;
  bottom: 6px;
  left: 7px;
  overflow: hidden;
  padding: 3px 5px;
  border-radius: 7px;
  background: rgba(255, 253, 248, 0.88);
  font-size: 8px;
  font-weight: 850;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-card {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  border-style: dashed;
  font-size: 10px;
  font-weight: 850;
  cursor: pointer;
}

.save-card:hover {
  background: #fff3d6;
}

.save-plus {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  font-size: 22px;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 24px;
  border-top: 2px solid var(--ink);
  background: var(--ink);
  color: #fff8ed;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.12em;
}

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

  .header-copy {
    display: none;
  }

  .workspace {
    grid-template-columns: 280px minmax(450px, 1fr);
  }

  .controls-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0 20px;
    border-top: 2px solid var(--ink);
    border-left: 0;
  }

  .controls-panel .panel-heading,
  .controls-panel .button-full,
  .controls-panel .control-note {
    grid-column: 1 / -1;
  }

  .saved-strip {
    grid-template-columns: 150px minmax(0, 1fr) 130px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: 100%;
    margin: 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .header-actions {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .header-actions .button {
    flex: 1;
    min-width: 80px;
  }

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

  .library-panel,
  .controls-panel {
    border: 0;
  }

  .library-panel {
    border-bottom: 2px solid var(--ink);
  }

  .stage-column {
    order: -1;
  }

  .controls-panel {
    display: block;
    border-top: 2px solid var(--ink);
  }

  .stage {
    width: min(100%, 560px);
  }

  .stage-actions {
    overflow-x: auto;
    scrollbar-width: none;
    justify-content: flex-start;
  }

  .stage-actions::-webkit-scrollbar { display: none; }

  .saved-strip {
    grid-template-columns: 1fr;
  }

  .saved-grid {
    grid-template-columns: repeat(3, minmax(92px, 1fr));
  }

  .save-card {
    min-height: 72px;
  }
}

@media (max-width: 520px) {
  .app-header,
  .panel,
  .stage-column {
    padding: 18px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
    flex-basis: 50px;
  }

  h1 {
    font-size: 36px;
  }

  .stage {
    border-radius: 24px;
  }

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

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

  .app-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}
