/*
======================================================
TRIPLE STAR
Responsive Layout - Mobile ottimizzato
Il desktop continua a usare css/game.css
======================================================
*/

/* ======================================================
   DESKTOP
====================================================== */

@media (min-width: 701px) {
  /* Nessuna modifica al layout desktop. */
}

/* ======================================================
   MOBILE VERTICALE
====================================================== */

@media (max-width: 700px) {

  html,
  body {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 100%;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    background: #02050b;
  }

  /*
   * Su mobile trasformiamo la macchina in una colonna.
   * display: contents permette di spostare i pannelli
   * della dashboard sopra e sotto il tavolo senza HTML nuovo.
   */
  .machine {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    border-width: 2px;
    overflow: visible;
  }

  .dashboard {
    display: contents;
  }

  .toolbar {
    order: 1;
  }

  .stats-panel {
    order: 2;
  }

  .table {
    order: 3;
  }

  .controls {
    order: 4;
  }

  .brand-panel {
    order: 5;
  }

  .pay-panel {
    order: 6;
  }

  .message {
    order: 7;
  }

  /* ====================================================
     BARRA SUPERIORE
  ==================================================== */

  .toolbar {
    min-height: 0;
    padding: 8px;
    gap: 7px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "player actions"
      "modes modes";
  }

  .player {
    grid-area: player;
    min-width: 0;
    font-size: 13px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .toolbar-actions {
    grid-area: actions;
    display: flex;
    gap: 5px;
  }

  .toolbar-actions .small-btn {
    min-height: 38px;
    padding: 5px 9px;
    border-radius: 9px;
    font-size: 12px;
  }

  .mode-switch {
    grid-area: modes;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
  }

  .mode {
    width: 100%;
    min-height: 46px;
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 18px;
  }

  /* ====================================================
     CREDITI, PUNTI E BET
  ==================================================== */

  .stats-panel {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 72px 34px;
    gap: 6px;
    padding: 7px;
  }

  .stat {
    min-width: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 25px minmax(0, 1fr);
    border-width: 2px;
    border-radius: 12px;
    overflow: hidden;
  }

  .stat label {
    min-width: 0;
    padding: 3px 1px 1px;
    font-size: 12px;
    line-height: 1;
  }

  .stat output {
    width: calc(100% - 8px);
    height: calc(100% - 6px);
    margin: 1px 4px 4px;
    border-radius: 7px;
    font-size: 24px;
  }

  .stars-strip {
    grid-column: 1 / -1;
    min-height: 34px;
    margin: 0;
    font-size: 24px;
    letter-spacing: 5px;
  }

  /* ====================================================
     TAVOLO MOBILE
  ==================================================== */

  .table {
    width: auto;
    min-height: 330px;
    margin: 6px 4px 4px;
    border-width: 2px;
    border-radius: 17px;
    overflow: hidden;
  }

  .table::before {
    inset: 4px;
    border-radius: 12px;
  }

  .items,
  .items.cards,
  .items.balls {
    width: 100%;
    height: 330px;
    min-height: 330px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    justify-items: center;
    gap: 7px;
    padding: 12px 8px 7px;
    overflow: hidden;
  }

  .item.card,
  .item.ball,
  .item.ball.joker-ball,
  .items.cards .item.card,
  .items.balls .item.ball,
  .items.balls .item.ball.joker-ball {
    width: 100%;
    height: 100%;
    min-width: 0;
    max-width: none;
    max-height: none;
    display: grid;
    grid-template-rows: minmax(0, 1fr) 36px;
    align-items: center;
    justify-items: center;
    overflow: hidden;
    transform: none;
  }

  /*
   * Le carte non superano la loro colonna.
   * In questo modo non risultano più attaccate.
   */
  .item.card img,
  .items.cards .item.card img {
    grid-row: 1;
    width: 86%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    justify-self: center;
  }

  /*
   * Le biglie usano meno larghezza della cella.
   * È il punto fondamentale per evitare sovrapposizioni.
   */
  .item.ball img,
  .item.ball.joker-ball img,
  .items.balls .item.ball img,
  .items.balls .item.ball.joker-ball img {
    grid-row: 1;
    width: 72%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    justify-self: center;
  }

  .item span,
  .item.ball span,
  .item.ball.joker-ball span {
    grid-row: 2;
    position: static !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    width: 100%;
    min-width: 0;
    min-height: 29px;
    margin: 2px 0 0;
    padding: 3px 1px;
    border-width: 1px;
    border-radius: 7px;
    font-size: clamp(8px, 2.3vw, 10px);
    line-height: 20px;
    text-align: center;
    white-space: nowrap;
  }

  .item.held,
  .item.ball.held,
  .item.ball.joker-ball.held {
    transform: none;
  }

  .item.card.held::after {
    inset: 0 0 36px;
    border-width: 2px;
    border-radius: 8px;
  }

  /* ====================================================
     PULSANTI DI GIOCO
  ==================================================== */

  .controls {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas:
      "minus minus start start plus plus"
      "repeat repeat repeat double double double";
    gap: 7px;
    padding: 7px;
  }

  #betMinus {
    grid-area: minus;
  }

  #startBtn {
    grid-area: start;
  }

  #betPlus {
    grid-area: plus;
  }

  #repeatBtn {
    grid-area: repeat;
  }

  #doubleBtn {
    grid-area: double;
  }

  .control {
    width: 100%;
    height: 51px;
    min-height: 51px;
    padding: 4px 2px;
    border-width: 2px;
    border-radius: 11px;
    font-size: 14px;
  }

  /* ====================================================
     TRIPLE STAR SOTTO IL TAVOLO
  ==================================================== */

  .brand-panel {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 122px;
    grid-template-rows: auto auto;
    gap: 5px 7px;
    padding: 7px 9px;
    overflow: hidden;
  }

  .brand {
    grid-column: 1 / -1;
    margin: 0;
    font-size: clamp(28px, 9vw, 40px);
    line-height: .95;
  }

  .multiplier-lines {
    width: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: 1fr;
    gap: 2px;
    padding: 5px;
    font-size: clamp(15px, 4.5vw, 20px);
  }

  .multiplier-lines div {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    line-height: 1;
  }

  .multiplier-lines span,
  .multiplier-lines strong {
    text-align: center;
    white-space: nowrap;
  }

  .active-multiplier {
    width: 100%;
    min-height: 45px;
    margin: 0;
    padding: 4px;
  }

  .active-multiplier small {
    font-size: 9px;
    line-height: 1;
  }

  .active-multiplier strong {
    font-size: 23px;
    line-height: 1;
  }

  /* ====================================================
     TABELLA PREMI SOTTO IL TAVOLO
  ==================================================== */

  .pay-panel {
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto auto;
    padding: 7px 9px;
  }

  .pay-panel h1 {
    margin: 0;
    padding: 3px 0 6px;
    font-size: 21px;
    line-height: 1;
  }

  .paytable {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(5, 32px);
    gap: 0 10px;
    min-height: 0;
    padding: 2px 0;
  }

  .paytable > div {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 4ch;
    align-items: center;
    gap: 3px;
    padding: 0 3px;
    border-bottom: 1px solid #566170;
    font-size: 10px;
    line-height: 1;
  }

  .paytable span {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: clip;
  }

  .paytable b {
    font-size: 11px;
    text-align: right;
  }

  .pay-panel p {
    margin: 5px 0 1px;
    font-size: 9px;
    line-height: 1.1;
  }

  .message {
    min-height: 36px;
    padding: 6px 4px;
    font-size: 10px;
    line-height: 1.15;
    letter-spacing: .6px;
  }
}

