* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #07060c; color: #d8d2e6;
  font-family: Georgia, 'Times New Roman', serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

button {
  font: inherit; color: #e6dff5; background: rgba(18, 15, 28, 0.72);
  border: 2px solid rgba(190, 175, 225, 0.45); touch-action: none;
}
button:active, button.on { background: rgba(120, 95, 170, 0.6); }
.round { width: 72px; height: 72px; border-radius: 50%; font-size: 28px; line-height: 1; }
.round.small { width: 46px; height: 46px; font-size: 16px; font-weight: bold; flex: none; }
.big { font-size: 22px; padding: 14px 34px; border-radius: 10px; margin: 8px; min-width: 220px; }

#top {
  position: fixed; left: 0; right: 0; top: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start;
  padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 0 calc(8px + env(safe-area-inset-left));
  pointer-events: none;
}
#top > * { pointer-events: auto; }
#hotbar { display: flex; gap: 3px; flex: 1 1 100%; max-width: 440px; }
.slot {
  position: relative; flex: 1 1 0; min-width: 0; max-width: 46px; aspect-ratio: 1; border-radius: 8px; padding: 0;
}
.slot canvas { pointer-events: none; width: 66%; height: 66%; image-rendering: pixelated; display: block; margin: 14% auto; }
.slot span { position: absolute; right: 2px; bottom: 0; font: bold 11px system-ui, sans-serif; text-shadow: 0 0 3px #000, 0 0 3px #000; pointer-events: none; }
.slot.sel { border-color: #ffd27a; box-shadow: 0 0 10px rgba(255, 190, 90, 0.6); }
#hotbar .slot.tool { background: rgba(60, 48, 90, 0.75); }
#hotbar .slot.gap { margin-right: 4px; }
#bagBtn { margin-left: auto; }

#quest {
  position: fixed; top: calc(56px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left));
  font-size: 13px; line-height: 1.5; text-shadow: 0 0 4px #000, 0 0 4px #000; pointer-events: none; max-width: calc(100vw - 130px);
}
#quest .done { color: #9be28a; }
#quest b { letter-spacing: 0.05em; font-variant: small-caps; color: #ffd27a; }

