/* =========================================================================
   RETROVIA — Mobile styles (shared by both themes)
   Estratto dal nuovo style.css, da usare con entrambi i temi
   ========================================================================= */

@media (max-width: 700px), (max-height: 520px) {
  html, body { height: 100%; overflow: hidden; }
  body { font-size: 14px; }
  .app { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

  .hud {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: calc(100% - 20px); max-width: 560px;
    margin: 8px auto 0; margin-top: max(8px, env(safe-area-inset-top));
    padding: 6px 10px;
    border-radius: var(--r);
  }
  .hud__brand { display: none; }
  .hud__center { flex: 0 1 auto; justify-content: center; gap: 8px; }
  .hud__turn { font-size: 13.5px; padding: 2px 8px; gap: 6px; white-space: normal; text-align: center; line-height: 1.2; }
  .hud__turn .turn-direction { font-size: 10.5px; }
  .hud__center .btn, .hud__actions .btn { display: none; }
  .hud__actions { gap: 0; }
  .hud .action-pips { border: 0; padding: 2px 4px; margin: 0; gap: 4px; }
  .hud::after { display: none; }
  .thinking { font-size: 11px; padding: 2px 8px 2px 6px; }

  .layout {
    display: flex; flex-direction: column;
    gap: 6px; padding: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom));
    min-height: 0;
  }
  .panel--other { order: 1; }
  .board-section { order: 2; flex: 1; min-height: 0; }
  .panel--dock { order: 3; }

  /* Schermo intero mobile: la lavagna occupa tutto, i giocatori diventano
     strisce sotto (o sotto/sopra). */
  .app.is-fullscreen .layout {
    display: flex; flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    min-height: 0;
  }
  .app.is-fullscreen .panel--other { order: 2; }
  .app.is-fullscreen .board-section { order: 1; flex: 1; min-height: 0; }
  .app.is-fullscreen .panel--dock { order: 3; }
  .app.is-fullscreen .panel--other,
  .app.is-fullscreen .panel--dock { grid-column: auto; grid-row: auto; }
  .app.is-fullscreen #panelA,
  .app.is-fullscreen #panelB { display: flex; }
  .app.is-fullscreen .panel { padding: 6px 10px; }
  .app.is-fullscreen .board-toolbar { gap: 4px; padding: 5px 7px; }
  .app.is-fullscreen .toolbar-row { flex-wrap: wrap; width: 100%; margin: 0; gap: 4px 8px; }
  .app.is-fullscreen .board-toolbar__fs-actions { width: 100%; justify-content: space-between; gap: 4px; margin: 4px 0 0; }
  .app.is-fullscreen .board-toolbar__fs-actions .btn { flex: 1; padding-left: 4px; padding-right: 4px; }
  .app.is-fullscreen .toolbar-row--fs { width: 100%; justify-content: center; margin: 0; }
  .app.is-fullscreen .board-toolbar__fs-center { justify-content: center; gap: 6px; }

  .board-toolbar__more { display: flex; }

  /* Strisce giocatori */
  .panel {
    flex: none; overflow: visible;
    padding: 6px 10px;
    border-radius: var(--r);
    display: flex; flex-wrap: wrap; flex-direction: row; align-items: center; gap: 4px 10px;
  }
  .panel::before { display: none; }
  .panel__player { font-size: 16px; margin: 0; gap: 7px; flex: 1 1 auto; flex-wrap: nowrap; }
  .panel__player .swatch { flex-basis: 10px; width: 10px; height: 10px; }
  .panel__direction, .panel__section-title, .active-section, .captured-section, .panel__stat { display: none; }

  .panel--dock .panel__stat { display: none; }

  .panel--other .panel__player { font-size: 14px; flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; gap: 6px; }
  .panel--other .panel__identity { font-size: 8px; padding: 1px 5px; letter-spacing: 0.06em; margin-left: 4px; }
  .panel--other .tile-counter { gap: 3px; }
  .panel--other .tile-counter__value { font-size: 13px; }
  .panel--other .tile-counter__bar { display: none; }
  .panel--other .reserve-list { flex: 0 0 auto; margin: 0; gap: 2px; }
  .panel--other .reserve-list li { flex: none; }
  .panel--other .reserve-item {
    padding: 4px 5px; gap: 4px;
    box-shadow: 0 1px 0 rgba(43,43,24,0.8), inset 0 1px 0 rgba(218,226,208,0.3);
  }
  .panel--other .reserve-item:disabled { opacity: 0.9; }
  .panel--other .reserve-item .piece-token--sm { width: 24px; height: 24px; }
  .panel--other .reserve-item__count { min-width: 15px; height: 15px; padding: 0 3px; font-size: 9px; line-height: 14px; }
  .panel--other .reserve-item__label { display: none; }
  .panel--other .reserve-list li { margin-right: 4px; }
  .panel--other .reserve-list li:last-child { margin-right: 0; }
  .panel--other .panel__clock { font-size: 13px; }

  .board-toolbar { padding: 5px 7px; gap: 4px; border-radius: var(--r); }
  .board-toolbar .btn--tool { font-size: 11px; padding: 5px 8px; gap: 5px; }
  .board-toolbar .btn--tool .btn__icon { width: 13px; height: 13px; }
  .board-toolbar__fs-turn { font-size: 13px; padding: 2px 7px; }
  .board-toolbar .btn--icon { width: 26px; height: 26px; }

  .board-viewport {
    min-height: 0;
    border-width: 5px;
    border-radius: var(--r);
    flex: 1 1 auto;
  }

  .move-report {
    right: 8px; bottom: 8px;
    width: min(300px, 78%);
    font-size: 12px;
  }
  .callout {
    left: 8px; bottom: 8px;
    top: auto;
    width: min(340px, 90vw);
    max-width: 90vw;
    height: auto;
    min-height: 0;
    max-height: none;
    display: flex;
    flex-direction: column;
    padding: 36px 22px 18px;
    gap: 0;
    background: linear-gradient(180deg, var(--sand-1), var(--sand-3));
    border: 1px solid var(--sand-5);
    border-radius: calc(var(--r) + 2px);
    box-shadow:
      0 3px 0 rgba(0,0,0,0.35),
      0 10px 24px rgba(0,0,0,0.5),
      inset 0 1px 0 rgba(218,226,208,0.4),
      inset 0 -1px 0 rgba(43,43,24,0.2);
    animation: callout-in 200ms cubic-bezier(.2,.8,.2,1);
  }

  /* riga in alto: icona + titolo, centrati verticalmente tra loro */
  .callout__header {
    display: flex;
    align-items: center;
    gap: 11px;
    padding-right: 28px;
  }
  .callout__spectre { flex: 0 0 42px; width: 42px; height: 42px; }
  .callout__title {
    margin: 0;
    font-size: 15px;
    line-height: 1.2;
    text-align: left;
    letter-spacing: 0.01em;
  }

  /* X nell'angolo in alto a destra, più in alto della riga del titolo */
  .callout__close {
    position: absolute;
    top: 10px; right: 8px;
    width: 24px; height: 24px;
    font-size: 14px;
  }

  /* testo centrato sotto, poi bottone centrato */
  .callout__body {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
  }
  .callout__text {
    margin: 0;
    max-width: 250px;
    font-size: 11.5px;
    line-height: 1.4;
    text-align: center;
  }
  .callout__btn {
    display: block;
    width: 160px;
    height: 36px;
    margin: 0;
  }
  .callout__btn.is-hidden { display: none; }

  #actionCallout {
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    max-width: calc(100vw - 32px);
    padding: 20px 18px 16px;
  }
  #actionCallout .callout__header { gap: 10px; }
  #actionCallout .callout__spectre {
    flex-basis: 38px;
    width: 38px; height: 38px;
  }
  #actionCallout .callout__spectre .piece-token--sm {
    width: 38px; height: 38px;
  }
  #actionCallout .callout__title { font-size: 16px; }
  #actionCallout .callout__body { margin: 12px 0 0; }
  #actionCallout .callout__text { font-size: 13px; line-height: 1.4; text-align: center; }
  #actionCallout .callout__body > .btn {
    height: 32px;
    margin: 12px 0 0;
    padding: 0 16px;
    font-size: 13px;
  }
}

