:root {
  color-scheme: light;
  --ink: #172a2b;
  --muted: #677473;
  --paper: #f3efe4;
  --panel: #fffdf7;
  --line: #d8d5ca;
  --green: #347b61;
  --green-dark: #205642;
  --lime: #d7ec72;
  --coral: #f5755c;
  --blue: #6bb8cd;
  --yellow: #f3c852;
  font-family: "Avenir Next", Avenir, "Trebuchet MS", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 0; min-height: 100%; }
body { margin: 0; overflow: hidden; color: var(--ink); background: var(--paper); }
button, input { color: inherit; font: inherit; -webkit-tap-highlight-color: transparent; }
button:not(:disabled) { cursor: pointer; }
button:disabled { cursor: wait; }
:focus-visible { outline: 4px solid rgba(52,123,97,.3); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.lab { width: min(1420px, calc(100vw - 42px)); height: calc(100vh - 30px); min-height: 690px; margin: 15px auto; display: grid; grid-template-rows: 76px minmax(0,1fr); overflow: hidden; border: 1px solid #cbc7ba; border-radius: 24px; background: var(--panel); box-shadow: 0 12px 32px rgba(27,45,43,.09); }
.lab-header { min-width: 0; display: grid; grid-template-columns: auto minmax(0,1fr); align-items: center; gap: 34px; padding: 0 22px; border-bottom: 1px solid var(--line); }
.lab-title { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.lab-title > div { display: flex; flex-direction: column; }
.lab-title span { color: var(--green); font-size: 9px; font-weight: 900; letter-spacing: .11em; text-transform: uppercase; }
.lab-title h1 { margin: 0; font-size: 25px; line-height: 1; letter-spacing: -.035em; }
.lab-mark { position: relative; width: 42px; height: 42px; display: block; border: 2px solid var(--ink); border-radius: 10px 16px 11px 15px; background: var(--lime); transform: rotate(-3deg); box-shadow: 3px 3px 0 var(--ink); }
.lab-mark i { position: absolute; left: 10px; width: 20px; height: 2px; border-radius: 2px; background: var(--ink); transform: rotate(-9deg); }
.lab-mark i:nth-child(1) { top: 11px; }
.lab-mark i:nth-child(2) { top: 19px; width: 16px; }
.lab-mark i:nth-child(3) { top: 27px; width: 22px; }
.mode-tabs { min-width: 0; display: flex; justify-content: flex-end; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.mode-tabs::-webkit-scrollbar { display: none; }
.mode-tab { min-height: 40px; padding: 0 13px; flex: 0 0 auto; border: 1px solid transparent; border-radius: 999px; color: #596866; background: transparent; font-size: 11px; font-weight: 800; transition: color 150ms ease-out, background 150ms ease-out, border-color 150ms ease-out, transform 150ms ease-out; }
.mode-tab:hover { color: var(--ink); background: #f0eee5; transform: translateY(-1px); }
.mode-tab.is-active { color: white; background: var(--ink); border-color: var(--ink); }
.mode-tab:disabled { opacity: .5; }

.workbench { min-height: 0; display: grid; grid-template-columns: minmax(400px, .88fr) minmax(490px, 1.12fr); }
.palette { min-height: 0; display: flex; flex-direction: column; padding: 25px 30px 22px; overflow-y: auto; border-right: 1px solid var(--line); background: #faf8f1; }
.challenge > span { display: block; color: var(--green); font-size: 10px; font-weight: 950; letter-spacing: .12em; text-transform: uppercase; }
.challenge h2 { margin: 5px 0 5px; font-size: clamp(29px, 3vw, 42px); line-height: 1; letter-spacing: -.045em; }
.challenge p { max-width: 540px; min-height: 38px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.trait-groups { display: grid; gap: 13px; margin-top: 18px; }
.trait-group { min-width: 0; }
.trait-group h3 { margin: 0 0 7px; color: #52615f; font-size: 10px; font-weight: 950; letter-spacing: .08em; text-transform: uppercase; }
.trait-options { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 7px; }
.trait-chip { min-width: 0; min-height: 48px; padding: 7px 8px; border: 1.5px solid #d6d5cd; border-radius: 11px; color: #475553; background: white; box-shadow: 0 2px 0 #e8e5dc; font-size: 10px; font-weight: 800; line-height: 1.15; transition: transform 150ms ease-out, border-color 150ms ease-out, box-shadow 150ms ease-out, background 150ms ease-out; }
.trait-chip:hover { transform: translateY(-2px); border-color: #81968e; box-shadow: 0 4px 0 #e0ddd3; }
.trait-chip.is-selected { color: var(--ink); border-color: var(--ink); background: var(--lime); box-shadow: 0 3px 0 var(--ink); transform: translateY(-1px); }
.trait-chip:disabled { opacity: .55; }
.colour-heading { min-height: 20px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.colour-heading h3 { margin-bottom: 5px; }
.colour-heading strong { color: var(--ink); font-size: 10px; }
.colour-grid { display: grid; grid-template-columns: repeat(8,minmax(38px,1fr)); gap: 7px; }
.colour-swatch { min-width: 38px; min-height: 44px; display: grid; place-items: center; padding: 3px; border: 2px solid transparent; border-radius: 10px; background: transparent; transition: transform 150ms ease-out, border-color 150ms ease-out, box-shadow 150ms ease-out; }
.colour-swatch span { width: 100%; height: 100%; min-height: 28px; display: block; border: 1px solid rgba(23,42,43,.28); border-radius: 7px; background: var(--swatch); box-shadow: inset 0 1px 0 rgba(255,255,255,.35); }
.colour-swatch:hover { transform: translateY(-2px); }
.colour-swatch.is-selected { border-color: var(--ink); background: white; box-shadow: 0 3px 0 var(--ink); transform: translateY(-1px); }
.colour-swatch:disabled { opacity: .5; }
.custom-idea { margin-top: 15px; }
.custom-label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.custom-label label { font-size: 11px; font-weight: 900; }
.custom-label label span, .custom-label small { color: var(--muted); font-size: 9px; font-weight: 700; }
.custom-idea input { width: 100%; min-height: 46px; margin-top: 6px; padding: 10px 12px; border: 1.5px solid #c8c8bf; border-radius: 11px; background: white; font-size: 12px; transition: border-color 150ms ease-out, box-shadow 150ms ease-out; }
.custom-idea input:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(52,123,97,.12); outline: 0; }
.custom-idea input:disabled { opacity: .6; }
.custom-idea input::placeholder { color: #8a9491; }
.custom-idea p { margin: 5px 1px 0; color: var(--muted); font-size: 9px; line-height: 1.35; }
.custom-idea .custom-error { padding: 7px 9px; border-radius: 8px; color: #713d27; background: #ffe3d2; font-size: 10px; font-weight: 800; }
.create-button { width: 100%; min-height: 64px; display: grid; grid-template-columns: 42px minmax(0,1fr); align-items: center; gap: 12px; margin-top: 20px; padding: 8px 17px; border: 2px solid var(--ink); border-radius: 14px; color: white; background: var(--green); box-shadow: 0 6px 0 var(--green-dark); text-align: left; transition: transform 150ms ease-out, box-shadow 150ms ease-out, background 150ms ease-out; }
.create-button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 0 var(--green-dark); background: #2d7158; }
.create-button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 var(--green-dark); }
.button-pencil { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--ink); background: var(--lime); }
.button-pencil svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.create-button strong, .create-button small { display: block; }
.create-button strong { font-size: 16px; }
.create-button small { max-width: 420px; margin-top: 2px; overflow: hidden; color: #dbece5; font-size: 9px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.safe-note { margin: 11px 0 0; color: #76817f; font-size: 9px; text-align: center; }

.drawing-board { min-height: 0; display: grid; grid-template-rows: 28px minmax(0,1fr) 132px; gap: 12px; padding: 21px 24px 18px; overflow: hidden; background: #e8e4d9; }
.board-topline { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.board-topline span { font-size: 12px; font-weight: 950; }
.board-topline small { color: var(--muted); font-size: 9px; font-weight: 750; }
.art-frame { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; border: 2px solid var(--ink); border-radius: 19px; background: #fffefa; box-shadow: 0 7px 0 rgba(23,42,43,.18); isolation: isolate; }
.art-frame::before { position: absolute; z-index: -1; inset: 0; content: ""; opacity: .35; background-image: linear-gradient(#dfe4dc 1px, transparent 1px), linear-gradient(90deg,#dfe4dc 1px,transparent 1px); background-size: 24px 24px; }
.empty-art { width: min(320px,60%); display: flex; flex-direction: column; align-items: center; text-align: center; }
.empty-art svg { width: min(230px,70%); color: #9ba6a0; overflow: visible; }
.empty-art path { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.doodle-main { stroke-width: 3; stroke-dasharray: 7 7; }
.doodle-detail { stroke-width: 4; }
.empty-art strong { margin-top: -12px; font-size: 19px; }
.empty-art span { max-width: 280px; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.4; }
#designImage { width: 100%; height: 100%; object-fit: contain; background: white; }
#designImage.is-revealed { animation: art-reveal 520ms cubic-bezier(.2,.8,.2,1) both; }
.creation-actions { position: absolute; z-index: 2; right: 14px; bottom: 14px; display: flex; gap: 8px; padding: 7px; border: 1px solid rgba(23,42,43,.2); border-radius: 14px; background: rgba(255,255,255,.94); box-shadow: 0 5px 18px rgba(23,42,43,.18); backdrop-filter: blur(8px); }
.creation-actions button { min-height: 46px; padding: 0 15px; border: 2px solid var(--ink); border-radius: 10px; background: white; font-size: 11px; font-weight: 950; box-shadow: 0 3px 0 var(--ink); }
.creation-actions button:first-child { color: white; background: var(--green); }
.creation-actions button:hover { transform: translateY(-1px); }
.sketching { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(255,254,250,.96); text-align: center; }
.sketch-paper { position: relative; width: min(320px,66%); aspect-ratio: 1; }
.scribbles { width: 100%; height: 100%; fill: none; stroke: var(--blue); stroke-width: 8; stroke-linecap: round; }
.scribbles path { stroke-dasharray: 320; stroke-dashoffset: 320; animation: draw-line 1.7s ease-in-out infinite; }
.scribbles path:nth-child(2) { animation-delay: .2s; stroke: var(--coral); }
.scribbles path:nth-child(3) { animation-delay: .4s; stroke: var(--yellow); }
.scribbles path:nth-child(4) { animation-delay: .6s; stroke: var(--green); }
.moving-pencil { position: absolute; left: 8%; top: 22%; width: 58px; height: 58px; fill: var(--lime); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; animation: pencil-sketch 1.7s ease-in-out infinite; filter: drop-shadow(3px 3px 0 rgba(23,42,43,.2)); }
.sketching strong { margin-top: -16px; font-size: 24px; letter-spacing: -.025em; }
.sketching > span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.error-card { width: min(390px,80%); display: flex; flex-direction: column; align-items: center; padding: 30px; border: 2px solid var(--ink); border-radius: 18px; background: #fff7ed; box-shadow: 6px 6px 0 var(--coral); text-align: center; }
.error-card svg { width: 65px; height: 65px; fill: none; stroke: var(--coral); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.error-card strong { margin-top: 8px; font-size: 23px; }
.error-card span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.error-card button { min-height: 42px; margin-top: 18px; padding: 0 17px; border: 2px solid var(--ink); border-radius: 10px; color: white; background: var(--green); box-shadow: 0 4px 0 var(--green-dark); font-weight: 900; }
.flourish { position: absolute; inset: 0; pointer-events: none; }
.flourish i { position: absolute; width: 12px; height: 12px; opacity: 0; border: 3px solid var(--coral); transform: rotate(45deg); }
.flourish i:nth-child(1) { left: 9%; top: 14%; }
.flourish i:nth-child(2) { left: 16%; bottom: 16%; border-color: var(--blue); }
.flourish i:nth-child(3) { right: 11%; top: 12%; border-color: var(--yellow); }
.flourish i:nth-child(4) { right: 16%; bottom: 17%; border-color: var(--green); }
.flourish i:nth-child(5) { left: 46%; top: 6%; border-radius: 50%; border-color: var(--blue); }
.flourish i:nth-child(6) { right: 7%; top: 48%; border-radius: 50%; }
.flourish.is-active i { animation: sparkle-pop 650ms ease-out both; }
.flourish.is-active i:nth-child(2), .flourish.is-active i:nth-child(5) { animation-delay: .08s; }
.flourish.is-active i:nth-child(3), .flourish.is-active i:nth-child(6) { animation-delay: .14s; }

.gallery { min-height: 0; display: grid; grid-template-rows: 24px minmax(0,1fr); }
.gallery-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gallery-heading h3 { margin: 0; font-size: 11px; }
.gallery-heading span { color: var(--muted); font-size: 9px; }
.gallery-strip { min-width: 0; display: flex; align-items: stretch; gap: 8px; overflow-x: auto; padding: 4px 0 3px; scrollbar-width: thin; }
.gallery-empty { flex: 1; display: grid; place-items: center; border: 1px dashed #bdbcb5; border-radius: 11px; color: #808987; font-size: 10px; }
.gallery-card { width: 116px; min-width: 116px; display: grid; grid-template-rows: minmax(0,1fr) 38px; overflow: hidden; border: 2px solid transparent; border-radius: 11px; background: white; transition: transform 150ms ease-out, border-color 150ms ease-out; }
.gallery-card:hover { transform: translateY(-2px); }
.gallery-card.is-active { border-color: var(--ink); }
.gallery-item { position: relative; min-height: 0; overflow: hidden; padding: 0; border: 0; background: white; }
.gallery-item img { width: 100%; height: 100%; display: block; object-fit: cover; }
.gallery-item span { position: absolute; left: 4px; bottom: 4px; max-width: calc(100% - 8px); padding: 2px 5px; overflow: hidden; border-radius: 5px; color: white; background: rgba(23,42,43,.82); font-size: 7px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.gallery-actions { display: grid; grid-template-columns: 42px 1fr; border-top: 1px solid var(--line); }
.gallery-actions button { min-width: 0; padding: 0 4px; border: 0; border-right: 1px solid var(--line); background: #fffdf7; font-size: 9px; font-weight: 900; }
.gallery-actions button:last-child { border-right: 0; }

@keyframes draw-line { 0% { stroke-dashoffset: 320; opacity: 0; } 18% { opacity: 1; } 60%,100% { stroke-dashoffset: 0; opacity: .7; } }
@keyframes pencil-sketch { 0% { transform: translate(0,0) rotate(-12deg); } 50% { transform: translate(225px,105px) rotate(-4deg); } 100% { transform: translate(20px,205px) rotate(-12deg); } }
@keyframes art-reveal { from { opacity: 0; transform: scale(.91) rotate(-1.5deg); filter: saturate(.5); } to { opacity: 1; transform: scale(1) rotate(0); filter: saturate(1); } }
@keyframes sparkle-pop { 0% { opacity: 0; transform: scale(.2) rotate(0); } 35% { opacity: 1; transform: scale(1.5) rotate(45deg); } 100% { opacity: 0; transform: scale(.8) rotate(80deg); } }

@media (max-height: 760px) {
  .lab { height: calc(100vh - 20px); min-height: 650px; margin: 10px auto; grid-template-rows: 68px minmax(0,1fr); }
  .palette { padding: 18px 24px 16px; }
  .challenge h2 { font-size: 31px; }
  .trait-groups { gap: 9px; margin-top: 12px; }
  .trait-chip { min-height: 42px; }
  .colour-swatch { min-height: 40px; }
  .custom-idea { margin-top: 11px; }
  .custom-idea input { min-height: 41px; }
  .create-button { min-height: 58px; margin-top: 12px; }
  .drawing-board { grid-template-rows: 24px minmax(0,1fr) 120px; padding: 16px 19px 13px; }
}

@media (max-width: 1080px) {
  .lab-header { gap: 20px; }
  .mode-tab { padding-inline: 10px; }
  .workbench { grid-template-columns: minmax(390px,.95fr) minmax(480px,1.05fr); }
  .palette { padding-inline: 22px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .lab { width: calc(100vw - 20px); height: auto; min-height: calc(100vh - 20px); margin: 10px; grid-template-rows: auto auto; overflow: visible; }
  .lab-header { grid-template-columns: 1fr; gap: 14px; padding: 16px 18px; }
  .mode-tabs { justify-content: flex-start; padding-bottom: 2px; }
  .workbench { grid-template-columns: 1fr; }
  .palette { overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .drawing-board { min-height: 700px; grid-template-rows: 28px 470px 132px; }
}

@media (max-width: 560px) {
  .lab { border-radius: 18px; }
  .lab-title h1 { font-size: 23px; }
  .mode-tab { min-height: 37px; padding-inline: 11px; }
  .palette { padding: 24px 18px 21px; }
  .trait-options { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .colour-grid { grid-template-columns: repeat(6,minmax(36px,1fr)); }
  .trait-chip { min-height: 47px; }
  .drawing-board { min-height: 620px; grid-template-rows: 28px 390px 132px; padding: 17px 14px 13px; }
  .empty-art { width: 82%; }
  .sketch-paper { width: 82%; transform: scale(.8); }
  .gallery-heading span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .moving-pencil { transform: translate(90px,100px) rotate(-8deg); }
  .scribbles path { stroke-dashoffset: 0; }
}
