/* ==========================================================================
   MOBILE LAYOUT (wird als letztes Stylesheet geladen → überschreibt alles)
   ========================================================================== */

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

*, *::before, *::after {
  box-sizing: border-box;
}

button, a, input {
  touch-action: manipulation;
}

@media (max-width: 640px) {

  /* ---------- Kopfzeile ---------- */
  .app-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .brand { gap: 8px; min-width: 0; }
  .brand-icon { font-size: 22px; }
  .brand-title { font-size: 15px; letter-spacing: 1px; white-space: nowrap; }
  .brand-badge { display: none; }

  .header-controls {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px;
    overflow: visible;
    padding: 0;
  }

  .header-controls > .nav-btn,
  .header-controls > .btn-bonus {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 6px;
    font-size: 12px;
    white-space: nowrap;
    text-align: center;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  #btn-sound { flex: 0 0 40px; }

  /* Benutzerbereich: eigene volle Zeile */
  .header-controls > .user-box {
    flex: 1 1 100%;
    display: flex;
    justify-content: space-between;
    gap: 6px;
  }
  .header-controls > .user-box[style*="none"] { display: none !important; }
  .user-box .user-pill {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    padding: 6px 10px;
  }
  .user-box .nav-btn { flex: 0 0 auto; padding: 6px 10px; font-size: 12px; }
  #btn-open-auth { width: 100%; padding: 10px; font-size: 14px; }

  /* ---------- Hauptbereich ---------- */
  .main-wrapper { padding: 6px 8px; }
  .slot-machine-wrapper { gap: 8px; max-width: 100%; }

  .slot-chassis {
    padding: 8px 6px 10px;
    border-radius: 16px;
    max-width: 100%;
  }

  #reels-container { gap: 3px; padding: 4px; }
  .slot-reel { height: calc(3 * min((100vw - 60px) / 5, 90px)); }
  .slot-symbol {
    height: min((100vw - 60px) / 5, 90px);
    padding: 3px;
  }

  /* ---------- Anzeigen (Guthaben / Einsatz / Gewinn) ---------- */
  .slot-hud {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
    margin-top: 8px;
  }
  .meter-card {
    min-width: 0;
    padding: 6px 4px;
    border-radius: 10px;
  }
  .meter-label {
    font-size: 9px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .meter-value {
    font-size: clamp(12px, 3.9vw, 18px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0;
  }

  /* ---------- Bedienleiste: [Turbo/Auto] [DREHEN] [− + / MAX] ---------- */
  .slot-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    margin-top: 10px;
  }
  .slot-controls > .control-group:first-child { order: 1; }
  .slot-controls > .spin-button-wrap { order: 2; }
  .slot-controls > .control-group:nth-child(2) { order: 3; }

  .slot-controls .control-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    min-width: 0;
  }
  .slot-controls > .control-group:first-child { grid-template-columns: 1fr; }
  #btn-max-bet { grid-column: 1 / -1; }

  .control-btn {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 6px 4px;
    font-size: 13px;
    white-space: nowrap;
  }

  .btn-spin-main {
    width: 84px;
    height: 84px;
    font-size: 13px;
    letter-spacing: 1px;
  }

  /* ---------- Fußzeile ---------- */
  .app-footer {
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    font-size: 10px;
    text-align: center;
  }

  /* ---------- Dialoge ---------- */
  dialog {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 16px 12px;
  }
  .admin-users-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-stats-grid { grid-template-columns: 1fr 1fr !important; }
  .pin-input { font-size: 22px; }
}

/* Sehr kleine Geräte (iPhone SE 1. Gen, 320px) */
@media (max-width: 360px) {
  .brand-title { font-size: 13px; }
  .header-controls > .nav-btn,
  .header-controls > .btn-bonus { font-size: 11px; padding: 7px 4px; }
  .btn-spin-main { width: 72px; height: 72px; font-size: 11px; }
  .control-btn { font-size: 12px; min-height: 36px; }
  .meter-label { font-size: 8px; }
}

/* Admin-Benutzerliste als Karten auf dem Handy */
@media (max-width: 640px) {
  .admin-actions-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .admin-search-input { width: 100%; }
  .admin-users-table-wrap { overflow-x: visible; max-height: none; }
  .admin-users-table-wrap table,
  .admin-users-table-wrap tbody,
  .admin-users-table-wrap tr,
  .admin-users-table-wrap td { display: block; width: 100%; }
  .admin-users-table-wrap thead { display: none; }
  .admin-users-table-wrap tr {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 6px 10px;
    padding: 10px;
    margin-bottom: 8px;
    border: 1px solid rgba(0, 240, 255, 0.2);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.35);
  }
  .admin-users-table-wrap td { padding: 0 !important; border: none !important; width: auto; }
  .admin-users-table-wrap td:nth-child(5),
  .admin-users-table-wrap td:nth-child(6) { grid-column: 1 / -1; }
  .admin-balance-controls { width: 100%; display: flex; flex-direction: column; gap: 6px; }
  .admin-ctrl-group { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 5px; width: 100%; }
  .admin-ctrl-group:last-child { grid-template-columns: 1fr 1fr; }
  .btn-quick-add, .btn-quick-deduct, .btn-quick-reset, .btn-quick-custom, .btn-admin-fs { 
    width: 100%; 
    padding: 8px 4px; 
    font-size: 11px; 
    text-align: center;
    white-space: nowrap; 
  }
}

/* Kompakte Tab-Leiste im Kopfbereich (Symbol + kleine Beschriftung) */
.header-controls .ico { line-height: 1; }
.header-controls .lbl { margin-left: 6px; }
@media (max-width: 640px) {
  .header-controls {
    display: grid;
    grid-template-columns: 0.8fr repeat(3, 1fr);
    gap: 6px;
  }
  .header-controls > .nav-btn,
  .header-controls > .btn-bonus {
    flex-direction: column;
    gap: 2px;
    padding: 6px 3px;
    min-height: 44px;
  }
  #btn-sound { flex: none; }
  .header-controls .ico { font-size: 16px; }
  .header-controls .lbl { margin-left: 0; font-size: 11px; letter-spacing: 0.2px; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .header-controls > .user-box { grid-column: 1 / -1; }
}
