:root {
  color-scheme: light;
  --ink: #482d38;
  --wine: #842f48;
  --paper: #fff6e6;
  --edge: #d7bfae;
  --mono: "Courier New", monospace;
}
* { box-sizing: border-box }
[hidden] { display: none !important }
html { min-height: 100%; background: #eddfcf }
body {
  margin: 0; min-height: 100vh; min-height: 100svh; display: grid; place-items: center;
  padding: clamp(22px, 5vw, 80px) clamp(15px, 4vw, 65px);
  font: 16px/1.5 "Segoe UI", system-ui, sans-serif; color: var(--ink);
  background-color: #f0e3d3;
  background-image: radial-gradient(ellipse at 12% 5%, #d99b9b48, transparent 54%),
    radial-gradient(ellipse at 88% 87%, #d69b8240, transparent 52%),
    repeating-linear-gradient(0deg, transparent 0 21px, #9e696610 21px 22px),
    repeating-linear-gradient(90deg, transparent 0 21px, #9e696610 21px 22px);
}
body:has(#world[inert]) { background: #e9e8e3 }
main { position: relative; isolation: isolate; width: min(100%, 1250px) }
#world {
  border: 1px solid #cbaea0; border-radius: 4px; overflow: hidden; position: relative;
  background: radial-gradient(ellipse at 100% 5%, #ffebd9a8, transparent 58%), var(--paper);
  box-shadow: 0 2px 1px #fff4e3, 0 4px 0 #cbb09b, 0 18px 45px -20px #7547376b, 0 50px 100px -58px #75473777;
}
#world[inert] { visibility: hidden }
.airmail { height: 7px; background: repeating-linear-gradient(128deg,#ab5060 0 16px,#fff1d8 16px 32px,#607b80 32px 48px,#fff1d8 48px 64px); opacity: .84 }
.postcard { display: grid; grid-template-columns: minmax(0,1.82fr) minmax(280px,1fr); padding: clamp(18px, 2.3vw, 34px); gap: clamp(22px, 3vw, 48px); align-items: start }
.picture { min-width: 0; margin: 0; align-self: center; }
.window { position: relative; isolation: isolate; overflow: hidden; aspect-ratio: 1.57; background: #213957; border-radius: 3px; box-shadow: 0 0 0 1px #4a343138 }
.view { position: absolute; inset: 0; background: url("assets/evening-street.webp") center 56% / cover no-repeat; }
.window::after { content:''; position:absolute; inset:0; pointer-events:none; box-shadow: inset 0 0 22px #34233c25; z-index:3 }
figcaption { display:flex; align-items:baseline; justify-content:space-between; gap:16px; padding:9px 2px 0; color: #71534b }
.photo-place { font: italic clamp(18px,2vw,23px)/1.2 Georgia,serif; }
.photo-date { font: 11px/1.2 var(--mono); text-transform:uppercase; letter-spacing:.11em }
.lights { position:absolute; inset:0; pointer-events:none }
.lights i { position:absolute; width:3px; height:3px; background:#fff1bd; box-shadow:0 0 5px #ffddad; animation: glint 5.4s ease-in-out infinite; }
.lights i:nth-child(1) { top:16%;left:28% }
.lights i:nth-child(2) { top:11%;left:63%;animation-delay:-2.1s }
.lights i:nth-child(3) { top:27%;left:76%;animation-delay:-3.7s }
@keyframes glint { 0%,55%,100% {opacity:0} 76% {opacity:.85} }
.window { --david-height:clamp(145px, 19vw, 268px); --guest-ratio:calc(170 / 185); }
.character, #guest { position:absolute; bottom:7%; filter:drop-shadow(1px 3px 1px #2d202967); }
/* David's PNGs have more transparent padding around the body than Aruzhan's. */
.character {
  height:calc(var(--david-height) * 1.068); aspect-ratio:.74; left:50%;
  bottom:calc(7% - var(--david-height) * var(--sole-inset,.017));
  transform:translateX(-50%); transition:left .85s cubic-bezier(.22,.78,.22,1);
}
.character:has(#pose[src$="/idle.png"],#pose[src$="/joy.png"]) { --sole-inset:.027 }
#pose { display:block; width:100%;height:100%; object-fit:contain; object-position:center bottom; image-rendering:pixelated; }
/* The brim sits at each sprite's hairline, even when the whole pose changes shape. */
.hat {
  --head-x: 50%; --brim-y: 13%; --cap-width: 55%; --cap-angle: -3deg;
  position:absolute; left:var(--head-x); top:var(--brim-y); width:var(--cap-width); aspect-ratio:60/38;
  background:url("assets/winter-cap.png") center / contain no-repeat; image-rendering:pixelated;
  transform-origin:38% 82%; transform:translate(-38%,-82%) rotate(var(--cap-angle)); pointer-events:none;
}
#pose[src$="/five.png"] + .hat { --head-x:60%; --brim-y:12.5%; }
#pose[src$="/wave.png"] + .hat { --head-x:56.5%; --brim-y:14%; }
#pose[src$="/joy.png"] + .hat { --head-x:49%; --brim-y:20%; --cap-width:43%; --cap-angle:1deg; }
#pose[src$="/clap.png"] + .hat { --head-x:50%; --brim-y:13%; --cap-width:53%; }
#pose[src$="/reach.png"] + .hat { --head-x:52%; --brim-y:57%; --cap-width:40%; --cap-angle:12deg; }
#pose[src$="/shock.png"] + .hat { --head-x:43%; --brim-y:26%; --cap-width:45%; }
#pose[src$="/brake.png"] + .hat { --head-x:57%; --brim-y:10%; --cap-angle:7deg; }
#guest { height:calc(var(--david-height) * var(--guest-ratio)); width:auto; left:57%; image-rendering:pixelated; transform-origin:50% 98%; animation: guest-arrives .9s cubic-bezier(.18,.8,.25,1) both }
.window.together .character { left:40% }
@keyframes guest-arrives { from { opacity:0; transform:translateY(9px) scale(.94); filter:brightness(1.7) drop-shadow(0 0 12px #ffe296) } to { opacity:1 } }
.note { min-width:0; align-self:stretch; display:flex; flex-direction:column; align-items:flex-start; position:relative; border-left:1px solid var(--edge); padding:0 0 5px clamp(18px,2.8vw,42px) }
.postage { align-self:flex-end; width:118px; height:73px; position:relative; margin:0 0 clamp(12px,2.7vw,42px); user-select:none }
.stamp { position:absolute; top:2px;right:4px;width:53px;height:65px;rotate:6deg;display:grid;place-items:center;color:#ffdfbd;background:radial-gradient(circle at 3px 3px,transparent 2px,#b64f5e 2.5px) -3px -3px / 7px 7px; }
.stamp:before { content:'';position:absolute;inset:5px;border:1px solid #ffd9b9;background:#a7475b;box-shadow:inset 0 0 0 2px #bd6970; }
.stamp-star {position:relative;font:36px/1 Georgia,serif}
.postmark { position:absolute; top:16px;right:42px; z-index:1;width:58px;height:55px;display:grid;align-content:center;justify-items:center;border:1px solid;border-radius:50%;color:#686c648c; rotate:-14deg;box-shadow:inset 0 0 0 2px #eee9ce,inset 0 0 0 3px #9c9d88; }
.postmark span,.postmark i {font:7px/1.15 var(--mono);letter-spacing:.07em}.postmark b{font:20px/1 Georgia,serif}
#recipient { margin:0 0 14px;font:italic 500 clamp(43px,5vw,69px)/1 Georgia,"Times New Roman",serif; letter-spacing:-.064em; color:#602e3c }
#line { margin:0; font:400 clamp(20px,1.85vw,27px)/1.38 Georgia,serif; text-wrap:pretty; overflow-wrap:break-word; }
#actions { display:flex; flex-wrap:wrap; gap:9px; padding-top:22px }
#actions:empty { display:none }
button,a { -webkit-tap-highlight-color:transparent }
button { cursor:pointer }
#actions button,.booth-save {
  display:inline-flex; align-items:center; justify-content:center; min-height:43px; padding:9px 16px;
  border:1px solid #9d6d68; border-radius:6px; color:#653747; background:#fff5e6;
  font:600 14px/1.3 "Segoe UI",system-ui,sans-serif; text-decoration:none; text-align:center;
  box-shadow:0 2px 0 #bd9890; transition:transform .13s,background-color .13s;
}
#actions button:first-child:not(.minor),.booth-save { color:#fff7e8; background:var(--wine); border-color:#713249; box-shadow:0 2px 0 #55283a }
#actions button:hover,.booth-save:hover { transform:translateY(-2px) }
#actions button:active,.booth-save:active { transform:translateY(1px) }
#actions button:disabled { cursor:wait;opacity:.65;transform:none }
:focus-visible { outline:3px solid #ac7542; outline-offset:4px }
#detail { width:100%; margin-top:14px;font-size:13px;color:#75605d }
#detail:empty { display:none }
#detail canvas { display:block; width:min(100%,210px); height:auto; margin:5px 0 13px; box-shadow:2px 4px 13px #48302a35; rotate:-1.6deg }
.signature { width:100%; padding-top:32px; margin-top:auto; text-align:right; font:italic 22px/1.15 Georgia,serif;color:#87505b; }
.signature span { font-size:14px }.signature i{color:#a85e69;font:18px Georgia,serif}
#world.arrive[inert] { visibility:visible }
#paper {
  position:fixed; inset:0; z-index:5; overflow:auto; color:#29384a; background:#f8fafc;
  font:16px/1.45 "Segoe UI",system-ui,sans-serif;
}
.exam-width { width:min(100% - 32px, 960px); margin-inline:auto }
.exam-header { background:#fff; border-bottom:4px solid #83b9e4 }
.exam-header .exam-width { display:flex; align-items:center; justify-content:space-between; gap:12px; min-height:56px; color:#264d73 }
.exam-header span { font-size:.875rem }
.exam-banner { background:#245e91; color:white }
.exam-banner .exam-width { display:flex; gap:18px; align-items:center; min-height:104px }
.exam-banner span { font:34px/1 Georgia,serif }
#exam-title { font-size:clamp(24px,4vw,37px); margin:0; font-weight:600 }
.exam-content { padding-block:16px 32px }
.exam-path { margin:0 0 22px; color:#4a6176; font-size:.875rem }
.exam-path span { margin-inline:6px }
.exam-content h2 { margin:0 0 18px; font-size:clamp(21px,3vw,27px); line-height:1.2 }
.exam-questions {
  margin:0; padding:0; list-style-position:inside; display:grid;
  grid-template-columns:repeat(auto-fit,minmax(min(100%,210px),1fr)); gap:12px;
}
.exam-questions li { padding:14px; background:#fff; border:1px solid #c1d6e6; border-radius:6px }
.exam-questions li::marker { color:#285f90; font-weight:700 }
.paper-david { display:none; position:absolute; top:12%; right:3%; width:clamp(80px,14vw,180px); image-rendering:pixelated; pointer-events:none }
#paper.torn { pointer-events:none; animation:shed .78s ease-in-out forwards; }
#paper.torn .paper-david { display:block; animation:grab-sheet .78s ease-out both }
@keyframes grab-sheet {
  from { transform:translate(80%,-32%) rotate(-12deg) }
  35%,100% { transform:translate(0) rotate(0) }
}
@keyframes shed {
  0%,20% { clip-path:polygon(0 0,100% 0,100% 100%,0 100%) }
  42% { clip-path:polygon(0 0,72% 0,77% 8%,86% 4%,91% 15%,100% 13%,100% 100%,0 100%) }
  72% { clip-path:polygon(0 0,38% 0,49% 15%,62% 10%,70% 36%,86% 33%,100% 53%,100% 100%,0 100%); transform:translate(-9%,8%) rotate(-4deg) }
  100% { clip-path:polygon(0 100%,0 100%,0 100%,0 100%); transform:translate(-32%,32%) rotate(-9deg); opacity:0; visibility:hidden }
}
@media(max-width:480px) {
  .exam-banner .exam-width { min-height:72px }
  .exam-questions { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px }
  .exam-questions li { font-size:.875rem; padding:10px; overflow-wrap:anywhere }
}
#hand[open] { position:fixed; inset:0; width:100vw;height:100dvh;max-width:none; max-height:none;margin:0;border:0;padding:0;background:radial-gradient(ellipse at center,#e8c8ae5e,#282337b3) }
#hand::backdrop { background:#34233155; backdrop-filter:blur(3px) }
#touch { display:grid;place-content:center;justify-items:center;gap:10px;width:100%;height:100%;border:0;background:none;color:var(--ink) }
#palm { height:min(74dvh,105vw);width:auto;image-rendering:pixelated }
#prompt { background:var(--paper);padding:.5em 1em;border-radius:20px;font:20px Georgia,serif }
@media(max-width:800px) {
 .postcard { grid-template-columns: minmax(0,1.45fr) minmax(230px,1fr);gap:18px;padding:16px; }
 .postage { margin-bottom:10px; transform:scale(.82); transform-origin:top right;height:54px }
 .note {padding-left:17px} .window {aspect-ratio:1.33} .signature {padding-top:22px}
}
@media(max-width:620px) {
 body { padding:17px 12px }.postcard { display:flex;flex-direction:column;gap:14px;padding:12px; }
 .picture {width:100%}.window { aspect-ratio:1.64; --david-height:clamp(108px,32vw,177px); }
 figcaption {padding:6px 2px 0}.photo-place {font-size:17px}.photo-date {font-size:10px}
 .note { border-left:0; border-top:1px solid var(--edge); padding:20px 6px 4px; display:block }
 .postage { float:right;zoom:.77; margin:-3px 0 0 8px;height:63px }
 #recipient {font-size:43px;margin-bottom:9px} #line {font-size:20px;min-height:2.6em}
 #actions {padding-top:15px} .signature {padding-top:13px;font-size:19px}
 #detail canvas {margin-inline:auto}
}
@media(prefers-reduced-motion:reduce) {
 *, *::before,*::after { animation-duration:.01ms!important; animation-iteration-count:1!important; transition-duration:.01ms!important; scroll-behavior:auto!important; }
}

