* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #06070c; color: #eef2f8; overscroll-behavior: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* ---------- schermate ---------- */
.screen {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 18px;
  background: #1b1b1b; overflow: auto;
}
#title { background-color: #6b4c2a; background-size: 96px 96px; image-rendering: pixelated; }
#title::before { content: ''; position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: -1; }
#loading {
  display: none; background: radial-gradient(circle at 50% 40%, #1a2740 0%, #080a12 70%);
}
.logoWrap { position: relative; width: min(720px, 96vw); }
#logoCv { width: 100%; height: auto; image-rendering: pixelated; display: block; }
#splash {
  position: absolute; right: 4%; bottom: 6px; color: #ffde3a; font-weight: 800;
  font-size: clamp(11px, 2.4vw, 17px); transform: rotate(-16deg); text-shadow: 2px 2px 0 #3f3000;
  animation: pulse .9s ease-in-out infinite alternate; white-space: nowrap;
}
@keyframes pulse { from { transform: rotate(-16deg) scale(1); } to { transform: rotate(-16deg) scale(1.08); } }
.mcmenu { display: flex; flex-direction: column; gap: 8px; width: min(420px, 92vw); }
.mcrow { display: flex; gap: 8px; }
.mcrow .mcb { flex: 1; }
.mcb {
  display: block; width: 100%; padding: 13px 10px; font-size: 15px; font-weight: 700; color: #fff;
  background: linear-gradient(#8b8b8b, #6c6c6c); border: 2px solid #000;
  box-shadow: inset 2px 2px 0 #ffffff55, inset -2px -2px 0 #00000066, 0 3px 0 #2b2b2b;
  text-shadow: 2px 2px 0 #2a2a2a; letter-spacing: .3px; image-rendering: pixelated;
}
.mcb:hover { background: linear-gradient(#a3a3a3, #7d7d7d); }
.mcb:active { transform: translateY(2px); box-shadow: inset 2px 2px 0 #ffffff33, inset -2px -2px 0 #00000066; }
.mcb.primary { background: linear-gradient(#63b34a, #3d8c31); }
.mcb.primary:hover { background: linear-gradient(#74c95a, #47a039); }
input#seedIn {
  width: 100%; padding: 12px 14px; border: 2px solid #000; background: #0d0d0d; color: #eef2f8;
  font-size: 15px; text-align: center; box-shadow: inset 2px 2px 0 #ffffff22;
}
input#seedIn::placeholder { color: #8a8a8a; }
.help {
  display: none; font-size: 12.5px; max-width: 560px; background: #000000aa; padding: 12px 16px;
  border: 2px solid #000; box-shadow: inset 2px 2px 0 #ffffff22; line-height: 1.6;
}
.help.on { display: block; }
.help ul { margin: 6px 0 0; padding-left: 18px; }
.ver { font-size: 11px; opacity: .5; position: fixed; left: 8px; bottom: 6px; }
.spin { width: 46px; height: 46px; border: 5px solid #2c3a52; border-top-color: #6ee06e; border-radius: 50%; animation: sp .9s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
/* ---------- HUD ---------- */
#hud { display: none; position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button, #hud #stick, #hud #hotbar { pointer-events: auto; }
.topbar {
  position: absolute; top: calc(6px + env(safe-area-inset-top)); left: 8px; right: 8px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.bar { display: flex; gap: 2px; margin-bottom: 3px; }
.bar b { width: 13px; height: 13px; display: block; border-radius: 3px; background: #2a3040; box-shadow: inset 0 0 0 1px #00000055; }
.bar.hp b.on { background: linear-gradient(#ff6b6b, #c62828); }
.bar.fd b.on { background: linear-gradient(#d8a34a, #8c5a1c); }
.bar.air b.on { background: linear-gradient(#7fd4ff, #2a7fb5); }
.bar.air { display: none; }
.right { text-align: right; font-size: 12px; font-weight: 700; display: flex; flex-direction: column; gap: 3px; }
.right span { background: #0009; padding: 3px 8px; border-radius: 8px; }

/* leva */
#stick {
  position: absolute; left: calc(14px + env(safe-area-inset-left)); bottom: 86px;
  width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle, #ffffff18, #ffffff08); border: 2px solid #ffffff28;
}
#knob {
  position: absolute; left: 34px; top: 34px; width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #eef2f8, #8f9db5); box-shadow: 0 3px 8px #0008;
}

/* pulsanti destra */
.btns {
  position: absolute; right: calc(12px + env(safe-area-inset-right)); bottom: 76px;
  display: grid; grid-template-columns: 66px 66px; gap: 8px; align-items: end;
}
.rb {
  width: 66px; height: 56px; border-radius: 14px; border: 2px solid #ffffff30;
  background: #16203280; color: #eef2f8; font-size: 11px; font-weight: 700; line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.rb b { font-size: 15px; }
.rb.small { font-size: 12px; grid-column: span 2; width: 140px; height: 40px; border-radius: 14px; flex-direction: row; }
.rb.act, .rb:active { background: #4ad24a80; }
.sb { border: 2px solid #ffffff30; background: #16203280; color: #eef2f8; border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 700; }

#btnMenu { position: absolute; left: calc(10px + env(safe-area-inset-left)); top: calc(52px + env(safe-area-inset-top)); pointer-events: auto; }

/* hotbar */
#hotbar {
  position: absolute; bottom: calc(8px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 4px; background: #0008; border-radius: 10px;
}
.slot {
  position: relative; width: 44px; height: 44px; border-radius: 8px;
  background: #1b2331cc; border: 2px solid #2f3b52; display: flex; align-items: center; justify-content: center;
}
.slot canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.slot.sel { border-color: #ffffff; box-shadow: 0 0 0 2px #ffffff40; transform: translateY(-3px); }
.slot .cnt {
  position: absolute; right: 2px; bottom: 0; font-size: 11px; font-weight: 800;
  text-shadow: 1px 1px 0 #000, -1px 1px 0 #000;
}
.slot .dur { position: absolute; left: 2px; bottom: 2px; height: 3px; background: #4ad24a; border-radius: 2px; display: none; }
#hotbar .slot { width: 42px; height: 42px; }

/* toast */
#toast {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 62px;
  background: #000a; padding: 7px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  opacity: 0; transition: opacity .25s; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; }

/* ---------- pannelli ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 30; background: #000a; display: none;
  align-items: center; justify-content: center; padding: 10px; overflow: auto;
}
#overlay.on { display: flex; }
#panel { width: min(760px, 100%); max-height: 96vh; overflow: auto; }
.panelIn { background: #141b26f2; border: 2px solid #33445f; border-radius: 14px; padding: 10px 12px 14px; }
.ptitle { font-size: 17px; font-weight: 800; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.x { background: #33415a; border: none; color: #fff; width: 32px; height: 32px; border-radius: 8px; font-size: 15px; }
.box { background: #0f1520; border: 1px solid #2a374d; border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.box h3 { margin: 0 0 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; opacity: .65; }
.row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.row .box { flex: 0 0 auto; margin-bottom: 0; }
.row .arrow { align-self: center; font-size: 22px; opacity: .6; }
.grid { display: grid; gap: 4px; }
.grid.c1 { grid-template-columns: repeat(1, 44px); }
.grid.c2 { grid-template-columns: repeat(2, 44px); }
.grid.c3 { grid-template-columns: repeat(3, 44px); }
.grid.c9 { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.grid.c9 .slot { width: 100%; aspect-ratio: 1; height: auto; }
.hotrow { margin-top: 6px; border-top: 1px dashed #2a374d; padding-top: 6px; }
.tip { font-size: 11.5px; opacity: .6; margin: 4px 0 0; }
.menu { background: #141b26f2; border: 2px solid #33445f; border-radius: 14px; padding: 20px; text-align: center; }
.menu h1 { margin: 0 0 12px; font-size: 24px; }
.menu button {
  display: block; width: 100%; margin: 6px 0; padding: 12px; border-radius: 10px; border: none;
  background: #3c4d6b; color: #eef2f8; font-size: 15px; font-weight: 700;
}
.menu button:first-of-type { background: linear-gradient(#5cc25c, #3d9c3d); color: #06210b; }
.fire { width: 26px; height: 44px; background: #0b0f16; border-radius: 6px; position: relative; overflow: hidden; margin: 0 auto; }
.fire i { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(#ffd24a, #ff6a1a); height: 0%; }
.prog { width: 70px; height: 10px; background: #0b0f16; border-radius: 6px; overflow: hidden; margin-top: 6px; }
.prog i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #6ee06e, #3d9c3d); }
.recipes { margin-top: 8px; }
.recipes h3 { font-size: 12px; opacity: .65; text-transform: uppercase; margin: 0 0 6px; }
.rlist { display: flex; flex-wrap: wrap; gap: 6px; max-height: 132px; overflow: auto; }
.rec {
  display: flex; align-items: center; gap: 6px; background: #1b2331; border: 1px solid #2f3b52;
  border-radius: 8px; padding: 4px 8px 4px 4px; font-size: 12px; cursor: pointer;
}
.rec:active { background: #2a3a52; }
.rec canvas { width: 26px; height: 26px; image-rendering: pixelated; }

#cursorItem {
  position: fixed; z-index: 50; width: 40px; height: 40px; pointer-events: none; display: none;
  left: 50%; top: 12px; transform: translateX(-50%);
  background: #0b0f16cc; border: 2px solid #6ee06e; border-radius: 8px;
}
#cursorItem canvas { width: 100%; height: 100%; image-rendering: pixelated; }
#cursorItem span { position: absolute; right: 2px; bottom: 0; font-size: 11px; font-weight: 800; text-shadow: 1px 1px 0 #000; }

@media (max-width: 520px) {
  #hotbar .slot { width: 36px; height: 36px; }
  .rb { width: 58px; height: 50px; font-size: 10px; }
  .btns { grid-template-columns: 58px 58px; }
  .rb.small { width: 124px; }
}

/* schede, scheda personaggio, ricettario */
.tabs { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.tab {
  flex: 1; padding: 9px 10px; border-radius: 9px; border: 1px solid #2f3d55;
  background: #1b2331; color: #cfd8e6; font-size: 13px; font-weight: 700;
}
.tab.on { background: linear-gradient(#5cc25c, #3d9c3d); color: #06210b; border-color: #3d9c3d; }
.box.grow { flex: 1 1 200px; min-width: 190px; }
.st { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; border-bottom: 1px solid #1e2836; }
.st span { opacity: .7; }
.st b { font-weight: 700; }
.stats2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.xpbar { height: 9px; background: #0b0f16; border-radius: 5px; overflow: hidden; margin-top: 6px; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, #8be04a, #4ad24a); }
.rec { align-items: flex-start; }
.rec span { display: flex; flex-direction: column; line-height: 1.25; }
.rec span i { font-style: normal; font-size: 10.5px; opacity: .6; }
.rec.off { opacity: .45; }
.rlist { max-height: 190px; }

/* barra esperienza nell'HUD */
#xpbar {
  position: absolute; bottom: calc(56px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  width: min(360px, 70vw); height: 10px; background: #0009; border-radius: 5px; overflow: visible;
}
#xpbar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #8be04a, #4ad24a); border-radius: 5px; }
#xpbar span {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; color: #b6f06a; text-shadow: 1px 1px 0 #000, -1px 1px 0 #000;
}

/* omino della scheda personaggio e classifiche */
.dollrow { display: flex; gap: 10px; align-items: center; }
#dollCv {
  width: 110px; height: 170px; image-rendering: pixelated;
  background: linear-gradient(#1b2534, #0d1219); border: 1px solid #2a374d; border-radius: 8px;
}
.box.doll { min-width: 210px; }
.namerow { display: flex; gap: 6px; }
.namerow input {
  flex: 1; min-width: 0; padding: 9px 10px; border: 2px solid #000; background: #0d0d0d;
  color: #eef2f8; font-size: 14px; font-family: inherit;
}
.namerow .mcb { width: auto; padding: 9px 14px; font-size: 13px; }
#boardBox .box { margin-bottom: 0; }

/* effetti attivi, ricerca ricette, bottoni delle stazioni */
#effects { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; max-width: 60vw; }
#effects span {
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  background: #000a; border-left: 3px solid #888;
}
.recsearch {
  width: 100%; padding: 7px 10px; margin-bottom: 6px; border: 1px solid #2f3d55;
  background: #0d1220; color: #eef2f8; font-size: 13px; font-family: inherit; border-radius: 8px;
}
.mcb.ench, .mcb.cut { text-align: left; margin-bottom: 6px; font-size: 13px; }
.mcb.ench i { display: block; font-style: normal; font-size: 10.5px; opacity: .75; font-weight: 500; }
.box.grow .mcb { margin-top: 6px; }

#btnMulti { background: linear-gradient(#4a86d8, #2f5fb0); }
#btnMulti:hover { background: linear-gradient(#5a96e8, #3a6fc0); }

#btnEmote { background: #7a3faf80; }
#btnEmote.act, #btnEmote:active { background: #b45ac2aa; }
