:root {
  --gold: #ffd27a; --brass: #c9963e; --ink: #1d0f04; --teal: #0d2a2e;
  --font: "Georgia", "Palatino Linotype", "Book Antiqua", serif;
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #050a0c; color: #f6ead0; font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 55%, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%); }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: #ff6a2a; transition: opacity 0.35s; mix-blend-mode: screen; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
.noshop .shopOnly { display: none !important; }
body.touch #glyphBar { display: none; }
body:not(.touch) #dpad { display: none; }
#stepPlate.over #stepN { color: #ff9a6a; }
/* popups always sit above the HUD; the HUD, banner and toast step aside while one is open */
#popup { z-index: 1000; background: rgba(3,8,10,0.8) !important; }
body.overlay #hud, body.overlay #banner, body.overlay #toast { visibility: hidden !important; }
#popPanel { background-color: #0d2a2e; background-clip: padding-box; }
#popPanel .btn { min-height: 48px; min-width: 130px; flex-shrink: 0; }
#popPanel.pop { animation: popFade 0.2s ease-out both; }
@keyframes popFade { from { opacity: 0; } }
#endBtns { position: absolute; left: 0; right: 0; bottom: 10%; z-index: 2; }

/* outlined display text */
.big, h2, .btn, #banner, #endText, .badge, #stepN, #goldN, #sGoldN {
  font-weight: 900; color: var(--gold);
  text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 4px 0 #000;
}

/* 9-slice plates */
.plate { border-style: solid; border-width: 14px 16px; border-image: url(assets/ui-button.webp) 165 45 131 45 fill / 14px 16px stretch; padding: 0 6px; display: flex; align-items: center; gap: 8px; min-height: 52px; }
.panel { border-style: solid; border-width: 34px; border-image: url(assets/ui-panel.webp) 110 92 110 92 fill / 34px stretch; padding: 4px 10px; }
.btn { border-style: solid; border-width: 14px 18px; border-image: url(assets/ui-button.webp) 165 45 131 45 fill / 14px 18px stretch; background: none;
  font-size: 20px; padding: 0 14px; min-height: 56px; min-width: 150px; transition: transform 0.12s, filter 0.12s; }
