* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #0b0820; color: #fff; }
body { font-family: "Trebuchet MS", system-ui, sans-serif; -webkit-user-select: none; user-select: none; }
#stage { position: fixed; inset: 0; }
#view { width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

.outl { text-shadow: -2px -2px 0 #1a1040, 2px -2px 0 #1a1040, -2px 2px 0 #1a1040, 2px 2px 0 #1a1040, 0 3px 0 #1a1040, 0 5px 0 rgba(0,0,0,0.35); }

.panel {
  border-style: solid; border-color: transparent; border-width: 14px;
  background: rgba(22, 14, 60, 0.82); border-radius: 18px;
  box-shadow: 0 0 0 3px #7dffd0 inset, 0 6px 12px rgba(0,0,0,0.45);
}
/* the generated panel plate, cropped to its drawn area by src/ui-art.js */
.panel-art .panel {
  border-image: var(--panel-img) var(--panel-slice) fill / 26px stretch;
  background: transparent; border-radius: 0; box-shadow: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.45));
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; font-weight: 900; }
#hudLeft {
  position: absolute; left: calc(10px + env(safe-area-inset-left, 0px)); top: 10px;
  padding: 4px 10px; min-width: 210px; display: flex; flex-direction: column; gap: 4px;
}
#hudLeft .row { display: flex; align-items: center; gap: 8px; }
.star { width: 26px; height: 26px; flex: 0 0 auto; background: #ffd25e; clip-path: polygon(50% 0, 62% 35%, 100% 38%, 70% 60%, 80% 100%, 50% 77%, 20% 100%, 30% 60%, 0 38%, 38% 35%); filter: drop-shadow(0 2px 0 #7a4a00); }
.big { font-size: 26px; color: #fff; letter-spacing: 1px; min-width: 70px; }
.small { font-size: 16px; color: #bfe9ff; margin-left: auto; }
#score, #timer, #chaosLabel, .looseChip b { text-shadow: -2px -2px 0 #1a1040, 2px -2px 0 #1a1040, -2px 2px 0 #1a1040, 2px 2px 0 #1a1040, 0 3px 0 #1a1040; }
.chaosIcon { width: 24px; height: 24px; flex: 0 0 auto; background: #ff5d8f; clip-path: polygon(50% 0, 100% 92%, 0 92%); position: relative; }
.chaosIcon::after { content: "!"; position: absolute; left: 0; right: 0; top: 5px; text-align: center; font-size: 15px; color: #2a0b30; font-weight: 900; }
#chaosBar { position: relative; flex: 1 1 auto; height: 20px; border-radius: 10px; background: rgba(10, 6, 30, 0.75); border: 2px solid #7dffd0; overflow: hidden; min-width: 140px; }
#chaosFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: linear-gradient(90deg, #7dffd0, #ffd25e 55%, #ff4d7e); transition: width 0.15s; }
#chaosBar.danger { animation: dangerPulse 0.5s infinite alternate; }
@keyframes dangerPulse { from { box-shadow: 0 0 0 rgba(255,60,100,0); border-color: #ff4d7e; } to { box-shadow: 0 0 14px rgba(255,60,100,0.9); border-color: #fff; } }
#chaosLabel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; color: #fff; }
#looseRow { gap: 6px; min-height: 28px; }
.looseChip { display: flex; align-items: center; gap: 2px; font-size: 16px; }
.looseChip img { width: 30px; height: 30px; border-radius: 50%; border: 2px solid currentColor; background: rgba(10,6,30,0.7); object-fit: cover; }
.looseChip b { color: #fff; }

#carry { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; gap: 8px; }
.slot { width: 46px; height: 46px; border-radius: 50%; border: 3px solid rgba(125,255,208,0.55); background: rgba(14, 10, 40, 0.6); box-shadow: inset 0 0 10px rgba(125,255,208,0.35); overflow: hidden; transition: transform 0.2s cubic-bezier(.34,1.56,.64,1); }
.slot img { width: 100%; height: 100%; object-fit: cover; }
.slot.filled { border-color: currentColor; transform: scale(1.08); }
.slot.pop { animation: slotPop 0.3s cubic-bezier(.34,1.56,.64,1); }
@keyframes slotPop { from { transform: scale(0.4); } to { transform: scale(1.08); } }

/* floating texts & arrows */
#fx, #arrows { position: fixed; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.ftext { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 26px; white-space: nowrap; color: #ffd25e;
  text-shadow: -2px -2px 0 #1a1040, 2px -2px 0 #1a1040, -2px 2px 0 #1a1040, 2px 2px 0 #1a1040, 0 4px 0 #1a1040; }
.arrow { position: absolute; width: 0; height: 0; border-left: 11px solid transparent; border-right: 11px solid transparent; border-bottom: 22px solid currentColor; filter: drop-shadow(0 0 4px rgba(0,0,0,0.8)); }

#banner { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(0); z-index: 20; pointer-events: none;
  font-weight: 900; font-size: clamp(30px, 7vw, 64px); color: #ffd25e; white-space: nowrap;
  text-shadow: -3px -3px 0 #2a0b40, 3px -3px 0 #2a0b40, -3px 3px 0 #2a0b40, 3px 3px 0 #2a0b40, 0 6px 0 #2a0b40, 0 10px 18px rgba(0,0,0,0.5); }
#banner.show { animation: slam 0.45s cubic-bezier(.34,1.56,.64,1) forwards; }
@keyframes slam { 0% { transform: translate(-50%, -50%) scale(2.4) rotate(-6deg); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1) rotate(-4deg); opacity: 1; } }
#toast { position: fixed; left: 50%; top: 66px; transform: translateX(-50%); z-index: 12; pointer-events: none; font-weight: 900; font-size: 18px;
  padding: 6px 16px; border-radius: 999px; background: rgba(40, 10, 50, 0.75); border: 2px solid #ff7fb0; opacity: 0; transition: opacity 0.2s, transform 0.2s; white-space: nowrap;
  text-shadow: 0 2px 0 #1a1040; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(4px); }

/* buttons */
.gbtn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; min-width: 150px; padding: 4px 22px;
  border-style: solid; border-color: transparent; border-width: 8px 20px; border-radius: 999px;
  background: linear-gradient(#ff8fc0, #d8457f); box-shadow: 0 0 0 3px #4a1530 inset;
  font-weight: 900; font-size: 19px; color: #fff; pointer-events: auto; white-space: nowrap;
  text-shadow: -2px -2px 0 #4a1530, 2px -2px 0 #4a1530, -2px 2px 0 #4a1530, 2px 2px 0 #4a1530, 0 3px 0 #4a1530;
  transition: transform 0.1s, filter 0.15s; filter: drop-shadow(0 4px 4px rgba(0,0,0,0.4)); }
/* the generated button plate, cropped to its drawn area by src/ui-art.js */
.btn-art .gbtn { border-image: var(--btn-img) var(--btn-slice) fill / 26px stretch; background: none; box-shadow: none; border-radius: 0; }
.gbtn:hover, .gbtn:focus-visible { filter: brightness(1.15) drop-shadow(0 0 8px #7dffd0); transform: scale(1.05); }
.gbtn:active { transform: scale(0.92); }
.trophy { width: 22px; height: 22px; flex: 0 0 auto; background: #ffd25e; clip-path: polygon(15% 0, 85% 0, 85% 30%, 65% 60%, 60% 75%, 80% 80%, 80% 100%, 20% 100%, 20% 80%, 40% 75%, 35% 60%, 15% 30%); filter: drop-shadow(0 2px 0 #4a1530); }

/* title */
#title { position: fixed; inset: 0; z-index: 30; overflow: hidden; cursor: pointer; }
#titleArt { position: absolute; inset: -3%; background: #0b0820 url("assets/title-bg.webp") center / cover no-repeat; animation: drift 16s ease-in-out infinite alternate; }
@keyframes drift { from { transform: scale(1.0) translate(0, 0); } to { transform: scale(1.05) translate(-1%, 1%); } }
#logo { position: absolute; left: 4%; top: 5%; width: auto; height: auto; max-width: 52%; max-height: 40%; opacity: 0; filter: drop-shadow(0 8px 12px rgba(0,0,0,0.5)); }
#logo.in { animation: logoIn 0.65s cubic-bezier(.34,1.56,.64,1) forwards, float 3.2s ease-in-out 0.7s infinite alternate; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-40px) scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes float { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-8px); opacity: 1; } }
#titleBottom { position: absolute; left: 0; right: 0; bottom: 7%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
#prompt { font-weight: 900; font-size: clamp(18px, 3.2vw, 30px); color: #fff; animation: pulse 1.4s ease-in-out infinite;
  text-shadow: -2px -2px 0 #1a1040, 2px -2px 0 #1a1040, -2px 2px 0 #1a1040, 2px 2px 0 #1a1040, 0 4px 0 #1a1040, 0 0 18px rgba(125,255,208,0.7); }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.65; transform: scale(0.96); } }

/* intro */
#introLayer { position: fixed; inset: 0; z-index: 40; background: #000 url("assets/title-bg.webp") center / cover no-repeat; }
#introVid { width: 100%; height: 100%; object-fit: cover; display: block; background: transparent; }
#skipBtn { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); min-width: 110px; }

/* help */
#help { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(5, 3, 20, 0.6); }
.helpPanel { width: min(580px, 92vw); max-height: 92vh; overflow-y: auto; padding: 16px 26px 18px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  border-width: 22px; animation: popIn 0.25s cubic-bezier(.34,1.56,.64,1); }
@keyframes popIn { from { transform: scale(0.7); opacity: 0; } to { transform: none; opacity: 1; } }
.helpPanel h2 { margin: 0; font-size: 26px; color: #7dffd0; font-weight: 900;
  text-shadow: -2px -2px 0 #1a1040, 2px -2px 0 #1a1040, -2px 2px 0 #1a1040, 2px 2px 0 #1a1040, 0 3px 0 #1a1040; }
#helpList { margin: 0; padding: 0 0 0 4px; list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 16px; font-weight: 700; line-height: 1.35; }
#helpList li { padding-left: 22px; position: relative; text-shadow: 0 2px 0 #1a1040; }
#helpList li::before { content: ""; position: absolute; left: 2px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: #ff7fb0; box-shadow: 0 0 6px #ff7fb0; }

#fade { position: fixed; inset: 0; z-index: 60; background: #0b0820; opacity: 0; pointer-events: none; transition: opacity 0.35s; }
#fade.on { opacity: 1; }

@media (max-height: 460px) {
  .big { font-size: 22px; }
  #hudLeft { min-width: 190px; top: 6px; }
  .slot { width: 40px; height: 40px; }
  #carry { top: 6px; }
  #toast { top: 54px; font-size: 16px; }
  .helpPanel { padding: 6px 18px 10px; gap: 4px; }
  .helpPanel h2 { font-size: 20px; }
  #helpList { font-size: 14px; gap: 3px; }
  .gbtn { min-height: 46px; font-size: 17px; }
}
