@font-face { font-family: "Fraunces"; src: url("fonts/fraunces.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Figtree"; src: url("fonts/figtree.woff2") format("woff2"); font-weight: 300 900; font-display: swap; }

:root {
  --cream: #F6F1E4; --paper: #FFF9EC; --red: #D9483B; --red-dark: #A9342A;
  --corn: #5B86C9; --ink: #2E2A24; --leaf: #5FAF4E; --wood: #C98A4B;
  --s: 1;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #DDEFE3; color: var(--ink);
  font-family: "Figtree", system-ui, sans-serif; font-weight: 500; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; font-variation-settings: "SOFT" 100, "WONK" 0; font-weight: 700; margin: 0; }

/* rushnyk ribbon: cream band, stitched red border, cross-stitch end bands */
.ribbon {
  position: absolute; background: var(--paper);
  border-radius: 10px;
  box-shadow: 0 3px 0 #E4D7BC, 0 10px 24px rgba(90, 60, 30, .18);
  outline: 2px dashed var(--red); outline-offset: -7px;
  padding: 14px 34px;
}
.ribbon::before, .ribbon::after {
  content: ""; position: absolute; top: 9px; bottom: 9px; width: 12px;
  background:
    repeating-linear-gradient(45deg, transparent 0 3px, var(--red) 3px 5px, transparent 5px 8px),
    repeating-linear-gradient(-45deg, transparent 0 3px, var(--red) 3px 5px, transparent 5px 8px);
  background-size: 12px 12px; opacity: .9; border-radius: 2px;
}
.ribbon::before { left: 12px; }
.ribbon::after { right: 12px; }

#quest { left: max(14px, env(safe-area-inset-left)); top: 14px; max-width: 440px; }
#quest h2 { font-size: 30px; line-height: 1.05; }
#qhint { margin: 4px 0 10px; font-size: 16px; font-weight: 600; }
#slots { display: flex; gap: 8px; }
.slot { width: 50px; height: 50px; border-radius: 50%; background: #E7DCC6; position: relative; overflow: hidden;
  box-shadow: inset 0 3px 6px rgba(80, 55, 30, .35), 0 1px 0 #fff; }
.slot::after { content: ""; position: absolute; left: 50%; top: 22%; width: 42%; height: 42%; transform: translateX(-50%);
  border-radius: 50%; background: #CDBFA5; box-shadow: 0 16px 0 6px #CDBFA5; }
.slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: scale(.4); z-index: 1; }
.slot.filled { background: #8CC77A; box-shadow: 0 0 0 3px #fff, 0 3px 6px rgba(80, 55, 30, .3); }
.slot.filled::after { display: none; }
.slot.filled img { opacity: 1; transform: scale(1); transition: transform .45s cubic-bezier(.34, 1.8, .5, 1), opacity .2s; }

#corner { position: absolute; z-index: 5; right: max(14px, env(safe-area-inset-right)); top: 14px; display: flex; gap: 10px; }
.roundbtn { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--paper); color: var(--ink);
  font-size: 24px; font-weight: 800; box-shadow: 0 4px 0 #D8C9AA, 0 6px 14px rgba(90, 60, 30, .2); cursor: pointer;
  display: grid; place-items: center; font-family: "Figtree", sans-serif; transition: transform .12s; }
.roundbtn:active { transform: translateY(3px) scale(.95, .9); box-shadow: 0 1px 0 #D8C9AA; }

/* primary: folk red pill with a darker pressable edge */
.redbtn { border: 0; background: var(--red); color: #fff; font-family: "Fraunces", Georgia, serif; font-weight: 700;
  border-radius: 999px; cursor: pointer; box-shadow: 0 7px 0 var(--red-dark), 0 12px 20px rgba(120, 40, 20, .25);
  transition: transform .14s cubic-bezier(.34, 1.6, .5, 1), box-shadow .14s; text-shadow: 0 2px 0 rgba(0, 0, 0, .15);
  position: relative; touch-action: none; }
.redbtn::before { content: ""; position: absolute; left: 14%; right: 14%; top: 6px; height: 30%; border-radius: 999px;
  background: linear-gradient(rgba(255, 255, 255, .28), rgba(255, 255, 255, 0)); pointer-events: none; }
.redbtn.big { font-size: 40px; padding: 10px 60px 14px; min-height: 72px; }
.redbtn.round { width: 56px; height: 56px; font-size: 24px; padding: 0; flex: none; font-family: "Figtree", sans-serif; }
.redbtn:active, .redbtn.pressed { transform: translateY(5px) scale(1.03, .92); box-shadow: 0 2px 0 var(--red-dark), 0 4px 8px rgba(120, 40, 20, .2); }
.redbtn:disabled { filter: saturate(.4) brightness(1.1); cursor: default; }

/* dialogue */
#tapcatch { position: absolute; inset: 0; cursor: pointer; }
#bubble { position: absolute; left: 0; top: 0; width: min(440px, calc(100vw - 24px)); background: var(--paper);
  border-radius: 26px; padding: 22px 24px 14px; box-shadow: 0 4px 0 #E2D4B6, 0 14px 28px rgba(90, 60, 30, .2);
  cursor: pointer; transform-origin: 50% 100%; animation: pop .38s cubic-bezier(.34, 1.7, .5, 1); }
#bubble .pill { position: absolute; left: 20px; top: -15px; background: var(--red); color: #fff; font-family: "Fraunces", Georgia, serif;
  font-weight: 700; font-size: 18px; padding: 4px 16px 6px; border-radius: 999px; box-shadow: 0 3px 0 var(--red-dark); }
#bubble.narrator .pill { background: var(--corn); box-shadow: 0 3px 0 #3F659F; }
#btext { font-size: 22px; line-height: 1.3; font-weight: 600; min-height: 1.3em; }
#bmore { font-size: 14px; font-weight: 700; color: var(--red); text-align: right; margin-top: 6px; opacity: .85; }
#bubble .tail { position: absolute; bottom: -18px; left: var(--tail, 40px); width: 0; height: 0;
  border-left: 14px solid transparent; border-right: 14px solid transparent; border-top: 20px solid var(--paper); }