.btn:hover, .btn.focus { filter: brightness(1.25) drop-shadow(0 0 8px rgba(255,200,100,0.7)); transform: scale(1.05); }
.btn:active { transform: scale(0.94); }
.btn.primary { color: #fff3c4; }
.small { font-size: 14px; color: #e8d6ae; text-shadow: 0 2px 0 #000, 0 0 4px #000; }
.dim { opacity: 0.7; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hudTop { position: absolute; top: 10px; left: calc(10px + var(--safe-l)); display: flex; gap: 8px; align-items: flex-start; }
#floorPlate { padding-left: 0; }
#clock { width: 46px; height: 46px; margin-left: -4px; filter: drop-shadow(0 2px 2px #000); }
.plateText { display: flex; flex-direction: column; line-height: 1.05; padding-right: 6px; }
.plateText .big { font-size: 19px; }
.plateText .small { font-size: 13px; max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { font-size: 20px; }
.chip .ico { width: 26px; height: 26px; }
#parN { font-size: 14px; color: #e8d6ae; margin-left: 2px; }
#hudBtns { position: absolute; top: 94px; left: calc(10px + var(--safe-l)); display: flex; gap: 10px; pointer-events: auto; }
.hbtn { width: 50px; height: 50px; border-radius: 50%; border: 3px solid #c9963e; background: radial-gradient(circle at 40% 35%, #1f4a50, #0b2226); color: var(--gold);
  display: flex; align-items: center; justify-content: center; padding: 0; position: relative; box-shadow: 0 3px 0 #000, inset 0 0 6px rgba(255,210,120,0.35); transition: transform 0.1s, filter 0.1s; }
.hbtn:hover { filter: brightness(1.25); }
.hbtn:active { transform: scale(0.9); }
.hbtn svg { width: 26px; height: 26px; }
.hbtn img { width: 34px; height: 34px; }
.badge { position: absolute; right: -6px; bottom: -6px; font-size: 15px; min-width: 22px; }

#glyphBar { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; pointer-events: auto; }
.gslot { width: 74px; height: 74px; border-radius: 50%; border: none; background: none; padding: 0; position: relative; transition: transform 0.12s, filter 0.12s; }
.gslot img { width: 100%; height: 100%; filter: drop-shadow(0 4px 3px #000); }
.gslot.locked img { filter: grayscale(1) brightness(0.35); }
.gslot:not(.locked):hover { transform: scale(1.08); filter: brightness(1.2); }
.gslot:not(.locked):active { transform: scale(0.9); }
.gslot .key { position: absolute; top: -4px; left: -4px; width: 24px; height: 24px; border-radius: 50%; background: #1d0f04; color: var(--gold); font-weight: 900; font-size: 14px; line-height: 22px; border: 2px solid var(--brass); }
.gslot .gname { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 13px; white-space: nowrap; font-weight: 700; color: #f3e2b8; text-shadow: 0 2px 0 #000, 0 0 3px #000; }
.gslot.cast { animation: castPop 0.3s; }
@keyframes castPop { 40% { transform: scale(1.25); filter: brightness(1.8); } }

#dpad { position: absolute; left: calc(18px + var(--safe-l)); bottom: 16px; display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); gap: 6px; pointer-events: auto; }
#dpad button { border-radius: 14px; border: 3px solid rgba(201,150,62,0.9); background: rgba(13,42,46,0.62); color: var(--gold); display: flex; align-items: center; justify-content: center; padding: 0; touch-action: none; box-shadow: 0 3px 0 rgba(0,0,0,0.6); }
#dpad button svg { width: 30px; height: 30px; }
#dpad button.on { background: rgba(201,150,62,0.6); transform: scale(0.94); }
#dpad .waitBtn { border-radius: 50%; }

#banner { position: fixed; left: 0; right: 0; top: 30%; text-align: center; font-size: 46px; pointer-events: none; opacity: 0; transition: opacity 0.4s, transform 0.4s; transform: scale(0.8); }
#banner.show { opacity: 1; transform: scale(1); }
#banner .small { display: block; font-size: 22px; font-weight: 700; margin-top: 4px; }
#subtitle { position: fixed; left: 50%; bottom: 112px; transform: translateX(-50%); max-width: min(70vw, 640px); padding: 10px 18px; background: rgba(8,18,20,0.78); border: 2px solid var(--brass); border-radius: 12px;
  font-size: 18px; text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.3s; color: #fff2d0; text-shadow: 0 2px 0 #000; }
#subtitle.show { opacity: 1; }
#subtitle b { color: var(--gold); }
#toast { position: fixed; left: 50%; top: 22%; transform: translate(-50%, 0); font-size: 20px; font-weight: 700; pointer-events: none; opacity: 0; transition: opacity 0.25s;
  color: #fff; text-shadow: 0 2px 0 #000, 0 0 6px #000; white-space: nowrap; }
#toast.show { opacity: 1; }

/* screens */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.bg { position: absolute; inset: 0; background-size: cover; background-position: center; }
.bg.dim::after { content: ""; position: absolute; inset: 0; background: rgba(4,10,12,0.55); }
#title .bg { animation: slowZoom 30s ease-in-out infinite alternate; }
@keyframes slowZoom { to { transform: scale(1.06); } }
#logo { position: absolute; left: 6%; top: 8%; width: 46%; max-height: 40%; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.8)); animation: logoIn 0.7s cubic-bezier(.2,1.6,.4,1) both, logoFloat 4s 0.7s ease-in-out infinite alternate; }
@keyframes logoIn { from { transform: translateY(-40px) scale(0.7); opacity: 0; } }
@keyframes logoFloat { to { transform: translateY(6px); } }
#startPrompt { position: absolute; left: 6%; width: 46%; top: 58%; text-align: center; font-size: 24px; font-weight: 900; color: #fff3c4; animation: pulse 1.6s ease-in-out infinite;
  text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink), 0 0 16px rgba(255,180,80,0.8); }
@keyframes pulse { 50% { opacity: 0.55; transform: scale(0.97); } }
.corner { position: absolute; top: 10px; width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(201,150,62,0.8); background: rgba(10,30,34,0.6); color: var(--gold);
  display: flex; align-items: center; justify-content: center; padding: 0; transition: transform 0.12s, filter 0.12s; }
.corner:hover { filter: brightness(1.3); } .corner:active { transform: scale(0.9); }
.corner svg { width: 26px; height: 26px; } .corner img { width: 32px; height: 32px; }
.corner.right { right: calc(12px + var(--safe-r)); } .corner.left { left: calc(12px + var(--safe-l)); }
.corner.inline { position: static; }
#sTopRight { position: absolute; top: 10px; right: calc(12px + var(--safe-r)); display: flex; gap: 10px; align-items: center; }
#sGold { min-height: 48px; }

#selPanel { position: relative; width: min(92vw, 760px); max-height: 92vh; display: flex; flex-direction: column; align-items: center; animation: popIn 0.3s cubic-bezier(.2,1.5,.4,1) both; }
#selPanel h2 { margin: 0 0 8px; font-size: 26px; }
#floorGrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; width: 100%; }
.fbtn { position: relative; border-style: solid; border-width: 10px 12px; border-image: url(assets/ui-button.webp) 165 45 131 45 fill / 10px 12px stretch; background: none; min-height: 64px; padding: 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--gold); transition: transform 0.12s, filter 0.12s; }
.fbtn .n { font-size: 24px; font-weight: 900; line-height: 1; text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink); }
.fbtn .st { font-size: 12px; letter-spacing: 1px; color: #ffcf5a; text-shadow: 0 1px 0 #000; height: 14px; }
.fbtn .st .off { color: #5a4a30; }
.fbtn.locked { filter: grayscale(0.9) brightness(0.55); cursor: default; }
.fbtn:not(.locked):hover, .fbtn.focus { filter: brightness(1.3) drop-shadow(0 0 6px rgba(255,200,100,0.8)); transform: scale(1.06); }
.fbtn:not(.locked):active { transform: scale(0.94); }
.fbtn .lock { width: 20px; height: 20px; }
#selInfo { margin-top: 6px; }
#bagRow { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; justify-content: center; align-items: center; min-height: 48px; }
.bagItem { display: flex; align-items: center; gap: 4px; border: 2px solid rgba(201,150,62,0.7); border-radius: 26px; padding: 3px 12px 3px 4px; background: rgba(0,0,0,0.35); color: #f3e2b8; font-size: 15px; font-weight: 700; min-height: 46px; }
.bagItem img { width: 38px; height: 38px; }
.bagItem.equip { border-color: var(--gold); box-shadow: 0 0 10px rgba(255,210,120,0.6); }
button.bagItem:hover { filter: brightness(1.2); }
.bagLabel { font-weight: 900; color: var(--gold); font-size: 15px; text-shadow: 0 2px 0 #000; }

#clear { background: rgba(3,8,10,0.5); }
#clearPanel { position: relative; width: min(86vw, 460px); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
#clearPanel h2 { margin: 0; font-size: 34px; animation: slam 0.45s cubic-bezier(.2,1.8,.4,1) both; }
@keyframes slam { from { transform: scale(2.2); opacity: 0; } }
#stars { display: flex; gap: 8px; margin: 2px 0; }
.star { width: 44px; height: 44px; background: #3a2c16; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.star.on { background: linear-gradient(#fff2a0, #f0a828); animation: starIn 0.4s cubic-bezier(.2,1.8,.4,1) both; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
#clearStats { font-size: 17px; font-weight: 700; color: #f3e2b8; text-shadow: 0 2px 0 #000; }
#clearScore { font-size: 30px; font-weight: 900; color: var(--gold); text-shadow: -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink); }
#clearCogs { display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 900; color: #ffe08a; text-shadow: 0 2px 0 #000; }
#clearCogs img { width: 30px; height: 30px; }
.row { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.corner.mini { top: -6px; right: -6px; width: 44px; height: 44px; }
.pop { animation: popIn 0.28s cubic-bezier(.2,1.5,.4,1) both; }
@keyframes popIn { from { transform: scale(0.6); opacity: 0; } }

#popup { background: rgba(3,8,10,0.6); }
#popPanel { width: min(90vw, 620px); max-height: 90vh; overflow: hidden; text-align: center; display: flex; flex-direction: column; }
#popPanel .popBody { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
#popPanel > .row { flex-shrink: 0; margin-bottom: 6px; }
#popPanel h2 { margin: 0 0 8px; font-size: 26px; }
#popPanel p { margin: 6px 0; font-size: 16px; line-height: 1.4; text-align: left; color: #f3e2b8; text-shadow: 0 1px 0 #000; }
#popPanel .glyphHelp { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 6px 0; }
#popPanel .glyphHelp > div { font-size: 13px; color: #f3e2b8; }
#popPanel .glyphHelp img { width: 48px; height: 48px; display: block; margin: 0 auto 2px; }
#popPanel .glyphHelp .gtx { display: block; }
#popPanel .glyphHelp b { color: var(--gold); display: block; }

#introLayer video { width: 100%; height: 100%; object-fit: cover; }
.sub { position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%); width: min(80vw, 760px); text-align: center; font-size: 22px; font-weight: 700; color: #fff2d0;
  text-shadow: 0 2px 0 #000, 0 0 8px #000, 0 0 2px #000; opacity: 0; transition: opacity 0.5s; }
.sub.show { opacity: 1; }
.btn.skip { position: absolute; top: 12px; right: calc(12px + var(--safe-r)); min-width: 110px; font-size: 18px; min-height: 50px; }
#ending .bg { animation: slowZoom 20s ease-out forwards; }
#endText { position: absolute; top: 14%; left: 0; right: 0; text-align: center; font-size: 44px; opacity: 0; transition: opacity 1.2s; }
#endText.show { opacity: 1; }
#endText .small { display: block; font-size: 22px; margin-top: 8px; }

/* phones (a locked landscape page is 704×396) */
@media (max-height: 500px) {
  .plateText .big { font-size: 16px; } .plateText .small { font-size: 12px; max-width: 120px; }
  .plate { min-height: 46px; border-width: 11px 13px; border-image-width: 11px 13px; }
  #clock { width: 38px; height: 38px; }
  .chip { font-size: 17px; } .chip .ico { width: 22px; height: 22px; }
  #hudBtns { top: 76px; gap: 8px; }
  .hbtn { width: 46px; height: 46px; }
  #dpad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); gap: 5px; bottom: 10px; }
  #subtitle { bottom: auto; top: 118px; font-size: 15px; max-width: 56vw; }
  #banner { font-size: 32px; top: 26%; } #banner .small { font-size: 17px; }
  #selPanel { width: min(94vw, 640px); border-width: 24px; border-image-width: 24px; }
  #selPanel h2 { font-size: 20px; margin-bottom: 4px; }
  .fbtn { min-height: 56px; } .fbtn .n { font-size: 20px; }
  #bagRow { margin-top: 6px; gap: 6px; }
  .bagItem { min-height: 44px; font-size: 13px; } .bagItem img { width: 32px; height: 32px; }
  #clearPanel { border-width: 24px; border-image-width: 24px; }
  #clearPanel h2 { font-size: 26px; } .star { width: 34px; height: 34px; } #clearScore { font-size: 24px; }
  .btn { min-height: 48px; font-size: 17px; min-width: 130px; }
  #popPanel { border-width: 22px; border-image-width: 22px; max-height: calc(100vh - 16px); padding: 0 6px; }
  #popPanel h2 { font-size: 20px; margin: 0 0 2px; }
  #popPanel p { font-size: 14px; margin: 3px 0; line-height: 1.3; }
  #popPanel .glyphHelp { margin: 2px 0; gap: 6px; } #popPanel .glyphHelp > div { font-size: 12px; } #popPanel .glyphHelp img { width: 34px; height: 34px; }
  #popPanel .row { margin-top: 4px; }
  .sub { font-size: 17px; }
  #endText { font-size: 30px; }
  #startPrompt { font-size: 19px; }
}

/* narrow portrait screens (a phone held upright) */
@media (max-width: 600px) {
  #selPanel { width: calc(100vw - 16px); border-width: 22px; border-image-width: 22px; padding: 4px 4px; }
  #floorGrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .fbtn { min-width: 0; min-height: 58px; border-width: 8px 9px; border-image-width: 8px 9px; }
  #clearPanel { width: calc(100vw - 24px); border-width: 24px; border-image-width: 24px; }
  #clearPanel h2 { font-size: 26px; padding: 0 38px; }
  /* How to Play: glyphs as a 2×2 grid, icon beside name + line */
  #popPanel { width: calc(100vw - 16px); border-width: 22px; border-image-width: 22px; padding: 2px 4px 4px; }
  #popPanel h2 { font-size: 22px; margin: 0 0 4px; }
  #popPanel p { font-size: 14px; line-height: 1.32; margin: 4px 0; }
  #popPanel .glyphHelp { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 6px; margin: 8px 0 4px; }
  #popPanel .glyphHelp > div { display: flex; align-items: center; gap: 6px; text-align: left; font-size: 12.5px; line-height: 1.25; }
  #popPanel .glyphHelp img { width: 38px; height: 38px; margin: 0; flex-shrink: 0; }
  #popPanel > .row { margin: 8px 0 10px; }
}
