/* Digits use a clear standard font: Pixelify Sans draws them oddly (5 looks like an S) */
@font-face { font-family: "ClearDigits"; src: local("Trebuchet MS Bold"), local("TrebuchetMS-Bold"), local("Verdana Bold"), local("Verdana-Bold"), local("Arial Bold"), local("Arial-BoldMT"); unicode-range: U+0030-0039; }
/* Lowercase e: Pixelify Sans with the crossbar closed (built from the Pixelify Sans OFL font) */
@font-face { font-family: "PixelE"; src: url("fonts/pixel-e-400.woff") format("woff"); font-weight: 400; unicode-range: U+0065; }
@font-face { font-family: "PixelE"; src: url("fonts/pixel-e-600.woff") format("woff"); font-weight: 600; unicode-range: U+0065; }
@font-face { font-family: "PixelE"; src: url("fonts/pixel-e-700.woff") format("woff"); font-weight: 700; unicode-range: U+0065; }
/* Pixel art UI: Stardew wood frames + Game Boy style dialog boxes */
:root {
  --wood: #8b4f24; --wood-dark: #5b3015; --wood-light: #c5803c;
  --parchment: #fbe7b5; --parchment-dark: #e8c47c;
  --ink: #2b1a0e; --gb-light: #f8f8e8; --gb-dark: #181810;
  --green: #5aa02c; --green-dark: #2f6a12; --orange: #e0702c;
}
* { box-sizing: border-box; }
html, body { font-variant-ligatures: none; font-feature-settings: "liga" 0, "clig" 0; margin: 0; height: 100%; overflow: hidden; background: #6cb4e8; font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; font-size: 19px; color: var(--ink); }
#scene { display: block; width: 100vw; height: 100vh; height: 100dvh; touch-action: none; image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }
h1, h2, .btn, #prompt { font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; }

/* Stardew style wooden frame around parchment */
.panel {
  position: fixed; background: var(--parchment); padding: 12px 16px; border: 4px solid var(--wood-dark);
  box-shadow: 0 0 0 4px var(--wood), 0 0 0 8px var(--wood-dark), 8px 8px 0 8px rgba(0,0,0,.35);
  image-rendering: pixelated;
}
.muted { color: #7a4a22; margin: 0 0 6px; line-height: 1.25; }
.btn {
  background: var(--orange); color: #fff; border: 4px solid var(--wood-dark); padding: 8px 12px; font-size: 17px; font-weight: 700; cursor: pointer;
  box-shadow: inset -4px -4px 0 #a8461a, inset 4px 4px 0 #f6a25e; text-shadow: 2px 2px 0 #7a2e08;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { box-shadow: inset 4px 4px 0 #a8461a; }
.btn:disabled { background: #9a9a8a; box-shadow: inset -4px -4px 0 #6a6a5a; text-shadow: none; cursor: default; }
input { font-variant-ligatures: none; font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; font-size: 19px; padding: 4px 10px; border: 4px solid var(--wood-dark); background: var(--gb-light); color: var(--ink); flex: 1; min-width: 0; outline: none; }
input:focus { border-color: var(--orange); }
form { display: flex; gap: 8px; align-items: center; }

#quest { top: 16px; left: 50%; transform: translateX(-50%); max-width: 90vw; text-align: center; line-height: 1.3; font-size: 18px; padding: 8px 14px; white-space: nowrap; }
/* Three sample slots: greyed bags until a sample fills one with that shop's icon */
#questSlots { display: inline-flex; gap: 5px; margin-left: 8px; vertical-align: middle; }
#questSlots .slot { width: 30px; height: 30px; display: inline-grid; place-items: center; font-size: 18px; font-style: normal; background: var(--gb-light); border: 3px solid var(--wood-dark); }
#questSlots .slot i { font-style: normal; filter: grayscale(1); opacity: .5; }
#questSlots .slot.filled { border-color: var(--green-dark); }
#questSlots .slot.filled i { filter: none; opacity: 1; animation: pulse .6s steps(3) 1; }
#help { bottom: 16px; left: 16px; font-size: 20px; max-width: 360px; line-height: 1.25; }
kbd { background: var(--gb-light); color: var(--ink); padding: 0 6px; border: 3px solid var(--ink); font-family: "Trebuchet MS", Verdana, Arial, sans-serif; font-size: .9em; font-weight: 700; }

/* Game Boy dialog box for the talk prompt */
#prompt {
  position: fixed; top: 26%; left: 50%; transform: translateX(-50%); background: var(--gb-light); color: var(--gb-dark); /* high enough to clear open Gift Finder results */
  padding: 12px 20px; font-size: 22px; font-weight: 600; line-height: 1.3; border: 4px solid var(--gb-dark); outline: 4px double var(--gb-dark); outline-offset: 4px; max-width: 90vw; text-align: center;
}

#chat { top: 96px; right: 20px; bottom: 120px; width: min(440px, calc(100vw - 40px)); display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
/* Close button, name and tagline stay pinned while the chat scrolls; negative margins cover the panel padding */
#chatHead { position: sticky; top: -12px; z-index: 2; margin: -12px -16px 0; padding: 12px 16px 4px; background: var(--parchment); border-bottom: 3px solid var(--parchment-dark); }
/* Sample button and message box stay pinned to the bottom of the chat while it scrolls */
#chatFoot { position: sticky; bottom: -12px; z-index: 2; margin: auto -16px -12px; padding: 8px 16px 12px; background: var(--parchment); border-top: 3px solid var(--parchment-dark); display: flex; flex-direction: column; gap: 8px; }
#chat h2 { margin: 0; padding-right: 34px; font-size: 24px; line-height: 1.15; }
#closeChat { position: absolute; top: 6px; right: 8px; border: 3px solid var(--wood-dark); background: #d9483b; color: #fff; font-size: 22px; width: 32px; height: 32px; line-height: 20px; cursor: pointer; font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; padding: 0; }
#vCard { font-size: 17px; line-height: 1.3; background: var(--parchment-dark); border: 3px solid var(--wood); padding: 8px 10px; }
#vCard a, #finishList a { color: #b23a12; }

#vProducts:empty { display: none; }
#vProducts h3 { margin: 0 0 6px; font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; font-size: 16px; font-weight: 700; }
.shelf { display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.item { display: block; text-decoration: none; color: var(--ink); background: var(--gb-light); border: 3px solid var(--wood-dark); box-shadow: 4px 4px 0 rgba(0,0,0,.25); font-size: 15px; line-height: 1.15; }
.item:hover { transform: translateY(-2px); border-color: var(--orange); }
.item img { width: 100%; height: 100px; object-fit: cover; display: block; border-bottom: 3px solid var(--wood-dark); background: #fff; }
.item span { display: block; padding: 4px 5px; height: 3.2em; overflow: hidden; }
.item b { display: block; padding: 0 5px 4px; color: var(--green-dark); }

#messages { flex: 1 0 auto; min-height: 160px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 10px 14px; max-width: 92%; line-height: 1.3; position: relative; }
.msg.assistant { background: var(--gb-light); color: var(--gb-dark); align-self: flex-start; border: 3px solid var(--gb-dark); outline: 3px double var(--gb-dark); outline-offset: 3px; margin: 4px; }
.msg.assistant::after { content: "▼"; position: absolute; right: 6px; bottom: 0; font-size: 14px; animation: blink 1s steps(2) infinite; }
.msg.user { background: #c8e6a0; align-self: flex-end; border: 3px solid var(--green-dark); }
@keyframes blink { 50% { opacity: 0; } }

#giftBar { bottom: 20px; left: 50%; transform: translateX(-50%); width: min(600px, calc(100vw - 840px)); min-width: 320px; }
#giftBar form span { font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; font-size: 24px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; color: var(--wood-dark); }
#giftResult { font-size: 20px; margin-top: 6px; line-height: 1.3; }
#giftResult:empty { display: none; }
#giftResult { position: relative; padding-right: 34px; }
#closeGift { position: absolute; top: 0; right: 0; border: 3px solid var(--wood-dark); background: #d9483b; color: #fff; font-size: 20px; width: 28px; height: 28px; line-height: 16px; cursor: pointer; padding: 0; font-family: inherit; }
/* Shop names in gift results: link-styled buttons that walk you to the stall */
.shopLink { background: none; border: 0; padding: 0; font: inherit; color: #1a4fc4; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.shopLink:hover { color: #0b3596; text-decoration-thickness: 2px; }
.shopLink:focus-visible { outline: 3px solid #1a4fc4; outline-offset: 2px; }

#finish { position: fixed; inset: 0; z-index: 20; background: rgba(24,24,16,.6); display: flex; align-items: center; justify-content: center; }
.finishCard { position: static; max-width: 580px; width: 90vw; max-height: 85vh; overflow-y: auto; }
.finishCard h1 { font-size: 30px; color: var(--green-dark); }
#finishList li { margin: 10px 0; line-height: 1.3; }

.toast {
  position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%); background: var(--gb-light); color: var(--gb-dark);
  font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; font-size: 24px; font-weight: 700; line-height: 1.3; padding: 16px 22px; border: 4px solid var(--gb-dark); outline: 4px double var(--gb-dark); outline-offset: 4px;
  animation: toast 2.6s steps(12) forwards; pointer-events: none; z-index: 10; text-align: center; max-width: 90vw;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -20%); } 15% { opacity: 1; transform: translate(-50%, -50%); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -80%); } }
#quest.pulse { animation: pulse .6s steps(3) 2; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (max-width: 800px) { #giftBar { width: calc(100vw - 40px); bottom: 80px; } #help { display: none; } }
.shipForm { display: flex; flex-direction: column; gap: 8px; align-items: stretch; background: var(--parchment-dark); border: 3px solid var(--wood); padding: 10px 12px; margin: 10px 0 14px; }
.shipForm h2 { font-size: 20px; margin: 0; }
.shipForm .row { display: flex; gap: 8px; }
.shipForm .row input:last-child { flex: 0 0 110px; }
.shipDone { background: var(--gb-light); border: 4px solid var(--gb-dark); outline: 4px double var(--gb-dark); outline-offset: 4px; padding: 12px; margin: 14px 4px; line-height: 1.3; }
#intro { position: relative; background: #a2dcf8; border: 4px solid var(--gb-dark); outline: 4px double var(--gb-dark); outline-offset: 3px; margin: 4px; }
#intro video, #intro canvas { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; image-rendering: pixelated; }
#replayIntro { position: absolute; right: 6px; bottom: 6px; font-size: 14px; padding: 4px 8px; }
#minimapWrap { right: 24px; bottom: 24px; padding: 4px; }
#toStart { position: absolute; right: 10px; bottom: 10px; padding: 4px 8px; font-size: 15px; }
#minimap { display: block; width: 300px; height: 240px; image-rendering: pixelated; background: #88c070; }
@media (max-width: 800px) { #minimap { width: 200px; height: 160px; } #minimapWrap { bottom: 160px; } }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.stallLabel {
  position: absolute; left: 0; top: 0; transform-origin: center; display: none;
  max-width: 260px; width: max-content; text-align: center; padding: 6px 12px 4px;
  font-family: "PixelE", "ClearDigits", "Pixelify Sans", system-ui, sans-serif; font-size: 24px; font-weight: 600; line-height: 1.3; color: var(--ink);
  background: var(--parchment); border: 4px solid var(--wood-dark); box-shadow: 0 0 0 3px var(--wood), 4px 4px 0 3px rgba(0,0,0,.35);
  white-space: normal; text-wrap: balance;
}
.stallLabel span { margin-right: 6px; font-size: 24px; }
@media (max-width: 1150px) and (min-width: 801px) { #help { display: none; } #giftBar { left: 24px; transform: none; width: calc(100vw - 460px); min-width: 0; } }
button, .btn, input, textarea { font-variant-ligatures: none; font-feature-settings: "liga" 0, "clig" 0; }
/* Game title, Stardew style gold lettering with a dark outline */
#gameTitle {
  position: fixed; top: 14px; left: 20px; margin: 0; z-index: 5; pointer-events: none;
  font-size: 44px; font-weight: 700; letter-spacing: 2px; line-height: 1; color: #f8d030;
  text-shadow: 3px 0 0 #5b3015, -3px 0 0 #5b3015, 0 3px 0 #5b3015, 0 -3px 0 #5b3015, 3px 3px 0 #5b3015, -3px 3px 0 #5b3015, 3px -3px 0 #5b3015, -3px -3px 0 #5b3015, 6px 6px 0 rgba(0,0,0,.35);
}
/* Quest sits near the top right, clear of the stall sign in the middle of the view, with its text balanced over
   two lines. The chat panel opens just below it (--quest-bottom is set from game.js) */
#quest { left: auto; right: 186px; transform: none; width: fit-content; margin: 0; min-width: 0; } /* clear of the season buttons */
@media (min-width: 1101px) { #chat { top: calc(var(--quest-bottom, 96px) + 14px); } }
@media (max-width: 1100px) { #gameTitle { font-size: 32px; } #quest { top: 70px; left: 5vw; right: 5vw; max-width: 90vw; } #chat { top: 160px; } }

/* Music and season buttons (autumn, winter), top right next to the quest */
#seasonBtns { position: fixed; top: 16px; right: 16px; z-index: 5; display: flex; gap: 8px; }
#seasonBtns .btn { width: 46px; height: 46px; padding: 0; font-size: 22px; line-height: 1; }

/* ---------- Phones and small screens ---------- */
#giftToggle { display: none; }
#prompt { cursor: pointer; }
html.touch #help { display: none; }
html:not(.touch) .touchUI, body.chatting .touchUI { display: none !important; }
button, .btn, input { touch-action: manipulation; }
/* Arrow pad bottom right, Talk button above it */
/* 3 x 38px + 2px gaps = 118px tall, so the pad's top lines up with the top of the minimap frame */
#dpad { position: fixed; right: 12px; bottom: 12px; z-index: 4; display: grid; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); gap: 2px; }
#dpad button { padding: 0; font-size: 15px; border-width: 3px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#dpad [data-key="ArrowUp"] { grid-area: 1 / 2; } #dpad [data-key="ArrowLeft"] { grid-area: 2 / 1; }
#dpad [data-key="ArrowRight"] { grid-area: 2 / 3; } #dpad [data-key="ArrowDown"] { grid-area: 3 / 2; }
#talkBtn { position: fixed; right: 16px; bottom: 140px; z-index: 4; width: 78px; height: 78px; border-radius: 50%; padding: 0; font-size: 18px;
  background: var(--green); box-shadow: inset -4px -4px 0 var(--green-dark), inset 4px 4px 0 #8ccc5c; text-shadow: 2px 2px 0 var(--green-dark); }
#touchHint { left: 50%; transform: translateX(-50%); bottom: 200px; width: min(320px, calc(100vw - 40px)); font-size: 15px; line-height: 1.3; text-align: center; z-index: 4; }

@media (max-width: 900px), (max-height: 520px) {
  #seasonBtns { top: 6px; right: 10px; gap: 5px; }
  #seasonBtns .btn { width: 32px; height: 32px; font-size: 16px; }
  #gameTitle { font-size: 20px; top: 10px; left: 12px; letter-spacing: 1px; }
  #quest { top: 40px; left: 12px; right: auto; margin: 0; width: auto; max-width: calc(100vw - 24px); font-size: 14px; padding: 6px 10px; text-align: left; white-space: normal; }
  #questSlots { margin-left: 6px; gap: 3px; }
  #questSlots .slot { width: 22px; height: 22px; font-size: 13px; border-width: 2px; }
  #help { display: none; }
  /* minimap bottom left, Gift Finder button bottom center */
  #minimapWrap { top: auto; right: auto; left: 12px; bottom: 12px; padding: 3px; }
  #minimap { width: 120px; height: 96px; }
  #toStart { right: 4px; bottom: 4px; font-size: 11px; padding: 2px 5px; border-width: 3px; }
  #giftToggle { display: block; position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 4; width: 50px; height: 50px; padding: 0; font-size: 24px; }
  #giftBar:not(.open) { display: none; }
  #giftBar { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; min-width: 0; transform: none; z-index: 6; padding: 10px 12px; max-height: calc(100dvh - 40px); overflow-y: auto; }
  #giftBar form span { font-size: 16px; }
  #giftBar input, #chatInput { font-size: 16px; } /* 16px stops iPhone zooming in on focus */
  #giftResult { font-size: 16px; }
  #prompt { top: 30%; font-size: 16px; padding: 8px 14px; }
  .stallLabel, .stallLabel span { font-size: 15px; } .stallLabel { max-width: 150px; padding: 4px 8px 2px; }
  .toast { font-size: 18px; }
  /* chat fills the screen */
  #chat { top: 8px; right: 8px; bottom: 8px; left: 8px; width: auto; z-index: 6; font-size: 16px; }
  #chat h2 { font-size: 20px; }
  #vCard { font-size: 15px; }
  .msg { padding: 8px 10px; }
}
@media (max-height: 520px) { /* phone held sideways */
  #talkBtn { width: 64px; height: 64px; bottom: 140px; }
  #touchHint { top: 84px; bottom: auto; font-size: 13px; padding: 6px 10px; }
  #giftToggle { bottom: 10px; width: 44px; height: 44px; font-size: 20px; }
}
