:root {
  --bg: #2a1430;
  --panel: #fff0f6;
  --card: #ffe0ec;
  --border: #2a1430;
  --text: #3a1838;
  --muted: #8a5c7c;
  --pink: #ff6fa8;
  --pink-dark: #c8407a;
  --green: #5cc47a;
  --green-dark: #3a8a56;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.hidden { display: none !important; }
canvas { position: fixed; left: 0; top: 0; display: block; image-rendering: pixelated; touch-action: none; }
button { font: inherit; color: inherit; }

/* ---- Top bar ---- */
#hud { position: fixed; top: calc(6px + env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; align-items: center; gap: 6px; z-index: 3; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hud-title, .hud-stat, .hud-btns { background: rgba(255,240,246,0.92); border: 2px solid var(--border); border-radius: 4px; }
.hud-title { font-weight: 800; font-size: 17px; padding: 5px 10px; color: var(--pink-dark); }
.hud-stat { padding: 6px 10px; font-size: 14px; color: var(--green-dark); }
.hud-btns { margin-left: auto; display: flex; padding: 1px; }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 5px 6px; border-radius: 3px; text-decoration: none; line-height: 1; touch-action: manipulation; }
.icon-btn:hover { background: rgba(255,111,168,0.18); }

#tummy { display: flex; align-items: center; gap: 6px; padding: 4px 8px; }
.tummy-icon { font-size: 15px; line-height: 1; }
.meter { display: block; width: 90px; height: 10px; background: #f0d0dc; border: 2px solid var(--border); border-radius: 2px; overflow: hidden; }
#tummy-fill { display: block; height: 100%; width: 100%; background: var(--green); box-shadow: inset 0 2px 0 rgba(255,255,255,0.4); transition: width 0.3s; }
#tummy-fill.low { background: var(--pink); }
#buffs { display: flex; gap: 4px; }
.buff { white-space: nowrap; background: rgba(255,240,246,0.92); border: 2px solid var(--border); border-radius: 4px; padding: 4px 7px; font-size: 13px; font-weight: 800; color: var(--pink-dark); }

/* ---- Hotbar ---- */
#bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(6px + env(safe-area-inset-bottom)); z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 3px; }
#held-name { font-weight: 800; font-size: 13px; color: #fff; text-shadow: 0 1px 0 var(--border), 1px 0 0 var(--border), -1px 0 0 var(--border), 0 -1px 0 var(--border); min-height: 17px; }
.bar-row { display: flex; align-items: center; gap: 6px; }
#hotbar { display: flex; gap: 3px; background: rgba(42,20,48,0.75); border: 2px solid var(--border); border-radius: 4px; padding: 3px; }
.slot { position: relative; width: 42px; height: 42px; padding: 0; background: rgba(255,240,246,0.18); border: 2px solid rgba(255,240,246,0.35); border-radius: 3px; cursor: pointer; touch-action: manipulation; display: flex; align-items: center; justify-content: center; }
.slot img { width: 28px; height: 28px; image-rendering: pixelated; pointer-events: none; filter: drop-shadow(1px 1px 0 rgba(42,20,48,0.6)); }
.slot .n { position: absolute; right: 2px; bottom: 0; font-size: 12px; font-weight: 800; color: #fff; text-shadow: 1px 1px 0 var(--border), -1px 0 0 var(--border), 0 -1px 0 var(--border); pointer-events: none; }
.slot.sel { border-color: #fff; background: rgba(255,111,168,0.55); box-shadow: 0 0 0 2px var(--pink); }
.tool-btn { width: 48px; height: 48px; font-size: 24px; background: var(--panel); border: 2px solid var(--border); border-radius: 4px; cursor: pointer; touch-action: manipulation; box-shadow: 0 3px 0 #c890aa; }
.tool-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c890aa; }
#btn-eat { background: #fff4c8; box-shadow: 0 3px 0 #d8a848; }
#btn-mode { background: #d8f8e0; box-shadow: 0 3px 0 var(--green-dark); }
#btn-mode.build { background: #ffd0e4; box-shadow: 0 3px 0 var(--pink-dark); }

/* ---- Touch pad ---- */
#pad { display: none; }
body.touch #pad { display: flex; position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); justify-content: space-between; z-index: 2; pointer-events: none; }
.pad-side { display: flex; gap: 10px; align-items: flex-end; pointer-events: auto; }
.pad-btn { width: 60px; height: 60px; border-radius: 50%; border: 2px solid rgba(42,20,48,0.7); background: rgba(255,240,246,0.55); font-size: 22px; color: var(--border); touch-action: none; }
.pad-btn.small { width: 46px; height: 46px; font-size: 16px; }
.pad-btn.down { background: rgba(255,111,168,0.7); }

/* ---- Buttons ---- */
.btn { font: inherit; background: var(--pink); color: #fff; border: 2px solid var(--border); border-radius: 4px; padding: 7px 12px; font-weight: 800; cursor: pointer;
  box-shadow: 0 3px 0 var(--pink-dark); display: inline-flex; align-items: center; justify-content: center; gap: 8px; touch-action: manipulation; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--pink-dark); }
.btn:disabled { background: #d8c4d0; color: #8a7484; box-shadow: 0 3px 0 #b8a4b0; border-color: #8a7484; cursor: not-allowed; }
.btn.big { font-size: 18px; padding: 11px 16px; width: 100%; margin-top: 14px; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.alt { background: var(--green); box-shadow: 0 3px 0 var(--green-dark); color: #0c2a14; }
.btn.alt:disabled { background: #d8c4d0; color: #8a7484; box-shadow: 0 3px 0 #b8a4b0; }

/* ---- Menus ---- */
#modal { position: fixed; inset: 0; background: rgba(42,20,48,0.55); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 12px; }
#modal-box { background: var(--panel); border: 3px solid var(--border); border-radius: 6px; box-shadow: 0 0 0 3px var(--pink), 0 10px 40px rgba(0,0,0,0.5);
  padding: 18px 20px; max-width: 560px; width: 100%; max-height: 92vh; max-height: 92dvh; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; }
#modal-box h2 { margin: 0 0 8px; color: var(--pink-dark); }
#modal-box h3 { margin: 16px 0 6px; color: var(--green-dark); font-size: 16px; }
#modal-box ol { padding-left: 20px; line-height: 1.5; }
#modal-box p { margin: 6px 0; }
.card { background: var(--card); border: 2px solid #f8b8d0; border-radius: 4px; padding: 10px 12px; margin-bottom: 8px; }
.card small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 12px; }
.opt-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 0; flex-wrap: wrap; }

.bag { max-width: 440px; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 3px; background: #4a2a4e; border: 2px solid var(--border); border-radius: 4px; padding: 4px; }
.bag .slot { width: auto; height: auto; aspect-ratio: 1; min-width: 0; }
.bag .slot img { width: 60%; height: auto; }
.bag .slot.hot { background: rgba(92,196,122,0.35); }
.bag .slot.pick { border-color: #ffe070; background: rgba(255,224,112,0.45); box-shadow: 0 0 0 2px #ffe070; }
.bag-tools { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.recipes { display: flex; flex-direction: column; gap: 5px; }
.recipe { display: flex; align-items: center; gap: 8px; background: var(--card); border: 2px solid #f8b8d0; border-radius: 4px; padding: 5px 8px; flex-wrap: wrap; font-size: 14px; font-weight: 700; }
.recipe.cant { opacity: 0.65; }
.recipe img { width: 20px; height: 20px; image-rendering: pixelated; vertical-align: middle; }
.recipe small { color: var(--muted); font-weight: 600; }
.recipe .arrow, .recipe .plus { color: var(--pink-dark); font-weight: 800; }
.recipe .ing.short small { color: #d0406c; }
.recipe .craft-btns { margin-left: auto; display: flex; gap: 4px; }

#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; pointer-events: none; width: min(92vw, 420px); }
.toast { background: var(--panel); color: var(--text); border: 3px solid var(--border); border-radius: 4px; padding: 9px 14px; box-shadow: 0 0 0 2px var(--pink), 0 6px 20px rgba(0,0,0,0.3); transition: opacity 0.5s, transform 0.5s; text-align: center; font-weight: 700; }
.toast.out { opacity: 0; transform: translateY(-10px); }

/* Phones */
@media (max-width: 700px), (max-height: 500px) {
  .hud-title { display: none; }
  .meter { width: 60px; }
  #hud { gap: 4px; left: 4px; right: 4px; top: calc(4px + env(safe-area-inset-top)); }
  .slot { width: 34px; height: 34px; }
  .slot img { width: 22px; height: 22px; }
  .tool-btn { width: 40px; height: 40px; font-size: 20px; }
  #bar { bottom: calc(4px + env(safe-area-inset-bottom)); }
  #modal-box { padding: 14px; }
}
/* Narrow screens: the hotbar sits at the very bottom and the touch pad moves above it. */
@media (max-width: 760px) {
  body.touch #pad { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
@media (max-width: 440px) {
  .slot { width: 30px; height: 30px; }
  .slot img { width: 20px; height: 20px; }
  #hotbar { gap: 2px; padding: 2px; }
  .bar-row { gap: 3px; }
  .tool-btn { width: 36px; height: 36px; font-size: 18px; }
  .recipe .craft-btns { margin-left: 0; width: 100%; }
  /* Narrow phones: power-ups shrink, the depth label hides while one is showing, and Eat floats above the bag. */
  .buff { padding: 3px 5px; font-size: 11px; }
  #hud:has(.buff) .hud-stat:not(#tummy) { display: none; }
  .hud-btns .icon-btn { padding: 5px 4px; }
  #btn-eat { position: absolute; right: 0; bottom: 100%; margin-bottom: 6px; }
  body.touch #pad { bottom: calc(132px + env(safe-area-inset-bottom)); }
}
.shelf-slots { margin-bottom: 4px; background: #6a3e58; }

/* ---- 2x2 crafting grid and recipe cards ---- */
.crafter { display: flex; align-items: center; gap: 10px; background: #4a2a4e; border: 2px solid var(--border); border-radius: 4px; padding: 8px; width: fit-content; max-width: 100%; }
.grid2 { display: grid; grid-template-columns: repeat(2, 44px); gap: 3px; }
.grid2 .slot, .out-col .slot { width: 44px; height: 44px; }
.big-arrow { color: #fff; font-size: 22px; font-weight: 800; }
.out-col { display: flex; flex-direction: column; align-items: center; gap: 4px; color: #fff; min-width: 90px; }
.out-col small { color: #f0d8e8; text-align: center; }
.out-col .slot.ready { border-color: #ffe070; background: rgba(255,224,112,0.35); box-shadow: 0 0 0 2px #ffe070; }
.rgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 6px 0; }
.rcard { background: var(--card); border: 2px solid #f8b8d0; border-radius: 4px; padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.rcard[data-book] { cursor: pointer; }
.rcard[data-book]:hover { border-color: var(--pink); }
.rcard.cant { opacity: 0.6; }
.rcard small { color: var(--muted); }
.rtop { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.rtop img { width: 24px; height: 24px; image-rendering: pixelated; }
.rins { display: flex; flex-wrap: wrap; gap: 2px 8px; }
.rins .ing { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; }
.rins img { width: 16px; height: 16px; image-rendering: pixelated; }
.rins .ing.short small { color: #d0406c; }
.rcard .craft-btns { display: flex; gap: 4px; margin-top: auto; }
details summary { cursor: pointer; font-weight: 700; color: var(--muted); margin: 6px 0; }
@media (max-width: 440px) { .rcard { font-size: 12px; } .rins .ing { font-weight: 600; } }

/* ---- Save files ---- */
.save-slot.current { border-color: var(--pink); }
.save-slot .playing { background: var(--green); color: #0c2a14; font-size: 11px; font-weight: 800; border-radius: 3px; padding: 1px 6px; margin-left: 4px; }

.rtop .made { margin-left: auto; color: var(--green-dark); font-weight: 800; }
.trophy-line { color: var(--muted); margin: 6px 0; }
.trophy-line b { color: var(--pink-dark); }
