:root {
  --ink: #1d1a17;
  --sepia: #4a3626;
  --paper: #efe6d2;
  --cream: #f4ead4;
  --blue: #1c2a42;
  --crimson: #9a2f29;
  --font: Georgia, serif;
}
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #07090d;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#game { position: fixed; inset: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ui {
  position: absolute; left: 0; top: 0; width: 960px; height: 540px;
  transform-origin: 0 0; pointer-events: none; font-family: var(--font); color: var(--ink);
}
#ui button, #ui .hit { pointer-events: auto; }
.layer { position: absolute; inset: 0; }
[hidden] { display: none !important; }

/* ---- art pieces ---- */
.panel {
  box-sizing: border-box;
  border-style: solid; border-width: 30px;
  border-image: url(../assets/ui-panel.webp) 96 fill / 30px stretch;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.55));
}
.plate {
  box-sizing: border-box;
  background: rgba(20, 26, 40, .78);
  border: 2px solid rgba(240, 228, 200, .55);
  outline: 1px solid rgba(20,16,10,.7);
  border-radius: 4px;
  color: var(--cream);
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
}
.btn {
  all: unset; box-sizing: border-box; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 4px 16px;
  border-style: solid; border-width: 6px 11px;
  /* the plate sits in the middle of its picture: slice past the transparent margin and push it outside with outset */
  border-image: url(../assets/ui-button.webp) 102 40 104 40 fill / 26px 16px / 20px 5px stretch;
  color: var(--cream); font-family: var(--font); font-weight: 900; font-size: 20px; line-height: 1.15;
  text-align: center;
  text-shadow: -1.5px -1.5px 0 #0c0f18, 1.5px -1.5px 0 #0c0f18, -1.5px 1.5px 0 #0c0f18, 1.5px 1.5px 0 #0c0f18, 0 3px 0 #0c0f18;
  transition: transform .12s ease, filter .12s ease;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.5));
}
.btn img { width: 30px; height: 30px; object-fit: contain; }
.btn:hover, .btn.focus { filter: brightness(1.25) drop-shadow(0 0 6px rgba(240,200,120,.85)); transform: scale(1.04); }
.btn.focus { outline: none; }
.btn:active, .btn.pressed { transform: scale(.94); }
.btn.small { min-height: 52px; font-size: 18px; padding: 4px 14px; }
.btn.dim { filter: grayscale(1) brightness(.6); }
.btn.on { filter: brightness(1.3) sepia(.6) hue-rotate(-20deg) saturate(2.2); }
.outlined {
  color: var(--cream); font-weight: 900;
  text-shadow: -2px -2px 0 #0c0f18, 2px -2px 0 #0c0f18, -2px 2px 0 #0c0f18, 2px 2px 0 #0c0f18, 0 4px 0 #0c0f18, 0 0 18px rgba(0,0,0,.7);
}

