:root {
  --bg: #f4f4f6; --paper: #fcfaf5; --ink: #26302b; --ink-2: #66706a; --line: rgba(38, 48, 43, 0.14); --line-2: rgba(38, 48, 43, 0.28);
  --accent: #3f6b5a; --clay: #b4694d;
  --nature: #4f7d68; --heroes: #86506a; --arts: #a97a2c; --cat: var(--accent);
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, "Segoe UI", sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", sans-serif;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .36  0 0 0 0 .34  0 0 0 0 .3  0 0 0 .5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
body[data-cat="nature"] { --cat: var(--nature); } body[data-cat="heroes"] { --cat: var(--heroes); } body[data-cat="arts"] { --cat: var(--arts); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; min-height: 100svh; font-family: var(--ui); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }

/* ------------------------------------------------ shared controls */
.pill, .icon, .btn { border: 1px solid var(--line-2); background: var(--paper); font-weight: 600; transition: background 0.15s, border-color 0.15s, transform 0.12s; }
.pill:hover, .icon:hover, .btn:hover { background: #fff; border-color: rgba(38, 48, 43, 0.5); }
.pill:active, .icon:active, .btn:active { transform: translateY(1px); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px 9px 10px; border-radius: 10px; font-size: 14.5px; }
.icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; padding: 0; }
.icon.off .waves { display: none; }
.btn { padding: 12px 22px; border-radius: 10px; font-size: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #355a4b; border-color: #355a4b; }
.link { background: none; border: 0; padding: 4px; color: var(--ink-2); font-weight: 500; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }
.view { position: relative; z-index: 1; }

/* ------------------------------------------------ home (iPad Files / Freeform feel) */
body[data-view="gallery"] { background: var(--bg); }
.home { max-width: 1160px; margin: 0 auto; padding: calc(34px + env(safe-area-inset-top, 0px)) clamp(18px, 3.4vw, 44px) 48px; }
.home-top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
h1 { font: 700 clamp(34px, 5vw, 44px)/1.05 var(--display); letter-spacing: -0.02em; }
.seg2 { position: relative; display: grid; grid-template-columns: 1fr 1fr; width: min(100%, 340px); margin-top: 18px; padding: 2px; background: rgba(118, 118, 128, 0.12); border-radius: 11px; }
.seg2 button { position: relative; z-index: 1; height: 34px; border: 0; background: none; font: 600 14px var(--ui); color: var(--ink); border-radius: 9px; transition: opacity 0.2s; }
.seg2 button[aria-selected="false"] { font-weight: 500; opacity: 0.75; }
.seg2-thumb { position: absolute; top: 2px; left: 2px; width: calc(50% - 2px); height: 34px; background: #fff; border-radius: 9px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04); transition: transform 0.35s cubic-bezier(0.3, 1.25, 0.5, 1); }
.seg2[data-tab="free"] .seg2-thumb { transform: translateX(100%); }
.sub { margin: 14px 0 4px; font: 400 15px/1.4 var(--ui); color: var(--ink-2); }
.sub b { color: var(--ink); font-weight: 600; }

.cat { padding-top: 30px; }
.cat-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.cat-head h2 { font: 700 22px/1.1 var(--display); letter-spacing: -0.01em; }
.cat-head p { color: var(--ink-2); font-size: 14px; }
.cat-count { margin-left: auto; font: 500 13px var(--ui); color: var(--ink-2); white-space: nowrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 26px 22px; }
.card { position: relative; display: grid; gap: 3px; text-align: left; padding: 0; background: none; border: 0; border-radius: 16px; transition: transform 0.3s cubic-bezier(0.34, 1.4, 0.5, 1); animation: cardIn 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both; animation-delay: calc(var(--i, 0) * 45ms); }
.card:hover { transform: translateY(-3px); }
.card:active { transform: scale(0.97); }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); } }
.card canvas, .card .tile { width: 100%; aspect-ratio: 1; border-radius: 16px; display: block; background: var(--paper); box-shadow: 0 0 0 1px rgba(60, 60, 67, 0.1), 0 4px 14px rgba(0, 0, 0, 0.06); transition: box-shadow 0.25s ease; margin-bottom: 8px; }
.card:hover canvas, .card:hover .tile { box-shadow: 0 0 0 1px rgba(60, 60, 67, 0.12), 0 14px 30px rgba(0, 0, 0, 0.12); }
.card-title { font: 600 15px/1.2 var(--ui); padding: 0 2px; }
.card-meta { font: 400 13px var(--ui); color: var(--ink-2); padding: 0 2px; }
.card-bar { height: 3px; border-radius: 99px; background: rgba(60, 60, 67, 0.12); overflow: hidden; margin: 6px 2px 0; }
.card-bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.card-chip { position: absolute; top: 10px; right: 10px; padding: 3px 9px; border-radius: 99px; background: rgba(255, 255, 255, 0.88); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); font: 600 11px var(--ui); box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.08); }
.card.is-done .card-chip { background: var(--accent); color: #fff; }
.card.new .tile { display: grid; place-items: center; color: var(--accent); background-color: #fff; background-image: radial-gradient(rgba(60, 60, 67, 0.25) 0.9px, transparent 1.1px); background-size: 20px 20px; background-position: 10px 10px; }
.card.new .plus { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12); }
.card.new { animation-delay: 0ms; }
.card .del { position: absolute; top: 8px; left: 8px; z-index: 2; min-width: 28px; height: 28px; padding: 0 9px; border-radius: 99px; border: 0; background: #ff3b30; color: #fff; font: 600 13px var(--ui); display: none; place-items: center; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
.editing .card .del { display: grid; animation: pop 0.25s cubic-bezier(0.34, 1.6, 0.5, 1); }
@keyframes pop { from { transform: scale(0.5); opacity: 0; } }
.editing .card:not(.new) canvas { transform: scale(0.96); }
.card canvas { transition: transform 0.25s ease, box-shadow 0.25s ease; }
.empty { margin: 8px 2px 0; color: var(--ink-2); font-size: 14px; }
.foot { margin-top: 44px; padding-top: 18px; border-top: 1px solid rgba(60, 60, 67, 0.14); text-align: center; color: var(--ink-2); font-size: 13px; }
#free { padding-top: 22px; }
#cats, #free { animation: pageIn 0.35s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------ studio (iPad Markup-style: white page, floating tool palette) */
#studio { --sf: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", sans-serif; --pg: #fbfbfc; --pill: #f3f3f5; --sys: #1c1c1e; --sys-2: #8e8e93; --fill: rgba(60, 60, 67, 0.12); }
body[data-view="studio"] { height: 100svh; min-height: 0; overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; background: #fbfbfc; }
#studio { height: 100svh; display: flex; flex-direction: column; font-family: var(--sf); color: var(--sys); background-color: var(--pg); background-image: radial-gradient(rgba(60, 60, 67, 0.28) 0.9px, transparent 1.1px); background-size: 22px 22px; background-position: 11px 11px; padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.s-top { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 10px clamp(14px, 2.4vw, 26px); min-height: 56px; }
.nav:active { opacity: 0.5; }
.nav { transition: opacity 0.15s; justify-self: start; display: inline-flex; align-items: center; gap: 2px; border: 0; background: none; padding: 8px 8px 8px 0; font: 400 17px var(--sf); color: var(--sys); border-radius: 10px; }
.nav.strong { font-weight: 600; padding: 8px 4px 8px 10px; }
.s-top h2 { font: 600 17px var(--sf); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.s-right { justify-self: end; display: flex; align-items: center; gap: 14px; }
.s-prog { display: inline-flex; align-items: center; gap: 8px; }
.bar { display: none; } .bar i { display: none; }
.s-prog b { font: 500 14px var(--sf); color: var(--sys-2); font-variant-numeric: tabular-nums; }

.s-main { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); padding: 0 clamp(14px, 2.4vw, 26px) 18px 168px; }
.stage { position: relative; min-width: 0; min-height: 0; container-type: size; display: grid; place-items: center; }
.paper-wrap { position: relative; width: min(100cqw - 4px, 100cqh - 4px, 1000px); aspect-ratio: 1; background: var(--paper); border-radius: 3px; box-shadow: 0 0 0 1px rgba(60, 60, 67, 0.12), 0 14px 44px rgba(0, 0, 0, 0.14); user-select: none; -webkit-user-select: none; }
.paper { position: absolute; inset: 0; overflow: auto; scrollbar-width: none; touch-action: none; cursor: none; overscroll-behavior: contain; border-radius: inherit; }
.paper::-webkit-scrollbar { display: none; }
.paper.panning { cursor: grab; } .paper.panning.grabbing { cursor: grabbing; }
.zoom { position: relative; width: 100%; height: 100%; background: var(--paper); }
.zoom > * { position: absolute; pointer-events: none; inset: 0; }
.zoom canvas { width: 100%; height: 100%; display: block; }
.grain { background-image: repeating-linear-gradient(0deg, rgba(60,50,30,0.032) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(60,50,30,0.032) 0 1px, transparent 1px 3px); mix-blend-mode: multiply; }
.cursor { position: absolute; pointer-events: none; left: 0; top: 0; border-radius: 50%; border: 1.5px solid rgba(38, 48, 43, 0.75); background: color-mix(in srgb, var(--c, #888) 32%, transparent); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85); z-index: 6; will-change: transform; }
.paper-wrap.erasing .cursor { border-style: dashed; background: rgba(255, 255, 255, 0.4); }
.note { position: absolute; pointer-events: none; top: 14px; left: 50%; transform: translateX(-50%); z-index: 7; max-width: 92%; padding: 9px 16px; border-radius: 14px; background: rgba(28, 28, 30, 0.92); color: #fff; font: 500 13.5px/1.35 var(--sf); text-align: center; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25); }
.note.show { animation: noteIn 0.25s ease-out; }
@keyframes noteIn { from { opacity: 0; transform: translate(-50%, -8px); } }

/* free draw mode */
#studio[data-mode="free"] .dot b, #studio[data-mode="free"] .grain, #studio[data-mode="free"] #guide, #studio[data-mode="free"] #inside, #studio[data-mode="free"] .s-prog { display: none; }
#studio[data-mode="free"] .paper-wrap, #studio[data-mode="free"] .zoom { background-color: #fff; }
#studio[data-mode="free"] .zoom { background-image: radial-gradient(rgba(60, 60, 67, 0.22) 0.9px, transparent 1.1px); background-size: 3.2% 3.2%; background-position: 1.6% 1.6%; }
.sw.wheel { position: relative; } .sw.wheel input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }
.dot.wheelring { background: conic-gradient(#ff3b30, #ffcc00, #34c759, #30b0c7, #0a84ff, #af52de, #ff3b30); }
.dot.wheelring i { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 0 0 3px #fff; }

/* entrance */
#studio:not([hidden]) .s-top { animation: fadeDown 0.4s ease both; }
#studio:not([hidden]) .paper-wrap { animation: canvasIn 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both; }
#studio:not([hidden]) .tb-pill { animation: pillIn 0.55s cubic-bezier(0.25, 1.2, 0.4, 1) 0.08s both; }
@keyframes fadeDown { from { opacity: 0; transform: translateY(-8px); } }
@keyframes canvasIn { from { opacity: 0; transform: scale(0.975); } }
@keyframes pillIn { from { opacity: 0; transform: translateX(-28px); } }

/* floating tool palette */
.toolbar { position: absolute; left: clamp(10px, 1.8vw, 22px); top: 0; bottom: 18px; width: 132px; display: grid; align-items: center; z-index: 5; pointer-events: none; }
.tb-pill { pointer-events: auto; width: 132px; max-height: 100%; display: flex; flex-direction: column; align-items: stretch; gap: 14px; padding: 26px 0 20px; background: var(--pill); border-radius: 66px; overflow: hidden; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14), 0 2px 6px rgba(0, 0, 0, 0.06); }
.tb-hist { display: flex; justify-content: center; gap: 12px; flex: none; }
.circ:active:not(:disabled) { transform: scale(0.9); }
.circ { transition: opacity 0.15s, background 0.15s, transform 0.18s cubic-bezier(0.34, 1.5, 0.5, 1); width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(120, 120, 128, 0.14); color: var(--sys); display: grid; place-items: center; padding: 0; }
.circ:hover:not(:disabled) { background: rgba(120, 120, 128, 0.24); }
.circ:disabled { opacity: 0.35; cursor: default; }
.tb-tools { display: grid; flex: none; }
.tool-i { position: relative; height: 56px; width: 100%; border: 0; background: none; padding: 0; overflow: visible; --o: -36px; }
.tool-i svg { position: absolute; width: 130px; height: 35px; top: 10px; left: var(--o); filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.14)); transition: left 0.38s cubic-bezier(0.34, 1.5, 0.5, 1), filter 0.2s; pointer-events: none; }
.tool-i:active svg { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2)); }
.tool-i:hover { --o: -28px; }
.tool-i.on { --o: -12px; }
.palette { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(2, 40px); justify-content: center; align-content: start; gap: 12px; padding: 8px 0 8px; overflow-y: auto; scrollbar-width: none; -webkit-mask-image: linear-gradient(transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%); mask-image: linear-gradient(transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%); }
.palette::-webkit-scrollbar { display: none; }
.sw { position: relative; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; background: none; border: 0; border-radius: 50%; }
.dot { position: relative; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: var(--t); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1); transition: transform 0.3s cubic-bezier(0.34, 1.5, 0.5, 1), box-shadow 0.22s ease; }
.sw:active .dot { transform: scale(0.9); }
.dot b { font: 600 14px var(--sf); font-variant-numeric: tabular-nums; }
.ok { position: absolute; width: 20px; height: 20px; stroke: var(--t); opacity: 0; transition: opacity 0.2s; }
.sw.on .dot { transform: scale(1.06); box-shadow: 0 0 0 3px var(--pill), 0 0 0 5px var(--sys); }
.sw .nm, .sw .left { display: none; }
.sw.finished .dot b { opacity: 0; } .sw.finished .ok { opacity: 1; }
#moreBtn { align-self: center; flex: none; }

.menu { opacity: 0; visibility: hidden; pointer-events: none; transform: translateX(-10px) scale(0.94); transform-origin: left bottom; transition: opacity 0.16s ease, transform 0.26s cubic-bezier(0.3, 1.3, 0.5, 1), visibility 0s 0.26s; position: absolute; left: 142px; bottom: 18px; width: 230px; padding: 6px; display: grid; gap: 1px; background: rgba(246, 246, 248, 0.94); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border-radius: 18px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2), 0 0 0 0.5px rgba(0, 0, 0, 0.08); }
.menu.open { opacity: 1; visibility: visible; pointer-events: auto; transform: none; transition: opacity 0.16s ease, transform 0.3s cubic-bezier(0.3, 1.3, 0.5, 1), visibility 0s; }
.menu > button { transition: background 0.12s; display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 0; border-radius: 12px; background: none; font: 400 15.5px var(--sf); text-align: left; color: var(--sys); }
.menu > button:hover { background: var(--fill); }
.menu > button.on { color: #0a6cf0; }
.menu > button.off { color: var(--sys-2); }
.menu > button.off .waves { display: none; }
.menu > button.danger { color: #d62f23; }
.menu .zoomctl { display: flex; align-items: center; justify-content: space-between; margin: 4px 6px; background: var(--fill); border-radius: 10px; overflow: hidden; }
.menu .zoomctl button { flex: 1; height: 38px; border: 0; background: none; font: 500 14px var(--sf); display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.menu .zoomctl button:hover { background: rgba(60, 60, 67, 0.1); }

/* ------------------------------------------------ finale */
.finale { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(38, 48, 43, 0.45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fade 0.3s ease-out; }
@keyframes fade { from { opacity: 0; } }
.finale-card { position: relative; width: min(440px, 100%); padding: 32px 28px 22px; text-align: center; background: var(--paper); border-radius: 12px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3); animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.3, 1); display: grid; justify-items: center; gap: 4px; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
.finale-card .x { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; font-size: 22px; line-height: 1; }
.eyebrow { font: 700 11px var(--ui); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.finale-card h2 { font: 600 34px var(--display); }
.finale-card .lead { margin: 4px 0 14px; font-size: 15px; }
#fPreview { width: 230px; height: 230px; border-radius: 3px; box-shadow: 0 0 0 1px var(--line), 0 14px 30px rgba(38, 48, 43, 0.16); background: #fff; margin-bottom: 16px; }
.finale-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.finale-card .link { margin-top: 8px; }

/* ------------------------------------------------ small screens */
@media (max-width: 760px) {
  .s-main { padding: 0 12px 0; display: flex; flex-direction: column; }
  .stage { flex: 1; }
  .toolbar { position: static; width: auto; display: block; padding: 8px 0 calc(10px + env(safe-area-inset-bottom, 0px)); }
  .tb-pill { width: 100%; max-height: none; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px; padding: 12px 14px 12px; border-radius: 30px; }
  .palette { order: -1; flex: 0 0 100%; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 40px; justify-content: start; overflow-x: auto; overflow-y: hidden; padding: 4px 6px 8px; -webkit-mask-image: none; mask-image: none; }
  .tb-hist { gap: 8px; }
  .tb-tools { display: flex; gap: 2px; }
  .tool-i { width: 44px; height: 62px; overflow: hidden; --o: 3px; }
  .tool-i svg { left: -43px; top: calc(var(--o) + 44px); transform: rotate(-90deg); }
  .tool-i:hover { --o: 3px; } .tool-i.on { --o: -6px; }
  .tool-i svg { transition: top 0.2s; }
  .menu { position: fixed; left: 12px; right: 12px; bottom: 150px; width: auto; }
  .s-top h2 { max-width: 40vw; }
}
@media (max-width: 680px) {
  .cat-count { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 14px; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
