/* MOCK-PEN-1 — คอกดาว mock (mobile-first 390px) */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --col-w: 390px;
  --night-hi: #2b2b55;
  --night: #1c1c3d;
  --night-lo: #14142e;
  --cream: #fff3d6;
  --gold: #ffd873;
  --ink: #3a2c22;
  --panel: #fffaf0;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans Thai", "Segoe UI", "Thonburi", sans-serif;
  background: var(--night-lo);
  color: var(--cream);
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* ---------- desktop side decoration (center column comes free) ---------- */
#side-deco {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1.5px 1.5px at 8% 18%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 15% 42%, #fff7 50%, transparent 51%),
    radial-gradient(2px 2px at 5% 66%, #ffd87377 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 22% 80%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 28%, #fff5 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 88% 22%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 48%, #fff7 50%, transparent 51%),
    radial-gradient(2px 2px at 94% 60%, #ffd87377 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 72% 84%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 84% 12%, #fff5 50%, transparent 51%),
    linear-gradient(180deg, #23234a 0%, #14142e 55%, #101024 100%);
}

#stage {
  position: relative; z-index: 1;
  max-width: var(--col-w);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--night);
  box-shadow: 0 0 60px #00000088;
}
@media (min-width: 700px) {
  #stage { max-width: 430px; }
}

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--col-w);
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 8px;
  z-index: 40; pointer-events: none;
  background: linear-gradient(180deg, #14142ecc 0%, transparent 100%);
}
@media (min-width: 700px) { #hud { max-width: 430px; } }
.hud-pill {
  display: flex; align-items: center; gap: 6px;
  background: #14142ecc; border: 1.5px solid #ffd87355;
  border-radius: 999px; padding: 7px 14px;
  font-weight: 700; font-size: 16px; color: var(--gold);
  backdrop-filter: blur(4px);
}
.dust-ico { filter: drop-shadow(0 0 4px #ffd873); }
.hud-pill.bump { animation: bump .45s ease; }
@keyframes bump { 30% { transform: scale(1.18); } }
.hud-title { font-size: 13px; opacity: .75; font-weight: 600; }
.hud-title small { opacity: .7; font-weight: 400; }

/* ---------- sky ---------- */
#sky {
  position: relative; height: 300px; overflow: hidden;
  background: linear-gradient(180deg, #191936 0%, var(--night-hi) 78%, #274046 100%);
}
#stars-far {
  position: absolute; inset: 0;
  background:
    radial-gradient(1.5px 1.5px at 12% 25%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 25% 60%, #fffb 50%, transparent 51%),
    radial-gradient(2px 2px at 38% 18%, #ffe9b3 50%, transparent 51%),
    radial-gradient(1px 1px at 52% 45%, #fff9 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 67% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 55%, #fffb 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 20%, #ffe9b3 50%, transparent 51%),
    radial-gradient(1px 1px at 45% 75%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 8% 70%, #fff7 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 73% 72%, #fff8 50%, transparent 51%);
  animation: twinkle 4.5s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

#moon {
  position: absolute; top: 44px; right: 30px; width: 96px; height: auto;
  filter: drop-shadow(0 0 22px #ffe9b366);
  animation: moon-float 7s ease-in-out infinite alternate;
}
@keyframes moon-float { from { transform: translateY(0); } to { transform: translateY(7px); } }

#moon-sign {
  position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%);
  white-space: nowrap;
  background: #14142ebb; border: 1.5px solid #ffd87344;
  color: #ffedbf; font-size: 12.5px; font-weight: 600;
  padding: 8px 14px; border-radius: 999px;
  backdrop-filter: blur(3px);
}

#shooting-star {
  position: absolute; top: 18%; left: -12%;
  width: 90px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, #fff);
  opacity: 0; pointer-events: none;
  transform: rotate(16deg);
}
#shooting-star.go { animation: shoot 1.1s ease-in forwards; }
@keyframes shoot {
  0%   { opacity: 0; transform: rotate(16deg) translateX(0); }
  12%  { opacity: 1; }
  100% { opacity: 0; transform: rotate(16deg) translateX(130vw); }
}
@media (min-width: 700px) {
  #shooting-star.go { animation-name: shoot-desk; }
  @keyframes shoot-desk {
    0%   { opacity: 0; transform: rotate(16deg) translateX(0); }
    12%  { opacity: 1; }
    100% { opacity: 0; transform: rotate(16deg) translateX(560px); }
  }
}

/* ---------- playfield (pen + field share coordinates) ---------- */
#playfield { position: relative; }

#pen {
  position: relative; height: 560px;
  background: url("assets/pen-ground.jpg") center / cover no-repeat;
}
#pen::before {  /* blend into sky */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 84px;
  background: linear-gradient(180deg, #274046 0%, transparent 100%);
  pointer-events: none;
}
#pen::after {   /* blend into field */
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 120px;
  background: linear-gradient(0deg, #171233 8%, #17123399 55%, transparent 100%);
  pointer-events: none;
}
.fence {
  position: absolute; top: -22px; left: 0;
  width: 100%; height: auto; pointer-events: none; z-index: 2;
}
.lantern {
  position: absolute; top: 64px; left: 18px; width: 58px; height: auto;
  pointer-events: none; z-index: 2;
  filter: drop-shadow(0 0 14px #ffd87355);
}

#field {
  position: relative; height: 470px;
  background: url("assets/field-ground.jpg") center / cover no-repeat;
}
#field::before {  /* blend from pen */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 90px;
  background: linear-gradient(180deg, #171233 0%, transparent 100%);
  pointer-events: none;
}
#field::after {  /* fade to page bottom */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 90px;
  background: linear-gradient(0deg, var(--night-lo) 0%, transparent 100%);
  pointer-events: none;
}
#field-label {
  position: absolute; top: 34px; left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  color: #cfc3ff; background: #14142e99; border: 1px solid #cfc3ff33;
  padding: 5px 12px; border-radius: 999px; pointer-events: none;
}

#tray-spacer { height: calc(96px + env(safe-area-inset-bottom, 0px)); background: var(--night-lo); }

/* ---------- animals ---------- */
.animal {
  position: absolute; z-index: 5;
  width: 84px; height: 84px;
  transform: translate(-50%, -100%);
  cursor: pointer;
  transition: filter .3s;
}
.animal .bob {
  width: 100%; height: 100%; position: relative;
  animation: bob 2.6s ease-in-out infinite;
}
.animal.walking .bob { animation: waddle .5s ease-in-out infinite; }
@keyframes bob    { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes waddle { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-5px) rotate(3deg); } }

