@font-face { font-family: 'Bungee'; src: url(../fonts/Bungee-normal-400.woff2) format('woff2'); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; src: url(../fonts/Chakra-normal-500.woff2) format('woff2'); font-style: normal; font-weight: 500; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; src: url(../fonts/Chakra-normal-700.woff2) format('woff2'); font-style: normal; font-weight: 700; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; src: url(../fonts/Chakra-italic-700.woff2) format('woff2'); font-style: italic; font-weight: 700; font-display: swap; }
:root {
  --ink: #12122a;
  --navy: #161c44;
  --navy-2: #222a5e;
  --red: #e8262e;
  --red-d: #9a1218;
  --yellow: #ffd21f;
  --yellow-d: #c08f00;
  --blue: #1f5fd6;
  --blue-l: #6aa0ff;
  --paper: #fff8ec;
  --paper-2: #c9cdea;
  --sunset: #ff7a3d;
  --magenta: #e6418a;
  --cyan: #39d6ff;
  --bevel: 14px;
  --display: 'Bungee', 'Chakra Petch', sans-serif;
  --ui: 'Chakra Petch', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--paper); font-family: var(--ui); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
::selection { background: var(--yellow); color: var(--ink); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
[hidden] { display: none !important; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- pulsanti ---------- */
.btn {
  --bg: var(--red); --fg: var(--paper); --sh: var(--red-d);
  position: relative; border: 0; padding: 12px 26px; min-height: 48px;
  background: var(--bg); color: var(--fg);
  font-family: var(--display); font-size: 17px; letter-spacing: .02em; text-transform: uppercase;
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
  box-shadow: inset 0 -5px 0 var(--sh);
  transition: transform .12s cubic-bezier(.2,.9,.3,1), background-color .12s, color .12s;
}
.btn:hover { --bg: var(--yellow); --fg: var(--ink); --sh: var(--yellow-d); transform: translateX(3px); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 var(--sh); }
.btn.alt { --bg: var(--blue); --sh: #103a8a; }
.btn.alt:hover { --bg: var(--yellow); --fg: var(--ink); --sh: var(--yellow-d); }
.btn.big { font-size: 22px; padding: 14px 40px; min-height: 56px; }
.btn.small { font-size: 14px; padding: 8px 18px; min-height: 40px; }
.btn:disabled { --bg: #3b4170; --fg: #8b90b8; --sh: #2a2f57; cursor: not-allowed; transform: none; }
.linkish { background: none; border: 0; padding: 0; color: var(--yellow); text-decoration: underline; text-underline-offset: 3px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 20px; }
.row.center { justify-content: center; }
.muted { color: var(--paper-2); }

/* ---------- schermate ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 20; overflow: auto; }
.screen.dim { background: rgba(10, 10, 30, .62); }
.panel { background: var(--yellow); padding: 3px; width: min(560px, 100%); clip-path: polygon(var(--bevel) 0, 100% 0, 100% calc(100% - var(--bevel)), calc(100% - var(--bevel)) 100%, 0 100%, 0 var(--bevel)); }
.panel.wide { width: min(980px, 100%); }
.panel .in {
  background: var(--navy); padding: 26px 28px 28px;
  clip-path: polygon(calc(var(--bevel) - 1px) 0, 100% 0, 100% calc(100% - var(--bevel) + 1px), calc(100% - var(--bevel) + 1px) 100%, 0 100%, 0 calc(var(--bevel) - 1px));
  background-image: linear-gradient(180deg, rgba(255,255,255,.04), transparent 40%);
}
.panel .in.scroll { max-height: calc(100dvh - 40px); overflow: auto; scrollbar-color: var(--yellow) var(--navy-2); }
h2 { font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.05; margin: 0 0 18px; color: var(--yellow); text-shadow: 3px 3px 0 var(--red), 5px 5px 0 var(--ink); text-wrap: balance; transform: skewX(-6deg); }
h3 { font-family: var(--ui); font-style: italic; font-weight: 700; font-size: 18px; margin: 22px 0 8px; color: var(--cyan); text-transform: uppercase; letter-spacing: .04em; }
p { line-height: 1.5; }

.field { display: grid; gap: 6px; margin: 0 0 16px; }
.field > span { font-weight: 700; font-size: 14px; letter-spacing: .03em; text-transform: uppercase; color: var(--paper-2); display: flex; justify-content: space-between; }
.field output { color: var(--yellow); }
.field input:not([type=range]), .field textarea, .field select {
  background: var(--ink); border: 2px solid var(--navy-2); padding: 12px 14px; font-size: 16px; color: var(--paper); border-radius: 0;
  -webkit-user-select: text; user-select: text; caret-color: var(--yellow);
}
.field input::placeholder, .field textarea::placeholder { color: #8b90b8; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--yellow); outline: none; }
input[type=range] { accent-color: var(--red); width: 100%; height: 28px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 700; margin: 6px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--red); }

.modes { border: 0; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.modes legend, .chips legend { font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: .03em; color: var(--paper-2); margin-bottom: 8px; padding: 0; }
.mode { display: block; cursor: pointer; }
.mode input { position: absolute; opacity: 0; }
.mode span { display: block; padding: 12px 14px 12px 16px; background: var(--ink); border: 2px solid var(--navy-2); color: var(--paper-2); line-height: 1.4; transition: border-color .15s, background-color .15s; }
.mode b { display: block; font-family: var(--display); font-weight: 400; font-size: 17px; color: var(--paper); margin-bottom: 2px; }
.mode input:checked + span { border-color: var(--yellow); background: var(--navy-2); }
.mode input:checked + span b { color: var(--yellow); }
.mode input:focus-visible + span { outline: 3px solid var(--yellow); outline-offset: 2px; }
.chips { border: 0; padding: 0; margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { width: 100%; }
.chips label input { position: absolute; opacity: 0; }
.chips label span { display: inline-block; padding: 8px 14px; background: var(--ink); border: 2px solid var(--navy-2); font-weight: 700; cursor: pointer; }
.chips label input:checked + span { background: var(--yellow); color: var(--ink); border-color: var(--yellow); }
.chips label input:focus-visible + span { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- titolo ---------- */
#title { overflow: hidden; background: radial-gradient(ellipse at 50% 120%, rgba(18,18,42,.0) 30%, rgba(18,18,42,.55) 100%); align-content: center; }
#title .speed {
  position: absolute; inset: -20%; pointer-events: none; opacity: .22;
  background: repeating-conic-gradient(from 0deg at 50% 46%, rgba(255,248,236,.9) 0deg 1.2deg, transparent 1.2deg 7deg);
  -webkit-mask: radial-gradient(circle at 50% 46%, transparent 18%, #000 60%); mask: radial-gradient(circle at 50% 46%, transparent 18%, #000 60%);
  animation: spin 90s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.title-wrap { position: relative; text-align: center; display: grid; justify-items: center; }
.logo {
  margin: 0; font-family: var(--display); font-weight: 400; line-height: .86; font-size: clamp(64px, 14vw, 168px);
  color: var(--yellow); transform: skewX(-10deg) rotate(-3deg);
  -webkit-text-stroke: clamp(3px, .5vw, 6px) var(--red); paint-order: stroke fill;
  text-shadow: 3px 3px 0 var(--red-d), 6px 6px 0 var(--red-d), 9px 9px 0 var(--ink), 12px 12px 0 var(--ink), 0 22px 40px rgba(18,18,42,.6);
  animation: logo-in .9s cubic-bezier(.16,1,.3,1) both;
}
.logo span { display: inline; }
.logo span:last-child { color: var(--paper); }
@keyframes logo-in { from { transform: skewX(-10deg) rotate(-3deg) scale(1.5); filter: blur(10px); opacity: 0; } }
.kana { margin: 14px 0 0; background: var(--red); color: var(--paper); font-weight: 700; font-size: clamp(16px, 2.6vw, 24px); letter-spacing: .5em; padding: 4px 6px 4px 22px; transform: skewX(-10deg); box-shadow: 6px 6px 0 var(--ink); }
.tag { margin: 18px 0 26px; font-weight: 700; font-style: italic; font-size: clamp(16px, 2.2vw, 20px); text-shadow: 2px 2px 0 var(--ink); }
.menu { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; max-width: 620px; }
.menu.col { flex-direction: column; align-items: stretch; }
.credit { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 16px; right: 16px; text-align: center; font-size: 14px; font-weight: 700; text-shadow: 1px 1px 0 var(--ink); }
.credit a { color: var(--yellow); text-underline-offset: 3px; }

/* ---------- mondi ---------- */
#world-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; max-height: 50dvh; overflow: auto; }
#world-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; background: var(--ink); border: 2px solid var(--navy-2); padding: 10px 12px; }
#world-list li:hover { border-color: var(--yellow); }
#world-list .w-name { font-weight: 700; font-size: 18px; }
#world-list .w-meta { font-size: 13px; color: var(--paper-2); }
.w-del { background: none; border: 2px solid var(--navy-2); color: var(--paper-2); padding: 8px 10px; font-weight: 700; }
.w-del:hover { border-color: var(--red); color: var(--paper); background: var(--red); }

/* ---------- cosa puoi fare ---------- */
.howto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 4px 28px; }
.howto-grid h3 { margin-top: 10px; }
.howto-grid p { margin: 0 0 8px; color: var(--paper-2); max-width: 65ch; }
.keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 20px; margin: 0; }
.keys div { display: flex; gap: 10px; align-items: baseline; }
.keys dt { font-weight: 700; background: var(--paper); color: var(--ink); padding: 2px 8px; font-size: 14px; white-space: nowrap; box-shadow: 0 3px 0 var(--paper-2); }
.keys dd { margin: 0; color: var(--paper-2); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button { pointer-events: auto; }
#topbar { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
#world-chip { background: var(--ink); border-left: 6px solid var(--red); padding: 6px 12px 6px 10px; display: flex; gap: 10px; align-items: baseline; transform: skewX(-8deg); box-shadow: 4px 4px 0 rgba(18,18,42,.5); }
#world-chip b { font-family: var(--display); font-weight: 400; font-size: 15px; color: var(--yellow); }
#world-chip span { font-weight: 700; font-size: 14px; color: var(--paper-2); }
#coords { background: rgba(18,18,42,.8); padding: 6px 10px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.topbtns { display: flex; gap: 8px; }
.icon-btn { width: 46px; height: 46px; background: var(--ink); color: var(--paper); border: 2px solid var(--navy-2); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--yellow); color: var(--ink); }
#crosshair { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; transform: translate(-50%, -50%); }
#breakbar { position: absolute; left: 50%; top: calc(50% + 28px); width: 64px; height: 8px; transform: translateX(-50%); background: var(--ink); border: 2px solid var(--ink); }
#breakbar i { display: block; height: 100%; width: 0; background: var(--yellow); }

#bottom { position: absolute; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 6px; }
#itemname { font-family: var(--display); font-size: 16px; color: var(--paper); text-shadow: 2px 2px 0 var(--ink); min-height: 20px; opacity: 0; transition: opacity .3s; }
#itemname.show { opacity: 1; }
#vitals { display: flex; gap: 22px; justify-content: space-between; width: min(500px, 96vw); }
.pips { display: flex; gap: 1px; }
.pips svg { width: 22px; height: 22px; filter: drop-shadow(1px 2px 0 rgba(18,18,42,.6)); }
#health svg { color: var(--red); }
#health svg.half { color: #f08a8e; }
#energy svg { color: var(--yellow); }
#energy svg.half { color: #fff0a6; }
.pips svg.empty { color: #3b4170; }
#health.low svg:not(.empty) { animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { color: var(--paper); } }
#hotbar { display: flex; gap: 4px; background: rgba(18,18,42,.82); padding: 4px; clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%); padding-left: 12px; padding-right: 12px; }
.slot { position: relative; width: 52px; height: 52px; background: var(--navy); border: 2px solid var(--navy-2); display: grid; place-items: center; pointer-events: auto; padding: 0; }
.slot img { width: 40px; height: 40px; image-rendering: auto; pointer-events: none; }
.slot .n { position: absolute; right: 3px; bottom: 0; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); }
.slot.sel { border-color: var(--yellow); background: var(--navy-2); box-shadow: inset 0 0 0 2px var(--ink); }
#hotbar .slot.sel { transform: translateY(-4px); }
.slot:hover { border-color: var(--paper-2); }
.slot.pick { border-color: var(--cyan); background: #1a3a6a; }

/* touch */
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .topbtns .touch-only { display: grid; }
#touch { position: absolute; inset: 0; }
#stick { position: absolute; left: max(22px, env(safe-area-inset-left)); bottom: 118px; width: 132px; height: 132px; border-radius: 50%; background: rgba(18,18,42,.38); border: 3px solid rgba(255,248,236,.35); pointer-events: auto; }
#stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: var(--red); border: 3px solid var(--ink); box-shadow: inset 0 -5px 0 var(--red-d); }
#tbtns { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: 112px; display: grid; grid-template-columns: repeat(2, 72px); gap: 10px; pointer-events: none; }
#tbtns button { width: 72px; height: 72px; border: 3px solid var(--ink); display: grid; place-items: center; align-content: center; gap: 2px; background: rgba(31,95,214,.85); color: var(--paper); pointer-events: auto; font-weight: 700; font-size: 11px; text-transform: uppercase; clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px); }
#tbtns button svg { width: 28px; height: 28px; }
#tbtns button.on, #tbtns button:active { background: var(--yellow); color: var(--ink); }
#t-break { background: rgba(232,38,46,.88) !important; }
#t-break:active { background: var(--yellow) !important; }
#t-jump { grid-column: 2; }

#hurt { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(232,38,46,.7) 100%), repeating-conic-gradient(from 0deg at 50% 50%, rgba(255,248,236,.0) 0 3deg, rgba(232,38,46,.25) 3deg 4deg); transition: opacity .35s; }
#hurt.on { opacity: 1; transition: none; }

#eyecatch { position: absolute; left: 0; right: 0; top: 30%; display: grid; place-items: center; pointer-events: none; }
.ec-band { display: grid; justify-items: center; padding: 14px 60px; background: var(--ink); color: var(--paper); transform: skewY(-4deg) scaleX(0); transform-origin: left center; box-shadow: 0 -6px 0 var(--red), 0 6px 0 var(--yellow); }
.ec-band b { font-family: var(--display); font-weight: 400; font-size: clamp(30px, 7vw, 64px); line-height: 1; color: var(--yellow); text-shadow: 4px 4px 0 var(--red); }
.ec-band span { font-weight: 700; font-style: italic; font-size: clamp(14px, 2.4vw, 20px); margin-top: 6px; }
#eyecatch.go .ec-band { animation: ec 3.2s cubic-bezier(.16,1,.3,1) both; }
@keyframes ec {
  0% { transform: skewY(-4deg) scaleX(0); filter: blur(6px); }
  12% { transform: skewY(-4deg) scaleX(1); filter: blur(0); }
  82% { transform: skewY(-4deg) scaleX(1); opacity: 1; }
  100% { transform: skewY(-4deg) scaleX(1) translateX(30%); opacity: 0; }
}

#toast { position: absolute; left: 50%; top: 74px; transform: translateX(-50%); background: var(--paper); color: var(--ink); font-weight: 700; padding: 8px 16px; opacity: 0; transition: opacity .25s; box-shadow: 4px 4px 0 var(--ink); max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#pointer-hint { position: absolute; left: 50%; top: 60%; transform: translateX(-50%); font-family: var(--display); font-size: 20px; background: var(--ink); padding: 10px 20px; color: var(--yellow); }

/* inventario */
.inv-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.inv-head h2 { margin: 0; }
.slots { display: grid; grid-template-columns: repeat(9, 52px); gap: 4px; justify-content: start; }
.hb-label { margin-top: 18px; }
#recipes { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
#recipes li { display: flex; align-items: center; gap: 8px; background: var(--ink); border: 2px solid var(--navy-2); padding: 8px 10px; }
#recipes li.ok { border-color: #3a4a8a; }
#recipes .r-out { display: flex; align-items: center; gap: 6px; font-weight: 700; min-width: 0; flex: 1; }
#recipes .r-out span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#recipes img { width: 34px; height: 34px; }
#recipes .r-need { display: flex; gap: 4px; align-items: center; font-size: 13px; font-weight: 700; color: var(--paper-2); }
#recipes .r-need span { display: inline-flex; align-items: center; }
#recipes .r-need img { width: 24px; height: 24px; }
#recipes .r-need .miss { color: #ff8a8e; }

/* morte */
.screen.red { background: radial-gradient(circle, rgba(232,38,46,.55), rgba(90,8,14,.92)); }
.dead-wrap { text-align: center; }
.dead-title { font-size: clamp(54px, 12vw, 120px); transform: skewX(-10deg) rotate(-4deg); text-shadow: 5px 5px 0 var(--ink), 10px 10px 0 rgba(18,18,42,.5); color: var(--paper); margin: 0 0 8px; }
#dead-msg { font-weight: 700; font-size: 20px; }

#loading { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: var(--ink); }
.ld-band { display: grid; gap: 12px; justify-items: center; }
.ld-band b { font-family: var(--display); font-weight: 400; font-size: 26px; color: var(--yellow); }
.ld-band i { width: 220px; height: 10px; background: linear-gradient(90deg, var(--red) 0 33%, var(--yellow) 33% 66%, var(--blue) 66%); background-size: 60px 100%; animation: ld .6s linear infinite; }
@keyframes ld { to { background-position: 60px 0; } }

@media (max-width: 640px) {
  .panel .in { padding: 20px 18px 22px; }
  h2 { font-size: 24px; }
  .slot { width: 38px; height: 38px; }
  .slot img { width: 30px; height: 30px; }
  .slot .n { font-size: 12px; }
  .slots { grid-template-columns: repeat(9, 34px); gap: 3px; }
  .slots .slot { width: 34px; height: 34px; }
  .slots .slot img { width: 26px; height: 26px; }
  .pips svg { width: 16px; height: 16px; }
  #vitals { width: 96vw; gap: 8px; }
  #hotbar { gap: 2px; padding-left: 10px; padding-right: 10px; }
  #recipes { grid-template-columns: 1fr; }
  .btn.big { font-size: 19px; padding: 12px 30px; }
}
@media (max-height: 500px) {
  #stick { bottom: 84px; width: 112px; height: 112px; }
  #tbtns { bottom: 84px; grid-template-columns: repeat(3, 62px); }
  #tbtns button { width: 62px; height: 62px; }
  #t-jump { grid-column: auto; }
  .logo { font-size: 72px; }
  .panel .in { padding: 16px 18px 18px; }
  h2 { font-size: 22px; margin-bottom: 10px; }
  .slots { grid-template-columns: repeat(9, 38px); gap: 3px; }
  .slots .slot { width: 38px; height: 38px; }
  .slots .slot img { width: 28px; height: 28px; }
  #inv-help { margin: 6px 0 10px; font-size: 14px; }
  .hb-label { margin-top: 10px; }
  .slot { width: 42px; height: 42px; }
  .slot img { width: 32px; height: 32px; }
  .pips svg { width: 17px; height: 17px; }
  .tag { margin: 10px 0 14px; }
}
@media (prefers-reduced-motion: reduce) {
  #title .speed { animation: none; }
  .logo { animation: none; }
}
