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

:root {
  color-scheme: light;
  --ink: #414a64;
  --muted: #8791a8;
  --paper: #fffdf7;
  --paper-deep: #f7f0df;
  --line: #d8d4e5;
  --purple: #8174be;
  --purple-soft: #ece9fb;
  --coral: #f07a70;
  --mint: #a8e1ce;
  --yellow: #f6cf67;
  --shadow: #d8cfbf;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; margin: 0; overscroll-behavior: none; }
body { color: var(--ink); background: #dcece7; font-family: Nunito, sans-serif; }
button { font: inherit; }

.game-shell {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  width: min(100%, 960px);
  min-height: 100dvh;
  margin: auto;
  padding: max(22px, env(safe-area-inset-top)) clamp(18px, 5vw, 58px) max(18px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: linear-gradient(135deg, #f5eddb 0%, #f7f2e7 48%, #e9f4ee 100%);
}

.game-shell::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  opacity: .55;
  background: repeating-linear-gradient(0deg, transparent 0 31px, rgba(176, 206, 217, .34) 32px 33px, transparent 34px 35px);
  pointer-events: none;
}

.game-shell::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  opacity: .25;
  background-image: radial-gradient(circle at 18% 17%, #fff 0 1px, transparent 1.5px), radial-gradient(circle at 72% 69%, #b19c76 0 1px, transparent 1.5px);
  background-size: 19px 23px, 27px 31px;
  pointer-events: none;
}

.paper-doodle { position: absolute; z-index: -1; color: #ffadc7; font: 47px/1 'Patrick Hand', cursive; opacity: .55; }
.doodle-one { top: 13%; left: 3%; transform: rotate(-14deg); }
.doodle-two { right: 4%; bottom: 13%; color: #a896e8; transform: rotate(15deg); }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 34px; }
.brand { display: flex; align-items: center; gap: 8px; color: #69738d; font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.brand-mark { color: var(--coral); font: 25px/1 'Patrick Hand', cursive; transform: rotate(-15deg); }
.xp-total { display: flex; align-items: center; gap: 9px; padding: 7px 11px; border: 1.5px solid #d7d2e8; border-radius: 12px 15px 11px 14px; background: rgba(255, 253, 247, .82); box-shadow: 2px 3px 0 rgba(196, 187, 171, .45); transform: rotate(1deg); }
.xp-total span, .eyebrow { color: #9994b8; font: 500 9px/1 'DM Mono', monospace; letter-spacing: .14em; }
.xp-total strong { color: var(--purple); font: 800 16px/1 Nunito, sans-serif; letter-spacing: .05em; }

.prompt-area { margin-top: clamp(28px, 5.5vh, 63px); text-align: center; }
.prompt-copy { display: grid; gap: 5px; }
.prompt-copy .eyebrow { margin: 0; }
h1 { margin: 0; color: #4c5671; font: 500 clamp(37px, 6vw, 58px)/.9 'Patrick Hand', cursive; letter-spacing: .01em; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.target-wrap { position: relative; display: grid; place-items: center; width: min(220px, 58vw); height: min(180px, 24vh); min-height: 145px; margin: 14px auto 2px; }
.target-wrap::before { content: ''; position: absolute; inset: 11px 14px 5px; border: 2px dashed #d9d4e9; border-radius: 47% 53% 49% 51%; background: rgba(255, 253, 247, .53); transform: rotate(-3deg); }
.target-label { position: absolute; top: 0; color: #b1aac8; font: 10px 'Patrick Hand', cursive; transform: rotate(-4deg); }
.target-wrap svg { position: relative; z-index: 1; width: min(142px, 37vw); height: min(142px, 37vw); overflow: visible; }
.target-shape { fill: var(--shape-color, var(--purple)); fill-opacity: .16; stroke: var(--shape-color, var(--purple)); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; transition: stroke .3s, fill .3s; }
.target-shape.open { fill: none; }  /* an open path (the spiral) has no sensible fill */
.target-wrap.shape-arrive svg { animation: target-arrive .62s cubic-bezier(.2, .8, .2, 1); }
.target-wrap.shape-arrive::before { animation: target-halo .62s ease-out; }

.timer-wrap { width: min(620px, 100%); margin: clamp(22px, 3.2vh, 33px) auto 13px; }
.timer-meta { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; color: #aaa4bc; font: 10px 'DM Mono', monospace; }
.timer-meta strong { color: var(--coral); font-size: 13px; font-weight: 500; }
.timer-track { height: 12px; padding: 2px; overflow: hidden; border: 1.5px solid #d5d0e2; border-radius: 99px; background: rgba(255, 253, 247, .72); transform: rotate(-.25deg); }
.timer-fill { width: 100%; height: 100%; border-radius: inherit; background: repeating-linear-gradient(105deg, #9fdec9 0 13px, #b9ead8 14px 20px); transform: scaleX(1); transform-origin: left center; }

.canvas-panel { position: relative; flex: 1; width: min(760px, 100%); min-height: clamp(275px, 45vh, 540px); margin: 0 auto; overflow: hidden; border: 2px solid #cbc7df; border-radius: 20px 26px 19px 25px; background-color: var(--paper); background-image: linear-gradient(90deg, transparent 49px, rgba(240, 122, 112, .25) 50px, rgba(240, 122, 112, .25) 51px, transparent 52px), repeating-linear-gradient(0deg, transparent 0 34px, #e4f0f5 35px 36px, transparent 37px 38px); box-shadow: 5px 6px 0 var(--shadow), 0 12px 25px rgba(90, 83, 72, .1); touch-action: none; }
.canvas-panel::after { content: ''; position: absolute; inset: 8px; border: 1px solid rgba(129, 116, 190, .16); border-radius: 13px 17px 12px 16px; pointer-events: none; }
.canvas-panel.drawing { border-color: var(--shape-color, var(--purple)); box-shadow: 5px 6px 0 var(--shadow), 0 0 0 4px rgba(129, 116, 190, .12); }
.canvas-panel.success { animation: success-breathe .55s ease; }
.canvas-panel.fail { animation: fail-shake .5s ease; }
#drawingCanvas { position: absolute; inset: 0; z-index: 2; display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; }
.canvas-guide { position: absolute; z-index: 1; top: 50%; left: 50%; display: grid; gap: 2px; color: #aeb9c9; text-align: center; pointer-events: none; transform: translate(-50%, -50%) rotate(-2deg); transition: opacity .2s; }
.canvas-guide span { font: 23px/1 'Patrick Hand', cursive; white-space: nowrap; }
.canvas-guide small { color: #c0c8d5; font: 9px 'DM Mono', monospace; letter-spacing: .08em; }
.drawing .canvas-guide { opacity: 0; }
.falling-layer { position: absolute; z-index: 3; inset: 0; overflow: visible; pointer-events: none; }
.falling-shape { position: absolute; overflow: visible; filter: drop-shadow(2px 4px 1px rgba(66, 74, 99, .18)); transform-origin: center; animation: drop-shape 1.38s cubic-bezier(.18, .65, .35, 1) forwards; }
.falling-shape .crayon { fill: var(--crayon); fill-opacity: .94; stroke: var(--crayon); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.falling-shape .crayon.open { fill: none; stroke-width: 6; }

.feedback { position: absolute; z-index: 5; top: 49%; left: 50%; display: grid; gap: 3px; opacity: 0; text-align: center; pointer-events: none; transform: translate(-50%, -50%) rotate(-3deg) scale(.6); }
.feedback.show { animation: feedback-float 1.08s ease-out forwards; }
.feedback.fail-feedback.show { animation: fail-stamp .88s cubic-bezier(.2, .75, .25, 1) forwards; }
.grade-mark { position: relative; display: grid; place-items: center; }
/* A teacher's pen loop around the mark: sized to sit clear of the letter, drawn
   on the moment the feedback appears via the stroke-dash animation below. */
.grade-circle { position: absolute; left: 50%; top: 50%; width: clamp(120px, 25vw, 190px); height: clamp(100px, 21vw, 158px); transform: translate(-50%, -53%) rotate(-4deg); overflow: visible; pointer-events: none; }
.grade-circle path { fill: none; stroke: var(--pen, var(--coral)); stroke-width: 4.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 400; stroke-dashoffset: 400; }
.feedback.show .grade-circle path { animation: grade-scribble .48s ease-out .14s forwards; }
.feedback-word { position: relative; z-index: 1; color: var(--pen, var(--coral)); font: 800 clamp(46px, 9vw, 72px)/.8 'Patrick Hand', cursive; letter-spacing: .01em; text-shadow: 2px 2px 0 #fff; }
.fail-feedback .grade-circle { width: clamp(158px, 34vw, 250px); height: clamp(132px, 28vw, 208px); }
.fail-feedback .grade-circle path { stroke-width: 5.6; }
.fail-feedback .feedback-word { font-size: clamp(70px, 15vw, 112px); text-shadow: 3px 3px 0 #f7d8d2, -2px -1px 0 rgba(116, 45, 45, .12); }
.feedback-score { margin-top: 8px; color: #75809a; font: 500 10px 'DM Mono', monospace; letter-spacing: .1em; }

.bottom-note { position: relative; display: flex; align-items: center; justify-content: center; min-height: 42px; margin-top: 10px; color: #8791a8; font: 16px/1 'Patrick Hand', cursive; }
.sound-toggle { position: absolute; right: 0; width: 35px; height: 35px; padding: 5px; color: #8791a8; border: 0; border-radius: 50%; background: rgba(255, 253, 247, .35); cursor: pointer; font-size: 20px; }
.sound-toggle:active { transform: scale(.92); }
.sound-toggle.off { opacity: .4; text-decoration: line-through; }

.start-screen, .game-over { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 26px; background: rgba(247, 241, 225, .86); backdrop-filter: blur(9px); transition: opacity .28s, visibility .28s; }
.start-content, .end-card { width: min(455px, 100%); padding: 31px clamp(22px, 5vw, 37px) 27px; text-align: center; border: 2px solid #cbc7df; border-radius: 21px 27px 19px 25px; background: rgba(255, 253, 247, .96); box-shadow: 6px 7px 0 var(--shadow); }
.tiny-stamp { display: grid; place-items: center; width: 38px; height: 38px; margin: -49px auto 15px; color: #fff; border: 3px solid #fff; border-radius: 13px 16px 12px 15px; background: var(--coral); box-shadow: 2px 3px 0 #dfc6b6; font-size: 21px; transform: rotate(-8deg); }
.start-content h2, .end-card h2 { margin: 11px 0 16px; color: #4f5872; font: 500 clamp(55px, 11vw, 79px)/.78 'Patrick Hand', cursive; letter-spacing: -.03em; }
.start-content h2 em { color: var(--coral); }
.start-content > p:not(.eyebrow):not(.challenge-received), .end-reason { max-width: 320px; margin: 0 auto; color: #7c879e; font-size: 14px; line-height: 1.52; }
.challenge-received { max-width: 315px; margin: 15px auto -5px; padding: 9px 12px; color: #746d97; border: 1px dashed #bdb5db; border-radius: 11px 13px 10px 14px; background: #f4f0ff; font: 17px/1.15 'Patrick Hand', cursive; transform: rotate(-1deg); }
.primary-button { display: flex; align-items: center; justify-content: space-between; width: min(300px, 100%); margin: 29px auto 15px; padding: 14px 16px 14px 19px; color: #4a536a; border: 2px solid #d8a94c; border-radius: 15px 18px 14px 19px; background: var(--yellow); box-shadow: 3px 4px 0 #e4c797; cursor: pointer; font-size: 14px; font-weight: 800; transition: transform .15s, box-shadow .15s; }
.primary-button:hover { filter: saturate(1.08) brightness(1.02); }
.primary-button:active, .share-button:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 #e4c797; }
.primary-button b, .share-button b { font: 25px/12px 'Patrick Hand', cursive; }
.start-content small { color: #9ca4b6; font: 10px 'DM Mono', monospace; }
.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.game-over { overflow-y: auto; background: rgba(247, 241, 225, .91); }
.fail-card { width: min(590px, 100%); border-color: #e7b1ad; box-shadow: 6px 7px 0 #e5ccc4; transform: rotate(-.35deg); }
.end-card .fail-title { margin: 14px 0 13px; color: #d95255; font-size: clamp(52px, 11vw, 78px); line-height: .78; letter-spacing: .005em; transform: rotate(-3deg); text-shadow: 3px 3px 0 #f7d8d2; }
.final-xp { margin: 25px auto 16px; padding: 14px; border-top: 2px dotted #e3c5c6; border-bottom: 2px dotted #e3c5c6; }
.final-xp span { display: block; color: #a78383; font: 9px 'DM Mono', monospace; letter-spacing: .15em; }
.final-xp strong { color: #d95255; font: 500 57px/.9 'Patrick Hand', cursive; }
.stat-row { display: flex; justify-content: center; gap: 37px; color: #8790a7; font-size: 12px; }
.stat-row b { margin-left: 4px; color: #65708b; font-family: 'DM Mono', monospace; }
.best-badge { margin: 15px 0 -2px; color: var(--purple); font: 800 14px 'Patrick Hand', cursive; letter-spacing: .06em; transform: rotate(-2deg); }
.challenge-panel { display: grid; grid-template-columns: minmax(0, 1fr) 210px; align-items: center; gap: 16px; margin: 21px auto -2px; padding: 14px; text-align: left; border: 1.5px dashed #c9c5dd; border-radius: 16px 20px 15px 19px; background: linear-gradient(135deg, #f8f5ff, #fffdf7); }
.challenge-copy h3 { margin: 5px 0 6px; color: #59627d; font: 500 29px/.95 'Patrick Hand', cursive; }
.challenge-copy > p:not(.eyebrow) { margin: 0; color: #7f88a0; font-size: 12px; line-height: 1.4; }
.share-button { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 12px; padding: 11px 12px 11px 14px; color: #4c5571; border: 2px solid #97cbbd; border-radius: 13px 15px 12px 16px; background: var(--mint); box-shadow: 2px 3px 0 #c7dfd6; cursor: pointer; font-size: 12px; font-weight: 800; transition: transform .15s, box-shadow .15s; }
.message-preview { padding: 8px; border: 2px solid #c6d8cf; border-radius: 14px 17px 13px 18px; background: #edf6f0; box-shadow: 2px 3px 0 #c6d8cf; font-family: Nunito, sans-serif; transform: rotate(1.5deg); }
.message-top { display: flex; align-items: center; gap: 5px; padding: 0 1px 6px; color: #687a72; font-size: 8px; font-weight: 800; }
.message-top i { margin-left: auto; color: #98aaa3; font-style: normal; letter-spacing: 1px; }
.message-avatar { display: grid; place-items: center; width: 15px; height: 15px; color: #fff; border-radius: 6px 7px 6px 7px; background: #9d8ae5; font-size: 9px; }
.message-bubble { width: 88%; margin: 0 0 6px auto; padding: 6px 7px; color: #496459; border-radius: 9px 9px 3px 9px; background: #bfead8; font-size: 9px; line-height: 1.25; }
.message-bubble strong { color: #4b4e70; }
.message-game-card { display: flex; align-items: center; gap: 6px; padding: 6px; color: #556179; border: 1px solid #c9c5dd; border-radius: 9px; background: #fffdf7; }
.mini-mark { display: grid; place-items: center; width: 23px; height: 23px; color: var(--coral); border-radius: 7px; background: #f5eddb; font-size: 16px; }
.message-game-card div { display: grid; gap: 1px; }
.message-game-card b { font-size: 7px; letter-spacing: .03em; }
.message-game-card small { color: #a0a4b1; font-size: 7px; }
.message-game-card em { margin-left: auto; color: var(--purple); font-size: 7px; font-style: normal; font-weight: 800; }
.message-link { margin-top: 5px; color: #9b8ebe; font-size: 7px; text-align: center; }
.end-card .primary-button { margin-top: 24px; }

@keyframes target-arrive { 0% { opacity: .08; transform: scale(.62) rotate(-8deg); } 36% { opacity: 1; transform: scale(1.13) rotate(2deg); filter: drop-shadow(0 0 12px rgba(129, 116, 190, .4)); } 100% { transform: scale(1) rotate(0); } }
@keyframes target-halo { 0% { background: rgba(255, 173, 199, .5); transform: rotate(-3deg) scale(.7); } 45% { background: rgba(246, 207, 103, .28); transform: rotate(1deg) scale(1.08); } 100% { background: rgba(255, 253, 247, .53); transform: rotate(-3deg) scale(1); } }
@keyframes feedback-float { 0% { opacity: 0; transform: translate(-50%, -28%) rotate(-7deg) scale(.55); } 18% { opacity: 1; transform: translate(-50%, -50%) rotate(-3deg) scale(1.12); } 32% { transform: translate(-50%, -50%) rotate(-3deg) scale(1); } 78% { opacity: 1; transform: translate(-50%, -78%) rotate(2deg) scale(1); } 100% { opacity: 0; transform: translate(-50%, -112%) rotate(3deg) scale(.9); } }
@keyframes fail-stamp { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-11deg) scale(1.8); } 22% { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(.9); } 38%, 100% { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(1); } }
@keyframes drop-shape { 0% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); } 14% { transform: translate(calc(var(--drift) * .12), -6px) rotate(calc(var(--spin) * -.12)) scale(1.02); } 100% { opacity: 0; transform: translate(calc(var(--drift) * 2.6), 120vh) rotate(calc(var(--spin) * 5)) scale(.78); } }
@keyframes grade-scribble { to { stroke-dashoffset: 0; } }
@keyframes success-breathe { 50% { box-shadow: 5px 6px 0 var(--shadow), 0 0 0 6px rgba(168, 225, 206, .28); } }
@keyframes fail-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px) rotate(-.35deg); } 75% { transform: translateX(7px) rotate(.35deg); } }

@media (max-width: 560px) {
  .game-shell { padding-left: 14px; padding-right: 14px; }
  .prompt-area { margin-top: 24px; }
  .target-wrap { min-height: 132px; }
  .target-wrap svg { width: 120px; height: 120px; }
  .canvas-panel { min-height: 320px; }
  .challenge-panel { grid-template-columns: 1fr; gap: 13px; }
  .challenge-copy { text-align: center; }
  .message-preview { width: min(245px, 100%); justify-self: center; }
  .fail-card { padding-left: 18px; padding-right: 18px; }
}

@media (max-height: 700px) {
  .prompt-area { margin-top: 16px; }
  .target-wrap { height: 110px; min-height: 100px; margin-top: 8px; }
  .target-wrap svg { width: 94px; height: 94px; }
  .timer-wrap { margin-top: 13px; }
  .canvas-panel { min-height: 210px; }
  .bottom-note { min-height: 32px; }
}

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