@media (max-width: 700px), (max-height: 520px) {
  .hud {
    width: calc(100% - 12px);
    max-width: none;
  }

  .layout {
    gap: 6px;
    padding: 6px;
  }

  .panel--other {
    order: 1;
  }

  .board-section {
    order: 2;
    display: flex;
    gap: 4px;
  }

  .panel--other,
  .panel--dock {
    display: grid;
    grid-template-columns: max-content max-content minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 8px;
    row-gap: 3px;
    padding: 5px 10px;
  }

  .panel--other,
  .panel--dock {
    order: 1;
  }

  .panel--dock {
    order: 3;
  }

  .panel--other .panel__player,
  .panel--dock .panel__player {
    grid-column: 1;
    grid-row: 1;
    flex: none;
    min-width: 0;
    margin: 0;
    font-size: 14px;
    gap: 6px;
  }

  .panel--other .panel__identity,
  .panel--dock .panel__identity {
    font-size: 8px;
    padding: 1px 5px;
    letter-spacing: 0.06em;
    margin-left: 4px;
  }

  .panel--dock:has(.panel__clock) .panel__identity {
    display: none;
  }

  .panel--dock .panel__clock {
    font-size: 12px;
    padding: 2px 4px;
  }

  .panel--other .tile-counter,
  .panel--dock .tile-counter {
    grid-column: 2;
    grid-row: 1;
    flex: none;
    gap: 3px;
    padding: 3px 4px;
  }

  .panel--other .tile-counter__value,
  .panel--dock .tile-counter__value {
    font-size: 13px;
  }

  .panel--other .tile-counter__bar,
  .panel--dock .tile-counter__bar {
    display: none;
  }

  .panel--other .reserve-list,
  .panel--dock .reserve-list {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    flex-flow: row nowrap;
    justify-content: flex-end;
    gap: 2px;
    width: 100%;
    min-width: 0;
    margin: 0;
    overflow: visible;
  }

  .panel--other .reserve-list li,
  .panel--dock .reserve-list li {
    flex: 0 0 auto;
    min-width: 0;
  }

  .panel--dock .reserve-list {
    gap: 6px;
  }

  .panel--other .captured-section,
  .panel--dock .captured-section {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 22px;
    gap: 10px;
    margin: 2px 0 0;
    padding: 4px 0 0;
    border-top: 1px solid rgba(43,43,24,0.45);
    color: var(--sand-6);
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
  }

  .panel--other .captured-section::before,
  .panel--dock .captured-section::before {
    content: 'Catturati';
    flex: 0 0 auto;
  }

  .panel--other .captured-list,
  .panel--dock .captured-list {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: 2px;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  .panel--other .captured-item,
  .panel--dock .captured-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    gap: 2px;
  }

  .panel--other .captured-item .piece-token--sm,
  .panel--dock .captured-item .piece-token--sm {
    width: 18px;
    height: 18px;
  }

  .panel--other .captured-item__count,
  .panel--dock .captured-item__count {
    position: static;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    font-size: 9px;
    line-height: 13px;
  }

  .panel--other .captured-section .panel__stat--empty,
  .panel--dock .captured-section .panel__stat--empty {
    display: none;
  }

  .panel--other .panel__direction,
  .panel--other .panel__section-title,
  .panel--other .active-section,
  .panel--other .panel__stat,
  .panel--other .reserve-item__label,
  .panel--dock .panel__direction,
  .panel--dock .panel__section-title,
  .panel--dock .active-section,
  .panel--dock .panel__stat,
  .panel--dock .reserve-item__label {
    display: none;
  }

  .panel--dock .reserve-item {
    width: auto;
    min-width: 42px;
    min-height: 42px;
    justify-content: center;
    gap: 3px;
    padding: 4px 6px;
    background: linear-gradient(180deg, var(--sand-2), var(--sand-4));
    border: 1px solid var(--sand-6);
    box-shadow: 0 1px 0 rgba(43,43,24,0.8), inset 0 1px 0 rgba(218,226,208,0.3);
  }

  .panel--dock .reserve-item:disabled {
    opacity: 0.9;
  }

  .panel--dock .reserve-item .piece-token--sm {
    width: 24px;
    height: 24px;
  }

  .panel--dock .reserve-item__count {
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    font-size: 9px;
    line-height: 14px;
  }

  .board-viewport {
    order: 1;
  }

  .board-hint {
    order: 2;
  }

  .board-toolbar {
    order: 3;
    padding: 5px 6px;
  }

  .toolbar-row--fs-modes {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
  }

  .toolbar-row--fs-modes > .btn--tool,
  .board-toolbar__actions #endTurnBtn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 40px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 2px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }

  .toolbar-row--fs-modes > .btn--tool .btn__icon {
    display: none;
  }

  .toolbar-row--fs-modes .btn__label {
    display: block;
    flex: 0 0 auto;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
  }

  .toolbar-actions {
    display: contents;
  }

  .board-toolbar__actions {
    display: contents;
  }

  .toolbar-row--fs-modes #moveModeBtn,
  .board-toolbar__actions #drawBtn,
  .board-toolbar__actions #abandonBtn,
  .board-zoom-controls,
  .board-floatbar .btn--tool {
    display: none;
  }

  .board-toolbar__more {
    flex: 0 0 40px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    font-size: 24px;
  }

  .board-floatbar {
    top: 8px;
    right: 8px;
    padding: 3px;
  }

  .board-review-controls {
    display: flex;
    gap: 4px;
  }

  .board-review-controls .btn--icon {
    width: 32px;
    height: 32px;
  }

  .board-hint {
    padding: 4px 8px;
    font-size: 11px;
  }

  .board-hint__link {
    display: none;
  }

  #sheetLangBtn {
    width: 100%;
  }
}