:root {
  --ink: #583954;
  --berry: #813e69;
  --rose: #bd6788;
  --edge: #ad8499;
  color: var(--ink);
  background: #f8e8ec;
}

body {
  background-color: #fceef0;
  background-image: repeating-linear-gradient(0deg, #eaadc127 0 11px, transparent 11px 22px), repeating-linear-gradient(90deg, #e8a8bd29 0 11px, transparent 11px 22px);
  background-size: 22px 22px;
  background-repeat: repeat;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.topbar, #studio { max-width: 1160px; margin-inline: auto; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 24px 4px 22px; }
.topbar h1 {
  display: flex; align-items: center; gap: 6px; margin: 0;
  font-size: clamp(30px, 3.7vw, 54px); line-height: 1; letter-spacing: -.02em;
  color: #954567; -webkit-text-stroke: .12em #fff9f3; paint-order: stroke fill;
  filter: drop-shadow(0 3px 0 #d094a6);
}
.topbar h1 svg { width: 1.28em; height: 1.04em; flex: none; transform: translateY(-.035em); }
.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
button, .button { font-family: inherit; font-weight: 700; }
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; border: 1.5px solid var(--edge); border-radius: 15px;
  padding: 4px 14px; background: #fffbf4; color: var(--ink);
  text-decoration: none; font-size: 17px; line-height: 1.15;
  box-shadow: inset 0 2px 0 #fff9, 0 3px 0 #cca9b5, 0 5px 7px #a86d851b;
}
.button svg, .zoom svg, .cabinet h2 svg, .pencil-case h2 svg, .gallery-header svg {
  width: 21px; height: 21px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.button:hover, .zoom button:hover { background-color: #fff; }
.button:active, #tools button:active, .zoom button:active { transform: translateY(2px); }
.icon-button { min-width: 46px; width: 46px; padding: 0; }
.back { gap: 5px; font-size: 16px; }
.gallery-open { background-color: #fde0e9; border-color: #bb819b; box-shadow: inset 0 2px 0 #fff8, 0 3px 0 #c997ac, 0 5px 7px #a86d851b; }
.gallery-open:hover { background-color: #ffe8ef; }
#sound[aria-pressed="true"] .sound-off, #sound[aria-pressed="false"] .sound-on { display: none; }
:focus-visible { outline: 3px solid #653b90; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

#studio {
  display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(295px, 1fr);
  grid-template-areas: "drawing pattern" "drawing cabinet" "drawing tools" "drawing .";
  gap: 16px 25px; align-items: start;
}
.drawing-space { grid-area: drawing; min-width: 0; }
.cutting-mat {
  position: relative; isolation: isolate; display: grid; justify-items: center;
  padding: 34px 0 16px; border: 2px solid #82b4ae; border-radius: 25px;
  background-color: #bfdfcf;
  background-image: linear-gradient(90deg, #f3fff44a 1px, transparent 1px), linear-gradient(#f3fff44a 1px, transparent 1px), linear-gradient(90deg, #f6ffea70 1.7px, transparent 1.7px), linear-gradient(#f6ffea70 1.7px, transparent 1.7px);
  background-size: 16px 16px, 16px 16px, 80px 80px, 80px 80px;
  background-position: center; box-shadow: inset 0 2px 0 #ecfff5b3, 0 4px 0 #9cbdb2, 0 10px 20px #95647729;
}
.cutting-mat::before {
  content: ""; position: absolute; inset: 9px; z-index: -1;
  border: 1px solid #edfbedb8; border-radius: 16px; pointer-events: none;
}
.cutting-mat::after {
  content: ""; position: absolute; top: 12px; bottom: 14px; left: 10px; width: 6px;
  background: repeating-linear-gradient(0deg, #719e9280 0 1px, transparent 1px 8px);
  pointer-events: none;
}
.paper {
  width: min(81%, 548px, max(398px, 63vh));
  position: relative; background: #fffbef; padding: clamp(10px, 1.2vw, 19px);
  border: 1px solid #dacdae; border-radius: 3px 5px 5px 2px;
  box-shadow: 1px 2px 0 #ece0c9, 1px 4px 0 #ded8c4, 2px 7px 12px #618b7f57;
}
#board {
  display: block; width: 100%; aspect-ratio: 1; height: auto; border-radius: 2px;
  outline: 1px solid #ebdfce; background: #fffaf0; touch-action: none;
}
#board:focus-visible { outline: 3px solid #835395; }
.tape { position: absolute; z-index: 2; width: 16%; height: clamp(15px, 2vw, 26px); pointer-events: none; }
.tape::before {
  content: ""; display: block; width: 100%; height: 100%; background-color: #f2b7c5;
  background-image: radial-gradient(#fff3e7 18%, transparent 20%); background-size: 8px 7px;
  clip-path: polygon(0 0,100% 0,98% 17%,100% 32%,98% 46%,100% 60%,98% 76%,100% 88%,99% 100%,0 100%,2% 84%,0 69%,2% 55%,0 39%,2% 23%);
  opacity: .93;
}
.tape-a { left: -4%; top: .3%; transform: rotate(-35deg); filter: drop-shadow(0 1px 0 #ae8c8559); }
.tape-b { right: -4%; top: .3%; transform: rotate(33deg); filter: drop-shadow(0 1px 0 #ae8c8559); }
.tape-b::before { background-color: #c7b1dc; background-image: repeating-linear-gradient(70deg, transparent 0 6px, #eee2ed 6px 9px); background-size: auto; }
.desk-pen, .desk-tape { position: absolute; pointer-events: none; }
.desk-pen { width: 8.7%; max-width: 61px; top: 28%; right: 1.2%; transform: rotate(12deg); filter: drop-shadow(3px 5px 2px #577f7663); }
.desk-tape { width: 13%; max-width: 86px; left: 1.2%; bottom: 11%; transform: rotate(-16deg); filter: drop-shadow(1px 4px 2px #648b7957); }
.board-controls { display: flex; align-items: center; justify-content: space-between; width: 81%; max-width: 548px; margin-top: 18px; gap: 8px; }
.zoom { display: inline-flex; align-items: center; border: 1.5px solid #79a59c; border-radius: 14px; background: #f3fbf0; box-shadow: 0 2px 0 #94b6a9; }
.zoom button { display: grid; place-items: center; min-width: 44px; min-height: 44px; border: 0; padding: 0; border-radius: 13px; background: transparent; color: #41675f; }
.zoom button + button { position: relative; }
.zoom button + button::before { content: ""; position: absolute; width: 1px; height: 20px; background: #bdd9c9; left: 0; }
.hint { border-color: #b49b77; background: #ffedae; color: #705338; box-shadow: inset 0 2px 0 #fff8, 0 2px 0 #afa281; }
.hint:hover { background-color: #fff1bb; }
#status { text-align: center; min-height: 1.4em; margin: 12px 8px 2px; font-size: 16px; font-weight: 600; color: #724d63; }
.finish-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.finish-actions:has(button:not([hidden])) { margin: 10px auto; }

.pattern-ticket {
  grid-area: pattern; display: flex; align-items: center; gap: 16px;
  padding: 13px 16px 13px 13px; background: #fff9e9; border: 1.5px solid #d6bba2;
  border-radius: 8px 20px 20px 8px; box-shadow: 1px 3px 0 #e1cabc, 0 7px 12px #9c697b16;
}
.mini-print { position: relative; flex: none; width: clamp(63px, 6.4vw, 84px); padding: 4px 4px 8px; background: #fffdfa; border: 1px solid #dbcaba; transform: rotate(-5deg); box-shadow: 1px 2px 3px #ad948367; }
.mini-print::before { position: absolute; z-index: 1; content: ""; width: 32%; height: 9px; left: 34%; top: -5px; transform: rotate(4deg); background: #f4c97ebf; }
#preview { display: block; width: 100%; height: auto; aspect-ratio: 1; background: #f8ece8; }
.pattern-info { flex: 1; min-width: 0; }
#pattern-name { margin: 0; font: 800 clamp(20px,2vw,29px)/1.06 Baloo, sans-serif; text-wrap: balance; color: #704263; }
.progress-row { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
#progress { display: block; appearance: none; height: 10px; min-width: 0; flex: 1; background: #efdfcd; border: 1px solid #d8bda7; border-radius: 9px; overflow: hidden; }
#progress::-webkit-progress-bar { background: #efdfcd; }
#progress::-webkit-progress-value { background: #d97aa2; border-radius: 9px; }
#progress::-moz-progress-bar { background: #d97aa2; border-radius: 9px; }
#progress-text { font-size: 14px; line-height: 1; font-weight: 700; color: #804e66; }

.cabinet {
  grid-area: cabinet; padding: 16px 15px 17px; background: #ebddeb;
  border: 2px solid #bca2bc; border-radius: 21px; box-shadow: inset 0 3px 0 #fff7, 0 4px 0 #c1a9bf, 0 8px 14px #9a688416;
}
.cabinet h2, .pencil-case h2 {
  display: flex; align-items: center; gap: 8px; margin: 0 0 10px 1px;
  font: 800 21px/1.1 Baloo, sans-serif; color: #694864;
}
.cabinet h2 svg { color: #946a95; }
#trays { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tray {
  --gem: #ce7da7;
  display: grid; position: relative; grid-template-columns: min-content minmax(0, 1fr); align-content: center; align-items: center; justify-items: center;
  gap: 1px 2px; min-width: 0; min-height: 59px; padding: 6px 5px 3px;
  border: 1.5px solid #b49ab6; border-radius: 9px 9px 13px 13px;
  background: repeating-linear-gradient(0deg,#fff0 0 4px,#e2d4de99 5px,#fffc 6px) top 4px center / calc(100% - 9px) calc(100% - 9px) no-repeat, #fbf3f4;
  box-shadow: inset 1px 2px 0 #fff, inset -1px -2px 0 #e4d2df, 0 2px 0 #bca2b9;
  line-height: 1; color: #614557;
}
.tray[aria-pressed="true"] { border-color: #994f79; outline: 2px solid #ab618a; outline-offset: 1px; background-color: #fff6d7; }
.tray:hover { border-color: #a3668b; }
.tray-number {
  grid-column: 1; display: grid; place-items: center; width: 18px; height: 20px; border-radius: 5px;
  background: #fffdf7; border: 1px solid #c7afb8; font-size: 15px; font-weight: 800;
}
.tray[aria-pressed="true"] .tray-number { border-color: #8a466c; background: #935476; color: #fff; }
.tray-gems { grid-column: 2; width: 100%; max-width: 62px; height: 29px; position: relative; isolation: isolate; filter: drop-shadow(0 1px 1px #694d5b52); }
.tray-gems::before, .tray-gems::after { content: ""; position: absolute; inset: 0; }
.tray-gems::before { background-color: var(--gem); -webkit-mask: url('./beads.svg') center / contain no-repeat; mask: url('./beads.svg') center / contain no-repeat; }
.tray-gems::after { background: url('./beads.svg') center / contain no-repeat; mix-blend-mode: hard-light; }
.tray-name { grid-column: 1 / -1; max-width: 100%; text-wrap: balance; font-size: 13px; font-weight: 700; background: #fbf3f4c9; border-radius: 4px; padding: 1px 4px; }
.tray[aria-pressed="true"] .tray-gems { animation: rattle .24s ease-out; }
.tray:disabled::after { content: "✓"; position: absolute; right: 3px; top: 2px; padding-inline: 2px; border-radius: 50%; background: #e2f2dc; color: #36573d; font-size: 12px; }
@keyframes rattle { 25% { transform: translateX(-2px) rotate(-4deg); } 65% { transform: translateX(2px) rotate(3deg); } }

.pencil-case { grid-area: tools; padding: 13px 15px 14px; border-radius: 17px; border: 1.5px solid #c7acaa; background: #fff1e7; box-shadow: 0 3px 0 #dabaaf; }
.pencil-case h2 { font-size: 18px; margin-bottom: 8px; color: #744f61; }
.pencil-case h2 svg { width: 18px; height: 18px; color: #a77883; }
#tools { display: flex; gap: 7px; }
#tools button {
  flex: 1; display: flex; justify-content: center; align-items: center; gap: 8px;
  min-height: 44px; padding: 3px 8px; border: 1px solid #c6a7ac; border-radius: 11px;
  background: #fffaf2; font-size: 16px; line-height: 1; box-shadow: 0 2px 0 #d5b5b4;
}
#tools button[aria-pressed="true"] { background: #f6cee0; border: 1.5px solid #ae698c; box-shadow: inset 0 2px 0 #fff7, 0 2px 0 #c28aa4; }
.tip { position: relative; width: 17px; height: 25px; display: inline-block; transform: rotate(26deg); }
.tip::before, .tip::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); }
.tip::before { width: 8px; height: 14px; background: linear-gradient(90deg,#d880a4,#ffd8e1 40%,#eaa0be); border: 1px solid #ae7488; border-radius: 3px 3px 1px 1px; }
.tip::after { top: 13px; width: var(--tip-width,5px); height: 8px; border: 1px solid #aa8763; background: linear-gradient(#edd3a1 0 50%,#eaa1ba 50%); border-radius: 2px 2px 3px 3px; }
[data-width="3"] { --tip-width: 12px; } [data-width="5"] { --tip-width: 17px; }

#gallery { max-width: min(660px, calc(100vw - 22px)); width: 100%; max-height: 88vh; max-height: 88dvh; padding: clamp(15px, 3vw, 25px); border: 2px solid #b490a7; border-radius: 22px; background: #fff7eb; color: var(--ink); box-shadow: 0 6px 0 #bf9cab, 0 20px 70px #65466040; }
#gallery::backdrop { background: #553a535c; }
#gallery[open] { display: flex; flex-direction: column; overflow: hidden; }
.gallery-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 15px; }
.gallery-header h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 31px; color: var(--berry); }
.gallery-header h2 svg { width: 29px; height: 29px; }
.difficulty-filter { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 700; }
.difficulty-filter select { min-height: 44px; padding: 3px 9px; color: var(--ink); background: #fffdfa; border: 1px solid var(--edge); border-radius: 10px; font: inherit; }
#patterns { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 11px; overflow-y: auto; overscroll-behavior: contain; padding: 4px 5px 6px; }
.pattern-card { min-width: 0; display: flex; align-items: center; flex-direction: column; gap: 5px; padding: 7px 7px 9px; border: 1.5px solid #d6b9bf; border-radius: 5px 9px 8px 7px; background: #fffdfa; box-shadow: 0 3px 0 #e7ceca; text-align: center; }
.pattern-card:is(:hover,[aria-current="true"],[aria-pressed="true"]) { background: #ffe9ee; border-color: #a36387; }
.pattern-card canvas { width: 100%; aspect-ratio: 1; height: auto; background: #f8edee; }
.pattern-card strong { font-size: 16px; line-height: 1.12; }
.pattern-detail { font-size: 13px; line-height: 1.15; color: var(--berry); }
.pattern-card small { font-size: 12.5px; font-weight: 600; line-height: 1.1; color: #7b5a68; margin-top: auto; }

#studio.shining {
  display: grid; place-items: center; grid-template: auto / minmax(0, 1fr); max-width: none; position: fixed; inset: 0; z-index: 5;
  padding: 14px; background: #f5e6ed; overflow: auto;
}
#studio.shining > :not(.drawing-space), #studio.shining .board-controls, #studio.shining .desk-pen, #studio.shining .desk-tape { display: none; }
#studio.shining .drawing-space { grid-area: auto; width: min(100%, 82vh, 950px); width: min(100%, 82dvh, 950px); }
#studio.shining .cutting-mat { padding: 20px; }
#studio.shining .paper { width: 100%; }

@media (min-width: 1500px) { .topbar { padding-top: 38px; padding-bottom: 28px; } }
@media (min-width: 701px) and (max-width: 890px) {
  .topbar { gap: 12px; }
  #studio { column-gap: 14px; grid-template-columns: minmax(0,1.45fr) minmax(270px,1fr); }
  .paper { width: 87%; }
  .desk-pen { width: 6.2%; right: -.5%; }
  .desk-tape { width: 9%; }
  .cabinet { padding: 13px 10px; } #trays { gap: 6px; }
}
@media (max-width: 700px) {
  body { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
  .topbar, #studio { max-width: 510px; }
  .topbar { gap: 7px; padding: 10px 0 13px; }
  .topbar h1 { font-size: clamp(20px, 6.1vw, 35px); gap: 1px; }
  .topbar h1 svg { width: 1.08em; }
  .top-actions { gap: 5px; }
  .back span { display: none; }
  .button { font-size: 15px; min-height: 44px; border-radius: 13px; gap: 5px; padding-inline: 9px; }
  .back, .icon-button { width: 44px; min-width: 44px; padding: 0; }
  .topbar .button svg { width: 18px; height: 18px; }
  #studio { grid-template: "pattern" auto "drawing" auto "cabinet" auto "tools" auto / minmax(0,1fr); gap: 12px; }
  .pattern-ticket { padding: 6px 11px 6px 9px; gap: 12px; border-radius: 6px 15px 15px 6px; }
  .mini-print { width: 51px; padding: 2px 2px 4px; }
  .mini-print::before { height: 6px; top: -3px; }
  #pattern-name { font-size: 20px; }
  .progress-row { margin-top: 5px; }
  #progress { height: 8px; }
  .cutting-mat { padding: 18px 0 9px; border-radius: 17px; }
  .cutting-mat::before { inset: 5px; border-radius: 12px; }
  .cutting-mat::after { left: 5px; width: 4px; }
  .paper { width: 88%; padding: 8px; }
  .tape { height: 16px; width: 14%; }
  .desk-pen { width: 5.3%; right: -.1%; top: 33%; transform: rotate(5deg); }
  .desk-tape { width: 10%; left: .3%; bottom: 12%; }
  .board-controls { width: 89%; margin-top: 9px; }
  #status { margin: 8px 4px 0; font-size: 14px; line-height: 1.18; }
  .cabinet { padding: 10px; border-radius: 16px; }
  .cabinet h2, .pencil-case h2 { font-size: 17px; margin-bottom: 6px; }
  .cabinet h2 svg, .pencil-case h2 svg { width: 17px; height: 17px; }
  #trays { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; }
  .tray { min-height: 44px; padding: 2px 6px; gap: 0 3px; }
  .tray-number { font-size: 14px; width: 15px; height: 17px; }
  .tray-gems { height: 22px; }
  .tray-name { font-size: 12px; padding: 0 2px; }
  .pencil-case { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 13px; }
  .pencil-case h2 { margin: 0; gap: 4px; font-size: 15px; }
  #tools { flex: 1; gap: 4px; }
  #tools button { padding-inline: 4px; gap: 3px; font-size: 14px; }
  #patterns { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
}
@media (max-width: 490px) {
  .gallery-open { width: 44px; min-width: 44px; padding: 0; }
  .gallery-open span { display: none; }
}
@media (max-width: 700px) and (max-height: 850px) {
  .topbar { padding-bottom: 9px; }
  #studio { row-gap: 9px; }
  .cutting-mat { padding-top: 15px; }
  .board-controls { margin-top: 7px; }
  #status { margin-top: 5px; }
}
@media (max-width: 375px) {
  .topbar h1 svg, .pencil-case h2 svg { display: none; }
  .topbar { gap: 5px; } .top-actions { gap: 3px; }
  .pattern-ticket { gap: 7px; }
}
@media (max-width: 345px) {
  .topbar { gap: 3px; }
  .topbar h1 { font-size: 17px; }
}