#bubble.narrator .tail, #bubble.notail .tail { display: none; }
#bubble.up .tail { bottom: auto; top: -18px; border-top: 0; border-bottom: 20px solid var(--paper); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* pull */
#pullbar { position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 14px; animation: rise .45s cubic-bezier(.34, 1.6, .5, 1); }
#btnPull { min-width: 260px; }
body:not(.portrait) #pullbar { left: auto; right: max(52px, env(safe-area-inset-right)); transform: none; animation: riseR .45s cubic-bezier(.34, 1.6, .5, 1); }
body:not(.portrait) #meter { width: min(400px, 36vw); }
@keyframes riseR { from { transform: translateY(120%); } to { transform: none; } }
#meter { width: min(440px, 86vw); height: 30px; border-radius: 999px; background: #EFE4CD; position: relative;
  box-shadow: inset 0 4px 6px rgba(80, 55, 30, .3), 0 0 0 4px var(--paper), 0 6px 14px rgba(90, 60, 30, .25); }
#mfill { position: absolute; left: 4px; top: 4px; bottom: 4px; width: 0; border-radius: 999px;
  background: linear-gradient(#7FC862, #4E9B3E); box-shadow: inset 0 3px 0 rgba(255, 255, 255, .35); }
#meter img { position: absolute; right: -26px; top: 50%; width: 58px; height: 58px; transform: translateY(-58%);
  filter: drop-shadow(0 3px 3px rgba(80, 55, 30, .35)); transition: transform .1s; }
#pullhint { font-weight: 700; font-size: 15px; background: rgba(255, 249, 236, .92); padding: 3px 12px; border-radius: 999px; }
@keyframes rise { from { transform: translate(-50%, 120%); } to { transform: translate(-50%, 0); } }

#complete { left: 50%; top: 16px; transform: translateX(-50%); text-align: center; padding: 14px 54px;
  animation: unfurl .6s cubic-bezier(.34, 1.5, .5, 1); transform-origin: 50% 50%; white-space: nowrap; }
#complete h1 { font-size: 44px; }
#complete p { margin: 2px 0 0; font-size: 20px; font-weight: 600; }
@keyframes unfurl { from { transform: translateX(-50%) scaleX(.05); opacity: .3; } to { transform: translateX(-50%) scaleX(1); opacity: 1; } }

#nextcard { left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px)); display: flex; align-items: center; gap: 14px; padding: 12px 34px 12px 30px;
  animation: slideup .55s cubic-bezier(.34, 1.4, .5, 1); cursor: pointer; }
#nextcard img { width: 110px; height: 110px; object-fit: contain; flex: none; }
.nc-text { flex: 1; }
.nc-label { color: var(--red); font-weight: 800; font-size: 14px; }
#nextcard h3 { font-size: 26px; }
#nextcard p { margin: 4px 0 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
@keyframes slideup { from { transform: translate(-50%, 140%); } to { transform: translate(-50%, 0); } }

