/* ==========================================================================
   Base & Variables (Mobile First Layout)
   ========================================================================== */

:root {
  --bg-dark: #0f1219;
  --bg-card: #181d2a;
  --bg-card-hover: #22293b;
  --border-color: #2d3548;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-gold: #f59e0b;
  --accent-gold-hover: #d97706;
  --accent-danger: #ef4444;
  --accent-success: #10b981;
  --accent-blue: #3b82f6;
  --radius: 8px;
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-family);
  line-height: 1.4;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
}

#app-container {
  width: 100%;
  max-width: 600px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-card);
  position: relative;
  overflow: hidden;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}
.screen.active {
  display: flex;
}

#screen-newgame {
  position: relative;
}

.screen-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 72px;
  display: flex;
  flex-direction: column;
}

/* Utility Flex & Text */
.flex-col { display: flex; flex-direction: column; }
.flex-row { display: flex; flex-direction: row; }
.justify-between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.my-2 { margin-top: 8px; margin-bottom: 8px; }
.my-3 { margin-top: 12px; margin-bottom: 12px; }
.mt-auto { margin-top: auto; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.font-bold { font-weight: bold; }

/* Header & Tab Bar */
.game-header {
  position: sticky;
  top: 0;
  z-index: 110;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  min-height: 52px;
  background-color: var(--bg-dark);
  border-bottom: 1px solid var(--border-color);
}
.header-icon-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
}
.header-icon-btn:hover { background: var(--bg-card-hover); }
.resource-badges { display: flex; gap: 5px; min-width: 0; }
.badge {
  background: var(--bg-card);
  min-height: 36px;
  height: 36px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  font-size: 0.82rem;
  border: 1px solid var(--border-color);
}
.header-resource { min-width: 42px; white-space: nowrap; }
.header-link { color: var(--text-main); cursor: pointer; }
.header-link:hover { background: var(--bg-card-hover); }
.save-status { font-size: 0.65rem; color: var(--accent-gold); position: absolute; right: 8px; bottom: -13px; z-index: 2; }
.header-actions { display:flex; gap:5px; align-items:center; }
#btn-install-pwa { display:none; }
#btn-install-pwa.is-visible { display:inline-flex; }
@media (max-width: 390px) {
  .game-header { grid-template-columns: 34px minmax(0, 1fr) auto; padding: 6px; gap: 4px; }
  .header-icon-btn { width: 34px; height: 34px; min-width: 34px; }
  .badge { min-height: 34px; height: 34px; padding: 0 6px; }
  .resource-badges, .header-actions { gap: 4px; }
}

.tab-bar {
  position: sticky;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  background-color: var(--bg-dark);
  border-top: 1px solid var(--border-color);
  height: 56px;
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
}
.tab-btn span { font-size: 1.1rem; }
.tab-btn.active { color: var(--accent-gold); font-weight: bold; }

.tab-panel { display: none; flex-direction: column; width: 100%; }
.tab-panel.active { display: flex; }

/* Cards & UI Components */
.card {
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 12px;
}

.warning-box {
  background-color: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--accent-danger);
  color: #fca5a5;
  padding: 10px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.section-title {
  font-size: 1rem;
  color: var(--accent-gold);
  margin-bottom: 8px;
}

/* Movimento & Mappa */
.tile-here {
  display: flex;
  align-items: center;
  gap: 12px;
}
.tile-icon-big { font-size: 2.2rem; }
.tile-type { font-weight: bold; font-size: 1.1rem; }

.dir-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.dir-btn:nth-child(1) { grid-column: 2; grid-row: 1; }
.dir-btn:nth-child(2) { grid-column: 1; grid-row: 2; }
.dir-btn:nth-child(3) { grid-column: 2; grid-row: 2; }
.dir-btn:nth-child(4) { grid-column: 3; grid-row: 2; }
.dir-control { min-height: 54px; }
.dir-unlock { grid-column: 1; grid-row: 1; }
.dir-camp { grid-column: 3; grid-row: 1; }
.dir-btn {
  background-color: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px;
  border-radius: var(--radius);
  font-weight: bold;
  cursor: pointer;
  text-align: center;
}
.dir-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.dir-btn:not(:disabled):active { border-color: var(--accent-gold); }

