/* =============================================================================
   Idle RPG — foglio di stile
   =============================================================================
   Estratto da index.html senza RIORDINARE le regole: in CSS l'ordine determina
   la cascata, quindi spostare blocchi durante un'estrazione può cambiare
   l'aspetto in modi silenziosi. Qui sono stati aggiunti solo commenti di
   sezione sui raggruppamenti già esistenti.

   Convenzioni del progetto:
   - I colori vivono TUTTI in :root come custom properties: nessun esadecimale
     sparso nelle regole (le poche eccezioni storiche sono marcate).
   - Zero dipendenze, zero build step: questo file si carica così com'è.
   - Le dimensioni in rem seguono la scala tipografica di html (vedi @media).
   ============================================================================= */

/* --- Token: colori e superfici ------------------------------------------ */
:root {
  --bg: #131711;
  --panel: #1c221a;
  --panel-2: #232b20;
  --border: #39422f;
  --ink: #e6dfc8;
  --muted: #90987f;
  --ember: #d99a3d;
  --blood: #b8503c;
  --bar-track: #10140e;
}
/* --- Reset e scala tipografica ------------------------------------------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
/* Scala tipografica: tutto ciò che è in rem cresce con lo schermo */
html { font-size: 16px; }
@media (min-width: 1600px) { html { font-size: 18px; } }
@media (min-width: 2200px) { html { font-size: 21px; } }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Alegreya Sans', sans-serif;
  min-height: 100vh;
  padding: 1rem;
}
/* --- Intestazioni e barra superiore --------------------------------------- */
h1, h2, .item-name, .slot-label {
  font-family: 'Metamorphous', serif;
  letter-spacing: 0.02em;
}

header {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  max-width: 69rem; margin: 0 auto 0.875rem;
  border-bottom: 1px solid var(--border); padding-bottom: 10px;
}
h1 { font-size: 1.25rem; color: var(--ember); }
.header-meta { display: flex; gap: 14px; color: var(--muted); font-size: 0.95rem; }
.header-actions { margin-left: auto; display: flex; gap: 8px; }

/* --- Layout e pannelli ---------------------------------------------------- */
.layout {
  max-width: 69rem; margin: 0 auto;
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 0.875rem;
}
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.875rem;
}
.panel h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted); margin-bottom: 10px;
}

