:root {
  color-scheme: dark;
  --bg: #171717;
  --panel: #222;
  --border: #444;
  --text: #eee;
  --muted: #aaa;
  --accent: #d93c50;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg) url("../sfondo.jpg") center top / cover fixed no-repeat;
  color: var(--text);
  font: 16px/1.4 system-ui, sans-serif;
}

main {
  position: relative;
  width: min(900px, calc(100% - 32px));
  min-height: 100dvh;
  height: auto;
  margin: 0 auto;
  padding: 16px 0 18px;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

header {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.05;
}

header p {
  margin: 0;
  color: var(--muted);
}

a {
  color: #ddd;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  align-items: end;
  margin: 14px 0 10px;
}

.stat {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  height: 44px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.stat span {
  display: inline;
  color: var(--muted);
  font-size: .8rem;
}

.stat span::after {
  content: ":";
}

.stat strong {
  display: inline;
  font-size: 1.45rem;
}

.health-bar {
  position: relative;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: #351616;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgb(0 0 0 / .7);
  isolation: isolate;
}

.health-bar::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--health-percent, 100%);
  background: var(--health-color, #b52b2b);
  z-index: -1;
  transition: width .2s ease, background-color .25s ease;
}

.health-bar.health-dead {
  background: #241010;
}

.health-bar.health-dead::before {
  background: #7f1d1d;
}

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #333;
  color: var(--text);
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #444;
}

button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.message {
  min-height: 42px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #ddd;
  text-align: center;
}

.score-message {
  margin-top: 10px;
  font-size: 1.15rem;
  font-weight: 700;
}

h2 {
  font-size: .9rem;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  margin: 10px 0 7px;
}

.turn {
  float: right;
  font-size: .75rem;
  font-weight: normal;
}

/* Modifiche Architetturali: Stanza e Carte */
.room {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex: 1; 
  min-height: 0; 
  width: 100%;
}

.card {
  padding: 0;
  background: transparent;
  border: 0;
  display: block;
  overflow: hidden;
  aspect-ratio: 243 / 400;
  height: 100%;
  max-height: 40vh;
  max-width: 23%;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 7px;
  box-shadow: 0 3px 10px rgb(0 0 0 / .35);
  user-select: none;
}

.card:hover:not(:disabled) img,
.card:focus-visible img {
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgb(0 0 0 / .45);
}

.card:disabled {
  opacity: .72;
}

.card-monster,
.card-weapon,
.card-potion {
  border: 0;
}

.card-compact {
  width: 74px;
  height: auto;
  max-height: none;
  aspect-ratio: auto;
}

.card-compact img {
  border-radius: 5px;
}

.card-compact:hover img,
.card-compact:focus-visible img {
  transform: none;
}

.lower {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
  min-height: 0;
  height: 196px;
  flex: 0 0 196px;
}

.lower h2 {
  margin-top: 0;
}

.pile {
  height: 196px;
  min-height: 196px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.empty {
  color: #666;
}

/* Modifiche Architetturali: Modale Nativo (<dialog>) */
dialog.modal {
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  margin: auto;
  max-width: 100%;
}

dialog.modal::backdrop {
  background: rgb(0 0 0 / .72);
}

.modal-box {
  width: min(420px, 100vw - 32px);
  background: #222;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.8);
}

.modal-box button {
  width: 100%;
  margin-top: 8px;
}

.secondary {
  background: transparent;
}

.modal-card-image {
  width: min(180px, 60vw);
  max-height: 280px;
  object-fit: contain;
  display: block;
  margin: 0 auto 14px;
  border-radius: 7px;
  box-shadow: 0 3px 10px rgb(0 0 0 / .4);
}

/* Modifiche Architetturali: Tooltip */
.card-info {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 32px));
  height: auto;
  margin: 0;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(43, 43, 43, 0.95);
  backdrop-filter: blur(4px);
  text-align: center;
  box-shadow: 0 4px 14px rgb(0 0 0 / .35);
  border: 1px solid var(--border);
}

.card-info[hidden] {
  visibility: hidden;
  display: none;
}

.card-info h3 {
  margin: 0;
  font-size: 1.25rem;
}

.card-info p {
  margin: 4px 0;
}

.card-info p:first-of-type {
  color: var(--muted);
}

.card-info p:last-of-type {
  margin-top: 12px;
  color: #ddd;
}

.kukis {
  text-align: center;
  font-size: 0.75rem;
  opacity: 0.45;
  margin: 40px 0 12px;
}

/* Regole */
.rules {
  max-width: 900px;
}

.rules h2 {
  margin-top: 24px;
  margin-bottom: 9px;
}

.rules ul {
  margin-top: 6px;
  padding-left: 24px;
}

.rules li {
  margin: 5px 0;
}

.rules-examples {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.rules-example {
  display: grid;
  grid-template-columns: 245px 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  background: rgb(34 34 34 / .84);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.example-cards {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 100px;
}

.example-cards img {
  width: 61px;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgb(0 0 0 / .35);
}

.example-symbol {
  font-size: 1.25rem;
  color: var(--muted);
  font-weight: 600;
}

.rules-example strong {
  color: #f0f0f0;
}

.rules-example p {
  margin: 5px 0 0;
  color: #ddd;
}

.rules-source {
  margin-top: 26px;
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
}

.rules-source em {
  font-style: italic;
}

/* Media Queries per Mobile */
@media (max-width: 650px) {
  main {
    width: min(100% - 20px, 900px);
    padding-top: 10px;
  }
  
  .topbar {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  
  .controls {
    grid-column: 1 / -1;
  }
  
  /* Layout a griglia 2x2 su mobile gestito in Flexbox */
  .room {
    flex-wrap: wrap;
    align-content: center;
  }
  
  .card {
    max-width: 47%;
    max-height: 28vh;
  }
  
  .lower {
    grid-template-columns: 1fr;
    gap: 8px;
    height: 160px;
    flex-basis: 160px;
  }
  
  .pile {
    height: 160px;
    min-height: 160px;
  }
  
  .card-info {
    min-height: 96px;
    height: auto;
  }

  .rules-example {
    grid-template-columns: 1fr;
    gap: 9px;
  }
  
  .example-cards {
    min-height: 100px;
  }
  
  .rules-example p {
    margin-top: 5px;
  }
}