.animal img.body {
  width: 100%; height: 100%; object-fit: contain; display: block;
  -webkit-user-drag: none; user-select: none;
}
.animal.flip img.body { transform: scaleX(-1); }
.animal.flip .stardots { transform: scaleX(-1); }

.animal .shadow {
  position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  width: 62%; height: 12px; border-radius: 50%;
  background: radial-gradient(closest-side, #00000055, transparent);
}

.stardots { position: absolute; inset: 0; pointer-events: none; }
.stardots .dot {
  position: absolute; width: 7px; height: 7px; margin: -3.5px;
  border-radius: 50%;
  background: #fff8e0; opacity: 0;
  transition: opacity .4s;
}
.stardots .dot.lit {
  opacity: 1;
  box-shadow: 0 0 6px 2px #ffe9a8cc, 0 0 14px 5px #ffd87366;
  animation: dot-pulse 2.8s ease-in-out infinite;
}
.stardots .dot.pop { animation: dot-pop .7s ease, dot-pulse 2.8s .7s ease-in-out infinite; }
@keyframes dot-pulse { 0%,100% { box-shadow: 0 0 6px 2px #ffe9a8cc, 0 0 14px 5px #ffd87366; } 50% { box-shadow: 0 0 9px 3px #fff3cf, 0 0 20px 8px #ffd87388; } }
@keyframes dot-pop { 0% { transform: scale(3.2); opacity: 0; } 60% { transform: scale(1.4); opacity: 1; } 100% { transform: scale(1); } }

.animal.happy .bob { animation: hop .5s ease 2; }
@keyframes hop { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-16px); } }

.animal .busy-tag {
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; white-space: nowrap;
  color: var(--ink); background: var(--gold);
  padding: 2px 8px; border-radius: 999px;
  display: none;
}
.animal.hauling .busy-tag { display: block; }

.animal .lively-tag {
  position: absolute; top: -14px; right: -4px;
  font-size: 12px; filter: drop-shadow(0 0 5px #9fd8ff);
  animation: bob 1.6s ease-in-out infinite;
  pointer-events: none;
}

.particle {
  position: absolute; z-index: 30; pointer-events: none;
  font-size: 15px; opacity: 0;
  animation: part 1s ease-out forwards;
}
@keyframes part {
  0%   { opacity: 0; transform: translateY(4px) scale(.6); }
  25%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-34px) scale(1.15); }
}