#title { left: max(14px, env(safe-area-inset-left)); top: 14px; text-align: left; width: min(400px, calc(100vw - 28px));
  padding: 16px 38px 16px; animation: pop .5s cubic-bezier(.34, 1.6, .5, 1); transform-origin: 0 0; transition: opacity .35s, transform .35s; }
#title.leaving { opacity: 0; transform: translateY(-14px) scale(.96); pointer-events: none; }
.t-kicker { color: var(--red); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; }
#title h1 { font-size: 38px; line-height: 1.05; margin: 2px 0; }
#tEp { font-family: "Fraunces", Georgia, serif; font-size: 20px; font-weight: 600; margin: 0 0 8px; color: #6B4A2E; }
.t-how { margin: 0 0 14px; font-size: 15px; }
#title .redbtn.big { font-size: 28px; padding: 8px 34px 12px; min-height: 60px; }
.t-save { margin: 12px 0 0; font-size: 14px; min-height: 1em; color: #6B4A2E; }

/* phone portrait: quest card becomes a top bar, controls dock at the bottom */
body.portrait #quest { left: 8px; right: 8px; top: 8px; max-width: none; padding: 9px 28px 10px; display: grid;
  grid-template-columns: 1fr; gap: 2px; }
body.portrait #quest h2 { font-size: 21px; padding-right: 110px; }
body.portrait #qhint { font-size: 14px; margin: 0 0 6px; padding-right: 104px; }
body.portrait #slots { gap: 5px; }
body.portrait .slot { width: 40px; height: 40px; }
body.portrait #corner { top: 14px; right: 18px; }
body.portrait .roundbtn { width: 48px; height: 48px; font-size: 21px; }
body.portrait #bubble { left: 12px !important; width: calc(100vw - 24px); top: auto !important; bottom: max(16px, env(safe-area-inset-bottom)); }
body.portrait #bubble .tail { display: none; }
body.portrait #btext { font-size: 19px; }
body.portrait .redbtn.big { font-size: 34px; padding: 8px 40px 12px; }
body.portrait #complete { top: 76px; padding: 10px 36px; }
body.portrait #complete h1 { font-size: 32px; }
body.portrait #nextcard img { width: 76px; height: 76px; }
body.portrait #nextcard h3 { font-size: 21px; }
body.portrait #nextcard p { font-size: 14px; }
body.portrait #title { left: 8px; right: 8px; width: auto; top: 8px; padding: 12px 30px 12px; }
body.portrait #title h1 { font-size: 28px; padding-right: 100px; }
body.portrait #tEp { font-size: 17px; }
body.portrait #title .redbtn.big { font-size: 24px; padding: 8px 28px 12px; }

/* short landscape screens (a phone on its side) */
body.short #quest { padding: 7px 28px 8px; }
body.short #quest h2 { font-size: 19px; }
body.short #qhint { font-size: 13px; margin: 1px 0 5px; }
body.short .slot { width: 36px; height: 36px; }
body.short #slots { gap: 5px; }
body.short .roundbtn { width: 48px; height: 48px; font-size: 20px; }
body.short #btext { font-size: 17px; }
body.short #bubble { padding: 16px 18px 8px; width: min(380px, 60vw); }
body.short #bmore { font-size: 12px; margin-top: 2px; }
body.short .redbtn.big { font-size: 28px; padding: 6px 40px 10px; min-height: 56px; }
body.short #pullbar { gap: 8px; bottom: 10px; }
body.short #meter { height: 24px; width: min(360px, 60vw); }
body.short #pullhint { display: none; }
body.short #complete { padding: 8px 40px; top: 8px; }
body.short #complete h1 { font-size: 28px; }
body.short #complete p { font-size: 15px; }
body.short #nextcard { padding: 8px 30px; bottom: 8px; }
body.short #nextcard img { width: 64px; height: 64px; }
body.short #nextcard h3 { font-size: 19px; }
body.short #nextcard p { font-size: 13px; }
body.short #title { padding: 9px 32px 9px; width: min(340px, 50vw); }
body.short #title .redbtn.big { font-size: 22px; min-height: 50px; padding: 6px 26px 10px; }
body.short #title h1 { font-size: 24px; }
body.short #tEp { font-size: 17px; margin-bottom: 4px; }
body.short .t-how { margin-bottom: 10px; font-size: 14px; }
body.short .t-save { margin-top: 6px; }
body.short .t-kicker { display: none; }