#toast {
  position: fixed; left: 50%; top: 27%; transform: translateX(-50%); text-align: center;
  font-size: 17px; padding: 8px 16px; border-radius: 10px; background: rgba(10, 8, 18, 0.8);
  border: 1px solid rgba(190, 175, 225, 0.4); opacity: 0; transition: opacity 0.3s; pointer-events: none; max-width: 86vw;
}
#toast.show { opacity: 1; }
@media (orientation: landscape) { #toast { top: auto; bottom: calc(14px + env(safe-area-inset-bottom)); max-width: calc(100vw - 340px); } }

#padLeft, #padRight { position: fixed; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; }
#padLeft { left: calc(14px + env(safe-area-inset-left)); }
#padRight { right: calc(14px + env(safe-area-inset-right)); flex-direction: column; align-items: flex-end; gap: 8px; }
#btnJ { width: 64px; height: 64px; padding: 0; margin-right: 6px; }
#btnA canvas { width: 34px; height: 34px; image-rendering: pixelated; pointer-events: none; vertical-align: middle; }
#padRight .row { gap: 10px; margin-right: 4px; }
.stick {
  position: relative; width: 136px; height: 136px; border-radius: 50%; touch-action: none;
  background: rgba(18, 15, 28, 0.45); border: 2px solid rgba(190, 175, 225, 0.35);
}
.knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: rgba(190, 175, 225, 0.45); border: 2px solid rgba(230, 220, 250, 0.6); pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.knob canvas { width: 30px; height: 30px; image-rendering: pixelated; }
#bagBtn { width: 46px; height: 46px; border-radius: 8px; flex: none; font-size: 13px; font-weight: bold; padding: 0; }

.panel {
  width: min(96vw, 430px); max-height: 94vh; display: flex; flex-direction: column; text-align: left;
  background: rgba(14, 11, 22, 0.96); border: 2px solid rgba(190, 175, 225, 0.4); border-radius: 12px; padding: 10px;
}
.tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.tabs button { flex: 1; font-size: 18px; padding: 9px 0; border-radius: 8px; }
.tabs button.sel { border-color: #ffd27a; color: #ffd27a; }
.tabs #bagClose { flex: none; width: 46px; }
#bagGrid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
#bagGrid .slot { max-width: none; }
#bagGrid .slot:nth-child(-n+8) { background: rgba(60, 48, 90, 0.7); }
#bagHint, #gearLine { font-size: 13px; opacity: 0.8; margin: 8px 2px 0; }
#craftList { overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.recipe { display: flex; align-items: center; gap: 10px; padding: 7px 2px; border-bottom: 1px solid rgba(190, 175, 225, 0.15); }
.recipe canvas { width: 36px; height: 36px; image-rendering: pixelated; flex: none; }
.recipe .what { flex: 1; font-size: 13px; line-height: 1.35; }
.recipe .what b { font-size: 15px; color: #e9e2f7; }
.recipe .what .ok { color: #9be28a; }
.recipe .what .no { color: #e58c8c; }
.recipe button { font-size: 15px; padding: 9px 12px; border-radius: 8px; flex: none; min-width: 74px; touch-action: pan-y; }
.recipe button:disabled { opacity: 0.35; }
.hide { display: none !important; }

.overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20, 14, 32, 0.86), rgba(4, 3, 8, 0.96)); text-align: center; padding: 20px;
}
.overlay.hidden { display: none; }
h1 { font-size: 64px; margin: 0 0 6px; letter-spacing: 0.12em; font-variant: small-caps; color: #e9e2f7; text-shadow: 0 0 24px rgba(150, 110, 220, 0.7); }
h2 { font-size: 34px; margin: 0 0 12px; font-variant: small-caps; letter-spacing: 0.1em; }
.how { font-size: 14px; opacity: 0.75; max-width: 320px; }

/* ----- Menus ----- */
body:not(.playing) #top, body:not(.playing) #quest, body:not(.playing) #padLeft, body:not(.playing) #padRight { display: none; }
.screen { position: fixed; inset: 0; display: flex; }
.screen.hidden { display: none; }
.screen.main { align-items: center; justify-content: flex-end; padding: 0 calc(7vw + env(safe-area-inset-right)) 0 0; }
.mainMenu { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.mainMenu h1 { font-size: clamp(46px, 11vw, 84px); margin-bottom: 10px; }
.stone {
  width: min(78vw, 290px); padding: 13px 10px; font-size: 21px; letter-spacing: 0.12em; font-variant: small-caps;
  color: #2a2230; background: linear-gradient(#ddd6ca, #b3a999); border: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  clip-path: polygon(2% 8%, 9% 0, 30% 5%, 52% 0, 74% 6%, 96% 0, 100% 30%, 97% 62%, 100% 92%, 82% 100%, 60% 94%, 38% 100%, 14% 95%, 0 100%, 3% 60%, 0 32%);
}
.stone:active { background: linear-gradient(#fff, #d8cfbf); }
@media (orientation: portrait) {
  .screen.main { align-items: stretch; justify-content: center; padding: calc(4vh + env(safe-area-inset-top)) 0 calc(5vh + env(safe-area-inset-bottom)); }
  .mainMenu h1 { margin-bottom: auto; }
}
.screen .panel { gap: 10px; }
.screen .panel h2 { margin: 2px 0 4px; font-size: 26px; text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.top { align-items: flex-start; }
.col { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.panel > .row > button, .choices button, #ncDice, #nwDice { font-size: 17px; padding: 11px 12px; border-radius: 8px; }
.panel > .row:last-child > button { flex: 1; }
button.go { border-color: #ffd27a; color: #ffd27a; }
label { font-size: 13px; opacity: 0.75; }
input {
  flex: 1; min-width: 0; font: 18px Georgia, serif; padding: 10px; border-radius: 8px; color: #e6dff5; background: #1a1524;
  border: 2px solid rgba(190, 175, 225, 0.45); user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
.choices { display: flex; gap: 6px; flex-wrap: wrap; }
.choices button { flex: 1; }
.choices button.sel { border-color: #ffd27a; color: #ffd27a; box-shadow: 0 0 8px rgba(255, 190, 90, 0.5); }
.swatches button { flex: none; width: 38px; height: 38px; padding: 0; border-radius: 50%; }
.perk { font-size: 14px; margin: 0; min-height: 2.6em; color: #cfe6c6; }
#heroPreview { width: 96px; height: 128px; image-rendering: pixelated; flex: none; background: rgba(0, 0, 0, 0.3); border-radius: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; touch-action: pan-y; max-height: 52vh; }
.item { display: flex; gap: 6px; }
.pickBtn { flex: 1; display: flex; align-items: center; gap: 10px; text-align: left; padding: 6px 10px; border-radius: 8px; min-height: 56px; min-width: 0; touch-action: pan-y; }
.pickBtn canvas { width: 36px; height: 48px; image-rendering: pixelated; flex: none; }
.pickBtn b { display: block; font-size: 18px; }
.pickBtn small { font-size: 12px; opacity: 0.75; }
.delBtn { flex: none; min-width: 46px; border-radius: 8px; font-size: 14px; padding: 0 8px; color: #e58c8c; touch-action: pan-y; }
#ver { font: 11px system-ui, sans-serif; opacity: 0.5; }
#oops { z-index: 10; }
#hearts { position: fixed; right: calc(10px + env(safe-area-inset-right)); top: calc(60px + env(safe-area-inset-top)); font-size: 15px; letter-spacing: 1px; color: #e0455a; text-shadow: 0 0 3px #000; pointer-events: none; max-width: 120px; text-align: right; line-height: 1.1; }
#hearts i { font-style: normal; }
#hearts i.off { color: #3a2a38; }
body:not(.playing) #hearts { display: none; }
#status { position: fixed; right: calc(10px + env(safe-area-inset-right)); top: calc(96px + env(safe-area-inset-top)); font: bold 12px system-ui, sans-serif; pointer-events: none; text-align: right; }
body:not(.playing) #status { display: none; }
#status .st { display: inline-block; padding: 2px 6px; margin-left: 3px; border-radius: 6px; background: rgba(10, 8, 18, 0.8); }
#status .frozen { color: #7fdcff; } #status .burning { color: #ffb347; } #status .poisoned { color: #b4ff4a; }
#beastList { overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#beastList .count { font-size: 14px; margin: 0 2px 6px; color: #ffd27a; }
.beast { display: flex; align-items: center; gap: 10px; padding: 7px 2px; border-bottom: 1px solid rgba(190, 175, 225, 0.15); }
.beast canvas.pic { width: 84px; height: 60px; flex: none; background: radial-gradient(ellipse at center, rgba(60, 50, 90, 0.5), rgba(10, 8, 18, 0.2)); border-radius: 8px; }
.beast canvas.drop { width: 28px; height: 28px; image-rendering: pixelated; flex: none; }
.beast .what { flex: 1; font-size: 13px; line-height: 1.35; }
.beast .what b { font-size: 15px; color: #e9e2f7; }
.beast .what .tier { opacity: 0.75; }
.beast.unknown .what b { color: #6a6080; }
.mods { font-size: 13px; line-height: 1.4; padding: 10px 2px 4px; }
.mods b { display: inline-block; min-width: 80px; }
/* Upright phone: the bar takes a row of its own, so Bag and pause sit lower; hearts go under them. */
@media (orientation: portrait) { #hearts { top: calc(98px + env(safe-area-inset-top)); } #status { top: calc(134px + env(safe-area-inset-top)); } }
#died { background: radial-gradient(ellipse at center, rgba(60, 8, 16, 0.82), rgba(6, 2, 4, 0.96)); }
#died h1 { color: #c9404f; text-shadow: 0 0 26px rgba(200, 40, 60, 0.7); font-size: clamp(44px, 12vw, 80px); }
#diedBox { max-width: min(88vw, 420px); margin: 6px 0 16px; padding: 12px 16px; text-align: left; border-radius: 10px; background: rgba(10, 8, 18, 0.85); border: 1px solid rgba(190, 175, 225, 0.4); font-size: 16px; line-height: 1.45; }
#diedBox b { display: block; color: #ffd27a; }

/* Pause menu: how much of the world fits on the screen. */
#zoomRow { gap: 14px; margin: 8px; font-size: 18px; min-width: 220px; justify-content: space-between; }
#zoomRow button { font-size: 24px; width: 52px; height: 48px; border-radius: 10px; padding: 0; }
#zoomRow button:disabled { opacity: 0.35; }
/* ?fps=1: the frame-time readout. */
#meter { position: fixed; left: 50%; bottom: 4px; transform: translateX(-50%); z-index: 50; font: 12px/1.3 monospace; color: #fff; background: rgba(0,0,0,0.6); padding: 2px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; }
#wearList { overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#wearList .count { font-size: 14px; margin: 0 2px 6px; color: #ffd27a; }
.accSlots { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin-bottom: 8px; }
.accSlots .slot { max-width: none; aspect-ratio: 1; background: rgba(90, 70, 30, 0.45); border-color: rgba(216, 178, 74, 0.6); }
.accNow { font-size: 13px; line-height: 1.4; margin: 0 2px 8px; color: #cfc6e6; }
.accNow b { color: #e9e2f7; }
#itemInfo { display: flex; gap: 10px; align-items: flex-start; margin: 8px 2px 0; padding: 8px; min-height: 40px; border-radius: 8px; background: rgba(40, 32, 64, 0.6); font-size: 13px; line-height: 1.35; color: #cfc6e6; }
#itemInfo:not(.on) { opacity: 0.7; }
#itemInfo canvas { width: 36px; height: 36px; image-rendering: pixelated; flex: none; }
#itemInfo b { font-size: 15px; color: #ffd27a; }
#itemInfo p { margin: 2px 0 0; }
#bagPage { overflow-y: auto; min-height: 0; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#minimap { position: fixed; right: calc(10px + env(safe-area-inset-right)); top: calc(118px + env(safe-area-inset-top)); border: 2px solid rgba(190, 175, 225, 0.5); border-radius: 6px; image-rendering: pixelated; background: rgba(10, 8, 18, 0.5); touch-action: manipulation; }
#minimap.mapBig { right: auto; left: 50%; top: calc(62px + env(safe-area-inset-top)); transform: translateX(-50%); }
body:not(.playing) #minimap { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  #minimap:not(.mapBig) { top: calc(60px + env(safe-area-inset-top)); right: calc(140px + env(safe-area-inset-right)); }
}
#minimap { padding: 0; box-sizing: content-box; }
@media (orientation: portrait) { #minimap:not(.mapBig) { top: calc(172px + env(safe-area-inset-top)); } } /* below the hearts, coins and food */
@media (orientation: portrait) {
  #minimap.mapBig { top: calc(140px + env(safe-area-inset-top)); }
}
#hearts .coins { color: #6ac0ff; font: bold 12px system-ui, sans-serif; letter-spacing: 0; }
#shopBtn { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); font-size: 16px; padding: 10px 16px; border-radius: 10px; border-color: #ffd27a; color: #ffd27a; max-width: 46vw; }
body:not(.playing) #shopBtn { display: none; }
#shop .tabs b { flex: 1; font-size: 18px; color: #ffd27a; align-self: center; }
#shopHello { font-style: italic; font-size: 14px; margin: 0 2px 6px; color: #e9e2f7; }
#shopCoins { font-size: 13px; margin: 0 2px 6px; color: #6ac0ff; }
#shopList { overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#shop .tabs #shopClose { flex: none; width: 46px; }
#shopList { min-height: 0; }
/* New world on a phone held sideways: room for all five difficulty modes in one row, and the
   Create button still on screen. */
#scrNewWorld .panel { overflow-y: auto; }
@media (orientation: landscape) and (max-height: 520px) {
  #scrNewWorld .panel { width: min(96vw, 640px); gap: 6px; padding: 8px 10px; }
  #scrNewWorld .panel h2 { font-size: 22px; margin: 0; }
  #scrNewWorld .choices { flex-wrap: nowrap; }
  #scrNewWorld .choices button, #scrNewWorld .row > button { padding: 7px 6px; font-size: 15px; }
  #scrNewWorld input { padding: 7px 10px; font-size: 16px; }
  #nwDiffAbout { min-height: 0; font-size: 13px; }
}
/* Messages show on top of everything, even the bag (so you see "You made ...!" while crafting). */
#toast { z-index: 30; background: rgba(14, 11, 22, 0.97); border-color: #ffd27a; }
#settings .tabs b { flex: 1; font-size: 18px; color: #ffd27a; align-self: center; }
#settings .tabs #settingsClose { flex: none; width: 46px; }
#settingsList .recipe button.on { border-color: #9be28a; color: #9be28a; }
/* The Gear view at the top of the Gear page. */
.gear { display: flex; gap: 10px; align-items: center; margin: 0 2px 4px; }
.gear .gearHero { width: 72px; height: 105px; flex: none; image-rendering: pixelated; background: radial-gradient(ellipse at center, rgba(60, 50, 90, 0.6), rgba(10, 8, 18, 0.2)); border-radius: 10px; }
.gearList { flex: 1; display: grid; gap: 3px; }
.gearRow { display: flex; gap: 8px; align-items: center; font-size: 13px; line-height: 1.25; }
.gearRow canvas { width: 26px; height: 26px; flex: none; image-rendering: pixelated; }
.gearRow .slotName { color: #ffd27a; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.gearRow small { color: #b8afd0; }
.gearTotals { margin: 4px 2px 10px; font-size: 13px; color: #9be28a; }
/* The Craft page's tabs: a row that wraps on a narrow phone. */
.craftTabs { display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 6px; }
.craftTabs button { flex: 1 1 auto; font-size: 13px; padding: 6px 8px; border-radius: 8px; min-width: 0; }
.craftTabs button.sel { border-color: #ffd27a; color: #ffd27a; }

/* Controls page */
#controls .tabs b { flex: 1; font-size: 18px; color: #ffd27a; align-self: center; }
#controls .tabs #controlsClose { flex: none; width: 46px; }
#controlsList { overflow-y: auto; min-height: 0; flex: 1; touch-action: pan-y; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 6px; }
#controlsList .recipe { gap: 6px; flex: none; }
#controls .how { margin: 4px 0 8px; }
#controlsList .recipe button { min-width: 92px; font-size: 13px; }
#controlsList .recipe button.wait { border-color: #ffd27a; color: #ffd27a; }
#controlsBtn, #controlsReset { margin-top: 10px; align-self: stretch; flex: none; }
/* Fighting buttons (souls.js): roll, block, heavy attack, Soup Thermos. Beside the aim stick on a
   phone held sideways; above the jump button when held upright. */
#fightRow .round.small { width: 42px; height: 42px; font-size: 18px; }
#btnSip { color: #ffb0d0; }
#btnSip.off { opacity: 0.4; }
@media (orientation: landscape) and (max-height: 520px) {
  #fightRow { position: fixed; right: calc(160px + env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); flex-direction: column; gap: 6px; }
}
/* Storage chests (storage.js) and food (food.js). */
#chestGrid, #chestBagGrid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
#chestGrid .slot, #chestBagGrid .slot { max-width: none; }
#chestGrid .slot { background: rgba(110, 76, 49, 0.6); }
#hearts .food { color: #e8c87a; font: bold 12px system-ui, sans-serif; letter-spacing: 0; }
#hearts .food.low { color: #ff7a5a; }
#status .st.buff { color: #c8a8ff; }
/* UI size (settings.js UI_SCALE): the buttons, hearts, map and panels grow or shrink together. */
#top, #hearts, #status, #quest, #toast, #padLeft, #padRight, #minimap, #shopBtn { zoom: var(--ui, 1); } /* #fightRow sits inside #padRight */
/* How many to make (the Craft page), and the bag's Drop button. */
.recipe { flex-wrap: wrap; }
.recipe .amt { flex-basis: 100%; display: flex; justify-content: flex-end; align-items: center; gap: 6px; font-size: 14px; color: #e9e2f7; }
.recipe .amt button { min-width: 40px; padding: 6px 10px; }
#dropBtn { margin-left: auto; flex: none; padding: 8px 14px; border-radius: 8px; }
/* The ending screen (ending.js). */
#won { background: radial-gradient(ellipse at center, rgba(70, 40, 110, 0.85), rgba(6, 4, 14, 0.97)); overflow-y: auto; justify-content: flex-start; padding: 16px 16px 24px; z-index: 40; }
#won h1 { color: #ffd84a; text-shadow: 0 0 26px rgba(255, 200, 60, 0.7); font-size: clamp(32px, 8vw, 60px); text-align: center; margin: 8px 0; }
#wonLines, #wonCredits { max-width: min(88vw, 440px); margin: 4px 0 10px; padding: 8px 14px; flex: none; border-radius: 10px; background: rgba(10, 8, 18, 0.85); border: 1px solid rgba(190, 175, 225, 0.4); font-size: 16px; line-height: 1.45; }
#wonLines p, #wonCredits p { margin: 3px 0; font-size: 15px; }
#wonBtn { flex: none; }
#wonCredits .credit { text-align: center; color: #cfc6e6; }
/* What's new (news.js). */
#news { z-index: 20; }
#newsList { max-height: 60vh; overflow-y: auto; text-align: left; }
#newsList .news { margin: 0 0 10px; }
#newsList .news b { color: #ffd27a; }
#newsList .news p { margin: 2px 0 0; font-size: 14px; line-height: 1.4; color: #cfc6e6; }
/* New hero on a phone held sideways: 8 classes in two short rows, and Create still on screen. */
#scrNewChar .panel { overflow-y: auto; }
@media (orientation: landscape) and (max-height: 520px) {
  #scrNewChar .panel { width: min(96vw, 640px); padding: 8px 10px; }
  #scrNewChar .panel h2 { font-size: 22px; margin: 0; }
  #ncClasses button { flex: 1 0 22%; padding: 6px 4px; font-size: 15px; }
  #scrNewChar input { padding: 7px 10px; font-size: 16px; }
}