/* Mappa Esplorata */
.map-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  background: var(--bg-card);
  padding: 8px;
  border-radius: var(--radius);
}
.map-row { display: flex; gap: 2px; }
.map-cell {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.9rem;
}
.map-cell.current { border-color: var(--accent-gold); box-shadow: 0 0 6px var(--accent-gold); }
.map-cell.unexplored { color: #444; opacity: 0.5; }

/* Hero Cards */
.hero-card {
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hero-head { display: flex; align-items: center; gap: 10px; }
.hero-icon { font-size: 1.8rem; }
.hero-name { font-weight: bold; font-size: 1rem; }
.hero-sub { font-size: 0.8rem; color: var(--text-muted); }

.hp-row { display: flex; align-items: center; gap: 8px; }
.hp-text { font-size: 0.8rem; min-width: 42px; text-align: right; color: var(--text-muted); }
.hp-bar {
  height: 8px;
  background-color: #334155;
  border-radius: 4px;
  overflow: hidden;
}
.hp-fill { height: 100%; background-color: var(--accent-success); transition: width 0.3s; }

.hero-stats {
  display: flex;
  justify-content: space-around;
  font-size: 0.85rem;
  background: var(--bg-card);
  padding: 4px;
  border-radius: 4px;
}

.hero-equip { display: flex; gap: 4px; margin-top: 4px; }
.equip-slot {
  flex: 1;
  background: var(--bg-card-hover);
  border: 1px dashed var(--border-color);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 6px 2px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.equip-slot.filled { border-style: solid; color: var(--text-main); border-color: var(--accent-gold); }

/* Albo d'Oro Items */
.albo-card {
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.albo-rank {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--accent-gold);
  min-width: 28px;
}
.albo-info { flex: 1; }
.albo-fate { font-size: 0.8rem; color: var(--accent-danger); margin-top: 2px; }

/* Buttons */
.btn {
  padding: 10px 14px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border-radius: var(--radius);
  border: none;
  font-weight: bold;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary { background-color: var(--accent-gold); color: #000; }
.btn-primary:hover { background-color: var(--accent-gold-hover); }
.btn-secondary { background-color: var(--bg-card-hover); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-outline { background: none; border: 1px solid var(--border-color); color: var(--text-muted); }
.btn-danger { background-color: var(--accent-danger); color: #fff; }
.btn-sm { padding: 4px 8px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Modals */
.modal {
  display: none;
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.modal.active { display: flex; }
.modal#levelup-modal { z-index: 130; }
#event-close-box { position: sticky; bottom: -16px; margin-bottom: -16px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); background: var(--bg-card); z-index: 3; }
.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px;
}

/* Modali e Liste */
.log-box {
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px;
  font-size: 0.85rem;
  max-height: 380px;
  overflow-y: auto;
}
.log-entry { padding: 4px 0; border-bottom: 1px solid #1e293b; }

/* Diario: il contenuto deve crescere liberamente e lasciare allo scroll
   principale della schermata il compito di mostrare tutte le piste.
   Evitiamo un secondo scroll interno che, su mobile, può troncare le quest
   senza rendere evidente che altro contenuto è disponibile. */
#panel-journal .log-box {
  max-height: none;
  overflow: visible;
}


.toast {
  position: fixed;
  left: 50%;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  max-width: min(92vw, 720px);
  text-align: center;
  transition: transform 0.3s, opacity 0.3s;
}
.toast-technical {
  top: 70px;
  transform: translateX(-50%) translateY(-100px);
  background-color: var(--accent-gold);
  color: #000;
}
.toast-narrative {
  bottom: 70px;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--accent-gold);
  color: #000;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background-color: var(--accent-danger); color: #fff; }

.hidden { display: none !important; }
/* Competenze e reclutamento: contenuti leggibili senza cambiare il layout generale. */
.hero-skills {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}
.hero-active-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.hero-active-skills .btn {
  white-space: normal;
}

/* HP sintetici durante l'esplorazione */
.explore-party-hp {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.explore-hero-hp {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1.4fr auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.explore-hero-name {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.explore-hero-hp .hp-text {
  min-width: 36px;
  font-size: 0.72rem;
}
.explore-hero-hp .hp-bar { width: 100%; }

.skill-info-inline, .item-info-inline {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.skill-info-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-muted);
  border-radius: 50%;
  width: 25px;
  height: 25px;
  padding: 0;
  cursor: pointer;
}
.hero-active-skills { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }


/* ---------- Incarichi ---------- */
.quest-card {
  border: 1px solid var(--border, #334155);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
  background: rgba(255,255,255,.025);
}
.quest-card.quest-ready {
  border-color: #d6b45a;
}
.quest-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.quest-giver { margin-top: 3px; }
.quest-objective { margin-top: 7px; font-size: .92rem; }

.death-modal-card { border-color: var(--accent-danger); }
.death-card { padding:12px; border:1px solid var(--accent-danger); border-radius:var(--radius); background:var(--bg-dark); }
.death-card h3 { margin-bottom:4px; }


.albo-fate.alive, .albo-fate.active { color: var(--accent-success); }
.albo-fate.dead { color: var(--accent-danger); }
.albo-fate.retired { color: #9ca3af; }
.albo-fate.departed { color: #7dd3fc; }
.albo-fate.general { color: #f97316; }
.albo-fate.government { color: #facc15; }
.whats-new-list { margin: 0 0 8px 20px; display:flex; flex-direction:column; gap:10px; }
.whats-new-group { margin-bottom: 8px; }
.whats-new-group summary { cursor:pointer; color: var(--accent-gold); padding: 4px 0; }
.whats-new-group ul { margin: 5px 0 0 18px; display:flex; flex-direction:column; gap:5px; }
.whats-new-version { margin: 3px 0; }
.whats-new-version details { border-left: 2px solid var(--border-color); padding-left: 8px; }
.quest-main { border-color: var(--accent-gold); box-shadow: 0 0 0 1px rgba(245,158,11,.12); }
.quest-choice-option { margin: 8px 0; }
.quest-choice-button { width: 100%; text-align: left; }
.quest-choice-description { margin: 4px 8px 0; padding-left: 8px; border-left: 2px solid var(--border-color); color: var(--text-muted); font-size: .82rem; line-height: 1.35; }


/* Help automatico */
.help-modal-card { max-height: 90vh; overflow-y: auto; position: relative; padding-top: 52px; }
.modal-close-x { position: sticky; top: 0; float: right; z-index: 5; width: 38px; height: 38px; margin: -42px -2px 4px 8px; border: 1px solid var(--border-color); border-radius: 50%; background: var(--bg-card); color: var(--text-main); font-size: 1.15rem; line-height: 1; cursor: pointer; }
.modal-close-x:hover, .modal-close-x:focus-visible { background: var(--bg-card-hover); color: var(--accent-gold); }
.help-content details { border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--bg-dark); margin: 7px 0; padding: 9px 10px; }
.help-content summary { cursor: pointer; font-weight: 600; }
.help-content p { margin: 8px 0 0; line-height: 1.4; }
.help-section { margin-bottom: 14px; }
.help-section > h3 { margin: 10px 0 6px; }
.help-skill-list { display:flex; flex-direction:column; gap:6px; margin-top:8px; }
.help-skill { text-align:left; border:1px solid var(--border-color); background:var(--bg-card-hover); color:var(--text-main); border-radius:6px; padding:7px; cursor:pointer; }
.help-skill span { display:block; font-size:.78rem; color:var(--text-muted); margin-top:3px; }
.help-skill em { display:block; font-size:.68rem; color:var(--accent-gold); margin-top:4px; font-style:normal; text-transform:capitalize; }
.company-name { margin-top:4px; font-weight:600; }
.company-members { margin-top:3px; line-height:1.35; }

.company-roll { padding: .7rem .9rem; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; margin-bottom: .35rem; text-align:center; }
.company-roll strong { display:block; font-size:1.05rem; }

.company-party-banner { padding: .65rem .8rem; margin-bottom: .8rem; border-radius: 12px; border: 1px solid rgba(255,255,255,.12); text-align:center; }

.item-actions { display:flex; gap:5px; align-items:center; flex-shrink:0; }


.newgame-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 10px 12px max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(24,29,42,0), var(--bg-card) 18px);
  z-index: 10;
}
#screen-newgame .screen-content {
  padding-bottom: 112px;
}

/* Chrome del gioco: il contenuto centrale è l'unica zona scrollabile. */
#screen-game > .screen-content {
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 72px;
}
#screen-game > .game-header {
  flex: 0 0 auto;
}
#screen-game > .tab-bar {
  flex: 0 0 56px;
}

/* Schermata di creazione: i comandi restano sempre raggiungibili sul fondo. */
#screen-newgame {
  min-height: 100%;
}
#screen-newgame > .screen-content {
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 118px;
}

@media (max-width: 600px) {
  #screen-game > .tab-bar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(56px + env(safe-area-inset-bottom));
  }
  #screen-game > .screen-content { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  #screen-newgame .newgame-actions {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}

.whats-new-card { max-height: 90vh; }
.whats-new-card .modal-footer { position: sticky; bottom: -16px; margin: 12px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bg-card); border-top: 1px solid var(--border-color); z-index: 2; }

#info-modal .modal-footer { display: flex; flex-wrap: wrap; gap: 10px; }

.journal-section { margin-top: 10px; }
.journal-section summary { cursor: pointer; padding: 7px 0; color: var(--text-main); }
.journal-entry { margin: 6px 0; font-size: .88rem; }

.race-info-inline { background: none; border: 0; padding: 0; margin: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.race-info-inline:hover, .race-info-inline:focus-visible { color: var(--accent-gold); }

.help-actions { margin: 0 0 10px; display: flex; justify-content: flex-end; }

.company-hof-card { align-items: flex-start; }
.company-hof-card .albo-fate { color: var(--text-muted, var(--text-main)); }

.boss-round { margin: 0.85rem 0; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); overflow: hidden; line-height: 1.55; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.boss-round-title { padding: .7rem .9rem; background: var(--bg-soft, rgba(127,127,127,.10)); border-bottom: 1px solid var(--border); font-size: 1.02rem; }
.boss-action { padding: .5rem .9rem; border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent); }
.boss-action strong { font-weight: 800; }
.boss-round .boss-action:last-of-type { border-bottom: 0; }
.boss-party-action { padding-top: .6rem; }
.boss-state-card { margin: .7rem; padding: .75rem .85rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-soft, rgba(127,127,127,.06)); box-shadow: inset 0 1px 0 rgba(255,255,255,.04); }
.boss-status-line.excellent { font-weight: 600; }
.boss-status-line.injured { font-weight: 650; }
.boss-status-line.bleeding span:last-child, .boss-status-line.critical span:last-child { color: #b91c1c; font-weight: 800; }
.boss-status-line.dead span:last-child { color: var(--muted, #777); font-style: italic; }
.boss-state-title { font-weight: 700; margin-bottom: .35rem; padding-bottom: .35rem; border-bottom: 1px solid var(--border); }
.boss-status-line { display: flex; gap: .35rem; align-items: baseline; padding: .18rem 0; }
.boss-status-icon { width: 1.35rem; flex: 0 0 1.35rem; text-align: center; }
.boss-status-line strong { margin: 0; }
.boss-status-line.bleeding span:last-child, .boss-status-line.critical span:last-child { color: #b91c1c; font-weight: 700; }
.boss-status-line.dead { opacity: .78; }
.boss-status-line.dead strong { text-decoration: line-through; }
.boss-death-notice { margin: .45rem .7rem .7rem; padding: .55rem .7rem; border-radius: 8px; background: rgba(127,127,127,.08); font-weight: 600; }
.boss-victory-line { padding: .65rem .9rem .8rem; }


.casino-games { margin-top: 10px; }
.casino-shop { display:flex; flex-direction:column; gap:8px; border-top:1px solid var(--border-color); padding-top:10px; }
/* Le due azioni di combattimento occupano una sola riga quando c'è spazio. */
#event-actions { display:flex; flex-wrap:nowrap; gap:8px; }
#event-actions .btn { flex:1 1 0; min-width:0; }

.first-visit-intro{list-style:none;margin:0;padding:0}.first-visit-intro p{margin:.7rem 0;line-height:1.45}
