/* ADVENTURE: Return of the Enchanted Chalice */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 30%, #15151f 0%, #0a0a10 70%);
  color: #e8e8f2;
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: relative;
  /* fit both axes: canvas is 800x560 (10:7) */
  width: min(100vw - 12px, calc((100dvh - 12px) * 10 / 7), 960px);
  user-select: none;
  -webkit-user-select: none;
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;
  background: #0b0b10;
  border: 2px solid #26263a;
  border-radius: 8px;
  box-shadow: 0 0 60px rgba(60, 60, 140, 0.25), 0 12px 40px rgba(0,0,0,0.6);
  image-rendering: pixelated;
  touch-action: none;
}

#gearBtn {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 25;
  width: 42px; height: 42px;
  font-size: 21px;
  color: #c8c8d8;
  background: rgba(20, 20, 32, 0.65);
  border: 1px solid #34345a;
  border-radius: 10px;
  cursor: pointer;
}
#gearBtn:hover { color: #ffd84a; border-color: #ffd84a; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 12, 0.85);
  z-index: 30;
  padding: 8px;
}

.panel {
  max-width: 640px;
  width: min(94%, 640px);
  max-height: min(96%, 96dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: clamp(14px, 3.5vw, 26px) clamp(16px, 4.5vw, 34px);
  background: linear-gradient(180deg, #141420 0%, #0e0e16 100%);
  border: 2px solid #2e2e48;
  border-radius: 10px;
  box-shadow: 0 0 40px rgba(80, 80, 200, 0.18);
  text-align: center;
}
.panel.small { max-width: 540px; }
.panel.left { text-align: left; }
.panel.left h1 { text-align: center; }

h1 {
  margin: 0;
  font-size: clamp(26px, 7vw, 42px);
  letter-spacing: clamp(3px, 1.5vw, 8px);
  color: #ffd84a;
  text-shadow: 0 0 18px rgba(255, 216, 74, 0.5), 3px 3px 0 #5a4408;
}
h1.red { color: #e23b30; text-shadow: 0 0 18px rgba(226,59,48,.5), 3px 3px 0 #58150f; }
h1.gold { font-size: clamp(20px, 5vw, 30px); letter-spacing: 4px; }
h1.small-h { font-size: clamp(20px, 5vw, 28px); letter-spacing: 5px; margin-bottom: 6px; }
h2 {
  margin: 6px 0 14px;
  font-size: clamp(11px, 3vw, 15px);
  font-weight: normal;
  letter-spacing: 3px;
  color: #9a9ab8;
  text-transform: uppercase;
}
h3 {
  margin: 16px 0 6px;
  font-size: clamp(12px, 3vw, 14px);
  letter-spacing: 2px;
  color: #ffd84a;
  text-transform: uppercase;
}

.story { font-size: clamp(11.5px, 2.9vw, 13.5px); line-height: 1.6; color: #c8c8d8; margin: 8px 0; }
.story em { color: #ffd84a; font-style: normal; }
.story.warn { color: #b08aff; }
ul.story { padding-left: 20px; margin: 6px 0; }
ul.story li { margin: 5px 0; }
.stats { color: #ffd84a; font-size: clamp(12px, 3vw, 14px); margin-top: 14px; }
.note { font-size: clamp(10.5px, 2.6vw, 12px); color: #8a8a9e; margin: 6px 0; }

.quests { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 6px; }
.quests button {
  font-family: inherit;
  font-size: clamp(13px, 3.4vw, 15px);
  text-align: left;
  color: #e8e8f2;
  background: #1a1a2a;
  border: 2px solid #34345a;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.quests button:hover {
  border-color: #ffd84a;
  background: #232338;
  transform: translateX(4px);
}
.quests button small { display: block; color: #8a8a9e; font-size: clamp(10px, 2.6vw, 11.5px); margin-top: 3px; }
.qn {
  display: inline-block;
  background: #ffd84a; color: #1a1a22;
  font-weight: bold;
  border-radius: 4px;
  padding: 1px 7px;
  margin-right: 8px;
}

.rowBtns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
button.primary, button.ghost {
  font-family: inherit;
  font-size: clamp(12px, 3vw, 14px);
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
}
button.primary {
  color: #1a1a22;
  background: #ffd84a;
  border: 2px solid #ffd84a;
  font-weight: bold;
}
button.primary:hover { background: #ffe57a; }
button.ghost {
  color: #c8c8d8;
  background: transparent;
  border: 2px solid #34345a;
}
button.ghost:hover { border-color: #ffd84a; color: #ffd84a; }

/* segmented choice (settings) */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.panel:not(.left) .seg { justify-content: center; }
.seg button {
  font-family: inherit;
  font-size: clamp(11px, 2.8vw, 13px);
  color: #c8c8d8;
  background: #1a1a2a;
  border: 2px solid #34345a;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
.seg button.sel { border-color: #ffd84a; color: #ffd84a; background: #232338; }

/* binding rows */
.bindings { margin: 4px 0; }
.bindRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  font-size: clamp(11.5px, 2.9vw, 13px);
  color: #c8c8d8;
}
.chip {
  font-family: inherit;
  font-size: clamp(11px, 2.8vw, 12.5px);
  min-width: 120px;
  color: #e8e8f2;
  background: #1a1a2a;
  border: 2px solid #34345a;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
.chip:hover { border-color: #ffd84a; }
.chip.capturing { border-color: #ffd84a; color: #ffd84a; animation: blink 1s steps(2) infinite; }

.keys { font-size: clamp(10.5px, 2.7vw, 12px); color: #8a8a9e; line-height: 1.7; margin-top: 14px; }
.tribute { font-size: clamp(9.5px, 2.4vw, 11px); color: #565670; margin-top: 12px; }
.tribute em { font-style: italic; }

.blink { animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---- on-screen pad (touch) ---- */
#pad {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}
#dpad {
  position: absolute;
  left: max(10px, 3vw);
  bottom: max(12px, 4vh);
  width: clamp(110px, 24vw, 150px);
  height: clamp(110px, 24vw, 150px);
  border-radius: 50%;
  background: rgba(40, 40, 70, 0.38);
  border: 2px solid rgba(150, 150, 220, 0.4);
  pointer-events: auto;
  touch-action: none;
}
#dpadKnob {
  position: absolute;
  left: 50%; top: 50%;
  width: 42%; height: 42%;
  margin: -21% 0 0 -21%;
  border-radius: 50%;
  background: rgba(180, 180, 240, 0.5);
  pointer-events: none;
}
#padBtns {
  position: absolute;
  right: max(10px, 3vw);
  bottom: max(12px, 4vh);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
}
#padDrop {
  width: clamp(70px, 17vw, 92px);
  height: clamp(70px, 17vw, 92px);
  border-radius: 50%;
  font-family: inherit;
  font-size: clamp(12px, 3vw, 15px);
  font-weight: bold;
  letter-spacing: 1px;
  color: #ffd84a;
  background: rgba(60, 50, 20, 0.45);
  border: 2px solid rgba(255, 216, 74, 0.55);
  touch-action: none;
  cursor: pointer;
}
#padPause {
  width: clamp(42px, 10vw, 52px);
  height: 34px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: #c8c8d8;
  background: rgba(40, 40, 70, 0.45);
  border: 2px solid rgba(150, 150, 220, 0.4);
  touch-action: none;
  cursor: pointer;
}
#padDrop:active, #padPause:active, #dpad:active { filter: brightness(1.5); }

/* portrait phones: pin the game to the top so the pad gets the space below */
@media (orientation: portrait) and (max-width: 700px) {
  body { align-items: flex-start; padding-top: 10px; }
}
