/* Bladebound — tema scuro da cripta: pietra blu notte, oro e braci. */
:root {
  --bg: #0b0d14;
  --surface: #141826;
  --surface-2: #1c2234;
  --line: #2a3150;
  --ink: #eef0f7;
  --muted: #98a0bd;
  --accent: #ffb83d;
  --accent-2: #ff6a2b;
  --accent-ink: #1a0f02;
  --danger: #ff4d5e;
  --good: #59d97a;
  --hp: #e8384f;
  --xp: #5aa8ff;
  --pixel: "Pixelify Sans", "Courier New", monospace;
  --body: "Figtree", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--body); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--pixel); font-weight: 700; letter-spacing: .02em; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border: 0; border-radius: 6px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%); color: var(--accent-ink);
  font: 700 1.05rem/1 var(--pixel); letter-spacing: .03em;
  box-shadow: 0 3px 0 #8a3510, 0 8px 24px -10px rgba(255, 140, 40, .7);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a3510; }
.btn:disabled { filter: grayscale(.8) brightness(.6); cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); color: var(--ink); box-shadow: 0 3px 0 #0a0c13; border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #1a0306; box-shadow: 0 3px 0 #7a1020; }
.btn.small { min-height: 44px; padding: 8px 12px; font-size: .95rem; }
.btn.wide { width: 100%; }
.err { color: var(--danger); margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.lbl { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
input[type=text], input[type=password], input[type=number] {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 6px;
  border: 1px solid var(--line); background: #0d101a; font-size: 16px;
}
input:focus { border-color: var(--accent); outline: none; }

/* ---------- Pagina d'accesso ---------- */
.auth-page {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 140, 40, .18), transparent 60%),
    repeating-linear-gradient(45deg, #0d1018 0 12px, #0b0d14 12px 24px);
}
.auth { width: 100%; max-width: 400px; display: grid; gap: 18px; }
.logo { text-align: center; display: grid; gap: 6px; justify-items: center; }
.logo canvas { image-rendering: pixelated; width: 128px; height: 96px; }
.logo h1 { font-size: 2.6rem; color: var(--accent); text-shadow: 3px 3px 0 #7a2c08; }
.logo p { margin: 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 14px; box-shadow: 0 20px 50px -20px #000; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #0d101a; padding: 4px; border-radius: 8px; }
.tabs button { min-height: 44px; border: 0; border-radius: 6px; background: none; color: var(--muted); font: 700 1rem var(--pixel); }
.tabs button[aria-selected=true] { background: var(--surface-2); color: var(--accent); }
.field { display: grid; gap: 6px; }
.hint { font-size: .85rem; color: var(--muted); margin: 0; }

/* ---------- Gioco ---------- */
.game-page { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

.hud {
  position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 8px; align-items: flex-start; justify-content: space-between;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.me-box { background: rgba(12, 15, 25, .82); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; min-width: 0; flex: 0 1 230px; min-height: 44px; display: grid; gap: 4px; }
.me-line { display: flex; justify-content: space-between; gap: 8px; font: 700 .95rem var(--pixel); white-space: nowrap; }
.me-line .name { overflow: hidden; text-overflow: ellipsis; }
.bar { height: 10px; background: #2a0d14; border-radius: 2px; overflow: hidden; position: relative; border: 1px solid #000; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--hp); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25); transition: width .15s; }
.bar.xp { height: 6px; background: #0d1a2e; }
.bar.xp > i { background: var(--xp); }
.bar-text { position: absolute; inset: 0; font: 700 9px/10px var(--pixel); text-align: center; color: #fff; text-shadow: 0 1px 0 #000; }
.hud-right { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; justify-content: flex-end; flex: 0 0 auto; }
.coins { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 10px; background: rgba(12, 15, 25, .82); border: 1px solid var(--line); border-radius: 8px; font: 700 1rem var(--pixel); color: var(--accent); }
.coin { width: 12px; height: 12px; background: var(--accent); box-shadow: inset -2px -2px 0 #b86d0c, 0 0 0 1px #5c3304; image-rendering: pixelated; }
.hud-btn { min-width: 44px; min-height: 44px; border-radius: 8px; border: 1px solid var(--line); background: rgba(20, 24, 38, .9); font: 700 .95rem var(--pixel); padding: 0 10px; }
.hud-btn:active { background: var(--surface-2); }

.status { position: absolute; left: 50%; transform: translateX(-50%); top: calc(max(8px, env(safe-area-inset-top)) + 64px); text-align: center; pointer-events: none; display: grid; gap: 4px; justify-items: center; width: min(92vw, 420px); }
.status .pill { background: rgba(12, 15, 25, .82); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font: 700 .85rem var(--pixel); }
.boss-bar { width: 100%; display: grid; gap: 2px; }
.boss-bar .bar { height: 12px; }
.boss-bar span { font: 700 .85rem var(--pixel); color: #ffb3b3; text-shadow: 0 1px 0 #000; }
@media (max-width: 599px) {
  .status { left: max(8px, env(safe-area-inset-left)); transform: none; justify-items: start; text-align: left; width: calc(100vw - 124px); }
  .toasts { top: calc(max(8px, env(safe-area-inset-top)) + 150px); }
}
#minimap { position: absolute; right: max(8px, env(safe-area-inset-right)); top: calc(max(8px, env(safe-area-inset-top)) + 56px); width: 96px; height: 72px; image-rendering: pixelated; background: rgba(12, 15, 25, .7); border: 1px solid var(--line); border-radius: 6px; pointer-events: none; }

/* Chat */
.chat { position: absolute; left: max(8px, env(safe-area-inset-left)); bottom: calc(max(8px, env(safe-area-inset-bottom)) + 4px); width: min(360px, calc(100vw - 16px)); display: grid; gap: 6px; pointer-events: none; }
.chat-log { display: grid; gap: 2px; max-height: 30vh; overflow: hidden; align-content: end; font-size: .9rem; }
.chat-log p { margin: 0; padding: 2px 8px; background: rgba(8, 10, 18, .7); border-radius: 4px; overflow-wrap: anywhere; text-shadow: 0 1px 0 #000; justify-self: start; max-width: 100%; }
.chat-log b { color: var(--accent); font-weight: 700; }
.chat-log p.sys { color: var(--muted); font-style: italic; }
.chat form { display: flex; gap: 6px; pointer-events: auto; }
.chat input { min-height: 44px; background: rgba(8, 10, 18, .92); }
.chat.closed form { display: none; }

/* Comandi a tocco */
.touch { display: none; }
.is-touch .touch { display: block; }
.is-touch .desk-only { display: none !important; }
.joy { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .06); transform: translate(-50%, -50%); pointer-events: none; }
.joy i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: rgba(255, 184, 61, .55); border: 2px solid rgba(255, 220, 150, .7); }
.actions { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 8px); display: grid; gap: 12px; justify-items: end; }
.act { width: 76px; height: 76px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .3); background: rgba(232, 56, 79, .55); font: 700 .9rem var(--pixel); color: #fff; text-shadow: 0 1px 0 #000; }
.act:active { background: rgba(232, 56, 79, .85); }
#touch-hint { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 40px); white-space: nowrap; }
.is-touch .chat { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 150px); width: min(300px, calc(100vw - 120px)); }
.is-touch .chat-log { max-height: 20vh; font-size: .82rem; }

/* Pulsante contestuale (entra nel negozio, apri forziere...) */
.context { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 12px); }
.is-touch .context { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 104px); }
.keys { position: absolute; right: 10px; bottom: 10px; font-size: .78rem; color: var(--muted); background: rgba(8, 10, 18, .7); padding: 6px 10px; border-radius: 6px; pointer-events: none; text-align: right; }

/* Messaggi brevi */
.toasts { position: absolute; left: 50%; transform: translateX(-50%); top: calc(max(8px, env(safe-area-inset-top)) + 112px); display: grid; gap: 6px; justify-items: center; pointer-events: none; width: min(92vw, 420px); z-index: 30; }
.toast { background: rgba(12, 15, 25, .94); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 6px; font-weight: 600; animation: toast 3.2s forwards; }
.toast.bad { border-left-color: var(--danger); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* Pannelli */
.sheet-bg { position: absolute; inset: 0; background: rgba(4, 5, 10, .6); z-index: 20; display: grid; align-items: end; justify-items: center; }
.sheet { width: 100%; max-width: 560px; max-height: min(86dvh, 760px); background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0; display: grid; grid-template-rows: auto auto 1fr; overflow: hidden; box-shadow: 0 -20px 60px -20px #000; }
@media (min-width: 700px) {
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 14px; border-bottom: 1px solid var(--line); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px 8px 16px; border-bottom: 3px solid var(--accent-2); }
.sheet-head h2 { font-size: 1.5rem; color: var(--accent); }
.sheet-head .x { min-width: 44px; min-height: 44px; border: 0; background: var(--surface-2); border-radius: 8px; font: 700 1.2rem var(--pixel); }
.sheet-tabs { display: flex; gap: 6px; padding: 8px 12px 0; overflow-x: auto; }
.sheet-tabs button { min-height: 44px; padding: 0 14px; border-radius: 8px 8px 0 0; border: 1px solid var(--line); border-bottom: 0; background: #0f1320; color: var(--muted); font: 700 .95rem var(--pixel); white-space: nowrap; }
.sheet-tabs button[aria-selected=true] { background: var(--surface-2); color: var(--accent); }
.sheet-body { overflow-y: auto; padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 10px; align-content: start; -webkit-overflow-scrolling: touch; }
.sheet-body > p { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.stat { background: #0f1320; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.stat b { display: block; font: 700 1.15rem var(--pixel); }
.stat span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; background: #0f1320; border: 1px solid var(--line); border-left: 4px solid var(--rc, #888); border-radius: 8px; padding: 8px; }
.item canvas { width: 40px; height: 40px; image-rendering: pixelated; background: #080a12; border-radius: 6px; }
.item .nm { font-weight: 700; color: var(--rc, var(--ink)); overflow-wrap: anywhere; }
.item .sub { font-size: .82rem; color: var(--muted); }
.item .btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 420px) {
  .item { grid-template-columns: 40px minmax(0, 1fr); }
  .item .btns { grid-column: 1 / -1; justify-content: stretch; }
  .item .btns > * { flex: 1; }
}
.slot-empty { color: var(--muted); font-style: italic; }
.section-title { font: 700 1.05rem var(--pixel); color: var(--muted); margin-top: 6px; }
.price-row { display: flex; gap: 6px; align-items: center; }
.price-row input { width: 110px; min-height: 44px; }
.diffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.diffs button { min-height: 64px; border-radius: 8px; border: 2px solid var(--line); background: #0f1320; display: grid; gap: 2px; place-content: center; padding: 6px; }
.diffs button b { font: 700 1rem var(--pixel); }
.diffs button span { font-size: .72rem; color: var(--muted); }
.diffs button[aria-pressed=true] { border-color: var(--accent); background: #2a1f10; }
.party { background: #0f1320; border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.party.mine { border-color: var(--accent); }
.party-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Fine dungeon */
.overlay { position: absolute; inset: 0; z-index: 25; background: rgba(4, 5, 10, .78); display: grid; place-items: center; padding: 16px; }
.overlay .card { max-width: 420px; width: 100%; text-align: center; max-height: 90dvh; overflow-y: auto; }
.overlay h2 { font-size: 2rem; }
.overlay h2.win { color: var(--accent); }
.overlay h2.lose { color: var(--danger); }
.overlay .item { text-align: left; }