/* ======================================================
   TELEFONI PICCOLI
====================================================== */

@media (max-width: 430px) {

  .toolbar-actions .small-btn {
    padding-inline: 7px;
    font-size: 11px;
  }

  .mode {
    font-size: 16px;
  }

  .stats-panel {
    grid-template-rows: 68px 31px;
    gap: 5px;
    padding: 6px;
  }

  .stat {
    grid-template-rows: 23px minmax(0, 1fr);
  }

  .stat label {
    font-size: 11px;
  }

  .stat output {
    font-size: 22px;
  }

  .stars-strip {
    font-size: 22px;
    letter-spacing: 4px;
  }

  .table {
    min-height: 310px;
  }

  .items,
  .items.cards,
  .items.balls {
    height: 310px;
    min-height: 310px;
    gap: 5px;
    padding-inline: 6px;
  }

  .item.card img,
  .items.cards .item.card img {
    width: 83%;
  }

  .item.ball img,
  .item.ball.joker-ball img,
  .items.balls .item.ball img,
  .items.balls .item.ball.joker-ball img {
    width: 68%;
  }

  .control {
    height: 49px;
    min-height: 49px;
    font-size: 13px;
  }

  .brand-panel {
    grid-template-columns: minmax(0, 1fr) 108px;
  }

  .paytable {
    grid-template-rows: repeat(5, 30px);
    gap: 0 6px;
  }

  .paytable > div {
    padding-inline: 2px;
    font-size: 9px;
  }

  .paytable b {
    font-size: 10px;
  }
}

/* ======================================================
   MOBILE ORIZZONTALE
====================================================== */

@media (max-height: 520px) and (orientation: landscape) {

  html,
  body {
    overflow: auto;
  }

  .machine {
    height: auto;
    min-height: 100dvh;
  }

  .stats-panel {
    grid-template-rows: 65px 28px;
  }

  .table {
    min-height: 280px;
  }

  .items,
  .items.cards,
  .items.balls {
    height: 280px;
    min-height: 280px;
  }

  .item.card img,
  .items.cards .item.card img {
    width: 72%;
  }

  .item.ball img,
  .item.ball.joker-ball img,
  .items.balls .item.ball img,
  .items.balls .item.ball.joker-ball img {
    width: 58%;
  }

  .controls {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-areas: "minus start repeat double plus";
  }

  .control {
    height: 47px;
    min-height: 47px;
    font-size: 13px;
  }
}
