:root {
  --ink: #253047;
  --muted: #667085;
  --paper: #fffefa;
  --cream: #fff8e8;
  --line: #e7dfcf;
  --coral: #ed655b;
  --coral-dark: #d94e45;
  --teal: #237a70;
  --yellow: #f4c85d;
  --shadow: 0 20px 55px rgba(71, 56, 32, .12);
  --soft-shadow: 0 8px 24px rgba(71, 56, 32, .09);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at 8% 8%, rgba(244, 200, 93, .24) 0 2px, transparent 3px),
    radial-gradient(circle at 92% 18%, rgba(35, 122, 112, .15) 0 2px, transparent 3px),
    var(--cream);
  background-size: 38px 38px, 52px 52px, auto;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.shell {
  width: min(1060px, calc(100% - 32px));
  margin: 0 auto;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.masthead { height: 88px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; }
.brand { color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 10px; font-family: "Fredoka", sans-serif; font-size: 21px; font-weight: 700; letter-spacing: -.03em; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; color: white; background: var(--coral); border-radius: 11px 16px 12px 15px; transform: rotate(-5deg); }
.mode-switch { display: flex; padding: 4px; background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 999px; }
.mode { border: 0; border-radius: 999px; padding: 9px 16px; background: transparent; color: var(--muted); font-weight: 800; cursor: pointer; transition: 160ms ease; }
.mode.active { background: var(--ink); color: white; box-shadow: 0 3px 10px rgba(37,48,71,.18); }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.language-picker { position: relative; display: flex; align-items: center; color: var(--teal); }
.language-picker svg { position: absolute; z-index: 1; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.language-icon { inset-inline-start: 11px; }
.language-chevron { inset-inline-end: 9px; }
.language-picker select { width: 132px; min-height: 42px; appearance: none; padding: 8px 31px 8px 35px; border: 1px solid #d8d0c2; border-radius: 13px; color: var(--ink); background: rgba(255,255,255,.92); box-shadow: var(--soft-shadow); font-size: 13px; font-weight: 900; cursor: pointer; direction: ltr; }
.language-picker select:hover { background: white; border-color: #c9ded8; }
.install-button { min-height: 42px; padding: 9px 15px; border: 1px solid #d8d0c2; border-radius: 999px; color: var(--teal); background: white; font-size: 14px; font-weight: 900; box-shadow: var(--soft-shadow); cursor: pointer; }
.mode:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 4px solid rgba(35, 122, 112, .25); outline-offset: 3px; }

.studio, .result { width: min(820px, 100%); margin: 22px auto 70px; }
.intro { text-align: center; max-width: 680px; margin: 0 auto 28px; }
.eyebrow, .challenge-label { color: var(--coral-dark); font-size: 12px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
h1, h2 { margin: 8px 0 12px; font-family: "Fredoka", sans-serif; letter-spacing: -.045em; line-height: .98; }
h1 { font-size: clamp(42px, 7vw, 72px); }
h2 { font-size: clamp(34px, 5vw, 54px); }
.lede { max-width: 570px; margin: 0 auto; color: var(--muted); font-size: 18px; line-height: 1.55; }

.challenge, .own-idea { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 17px 18px 17px 22px; margin-bottom: 16px; background: #fff2d2; border: 1px solid #eed69e; border-radius: 18px; box-shadow: var(--soft-shadow); }
.challenge strong { display: block; margin-top: 2px; font-family: "Fredoka", sans-serif; font-size: clamp(19px, 3vw, 25px); letter-spacing: -.02em; }
.round-button { flex: 0 0 auto; width: 44px; height: 44px; border: 0; border-radius: 50%; color: white; background: var(--teal); font-size: 25px; cursor: pointer; transition: transform 150ms ease, background 150ms ease; }
.round-button:hover { background: #1c685f; transform: rotate(-12deg); }
.own-idea { display: block; background: white; border-color: var(--line); }
.own-idea label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.own-idea input { width: 100%; padding: 6px 0; border: 0; border-bottom: 2px solid var(--line); outline: 0; color: var(--ink); font-family: "Fredoka", sans-serif; font-size: 22px; background: transparent; }
.own-idea input:focus { border-color: var(--teal); }

.paper-wrap { position: relative; padding: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.paper-topline { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 12px; padding: 0 3px 12px; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.source-switch { display: flex; flex: 0 0 auto; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: #f8f5ee; }
.source-option { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 6px 10px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 900; letter-spacing: .02em; text-transform: none; cursor: pointer; transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease; }
.source-option svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.source-option.active { color: var(--ink); background: white; box-shadow: 0 2px 7px rgba(71,56,32,.12); }
.source-option:disabled { cursor: wait; opacity: .55; }
.paper-actions { display: flex; align-items: center; gap: 7px; }
.history-actions { display: flex; align-items: center; gap: 3px; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 10px; color: var(--teal); background: transparent; cursor: pointer; transition: background 150ms ease, color 150ms ease, opacity 150ms ease; }
.icon-button:hover:not(:disabled) { background: #eaf5f1; }
.icon-button:disabled { color: #aaa398; cursor: not-allowed; opacity: .5; }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.text-button { border: 0; padding: 5px; color: var(--coral-dark); background: transparent; font-size: 13px; font-weight: 800; cursor: pointer; }
.text-button:disabled { cursor: not-allowed; opacity: .45; }
.replay-button { display: flex; align-items: center; gap: 5px; min-height: 38px; padding: 7px 10px; border: 1px solid #f1c4bf; border-radius: 11px; color: var(--coral-dark); background: #fff0ed; font-size: 12px; font-weight: 900; cursor: pointer; transition: background 150ms ease, color 150ms ease, transform 150ms ease, opacity 150ms ease; }
.replay-button:hover:not(:disabled) { background: #ffe2de; transform: translateY(-1px); }
.replay-button[aria-pressed="true"] { color: white; background: var(--coral); border-color: var(--coral); }
.replay-button:disabled { cursor: not-allowed; opacity: .4; }
.replay-button svg { width: 17px; height: 17px; fill: currentColor; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.replay-button .replay-stop-icon { display: none; fill: none; stroke-width: 2.6; stroke-linecap: round; }
.replay-button[aria-pressed="true"] .replay-play-icon { display: none; }
.replay-button[aria-pressed="true"] .replay-stop-icon { display: block; }
.expand-button { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 7px 11px; border: 1px solid #c9ded8; border-radius: 11px; color: var(--teal); background: #eaf5f1; font-size: 12px; font-weight: 900; letter-spacing: 0; text-transform: none; cursor: pointer; transition: background 150ms ease, transform 150ms ease; }
.expand-button:hover { background: #dceee8; transform: translateY(-1px); }
.expand-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.expand-button .collapse-icon { display: none; }
.expand-button[aria-pressed="true"] .expand-icon { display: none; }
.expand-button[aria-pressed="true"] .collapse-icon { display: block; }
#drawing { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; border-radius: 14px; background: white; background-image: radial-gradient(#e6e1d8 1.3px, transparent 1.3px); background-size: 22px 22px; box-shadow: inset 0 0 0 1px #eee8dc; cursor: crosshair; touch-action: none; }
.studio.photo-mode #drawing { background-image: none; cursor: default; box-shadow: inset 0 0 0 2px #c9ded8; }
.photo-empty { position: absolute; inset: 62px 16px 16px; display: flex; align-items: center; justify-content: center; border: 2px dashed #bfddd4; border-radius: 14px; background: rgba(231,244,239,.92); }
.photo-empty button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 52px; padding: 13px 19px; border: 1px solid #9bcdbf; border-radius: 14px; color: var(--teal); background: white; box-shadow: var(--soft-shadow); font-weight: 900; cursor: pointer; transition: transform 150ms ease, background 150ms ease; }
.photo-empty button:hover { background: #f4fffb; transform: translateY(-2px); }
.photo-empty svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.photo-frame-action { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 34px; padding: 6px 9px; border: 1px solid #bfddd4; border-radius: 10px; color: var(--teal); background: #e7f4ef; font-size: 11px; font-weight: 900; cursor: pointer; }
.photo-frame-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.studio.photo-mode .toolbox { display: none; }
.replay-overlay { position: absolute; inset: 63px 16px 16px; z-index: 2; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
.replay-panel { width: min(430px, 100%); padding: 12px 15px 13px; border: 1px solid rgba(237,101,91,.35); border-radius: 15px; background: rgba(255,254,250,.94); box-shadow: 0 10px 28px rgba(71,56,32,.15); backdrop-filter: blur(6px); }
.replay-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.replay-heading strong { overflow: hidden; color: var(--ink); font-family: "Fredoka", sans-serif; font-size: 15px; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.replay-heading > span:last-child { margin-inline-start: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 900; white-space: nowrap; }
.replay-mark { display: grid; place-items: center; flex: 0 0 auto; width: 25px; height: 25px; color: white; background: var(--coral); border-radius: 8px 10px 8px 9px; font-size: 15px; animation: replay-pulse 900ms ease-in-out infinite alternate; }
.replay-progress { height: 6px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: #f4d8d3; }
.replay-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--coral); transition: width 80ms linear; }

.toolbox { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: min(600px, calc(100% - 20px)); margin: -2px auto 24px; padding: 14px 18px; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 0 0 20px 20px; box-shadow: var(--soft-shadow); }
.colors, .sizes { display: flex; align-items: center; gap: 11px; }
.swatch { width: 34px; height: 34px; padding: 0; border: 3px solid white; border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px #d8d2c8; cursor: pointer; transition: transform 150ms ease, box-shadow 150ms ease; }
.swatch.selected { transform: translateY(-3px) scale(1.08); box-shadow: 0 0 0 3px var(--ink); }
.swatch.eraser { display: flex; place-items: center; justify-content: center; color: var(--ink); font-weight: 900; background: white; }
.swatch.eraser svg { width: 24px; height: 24px; fill: #f4b0aa; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.swatch.eraser span { display: none; pointer-events: none; }
.sizes { padding-inline-start: 17px; border-inline-start: 1px solid var(--line); }
.size { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.size i { display: block; width: 7px; height: 7px; border-radius: 50%; background: #9b9488; }
.size:nth-child(2) i { width: 12px; height: 12px; }
.size:nth-child(3) i { width: 19px; height: 19px; }
.size.selected { background: #ebe7df; }
.size.selected i { background: var(--ink); }

.magic-actions { display: flex; flex-wrap: wrap; align-items: stretch; justify-content: center; gap: 14px; width: min(650px, 100%); margin: 0 auto; }
.style-toggle { flex: 0 0 128px; display: grid; place-content: center; gap: 3px; min-height: 58px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 16px; color: var(--teal); background: rgba(255,255,255,.94); box-shadow: var(--soft-shadow); text-align: start; cursor: pointer; transition: transform 150ms ease, color 150ms ease, background 150ms ease; }
.style-toggle span { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .12em; line-height: 1; text-transform: uppercase; }
.style-toggle strong { font-family: "Fredoka", sans-serif; font-size: 16px; line-height: 1.1; }
.style-toggle[aria-pressed="true"] { color: #8d5422; background: #fff2d2; border-color: #eed69e; }
.style-toggle:hover { transform: translateY(-2px); }
.style-toggle:disabled { cursor: wait; opacity: .62; transform: none; }
.create-button, .secondary-button { border: 0; border-radius: 16px; padding: 17px 24px; font-weight: 900; cursor: pointer; transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease; }
.create-button { display: flex; justify-content: center; align-items: center; gap: 14px; width: min(410px, 100%); margin: 0 auto; color: white; background: var(--coral); box-shadow: 0 8px 0 #bf453e, 0 17px 28px rgba(191,69,62,.20); font-family: "Fredoka", sans-serif; font-size: 21px; }
.magic-actions .create-button { flex: 1 1 380px; }
.create-button b { font-size: 19px; }
.create-button:hover { background: #f16f66; transform: translateY(-2px); box-shadow: 0 10px 0 #bf453e, 0 20px 30px rgba(191,69,62,.23); }
.create-button:active { transform: translateY(5px); box-shadow: 0 3px 0 #bf453e; }
.create-button:disabled { cursor: wait; filter: grayscale(.2); opacity: .7; }
.privacy-note { margin: 18px 0 0; text-align: center; color: #8a8378; font-size: 13px; }

.result { margin-top: 38px; animation: appear 400ms ease both; }
.result-heading { text-align: center; margin-bottom: 30px; }
.art-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: stretch; }
.art-card { position: relative; display: flex; flex-direction: column; min-width: 0; margin: 0; padding: 12px; background: white; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--soft-shadow); }
.art-card figcaption { padding: 4px 4px 12px; color: var(--muted); font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.art-media { width: 100%; height: auto; overflow: hidden; aspect-ratio: 3 / 2; border-radius: 13px; background: #f8f5ee; }
.art-card img { display: block; width: 100%; height: 100%; border-radius: inherit; object-fit: contain; }
.magic-card { border-color: #efbb75; transform: rotate(1deg); box-shadow: 0 0 0 2px #efbb75, var(--shadow); }
.magic-card figcaption { color: var(--coral-dark); }
.spark { position: absolute; z-index: 2; color: var(--yellow); font-size: 28px; filter: drop-shadow(0 2px 0 white); }
.spark-one { top: -17px; right: 26px; }.spark-two { bottom: 8px; left: -16px; font-size: 38px; }
.story-card { display: flex; align-items: center; gap: 20px; margin: 28px 0; padding: 22px 25px; background: #e7f4ef; border: 1px solid #bfddd4; border-radius: 20px; }
.story-icon { flex: 0 0 auto; display: grid; place-items: center; width: 53px; height: 53px; color: white; background: var(--teal); border-radius: 15px 20px 17px 22px; font-size: 28px; transform: rotate(-5deg); }
.story-card p { margin: 5px 0 0; font-size: 18px; line-height: 1.5; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.secondary-button { background: white; border: 1px solid var(--line); box-shadow: var(--soft-shadow); }
.secondary-button:hover { transform: translateY(-2px); background: #fffdf8; }
.task-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; color: var(--teal); text-decoration: none; }
.task-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pdf-button { display: flex; align-items: center; justify-content: center; gap: 9px; }
.pdf-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.create-button.compact { width: auto; margin: 0; padding: 15px 24px; font-family: "Nunito", sans-serif; font-size: 16px; }

.overlay, .dialog-backdrop { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 20px; background: rgba(255,248,232,.9); backdrop-filter: blur(9px); }
.overlay strong { margin-top: 18px; font-family: "Fredoka", sans-serif; font-size: 28px; }
.overlay p { margin: 7px 0; color: var(--muted); }
.loader-orbit { position: relative; display: grid; place-items: center; width: 88px; height: 88px; border: 3px dashed var(--coral); border-radius: 50%; animation: spin 2.4s linear infinite; }
.loader-orbit span { color: var(--teal); font-size: 34px; animation: spin 2.4s linear infinite reverse; }
.dialog-backdrop { z-index: 30; background: rgba(37,48,71,.42); }
.dialog-card { width: min(430px, 100%); padding: 30px; text-align: center; background: var(--paper); border-radius: 24px; box-shadow: var(--shadow); }
.dialog-mark { display: grid; place-items: center; width: 55px; height: 55px; margin: 0 auto 15px; border-radius: 50%; color: white; background: var(--coral); font-family: "Fredoka", sans-serif; font-size: 30px; }
.dialog-card h2 { font-size: 32px; }
.dialog-card p { color: var(--muted); line-height: 1.55; }
.photo-backdrop { position: fixed; inset: 0; z-index: 35; display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; background: rgba(37,48,71,.56); backdrop-filter: blur(9px); }
.photo-source-card, .crop-card { position: relative; width: min(560px, 100%); padding: 28px; background: var(--paper); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); animation: appear 220ms ease both; }
.photo-source-card { text-align: center; }
.photo-source-card h2, .crop-card h2 { margin: 0; font-size: 30px; letter-spacing: 0; line-height: 1.1; }
.photo-source-card > p, .crop-heading p { margin: 8px 0 22px; color: var(--muted); line-height: 1.45; }
.modal-close { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: #eee8dc; cursor: pointer; }
.photo-source-card > .modal-close { position: absolute; top: 16px; inset-inline-end: 16px; }
.modal-close:hover { color: var(--ink); background: #e5ded1; }
.modal-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.photo-source-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.photo-source-button { display: flex; min-width: 0; min-height: 112px; padding: 18px 12px; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border: 1px solid #bfddd4; border-radius: 16px; color: var(--teal); background: #e7f4ef; font-weight: 900; cursor: pointer; transition: transform 150ms ease, background 150ms ease; }
.photo-source-button:hover { background: #d9eee7; transform: translateY(-2px); }
.photo-source-button svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.crop-card { width: min(780px, 100%); }
.crop-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.crop-heading p { margin-bottom: 16px; }
.crop-stage { position: relative; width: 100%; overflow: hidden; aspect-ratio: 3 / 2; border-radius: 14px; background: #141922; box-shadow: 0 0 0 1px rgba(37,48,71,.18); }
#photo-crop-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#photo-crop-canvas:active { cursor: grabbing; }
.crop-ratio { position: absolute; inset-inline-end: 10px; bottom: 10px; padding: 4px 7px; border-radius: 7px; color: white; background: rgba(20,25,34,.75); font-size: 11px; font-weight: 900; pointer-events: none; }
.zoom-control { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 9px; min-height: 50px; margin-top: 12px; color: var(--muted); font-size: 13px; font-weight: 900; }
.zoom-control svg { width: 19px; height: 19px; fill: none; stroke: var(--teal); stroke-width: 2; stroke-linecap: round; }
.zoom-control input { width: 100%; accent-color: var(--teal); cursor: pointer; }
.crop-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 10px; }
.crop-actions .secondary-button, .crop-actions .create-button { margin: 0; min-height: 52px; }
#confetti { position: fixed; inset: 0; z-index: 25; width: 100%; height: 100%; pointer-events: none; }
.install-tip { position: fixed; inset-inline-end: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 18; display: flex; align-items: center; gap: 12px; width: min(360px, calc(100% - 36px)); padding: 12px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,254,250,.97); box-shadow: var(--shadow); }
.install-tip img { flex: 0 0 auto; border-radius: 12px; }
.install-tip p { display: grid; gap: 2px; margin: 0; line-height: 1.3; }
.install-tip strong { font-family: "Fredoka", sans-serif; }
.install-tip span { color: var(--muted); font-size: 13px; }
.install-tip button { align-self: flex-start; width: 32px; height: 32px; margin-inline-start: auto; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: #eee8dc; font-size: 22px; cursor: pointer; }

html[dir="rtl"] body, html[dir="rtl"] button, html[dir="rtl"] input, html[dir="rtl"] select { font-family: "Noto Sans Arabic", "Nunito", sans-serif; }
html[dir="rtl"] h1, html[dir="rtl"] h2, html[dir="rtl"] .brand, html[dir="rtl"] .challenge strong, html[dir="rtl"] .create-button, html[dir="rtl"] .style-toggle strong, html[dir="rtl"] .overlay strong, html[dir="rtl"] .install-tip strong { font-family: "Noto Sans Arabic", "Nunito", sans-serif; letter-spacing: 0; }
html[dir="rtl"] h1, html[dir="rtl"] h2 { line-height: 1.18; }
html[dir="rtl"] .eyebrow, html[dir="rtl"] .challenge-label, html[dir="rtl"] .paper-topline, html[dir="rtl"] .own-idea label, html[dir="rtl"] .style-toggle span, html[dir="rtl"] .art-card figcaption { letter-spacing: 0; }
html[dir="rtl"] .brand-mark, html[dir="rtl"] .story-icon { transform: rotate(5deg); }
html[lang^="zh"] .eyebrow, html[lang^="zh"] .challenge-label, html[lang^="zh"] .paper-topline, html[lang^="zh"] .own-idea label, html[lang^="zh"] .style-toggle span, html[lang^="zh"] .art-card figcaption { letter-spacing: .06em; }

/* Urdu reads right-to-left, but the canvas remains the visual work surface.
   Keep it on the left so the guidance and actions follow the reading order. */
@media (min-width: 900px) {
  html[dir="rtl"] .studio {
    grid-template-areas:
      "intro paper"
      "challenge paper"
      "create paper"
      "privacy tools";
  }
  html[dir="rtl"] .intro h1 { max-width: 12ch; }
  html[dir="rtl"] .intro .lede { max-width: 32ch; }
}

body.drawing-expanded { overflow: hidden; }
body.drawing-expanded .paper-wrap { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(94px, calc(80px + env(safe-area-inset-bottom))) max(16px, env(safe-area-inset-left)); border: 0; border-radius: 0; background: var(--cream); box-shadow: none; }
body.drawing-expanded .paper-topline { flex: 0 0 auto; min-height: 48px; padding: 0 2px 10px; }
body.drawing-expanded .paper-topline > span { font-family: "Fredoka", sans-serif; font-size: 18px; letter-spacing: -.01em; text-transform: none; }
body.drawing-expanded #drawing { flex: 1 1 auto; min-height: 0; height: auto !important; aspect-ratio: auto; border-radius: 18px; box-shadow: inset 0 0 0 2px #e6ddcd, var(--soft-shadow); }
body.drawing-expanded .toolbox { position: fixed; z-index: 61; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); width: min(720px, calc(100% - 24px)); margin: 0; padding: 10px 14px; border-radius: 18px; transform: translateX(-50%); }
body.drawing-expanded .swatch, body.drawing-expanded .size { width: 48px; height: 48px; }
body.drawing-expanded .swatch.eraser { width: auto; min-width: 104px; padding: 0 13px; border-radius: 15px; gap: 7px; }
body.drawing-expanded .swatch.eraser span { display: inline; font-size: 14px; }
body.drawing-expanded .expand-button { min-height: 42px; padding-inline: 14px; color: white; background: var(--teal); }
body.drawing-expanded .expand-button:hover { background: #1c685f; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes appear { from { opacity: 0; transform: translateY(12px); } }
@keyframes replay-pulse { from { transform: rotate(-7deg) scale(.94); } to { transform: rotate(7deg) scale(1.04); } }

@media (max-width: 650px) {
  .shell { width: min(100% - 20px, 820px); }
  .masthead { min-height: 112px; height: auto; padding-block: 10px; grid-template-columns: 1fr auto; grid-template-areas: "brand actions" "mode mode"; gap: 8px 12px; }
  .brand { grid-area: brand; justify-self: start; }
  .brand span:last-child { display: none; }
  .mode-switch { grid-area: mode; justify-self: center; }
  .mode { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
  .header-actions { grid-area: actions; justify-self: end; gap: 5px; }
  .language-picker select { width: 100px; min-height: 40px; padding-inline: 30px 24px; font-size: 12px; }
  .language-icon { inset-inline-start: 9px; }
  .language-chevron { inset-inline-end: 7px; }
  .install-button { min-height: 40px; padding-inline: 9px; font-size: 12px; }
  .studio { margin-top: 12px; }
  .intro { margin-bottom: 21px; }
  .lede { font-size: 16px; }
  .toolbox { width: calc(100% - 12px); padding: 12px 10px; gap: 8px; }
  .colors { gap: 5px; }.swatch, .size { width: 30px; height: 30px; }
  .sizes { gap: 2px; padding-inline-start: 8px; }
  .art-grid { grid-template-columns: 1fr; }
  .magic-card { transform: none; }
  .result-actions { flex-direction: column-reverse; }
  .result-actions button, .result-actions .task-button { width: 100%; }
  .story-card { align-items: flex-start; padding: 18px; }
  .magic-actions { gap: 9px; }
  .magic-actions .create-button { flex-basis: auto; width: auto; padding-inline: 15px; font-size: 18px; }
  .style-toggle { flex-basis: 105px; padding-inline: 9px; }
  .style-toggle strong { font-size: 14px; }
  .paper-topline { align-items: flex-start; }
  .paper-topline { flex-wrap: wrap; }
  .paper-actions { gap: 3px; margin-inline-start: auto; }
  .icon-button { width: 32px; height: 32px; }
  .expand-button { padding-inline: 8px; }
  .replay-button { padding-inline: 8px; }
  .replay-button span { display: none; }
  .expand-label { display: none; }
  body.drawing-expanded .expand-label { display: inline; }
  body.drawing-expanded .paper-wrap { padding-bottom: max(144px, calc(132px + env(safe-area-inset-bottom))); }
  body.drawing-expanded .toolbox { flex-wrap: wrap; justify-content: center; row-gap: 5px; padding: 8px; }
  body.drawing-expanded .colors { gap: 5px; }
  body.drawing-expanded .swatch, body.drawing-expanded .size { width: 40px; height: 40px; }
  body.drawing-expanded .swatch.eraser { min-width: 46px; padding: 0 9px; border-radius: 12px; }
  body.drawing-expanded .swatch.eraser span { display: none; }
  body.drawing-expanded .sizes { flex-basis: 100%; justify-content: center; padding: 4px 0 0; border-top: 1px solid var(--line); border-inline-start: 0; }
  .photo-backdrop { align-items: flex-end; padding: 10px 10px max(10px, env(safe-area-inset-bottom)); }
  .photo-source-card, .crop-card { padding: 20px; border-radius: 20px; }
  .photo-source-card h2, .crop-card h2 { padding-inline-end: 34px; font-size: 25px; }
  .photo-source-actions { grid-template-columns: 1fr; }
  .photo-source-button { min-height: 72px; flex-direction: row; }
  .crop-card { max-height: calc(100dvh - 20px - env(safe-area-inset-bottom)); overflow-y: auto; }
  .crop-heading p { margin-top: 5px; font-size: 13px; }
  .crop-actions { display: grid; grid-template-columns: .8fr 1.2fr; }
  .crop-actions button { width: 100%; padding-inline: 12px; }
  .crop-actions .create-button { font-size: 15px; }
}

@media (min-width: 700px) and (max-width: 1180px) {
  .shell { width: min(100% - 40px, 1060px); }
  .mode, .install-button { min-height: 46px; padding-inline: 18px; }
  .round-button { width: 50px; height: 50px; }
  .swatch, .size { width: 44px; height: 44px; }
  .swatch { border-width: 4px; }
  .create-button, .secondary-button { min-height: 58px; }
}

@media (min-width: 900px) {
  .shell { width: min(100% - 40px, 1180px); }
  .masthead { height: 68px; }
  .studio {
    display: grid;
    grid-template-columns: minmax(300px, .72fr) minmax(520px, 1.28fr);
    grid-template-areas:
      "intro paper"
      "challenge paper"
      "create paper"
      "privacy tools";
    gap: 14px 22px;
    align-items: start;
    width: 100%;
    margin: 4px auto 28px;
  }
  .intro { grid-area: intro; margin: 10px 0 0; text-align: start; }
  .intro .eyebrow { margin-top: 0; }
  .intro h1 { max-width: 9ch; margin-block: 8px 10px; font-size: clamp(43px, 4.7vw, 62px); }
  .intro .lede { margin: 0; font-size: 16px; }
  .challenge, .own-idea { grid-area: challenge; margin: 0; }
  .paper-wrap { grid-area: paper; align-self: stretch; }
  #drawing { height: auto; aspect-ratio: 3 / 2; }
  .toolbox { grid-area: tools; width: 100%; margin: -8px 0 0; border-radius: 0 0 20px 20px; }
  .magic-actions { grid-area: create; align-self: end; width: 100%; }
  .magic-actions .create-button { width: 100%; }
  .style-toggle { flex-basis: 112px; }
  .privacy-note { grid-area: privacy; margin: 5px 0 0; text-align: start; }
  .result { width: min(980px, 100%); margin-top: 18px; }
  .result-heading { margin-bottom: 20px; }
  .result-heading h2 { font-size: 46px; }
  .story-card { margin-block: 20px; }
}

@media (display-mode: standalone) {
  .masthead { padding-top: env(safe-area-inset-top); min-height: calc(82px + env(safe-area-inset-top)); height: auto; }
  .privacy-note { padding-bottom: env(safe-area-inset-bottom); }
}

@media (display-mode: standalone) and (max-width: 650px) {
  .masthead { min-height: calc(112px + env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