/* ---- Combat ---- */
/* --- Arena di combattimento e barre ---------------------------------------- */
.arena { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.combatant {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px;
}
.combatant .name { font-weight: 700; margin-bottom: 8px; min-height: 1.4em; }

.bar {
  position: relative; height: 1.25rem;
  background: var(--bar-track);
  border: 1px solid var(--border); border-radius: 3px;
  overflow: hidden; margin-bottom: 6px;
}
.bar .fill { height: 100%; width: 0%; transition: none; }
.bar.hp .fill { background: linear-gradient(180deg, #6f9b4e, #4e7336); }
.bar.hp.enemy .fill { background: linear-gradient(180deg, #c06a52, var(--blood)); }
.bar.atk { height: 0.5rem; }
.bar.atk .fill { background: var(--ember); }
.bar.xp { height: 1rem; margin-top: 0.625rem; }
.bar.xp .fill { background: #7d6bb5; }
.bar.xp .bar-text { font-size: 0.68rem; color: #cfc8e8; }
.bar .bar-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; color: var(--ink); text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* ---- Tooltip ---- */
[data-tt] { cursor: help; }
.stat-row[data-tt] span:first-child { border-bottom: 1px dotted var(--muted); }
  .bar.atk.offhand { height: 6px; opacity: 0.75; margin-top: 2px; }
  .bar.atk.offhand .fill { background: linear-gradient(90deg, #8a6d3b, #b8904a); }

/* --- Tooltip -------------------------------------------------------------- */
#tooltip {
  position: fixed; z-index: 100; max-width: 34rem;
  background: #0d100b; border: 1px solid var(--ember);
  border-radius: 5px; padding: 8px 10px;
  font-size: 0.8rem; line-height: 1.4; color: var(--ink);
  pointer-events: none; opacity: 0; transition: opacity 0.12s;
}
#tooltip.visible { opacity: 1; }
/* --- Mappa delle zone e spedizione ----------------------------------------- */
.zone-strip {
  display: flex; justify-content: space-between; align-items: baseline;
  color: var(--muted); font-size: 0.9rem; margin-bottom: 8px;
}
#zone-name { color: var(--ink); font-weight: 700; }
#zone-map { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.map-link { color: var(--border); }
.map-node {
  font-family: 'Metamorphous', serif; font-size: 0.72rem;
  padding: 5px 10px; border-radius: 4px;
}
.map-node.locked { opacity: 0.45; cursor: not-allowed; }
.map-node.current { border-color: var(--ember); color: var(--ember); }
.map-node.cleared { border-color: #5fbf6e; }
.mob-marker { color: var(--ember); font-size: 0.78rem; }
#retreat { margin-left: auto; }
#retreat.embark { background: var(--ember); color: #1a1408; border-color: var(--ember); font-weight: 700; }
#wounded-badge { color: var(--blood); font-size: 0.8rem; }
#depth-bonus { color: var(--ember); }

/* ---- Item cells (zaino ed equip compatti) ---- */
/* --- Celle oggetto, equipaggiamento, zaino e deposito ---------------------- */
.cell-grid { display: flex; flex-wrap: wrap; gap: 8px; }
#equipment { display: flex; flex-wrap: wrap; gap: 12px; }
.cell-wrap { text-align: center; }
.item-cell {
  position: relative; width: 3.25rem; height: 3.25rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2);
  border: 2px solid var(--rarity, var(--border));
  border-radius: 6px; cursor: pointer;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.5);
}
.item-cell:hover { filter: brightness(1.25); }
.item-cell.empty { border-style: dashed; cursor: default; color: var(--muted); }
.item-cell.empty:hover { filter: none; }
.cell-icon { font-size: 1.7rem; line-height: 1; }
img.icon-img { width: 85%; height: 85%; object-fit: contain; image-rendering: auto; pointer-events: none; }
img.tt-icon { width: 1.4em; height: 1.4em; vertical-align: -0.3em; }
svg.cur { width: 1em; height: 1em; vertical-align: -0.12em; }
img.portrait {
  width: 2em; height: 2em; vertical-align: -0.6em;
  border-radius: 4px; border: 1px solid var(--border);
  object-fit: cover; background: var(--bar-track);
}
.cell-lock { position: absolute; top: -7px; left: -7px; font-size: 0.65rem; }
.item-cell.locked { box-shadow: inset 0 0 8px rgba(0,0,0,0.5), 0 0 0 1px var(--ember); }
.item-cell.filtered-out {
  opacity: 0.28; filter: grayscale(0.85) brightness(0.55);
  pointer-events: none; cursor: default;
}
.stash-tools select { flex: 1; }
.stash-full { color: var(--blood); font-weight: 700; }
/* --- Eredità e prestigio --------------------------------------------------- */
.legacy-gen { font-size: 0.9rem; margin-bottom: 8px; }
.legacy-branch { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 6px; font-size: 0.85rem; }
.legacy-branch button { min-width: 2.2rem; }
.legacy-points { color: var(--ember); font-weight: 700; }
.modal-card .cell-grid { margin-top: 0.6rem; }
.item-cell.picked { outline: 2px solid var(--ember); }
.picker-count { margin-top: 0.6rem; font-size: 0.85rem; color: var(--muted); }
.heir-name-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.7rem; font-size: 0.85rem; }
.heir-name-row input {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--ink); border-radius: 4px; padding: 0.45rem 0.6rem; font-size: 0.9rem;
}
.heir-name-row input:focus { outline: 2px solid var(--ember); outline-offset: 1px; }
.resist-row { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; }
.resist-badge { font-size: 0.68rem; padding: 1px 5px; border-radius: 3px; border: 1px solid var(--border); }
.resist-badge.res { color: #e07b7b; }
.resist-badge.weak { color: #7bc98a; }
#version-btn { position: relative; font-variant-numeric: tabular-nums; }
#version-btn.has-news::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ember); box-shadow: 0 0 4px var(--ember);
}
.cl-version { margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px solid var(--border); }
.cl-version:first-of-type { margin-top: 0.4rem; padding-top: 0; border-top: none; }
.cl-head { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.cl-num { font-weight: 700; color: var(--ember); font-variant-numeric: tabular-nums; }
.cl-title { font-size: 0.9rem; }
.cl-date { font-size: 0.75rem; color: var(--muted); margin-left: auto; }
.cl-entry { display: flex; gap: 0.5rem; margin-top: 6px; font-size: 0.84rem; line-height: 1.45; }
.cl-tag {
  flex: 0 0 auto; font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 5px; border-radius: 3px; border: 1px solid var(--border); height: fit-content;
}
.cl-tag.feature { color: #7bc98a; }
.cl-tag.balance { color: #d4a24a; }
.cl-tag.fix { color: #8ab4d8; }
.cl-body { max-height: 55vh; overflow-y: auto; padding-right: 4px; }
.cl-new { font-size: 0.72rem; color: var(--ember); border: 1px solid var(--ember); border-radius: 3px; padding: 1px 5px; }
.auto-salvage-row { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; flex: 1; }
.auto-salvage-row select { flex: 1; }
.dg-keys { font-size: 0.85rem; margin-bottom: 8px; }
.dg-keys b { color: var(--ember); }
.dg-mod { font-size: 0.8rem; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; margin-bottom: 8px; }
.dg-mod .dg-mod-name { color: #d4a24a; font-weight: 700; }
.dg-entry { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.dg-entry:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.dg-head { display: flex; align-items: baseline; gap: 0.4rem; }
.dg-name { font-size: 0.92rem; }
.dg-best { margin-left: auto; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dg-rules { font-size: 0.74rem; color: var(--blood); margin: 4px 0 6px; }
.dg-active { border: 1px solid var(--ember); border-radius: 4px; padding: 8px; font-size: 0.85rem; }
.dg-enter-row { display: flex; gap: 0.4rem; }
.dg-enter-row select { flex: 0 0 auto; }
.dg-enter-row button { flex: 1; }
.tt-heirloom { color: #d4a24a; font-size: 0.78rem; margin-top: 4px; }
.tt-depth { color: #8ab4d8; font-size: 0.78rem; margin-top: 4px; }
/* Meccaniche del boss: il telegrafo è l'unica cosa che il giocatore può
   "vedere arrivare" in un idle — deve essere impossibile da ignorare */
#mob-atk-bar.charging {
  background: linear-gradient(90deg, var(--ember), var(--blood));
  animation: windup var(--windup, 1.5s) linear forwards;
  box-shadow: 0 0 10px var(--blood);
}
@keyframes windup { from { width: 0%; } to { width: 100%; } }
#mob-name.telegraph { animation: pulse-warn 0.5s ease-in-out infinite; }
@keyframes pulse-warn { 0%,100% { color: var(--ink); } 50% { color: var(--blood); } }
#mob-name.enraged { color: var(--blood); text-shadow: 0 0 8px rgba(200,60,60,0.5); }
#mob-name.enraged::after { content: ' 🔥'; }
.struck { animation: shake 0.35s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.mastery-block { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.mastery-title { font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
.mastery-row { display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.8rem; margin-top: 3px; }
.mastery-stars { color: #d4a24a; letter-spacing: 1px; white-space: nowrap; }
.mastery-zone { flex: 0 0 auto; }
.mastery-fx { color: var(--muted); }
.mastery-total { margin-top: 5px; font-size: 0.8rem; color: #d4a24a; }
.tt-mastery-fx { color: var(--muted); padding-left: 8px; }
.reforge-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.reforge-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px dotted var(--border);
}
.reforge-actions { display: flex; gap: 6px; }
.reforge-note { color: var(--muted); font-size: 0.78rem; margin-top: 8px; }
.forge-status { font-size: 0.9rem; margin-bottom: 8px; }
.vendor-offer { background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 10px; margin-bottom: 8px; }
.forge-bar { height: 1.25rem; }
.forge-bar .fill { background: linear-gradient(180deg, #e0a44d, #b3742a); }
.embark-like { background: var(--ember); color: #1a1408; border-color: var(--ember); font-weight: 700; }

/* Tooltip item */
.tt-item-name { font-family: 'Metamorphous', serif; font-size: 0.95rem; margin-bottom: 2px; }
.tt-item-meta { color: var(--muted); font-size: 0.75rem; margin-bottom: 6px; }
.tt-item-stats { margin-bottom: 4px; }
.tt-affix { color: #9fc48a; }
.tt-wclass { color: var(--ember); font-size: 0.78rem; margin-bottom: 4px; }
.tt-item-lore { color: var(--muted); font-style: italic; font-size: 0.75rem; margin-top: 6px; }
.tt-hint { color: var(--ember); font-size: 0.72rem; margin-top: 8px; }
.tt-compare { display: flex; gap: 14px; }
.tt-card { min-width: 0; max-width: 16rem; flex: 1; }
.tt-compare .tt-card + .tt-card { border-left: 1px solid var(--border); padding-left: 14px; }
.tt-card-header {
  color: var(--muted); font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.1em; margin-bottom: 4px;
}
.tt-zone-row { font-size: 0.82rem; margin-top: 4px; }
.tt-zone-row.tt-warn { color: var(--ember); }
.tt-diff { margin-top: 8px; padding-top: 6px; border-top: 1px dotted var(--border); }
.diff-row { display: flex; justify-content: space-between; font-size: 0.82rem; padding: 1px 0; }
.diff-up { color: #6fce7e; }
.diff-down { color: #e07a63; }

/* Breakdown stat */
/* ---- Riquadro oggetto ---- */
#item-modal { display: none; }
#item-modal.open { display: block; position: fixed; inset: 0; z-index: 90; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(24rem, calc(100vw - 2rem)); max-height: 85vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 1.1rem; box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
.modal-close {
  position: absolute; top: 0.5rem; right: 0.5rem;
  width: 2rem; height: 2rem; border-radius: 50%;
  background: transparent; color: var(--muted);
}
.modal-close:hover { color: var(--blood); border-color: var(--blood); }
.modal-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.9rem; }
.modal-actions button {
  min-height: 2.75rem; font-size: 0.92rem; width: 100%;
}
.modal-actions .primary { background: var(--ember); color: #1a1408; border-color: var(--ember); font-weight: 700; }
button.danger { background: transparent; color: var(--blood); border-color: var(--blood); }
button.danger:hover { background: var(--blood); color: var(--ink); }
.modal-confirm { margin-top: 0.9rem; font-size: 0.9rem; color: var(--blood); }

.stat-breakdown { color: var(--muted); font-size: 0.8rem; }
.stat-gear { color: #9fc48a; }

button {
  font-family: inherit; font-size: 0.82rem; font-weight: 500;
  background: var(--border); color: var(--ink);
  border: 1px solid #4a5540; border-radius: 4px;
  padding: 4px 12px; cursor: pointer;
}
button:hover { background: #46523a; }
button:focus-visible { outline: 2px solid var(--ember); outline-offset: 1px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--blood); border-color: var(--blood); }

.slot-label {
  display: block; font-size: 0.68rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 4px;
}
.empty-note { color: var(--muted); font-size: 0.88rem; }
.bulk-bar { display: flex; gap: 6px; margin-bottom: 10px; align-items: center; }
.bulk-bar select {
  font-family: inherit; font-size: 0.82rem;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px;
}

/* ---- Stats & log ---- */
.stat-row {
  display: flex; justify-content: space-between;
  padding: 4px 0; border-bottom: 1px dotted var(--border); font-size: 0.9rem;
}
#log {
  --log-rows: 5;
  --log-row-h: 1.5625rem;
  height: calc(var(--log-rows) * var(--log-row-h));
  overflow-y: auto; font-size: 0.85rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.log-entry {
  height: var(--log-row-h); line-height: var(--log-row-h);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px dotted var(--border); color: var(--muted);
}
.log-entry:first-child { color: var(--ink); }

/* ---- Options ---- */
.option-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 0.9rem;
}
.option-row input[type="checkbox"] { width: 1.2rem; height: 1.2rem; accent-color: var(--ember); cursor: pointer; }
.auto-embark-toggle {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.78rem; color: var(--muted); cursor: pointer; user-select: none;
  margin-left: 0.5rem;
}
.auto-embark-toggle input { width: 1rem; height: 1rem; accent-color: var(--ember); cursor: pointer; }
.auto-embark-toggle:hover { color: var(--ink); }
.save-io { display: flex; gap: 0.5rem; }
.save-io button { flex: 1; }
.option-row select {
  font-family: inherit; font-size: 0.85rem;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px;
}

.col { display: flex; flex-direction: column; gap: 14px; }