/* ---------- shards ---------- */
.shard {
  position: absolute; z-index: 4;
  transform: translate(-50%, -50%);
  cursor: pointer; border: none; background: none; padding: 0;
}
.shard img {
  display: block; width: 100%; height: auto;
  filter: drop-shadow(0 0 10px #ffe9a877);
  animation: shard-breathe 3.2s ease-in-out infinite;
  -webkit-user-drag: none;
}
@keyframes shard-breathe { 0%,100% { filter: drop-shadow(0 0 7px #ffe9a866); } 50% { filter: drop-shadow(0 0 14px #ffe9a8aa); } }
.shard.s { width: 44px; }
.shard.m { width: 64px; }
.shard.l { width: 96px; }
.shard .timer {
  position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--cream); border: 1.5px solid #d9b96a;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  display: none;
}
.shard.working .timer { display: block; }
.shard.working img { animation: shard-wiggle .8s ease-in-out infinite; }
@keyframes shard-wiggle { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }

.shard.fly {
  transition: all .8s cubic-bezier(.4,-.2,.6,1);
  z-index: 45;
}

/* ---------- tray ---------- */
#tray {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--col-w);
  display: flex; gap: 10px; justify-content: center;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: linear-gradient(0deg, #101024f5 65%, transparent 100%);
  z-index: 40;
}
@media (min-width: 700px) { #tray { max-width: 430px; } }
.tray-btn {
  flex: 1; max-width: 170px; min-height: 56px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(180deg, #fffaf0, #ffe9c4);
  border: 2px solid #d9b96a; border-radius: 18px;
  font-family: inherit; font-size: 15px; font-weight: 700; color: var(--ink);
  cursor: pointer; box-shadow: 0 3px 0 #b8934c, 0 6px 14px #00000055;
}
.tray-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #b8934c; }
.tray-btn img { width: 30px; height: 30px; object-fit: contain; }
.tray-btn b { color: #a4670f; }

/* ---------- popover ---------- */
#popover {
  position: fixed; z-index: 60;
  background: var(--panel); color: var(--ink);
  border: 2px solid #d9b96a; border-radius: 16px;
  padding: 12px 14px; width: 180px;
  box-shadow: 0 8px 24px #000a;
  transform: translate(-50%, -100%);
}
#popover::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -8px;
  border: 8px solid transparent; border-top-color: #d9b96a; border-bottom: none;
}
.pop-name { font-weight: 800; font-size: 15px; margin-bottom: 3px; }
.pop-stars { font-size: 12px; color: #8a6d3b; margin-bottom: 9px; }
.pop-btn {
  width: 100%; min-height: 44px;
  background: linear-gradient(180deg, #ffe083, #ffc93d);
  border: 2px solid #d9a13d; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 800; color: #6b4300;
  cursor: pointer; box-shadow: 0 2px 0 #c68a1e;
}
.pop-btn:active { transform: translateY(2px); box-shadow: none; }
.pop-btn[disabled] { filter: grayscale(.7); opacity: .6; }

/* ---------- sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; }
.sheet-panel {
  pointer-events: auto;
  width: 100%; max-width: var(--col-w);
  background: var(--panel); color: var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  box-shadow: 0 -8px 30px #000b;
  transform: translateY(105%);
  transition: transform .32s cubic-bezier(.25,.9,.35,1);
  max-height: 62vh; display: flex; flex-direction: column;
}
@media (min-width: 700px) { .sheet-panel { max-width: 430px; } }
.sheet-panel.tall { max-height: 82vh; }
.sheet:not(.hidden) .sheet-panel { transform: translateY(0); }
.sheet.hidden { visibility: hidden; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 16px; font-weight: 800; margin-bottom: 12px;
}
.sheet-close {
  width: 44px; height: 44px; border-radius: 12px; border: 2px solid #d9b96a;
  background: #fff; color: var(--ink); font-size: 16px; font-weight: 700; cursor: pointer;
}

#picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; overflow-y: auto; }
.pick-cell {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 2px solid #e4cf9e; border-radius: 14px; background: #fff;
  padding: 10px 4px 8px; cursor: pointer; font-family: inherit;
  font-size: 12.5px; font-weight: 700; color: var(--ink);
}
.pick-cell img { width: 56px; height: 56px; object-fit: contain; }
.pick-cell:active { background: #fff3d6; }
.pick-cell[disabled] { opacity: .45; }
.pick-cell small { font-weight: 600; color: #a4670f; font-size: 10.5px; }

#book-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.book-cell {
  border-radius: 12px; padding: 8px 3px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 9.5px; text-align: center; min-height: 84px; justify-content: flex-end;
}
.book-cell.lit { background: linear-gradient(180deg, #2b2b55, #1c1c3d); color: var(--gold); border: 1.5px solid #ffd87388; font-weight: 700; }
/* no filter on imgs inside the scrollable grid — WebKit leaves stale layer tiles */
.book-cell.lit img { width: 46px; height: 46px; object-fit: contain; }
.book-cell.lit { box-shadow: inset 0 0 14px #ffd87322; }
.book-cell.dark { background: #26263f; color: #8a8ab0; border: 1.5px solid #35355c; }
.book-cell.dark .sil { font-size: 20px; opacity: .5; filter: grayscale(1); }

#backdrop {
  position: fixed; inset: 0; background: #000a; z-index: 55;
  opacity: 1; transition: opacity .3s;
}
#backdrop.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
.hidden { }

/* popover hidden helper */
#popover.hidden { display: none; }

/* ---------- toast ---------- */
#toast-holder {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 100px);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: #14142eee; color: var(--cream);
  border: 1.5px solid #ffd87366; border-radius: 999px;
  padding: 10px 18px; font-size: 13.5px; font-weight: 600;
  animation: toast-in .3s ease, toast-out .4s ease 2.6s forwards;
  text-align: center; max-width: 92vw; white-space: normal;
}
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
