@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Nunito:wght@600;700;800&display=swap');

:root {
  --ink: #4b3567;
  --lavender: #7351a4;
  --paper: #fffdf8;
  --pink: #ff7fb4;
  --shadow: 0 16px 38px rgba(109, 71, 139, 0.16);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at 8% 16%, rgba(255,255,255,.8) 0 2px, transparent 3px) 0 0 / 42px 42px,
    radial-gradient(circle at 80% 15%, #fff2aa 0 2px, transparent 3px) 0 0 / 76px 76px,
    linear-gradient(135deg, #ffe8f1, #eee4ff 48%, #daf5ff);
}

.app-shell { width: min(1200px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 22px; }

.hero { display: flex; align-items: center; gap: 15px; margin: 0 5px 26px; }
.logo-mark { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 21px 21px 21px 6px; background: linear-gradient(135deg, #ff8dbb, #ffbd7f); color: #fff; font-size: 31px; box-shadow: 0 7px 0 rgba(255, 255, 255, .55), 0 12px 22px rgba(214, 91, 146, .24); transform: rotate(-8deg); }
.eyebrow { margin: 0 0 -2px; color: #8f75af; font-size: .83rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font-family: "Baloo 2", cursive; font-size: clamp(1.8rem, 4vw, 2.75rem); line-height: 1.05; letter-spacing: -.025em; }
.icon-button { margin-left: auto; width: 46px; height: 46px; border: 0; border-radius: 50%; color: #8565a8; background: rgba(255,255,255,.78); font-size: 1.35rem; box-shadow: 0 4px 12px rgba(105, 76, 136, .13); cursor: pointer; }
.icon-button[aria-pressed="true"] { background: #fff3a2; color: #b56d2d; }

.studio { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 24px; align-items: start; }
.tool-panel, .canvas-card { border: 1px solid rgba(255,255,255,.85); background: rgba(255,255,255,.77); box-shadow: var(--shadow); backdrop-filter: blur(9px); }
.tool-panel { display: flex; flex-direction: column; padding: 22px; border-radius: 28px; }
.tool-options { flex: 0 1 auto; }
.tool-actions { flex: 0 0 auto; margin-top: auto; }
.tool-group { padding: 0 0 20px; margin: 0 0 19px; border-bottom: 2px dashed #e6d8f1; }
.tool-label { display: block; margin: 0 0 11px; color: #70588c; font-size: .84rem; font-weight: 800; letter-spacing: .04em; }
.tool-label output { float: right; padding: 0 7px; border-radius: 12px; color: #fff; background: #a58bc8; font-size: .75rem; }
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.background-palette { display: flex; flex-wrap: wrap; gap: 8px; }
.color-button { width: 36px; aspect-ratio: 1; border: 3px solid transparent; border-radius: 50%; background: var(--color); box-shadow: inset 0 -4px 0 rgba(0,0,0,.09); cursor: pointer; transition: transform .16s, box-shadow .16s; }
.color-button:hover { transform: translateY(-2px) scale(1.04); }
.color-button.active { border-color: #fff; outline: 3px solid var(--color); box-shadow: 0 3px 7px rgba(71,51,97,.25); }
.background-button { width: 28px; height: 28px; border: 3px solid #fff; border-radius: 50%; outline: 2px solid transparent; background: var(--background); box-shadow: 0 2px 4px rgba(71,51,97,.14); cursor: pointer; }
.background-button.active { outline-color: #a786c3; box-shadow: 0 3px 7px rgba(71,51,97,.24); }
.custom-color-option { display: inline-grid; gap: 4px; margin: 11px 0 0; color: #82679d; font-size: .62rem; font-weight: 800; text-align: center; cursor: pointer; }
.custom-color-button { width: 36px; height: 36px; padding: 0; border: 3px solid transparent; border-radius: 50%; outline: 3px solid transparent; background: transparent; cursor: pointer; }
.custom-color-button::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-button::-webkit-color-swatch { border: 3px solid #fff; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0,0,0,.09); }
.custom-color-button.active { outline-color: var(--custom-color, #ff5c96); box-shadow: 0 3px 7px rgba(71,51,97,.25); }
input[type="range"] { width: 100%; height: 9px; appearance: none; border-radius: 20px; outline: none; background: linear-gradient(to right, #9d77c3 28%, #eadff3 28%); }
input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; appearance: none; border: 3px solid white; border-radius: 50%; background: #8f6bb5; box-shadow: 0 2px 6px rgba(55, 36, 76, .25); }
.select-wrap { position: relative; display: block; }
.select-wrap::after { position: absolute; top: 47%; right: 15px; width: 8px; height: 8px; border-right: 2px solid #855fa8; border-bottom: 2px solid #855fa8; content: ''; pointer-events: none; transform: rotate(45deg) translateY(-50%); }
.select-wrap select { width: 100%; padding: 12px 36px 12px 12px; border: 2px solid #dfcdea; border-radius: 13px; outline: none; color: #72508d; background: #fbf8ff; font-family: inherit; font-size: .77rem; font-weight: 800; cursor: pointer; appearance: none; }
.select-wrap select:focus { border-color: #a77aca; box-shadow: 0 0 0 3px #eee1f8; }
.paint-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 9px; }
.paint-mode-button { display: flex; align-items: center; justify-content: center; min-height: 39px; padding: 8px 5px; border: 2px solid #e6d8f0; border-radius: 13px; color: #876aa7; background: #fff; font-size: .75rem; line-height: 1; text-align: center; cursor: pointer; }
.paint-mode-button.active { border-color: #ad8bd2; color: #704b9e; background: #f4eaff; }
.emoji-palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.emoji-button { width: 38px; height: 35px; border: 2px solid transparent; border-radius: 11px; background: #fff; font-size: 1.28rem; line-height: 1; cursor: pointer; transition: transform .14s, background .14s; }
.emoji-button:hover { background: #fff1f7; transform: translateY(-2px); }
.emoji-button.active { border-color: #e596bf; background: #ffe8f2; transform: translateY(-1px); }
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: -3px; }
button { font-family: inherit; font-weight: 800; }
.secondary-button { padding: 10px 5px; border: 0; border-radius: 13px; color: #765993; background: #eee6f5; cursor: pointer; }
.secondary-button:disabled { opacity: .45; cursor: not-allowed; }
.save-button { width: 100%; margin-top: 14px; padding: 13px; border: 0; border-radius: 15px; color: white; background: linear-gradient(135deg, #ff7eaf, #ff9a75); font-size: .94rem; box-shadow: 0 7px 0 #e76e9c, 0 10px 15px rgba(213, 84, 135, .22); cursor: pointer; transition: transform .15s, box-shadow .15s; }
.save-button:active { transform: translateY(4px); box-shadow: 0 3px 0 #e76e9c, 0 6px 10px rgba(213, 84, 135, .2); }
.gallery-button { width: 100%; margin-top: 13px; padding: 10px; border: 2px solid #dfccea; border-radius: 14px; color: #765691; background: #fff; font-size: .8rem; cursor: pointer; }
.gallery-button:hover { background: #faf4ff; }

.canvas-card { overflow: hidden; padding: 17px; border-radius: 30px; }
.canvas-topline { display: flex; align-items: center; justify-content: space-between; min-height: 30px; padding: 0 6px 12px; }
.canvas-topline p { margin: 0; color: #846c9d; font-size: .88rem; font-weight: 800; }
.sparkle-count { color: #ff9b70; letter-spacing: 4px; }
.canvas-frame { position: relative; overflow: hidden; border: 4px solid #fff; border-radius: 22px; background-color: var(--canvas-background, #fffefa); background-image: radial-gradient(#eadff1 1.1px, transparent 1.1px); background-size: 18px 18px; box-shadow: inset 0 0 0 1px #e5d9eb; touch-action: none; }
canvas { display: block; width: 100%; height: min(67vw, 630px); min-height: 390px; cursor: crosshair; }
.axis { position: absolute; z-index: 2; pointer-events: none; opacity: .77; }
.axis-x { top: 0; bottom: 0; left: 50%; border-left: 2px dashed #c7addb; }
.axis-y { left: 0; right: 0; top: 50%; border-top: 2px dashed #c7addb; }
.axis.hidden, .hex-axes.hidden { display: none; }
.hex-axes { position: absolute; z-index: 2; inset: 0; pointer-events: none; }
.hex-axes i { position: absolute; top: 50%; left: 50%; width: 54%; border-top: 2px dashed #c7addb; transform: rotate(var(--rotation)); transform-origin: left center; }
.empty-message { position: absolute; z-index: 1; top: 50%; left: 50%; display: grid; place-items: center; width: 150px; height: 110px; border-radius: 50%; color: #aa94be; background: rgba(255,255,255,.7); text-align: center; pointer-events: none; transform: translate(-50%, -50%); transition: opacity .25s, transform .25s; }
.empty-message span { padding-top: 14px; font-size: 1.5rem; }
.empty-message p { margin: -17px 0 12px; font-size: .77rem; font-weight: 800; line-height: 1.2; }
.empty-message.hidden { opacity: 0; transform: translate(-50%, -50%) scale(.85); }
footer { padding: 17px 0 0; color: #816594; text-align: center; font-size: .84rem; font-weight: 800; }
footer p { margin: 0; }
.confetti-layer { position: fixed; z-index: 10; inset: 0; overflow: hidden; pointer-events: none; }
.confetti { position: absolute; top: -24px; width: 11px; height: 18px; border-radius: 3px; background: var(--confetti-color); animation: confetti-fall 2.5s cubic-bezier(.18,.7,.35,1) var(--delay) forwards; }
@keyframes confetti-fall { to { transform: translate(var(--drift), 112vh) rotate(var(--spin)); opacity: .9; } }
.gallery-modal { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(56, 34, 80, .43); backdrop-filter: blur(5px); }
.gallery-modal[hidden] { display: none; }
.gallery-card { position: relative; width: min(690px, 100%); max-height: min(720px, 92vh); overflow: auto; padding: 31px; border: 2px solid rgba(255,255,255,.85); border-radius: 28px; background: #fffdfb; box-shadow: 0 20px 55px rgba(48, 25, 70, .3); }
.gallery-card h2 { margin: 0; font-family: "Baloo 2", cursive; font-size: 2rem; }
.gallery-intro { margin: -2px 0 19px; color: #83689c; font-size: .85rem; font-weight: 700; }
.close-gallery { position: absolute; top: 16px; right: 17px; width: 35px; height: 35px; border: 0; border-radius: 50%; color: #815e9d; background: #f0e6f6; font-size: 1.5rem; line-height: 1; cursor: pointer; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 15px; }
.gallery-item { overflow: hidden; border: 2px solid #eadbf1; border-radius: 16px; background: #fff; }
.gallery-item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #fffefa; }
.gallery-item p { margin: 7px 9px 9px; color: #806598; font-size: .68rem; font-weight: 800; text-align: center; }
.gallery-empty { grid-column: 1 / -1; padding: 29px 8px; border: 2px dashed #e4d4ec; border-radius: 18px; color: #9b80ae; text-align: center; font-weight: 800; }

@media (max-width: 900px) { .studio { grid-template-columns: 1fr; } .tool-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 22px; } .tool-group { margin-bottom: 15px; } .action-row { grid-column: 1 / -1; align-self: start; } .save-button, .gallery-button { grid-column: span 1; align-self: start; margin-top: 0; } canvas { height: min(86vw, 600px); } }
@media (max-width: 620px) { .app-shell { width: min(100% - 20px, 1200px); padding-top: 19px; } .hero { margin-bottom: 17px; } .logo-mark { width: 47px; height: 47px; font-size: 25px; } .tool-panel { display: block; padding: 17px; } .tool-group { margin-bottom: 16px; padding-bottom: 16px; } .canvas-card { padding: 10px; border-radius: 22px; } .canvas-topline { padding: 2px 4px 9px; } .canvas-topline p { font-size: .75rem; } .sparkle-count { font-size: .8rem; } canvas { height: 94vw; min-height: 330px; } .gallery-card { padding: 27px 18px 20px; } }
@media (min-width: 901px) and (max-width: 1100px), (min-width: 901px) and (max-height: 750px) {
  html, body { height: 100%; overflow: hidden; }
  .app-shell { display: flex; flex-direction: column; width: min(100% - 24px, 1060px); height: 100dvh; padding: 8px 0; }
  .hero { flex: 0 0 42px; gap: 9px; margin-bottom: 7px; }
  .logo-mark { width: 40px; height: 40px; border-radius: 14px 14px 14px 4px; font-size: 21px; }
  .eyebrow { font-size: .61rem; }
  h1 { font-size: 1.45rem; }
  .icon-button { width: 35px; height: 35px; font-size: 1.02rem; }
  .studio { flex: 1; min-height: 0; grid-template-columns: 280px minmax(0, 1fr); gap: 12px; align-items: stretch; }
  .tool-panel, .canvas-card { height: 100%; overflow: hidden; }
  .tool-panel { padding: 10px; border-radius: 19px; }
  .tool-group { margin-bottom: 3px; padding-bottom: 4px; }
  .tool-label { margin-bottom: 3px; font-size: .63rem; }
  .palette { gap: 5px; }
  .color-button, .custom-color-button { width: 26px; }
  .custom-color-button { height: 26px; }
  .custom-color-option { gap: 2px; margin-top: 2px; font-size: .49rem; }
  .background-palette { gap: 5px; }
  .background-button { width: 19px; height: 19px; }
  .select-wrap select { padding: 6px 25px 6px 7px; font-size: .59rem; }
  .select-wrap::after { right: 10px; width: 6px; height: 6px; }
  .paint-tools { gap: 4px; margin-bottom: 3px; }
  .paint-mode-button { min-height: 27px; padding: 4px 2px; font-size: .57rem; }
  .emoji-palette { gap: 3px; }
  .emoji-button { width: 28px; height: 24px; border-radius: 8px; font-size: .9rem; }
  .action-row { gap: 5px; }
  .secondary-button { padding: 6px 3px; font-size: .64rem; }
  .save-button { margin-top: 5px; padding: 8px; font-size: .7rem; box-shadow: 0 4px 0 #e76e9c, 0 6px 9px rgba(213,84,135,.2); }
  .gallery-button { margin-top: 5px; padding: 6px; font-size: .62rem; }
  .canvas-card { display: flex; flex-direction: column; padding: 9px; border-radius: 20px; }
  .canvas-topline { flex: 0 0 21px; min-height: 21px; padding: 0 2px 5px; }
  .canvas-topline p { font-size: .64rem; }
  .canvas-frame { flex: 1; min-height: 0; }
  canvas { width: 100%; height: 100%; min-height: 0; }
  footer { display: none; }
}

@media (min-width: 1101px) and (min-height: 751px) and (max-height: 950px) {
  html, body { height: 100%; overflow: hidden; }
  .app-shell { display: flex; flex-direction: column; width: min(1400px, calc(100% - 48px)); height: 100dvh; padding: 18px 0; }
  .hero { flex: 0 0 56px; margin-bottom: 12px; }
  .studio { flex: 1; min-height: 0; grid-template-columns: 350px minmax(0, 1fr); gap: 22px; align-items: stretch; }
  .tool-panel, .canvas-card { height: 100%; overflow: hidden; }
  .tool-panel { display: flex; padding: 15px; }
  .tool-group { margin-bottom: 7px; padding-bottom: 7px; }
  .tool-label { margin-bottom: 5px; font-size: .73rem; }
  .palette { gap: 5px; }
  .color-button, .custom-color-button { width: 29px; }
  .custom-color-button { height: 29px; }
  .custom-color-option { margin-top: 3px; font-size: .52rem; }
  .background-palette { gap: 6px; }
  .background-button { width: 22px; height: 22px; }
  .select-wrap select { padding: 8px 27px 8px 8px; font-size: .63rem; }
  .paint-tools { gap: 5px; margin-bottom: 5px; }
  .paint-mode-button { min-height: 31px; padding: 5px 3px; font-size: .61rem; }
  .emoji-palette { gap: 4px; }
  .emoji-button { width: 28px; height: 27px; border-radius: 8px; font-size: .9rem; }
  .action-row { gap: 7px; }
  .secondary-button { padding: 7px 3px; font-size: .68rem; }
  .save-button, .gallery-button { align-self: start; margin-top: 6px; }
  .save-button { padding: 9px; font-size: .74rem; box-shadow: 0 5px 0 #e76e9c, 0 7px 11px rgba(213,84,135,.2); }
  .gallery-button { padding: 8px; font-size: .67rem; }
  .canvas-card { display: flex; flex-direction: column; padding: 13px; }
  .canvas-topline { flex: 0 0 25px; min-height: 25px; padding: 0 3px 8px; }
  .canvas-topline p { font-size: .74rem; }
  .canvas-frame { flex: 1; min-height: 0; }
  canvas { width: 100%; height: 100%; min-height: 0; }
  footer { display: none; }
}

/* Keep the roomy desktop canvas while presenting one calm, consistent tool column. */
@media (min-width: 1101px) and (min-height: 751px) and (max-height: 950px) {
  .studio { grid-template-columns: 330px minmax(0, 1fr); }
  .tool-panel { display: flex; padding: 16px; }
  .tool-group { margin: 0 0 9px; padding: 0 0 9px; }
  .tool-label { margin-bottom: 6px; font-size: .75rem; }
  .palette { gap: 8px; }
  .color-button, .custom-color-button { width: 33px; }
  .custom-color-button { height: 33px; }
  .custom-color-option { margin-top: 5px; font-size: .56rem; }
  .background-palette { gap: 8px; }
  .background-button { width: 24px; height: 24px; }
  .select-wrap select { min-height: 36px; padding: 8px 30px 8px 10px; font-size: .67rem; }
  .paint-tools { gap: 8px; margin-bottom: 7px; }
  .paint-mode-button { min-height: 36px; padding: 7px; font-size: .68rem; }
  .emoji-palette { gap: 5px; }
  .emoji-button { width: 33px; height: 30px; border-radius: 9px; font-size: 1rem; }
  .action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 0; }
  .secondary-button { display: flex; align-items: center; justify-content: center; min-height: 36px; padding: 7px; font-size: .7rem; }
  .save-button, .gallery-button { display: flex; align-items: center; justify-content: center; width: 100%; margin-top: 9px; }
  .save-button { min-height: 42px; padding: 9px; font-size: .78rem; }
  .gallery-button { min-height: 36px; padding: 7px; font-size: .7rem; }
}

/* The app itself always fits the visible desktop/tablet viewport; only the canvas flexes. */
@media (min-width: 901px) {
  html, body { height: 100%; overflow: hidden; }
  .app-shell { display: flex; flex-direction: column; height: 100dvh; }
  .studio { flex: 1; min-height: 0; }
  .tool-panel, .canvas-card { height: 100%; overflow: hidden; }
  .canvas-card { display: flex; flex-direction: column; }
  .canvas-topline { flex: 0 0 auto; }
  .canvas-frame { flex: 1; min-height: 0; }
  canvas { height: 100%; min-height: 0; }
  footer { display: none; }
}

@media (min-width: 621px) {
  .tool-options { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; min-height: 0; }
  .tool-actions { margin-top: 0; }
}

/* Narrow portrait screens need a compact layout so the action controls never fall below the fold. */
@media (max-width: 620px) {
  html, body { height: 100%; overflow: hidden; }
  .app-shell { display: flex; flex-direction: column; width: min(100% - 14px, 620px); height: 100dvh; padding: 7px 0; }
  .hero { flex: 0 0 46px; gap: 8px; margin: 0 3px 6px; }
  .logo-mark { width: 39px; height: 39px; border-radius: 13px 13px 13px 4px; font-size: 21px; }
  .eyebrow { display: none; }
  h1 { font-size: 1.42rem; }
  .icon-button { width: 34px; height: 34px; font-size: 1rem; }
  .studio { flex: 1; min-height: 0; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 7px; }
  .tool-panel { display: flex; padding: 8px; border-radius: 19px; }
  .tool-options { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
  .color-tools, .stamp-tools { grid-column: 1 / -1; }
  .tool-group { margin: 0 0 5px; padding: 0 0 5px; }
  .tool-label { margin-bottom: 3px; font-size: .66rem; }
  .palette { gap: 5px; }
  .color-button, .custom-color-button { width: 28px; }
  .custom-color-button { height: 28px; }
  .custom-color-option { margin-top: 2px; font-size: .5rem; }
  .background-palette { gap: 4px; }
  .background-button { width: 20px; height: 20px; }
  .select-wrap select { min-height: 30px; padding: 6px 24px 6px 7px; font-size: .58rem; }
  .paint-tools { gap: 6px; margin-bottom: 4px; }
  .paint-mode-button { min-height: 29px; padding: 5px; font-size: .6rem; }
  .emoji-palette { gap: 4px; }
  .emoji-button { width: 29px; height: 25px; font-size: .88rem; }
  .tool-actions { margin-top: 2px; }
  .action-row { gap: 6px; }
  .secondary-button { display: flex; align-items: center; justify-content: center; min-height: 29px; padding: 5px; font-size: .62rem; }
  .save-button { display: flex; align-items: center; justify-content: center; min-height: 35px; margin-top: 5px; padding: 7px; font-size: .68rem; }
  .gallery-button { display: flex; align-items: center; justify-content: center; min-height: 29px; margin-top: 5px; padding: 5px; font-size: .62rem; }
  .canvas-card { display: flex; flex-direction: column; min-height: 0; height: auto; padding: 8px; border-radius: 19px; }
  .canvas-topline { flex: 0 0 19px; min-height: 19px; padding: 0 2px 4px; }
  .canvas-topline p { font-size: .6rem; }
  .canvas-frame { flex: 1; min-height: 0; }
  canvas { width: 100%; height: 100%; min-height: 0; }
  footer { display: none; }
}