/* ---- title ---- */
#logo {
  position: absolute; left: 50px; top: 34px; width: 520px; max-height: 190px; object-fit: contain; object-position: left top;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.7));
  animation: logoIn .7s cubic-bezier(.2,1.4,.4,1) both, float 5s ease-in-out 1s infinite;
}
@keyframes logoIn { from { opacity: 0; transform: translateY(-40px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
#startPrompt {
  position: absolute; left: 0; right: 0; bottom: 46px; text-align: center; font-size: 24px; letter-spacing: 2px;
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

/* ---- HUD ---- */
#hud { pointer-events: none; }
/* shared zones (set by src/layout.js): --padL/R/T/B safe margins, --pzW/--pzH the pause corner, --hudL right of the back corner */
body.touch #btnNote, body.touch #btnAuto { display: none !important; } /* the touch buttons B / C do these on phones */
#hudPanel { position: absolute; left: var(--hudL, 64px); top: var(--hudT, 10px); min-width: 132px; width: max-content; height: 56px; padding: 3px 12px; display: flex; flex-direction: column; justify-content: center; }
#hudTime { font-size: 24px; font-weight: 900; line-height: 1; letter-spacing: 1px; color: #f6e2b0; text-shadow: 0 2px 0 #000; }
#hudLoc { font-size: 15px; line-height: 1.2; white-space: nowrap; opacity: .9; }
#btnNote { position: absolute; left: 228px; top: calc(var(--hudT, 10px) - 1px); min-height: 58px; padding: 4px 14px; font-size: 18px; }
#btnAuto { position: absolute; top: calc(var(--hudT, 10px) - 1px); min-height: 58px; }
#hudGold { position: absolute; top: calc(var(--padT, 10px) + 3px); right: var(--pzW, 70px); height: 50px; padding: 0 12px 0 6px; display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 900; }
#hudGold img { width: 36px; height: 36px; }

/* ---- investigation ---- */
/* info stays top-left (under the time), actions run down the right edge under the pause corner */
#invProg { position: absolute; left: var(--hudL, 64px); top: calc(var(--hudT, 10px) + 64px); width: max-content; min-width: 132px; padding: 4px 12px; font-size: 16px; line-height: 1.35; }
#invCol { position: absolute; right: var(--padR, 12px); top: var(--pzH, 70px); width: var(--colW, 116px); display: flex; flex-direction: column; gap: 8px; }
#invCol.two { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; width: calc(var(--colW, 116px) * 2 + 8px); }
#ui #invCol .btn { width: var(--colW, 116px); min-height: var(--btnH, 52px); padding: 2px 6px; font-size: 18px; }
#invCol .btn.here { filter: brightness(1.35) sepia(.5) drop-shadow(0 0 6px rgba(240,200,120,.8)); }
#invCol .btn.deduce { border-image-source: url(../assets/ui-button.webp); filter: hue-rotate(150deg) saturate(2.5) brightness(1.1) drop-shadow(0 0 8px rgba(255,120,90,.8)); animation: pulse 1.6s ease-in-out infinite; }

/* ---- text box ---- */
/* the box sits on the safe bottom edge, left of the touch buttons (--tbR), and grows upward to --tbMax (under the faces) */
#tb { inset: auto; left: var(--padL, 12px); right: var(--tbR, 12px); bottom: var(--padB, 10px); display: flex; flex-direction: column; align-items: flex-start; }
#tbName { position: relative; margin: 0 0 -14px 26px; min-height: 46px; padding: 2px 18px; font-size: 19px; z-index: 2; pointer-events: none; }
#tbBox { position: relative; align-self: stretch; min-height: var(--tbMin, 182px); max-height: var(--tbMax, 240px); overflow: hidden; padding: 10px 16px 14px 12px;
  border-width: var(--tbB, 30px); border-image-width: var(--tbB, 30px); }
#tbText { font-size: var(--tbFs, 21px); line-height: 1.55; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
#tbText.narr { color: #3b2c20; }
.tbRest { visibility: hidden; }
#tbNext { position: absolute; right: 2px; bottom: -2px; font-size: 16px; color: var(--crimson); animation: bob .9s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* ---- cards ---- */
#card { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; }
#cardSmall { font-size: 22px; letter-spacing: 6px; opacity: .85; }
#cardBig { font-size: 64px; letter-spacing: 8px; margin: 6px 0; }
#cardSub { font-size: 22px; letter-spacing: 2px; max-width: 760px; }
#card.show > * { animation: cardIn 1.2s cubic-bezier(.2,1,.3,1) both; }
#card.show #cardBig { animation-delay: .15s; }
#card.show #cardSub { animation-delay: .4s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); letter-spacing: 16px; } to { opacity: 1; transform: none; } }

/* ---- modal ---- */
/* every panel keeps clear of the pause corner (top and both sides, so it stays centred) and the safe bottom edge,
   and scrolls inside when its content is taller */
#modal, #note, .infoLayer { box-sizing: border-box; padding: var(--pzH, 64px) var(--pzW, 64px) var(--padB, 10px); }
#modal { display: flex; align-items: center; justify-content: center; background: rgba(5,6,10,.35); pointer-events: auto; }
#modalPanel, .infoPanel { max-width: 100%; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  scrollbar-width: thin; scrollbar-color: rgba(74,54,38,.55) transparent; }
#modalPanel > *, .infoPanel > * { flex-shrink: 0; }
#modalPanel { width: 640px; padding: 8px 14px; display: flex; flex-direction: column; gap: 10px; animation: popIn .26s cubic-bezier(.2,1.5,.4,1) both; }
#modalPanel.wide { width: 920px; }
@keyframes popIn { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: none; } }
.mTitle { font-size: 26px; font-weight: 900; text-align: center; color: var(--crimson); letter-spacing: 3px; }
.mText { font-size: 19px; line-height: 1.6; color: var(--ink); white-space: pre-wrap; }
.mSmall { font-size: 15px; color: var(--sepia); text-align: center; }
.mRow { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.mCol { display: flex; flex-direction: column; gap: 8px; }
.mCol .btn { width: 100%; font-size: 19px; min-height: 56px; }
.rule { font-size: 18px; line-height: 1.55; padding-left: 1.8em; text-indent: -1.8em; }
.qcount { font-size: 15px; color: var(--sepia); text-align: center; letter-spacing: 2px; }
@media (pointer: coarse) { #ui .btn { min-height: 68px; } #ui .btn.small { min-height: 66px; } #ui .ev, #ui .who { min-height: 68px !important; } }
.ev-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.ev { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  min-height: 104px; padding: 4px; border: 2px solid rgba(60,40,25,.45); border-radius: 4px; background: rgba(255,250,235,.6);
  font-family: var(--font); font-size: 15px; line-height: 1.2; text-align: center; color: var(--ink); transition: transform .12s, background .12s; }
.ev img { width: 56px; height: 56px; object-fit: contain; }
.ev:hover, .ev.focus { background: rgba(255,236,190,.95); border-color: var(--crimson); transform: scale(1.05); }
.ev.gone { visibility: hidden; }
.who-grid { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.who { all: unset; box-sizing: border-box; cursor: pointer; width: 104px; display: flex; flex-direction: column; align-items: center; padding: 4px;
  border: 2px solid rgba(60,40,25,.45); border-radius: 4px; background: rgba(255,250,235,.6); font-family: var(--font); font-weight: 900; font-size: 16px; line-height: 1.2; text-align: center; color: var(--ink); transition: transform .12s, background .12s; }
.who canvas { width: 88px; height: 88px; }
.who:hover, .who.focus { background: rgba(255,236,190,.95); border-color: var(--crimson); transform: scale(1.05); }
.who.gone { visibility: hidden; }
.rank { font-size: 92px; font-weight: 900; color: var(--crimson); text-align: center; line-height: 1; animation: stamp .5s cubic-bezier(.3,1.8,.5,1) .3s both; text-shadow: 0 0 2px #fff; }
@keyframes stamp { from { opacity: 0; transform: scale(2.4) rotate(-14deg); } to { opacity: 1; transform: rotate(-8deg); } }
.stat { display: flex; justify-content: space-between; font-size: 18px; border-bottom: 1px dashed rgba(60,40,25,.4); padding: 3px 0; }
.stat img { width: 24px; height: 24px; vertical-align: middle; }

/* ---- notebook ---- */
#note { display: flex; align-items: center; justify-content: center; background: rgba(5,6,10,.5); pointer-events: auto; }
#notePanel { position: relative; width: 900px; height: 510px; max-width: 100%; max-height: 100%; padding: 4px 10px; display: flex; flex-direction: column; animation: popIn .24s cubic-bezier(.2,1.5,.4,1) both; }
#noteTabs { display: flex; flex-wrap: wrap; gap: 8px; padding-right: 130px; flex: none; }
#noteTabs .btn { min-height: 50px; font-size: 17px; padding: 2px 14px; }
#noteTabs .btn.cur { filter: brightness(1.35) sepia(.5) drop-shadow(0 0 6px rgba(240,200,120,.8)); }
#noteClose { position: absolute; right: 0; top: 0; }
#noteBody { flex: 1; overflow-y: auto; margin-top: 8px; padding-right: 6px; scrollbar-width: none; touch-action: pan-y; pointer-events: auto; }
#noteBody::-webkit-scrollbar { display: none; }
.nItem { display: flex; gap: 10px; align-items: flex-start; padding: 6px 4px; border-bottom: 1px dashed rgba(60,40,25,.35); }
.nItem img, .nItem canvas { width: 56px; height: 56px; flex: none; object-fit: contain; }
.nName { font-weight: 900; font-size: 18px; color: var(--ink); }
.nName .tag { font-size: 13px; color: #fff; background: var(--crimson); padding: 1px 6px; border-radius: 3px; margin-left: 6px; vertical-align: 2px; }
.nName .tag.fs { background: var(--blue); }
.nDesc { font-size: 16px; line-height: 1.5; color: #3b2c20; }
.nSecret { font-size: 15px; line-height: 1.5; color: var(--crimson); margin-top: 4px; }
.nTime { flex: none; width: 108px; font-weight: 900; font-size: 18px; color: var(--crimson); }
.nEmpty { font-size: 16px; color: var(--sepia); padding: 20px; text-align: center; }

/* ---- toast ---- */
#toast { display: flex; justify-content: center; pointer-events: none; }
#modal:not([hidden]) ~ #toast, #note:not([hidden]) ~ #toast { visibility: hidden; } /* never over a panel */
#toastIn { margin-top: calc(var(--padT, 10px) + 66px); max-width: calc(100% - 2 * var(--sideRes, 200px)); box-sizing: border-box; height: fit-content; padding: 8px 18px; font-size: 18px; font-weight: 900; display: flex; align-items: center; gap: 8px; animation: toastIn .3s cubic-bezier(.2,1.5,.4,1) both; }
#toastIn img { width: 34px; height: 34px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: none; } }

/* ---- info popup, quiz feedback, results ---- */
.infoLayer { display: flex; align-items: center; justify-content: center; background: rgba(5,6,10,.5); pointer-events: auto; z-index: 5; }
.infoPanel { width: 700px; padding: 8px 14px; display: flex; flex-direction: column; gap: 10px; animation: popIn .26s cubic-bezier(.2,1.5,.4,1) both; }
.qText { font-weight: 900; text-align: center; }
.mFeedback { min-height: 24px; font-size: 18px; font-weight: 900; text-align: center; color: var(--crimson); }
.mFeedback.ok { color: #2f5a35; }
.mFeedback.pop { animation: popIn .25s cubic-bezier(.2,1.5,.4,1) both; }
.hintRow:empty { display: none; }
.hintBtn img { width: 28px; height: 28px; }
#modalPanel.wide .ev-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.ev.right, .who.right, .btn.right { background: rgba(214,236,200,.95); border-color: #2f5a35; transform: scale(1.06); }
.resTop { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 4px 0 6px; }
.rankName { font-size: 28px; font-weight: 900; color: var(--ink); letter-spacing: 2px; }
.stats { width: 420px; margin: 0 auto; }
#hudGold { pointer-events: auto; cursor: pointer; }

/* ---- video ---- */
#vid { position: fixed; inset: 0; background: #000 url(../assets/title-bg.webp) center / cover no-repeat; z-index: 20; }
#video { width: 100%; height: 100%; object-fit: cover; }
#skipBtn { position: absolute; right: 24px; bottom: 24px; }
