/**
 * BeatMaster - Responsive Fixes & Auto-Anpassungen
 *
 * Stellt sicher, dass die App immer optimal auf Mobilgeräten dargestellt wird
 * - Kein horizontales Scrollen
 * - Automatische Font-Anpassungen
 * - Optimierte Button-Größen
 * - Flexible Layouts
 */

/* ============================================
   BASE FIXES - Verhindert horizontales Scrollen
   ============================================ */

* {
  box-sizing: border-box;
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

#app,
#main-content,
.screen-container {
  max-width: 100vw;
  overflow-x: hidden;
}

/* Verhindere zu breite Elemente */
img,
video,
iframe,
canvas {
  max-width: 100%;
  height: auto;
}

/* ============================================
   TEXT & FONT AUTO-ANPASSUNGEN
   ============================================ */

/* Base Font Size - responsive */
html {
  font-size: 16px;
}

@media (max-width: 375px) {
  html {
    font-size: 14px;
  }
}

@media (max-width: 320px) {
  html {
    font-size: 14px; /* Mindestens 14px für gute Lesbarkeit */
  }
}

/* Verhindere zu lange Texte ohne Umbruch */
h1, h2, h3, h4, h5, h6,
p, span, div {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Lange URLs oder Code */
pre, code {
  max-width: 100%;
  overflow-x: auto;
  word-break: break-all;
  white-space: pre-wrap;
}

/* ============================================
   BUTTON AUTO-ANPASSUNGEN
   ============================================ */

/* Buttons sollen sich an Viewport anpassen */
button,
.btn,
a.btn,
input[type="button"],
input[type="submit"] {
  min-height: 48px; /* 48px für optimale Touch-Targets */
  min-width: 48px;
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
}

@media (max-width: 375px) {
  button,
  .btn,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 48px;
    padding: 0.65rem 1.25rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 320px) {
  button,
  .btn,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 48px;
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
  }
}

/* Icon-Buttons und kleine interaktive Elemente */
.btn-icon,
button[aria-label],
.modal-close,
.notification-close {
  min-width: 48px !important;
  min-height: 48px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Clickable Elements */
a[href],
[onclick],
[role="button"] {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* ============================================
   FORM INPUTS AUTO-ANPASSUNGEN
   ============================================ */

input,
select,
textarea {
  max-width: 100%;
  font-size: 16px; /* Verhindert Auto-Zoom auf iOS */
}

@media (max-width: 375px) {
  input,
  select,
  textarea {
    padding: 0.65rem 0.9rem;
  }
}

/* ============================================
   MODAL AUTO-ANPASSUNGEN
   ============================================ */

.modal {
  max-width: 95vw !important;
  margin: 0 auto;
}

.modal-header,
.modal-body,
.modal-footer {
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (max-width: 375px) {
  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .modal-title {
    font-size: 1.1rem;
  }
}

/* ============================================
   CARD GRIDS AUTO-ANPASSUNGEN
   ============================================ */

/* Song Cards - Grid Layout */
.song-card {
  min-width: 0; /* Erlaubt Flexbox Shrinking */
}

/* Flex Wrapping für Button-Gruppen */
.flex-wrap {
  flex-wrap: wrap !important;
}

/* ============================================
   HEADER & NAVIGATION AUTO-ANPASSUNGEN
   ============================================ */

header {
  max-width: 100vw;
  overflow-x: hidden;
}

header h1 {
  font-size: clamp(1rem, 4vw, 1.25rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   TABLE AUTO-ANPASSUNGEN
   ============================================ */

table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  display: block;
}

/* ============================================
   LONG CONTENT AUTO-ANPASSUNGEN
   ============================================ */

/* Lange Listen horizontal scrollbar */
.horizontal-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tags und Chips sollten umbrechen */
.tags-container,
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ============================================
   LANDSCAPE WARNUNG - App nur für Hochformat
   ============================================ */

/* Only show on small touch devices in landscape (avoid breaking desktop/tablet) */
@media (orientation: landscape) and (max-width: 900px) and (max-height: 500px) and (pointer: coarse) {
  /* Zeige Warnung bei Landscape */
  body::before {
    content: '📱 Bitte drehe dein Gerät ins Hochformat';
    /* Override garbled encoding in some environments */
    content: 'Bitte drehe dein Gerät ins Hochformat';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 32, 35, 0.98);
    color: #00d9ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    padding: 2rem;
    z-index: 9999;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }

  /* Verstecke App-Inhalt im Landscape */
  #app {
    display: none;
  }
}

/* ============================================
   SCROLL BEHAVIOR
   ============================================ */

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
}

/* Custom Scrollbar für Webkit-Browser */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 217, 255, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 217, 255, 0.5);
}

/* ============================================
   SAFE AREA INSETS (iPhone X+)
   ============================================ */

@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  footer,
  .bottom-bar {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ============================================
   ACCESSIBILITY - HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
  button,
  .btn {
    border: 2px solid currentColor;
  }

  input,
  select,
  textarea {
    border: 2px solid rgba(255, 255, 255, 0.5);
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   EMERGENCY FIX - Absolut sicherstellen dass nichts überläuft
   ============================================ */

.overflow-x-hidden {
  overflow-x: hidden !important;
}

.max-w-full {
  max-width: 100% !important;
}

/* Container max-width fix */
.container,
.max-w-md {
  max-width: min(768px, 100vw) !important;
}

/* Flex items dürfen nicht überlaufen */
.flex > * {
  min-width: 0;
  min-height: 0;
}

/* Grid items dürfen nicht überlaufen */
.grid > * {
  min-width: 0;
  min-height: 0;
}

/* ============================================
   MOBILE-SPECIFIC IMPROVEMENTS
   ============================================ */

/* Optimiere Tap-Highlighting für iOS */
* {
  -webkit-tap-highlight-color: rgba(0, 217, 255, 0.2);
}

/* Smooth Scrolling auf allen Plattformen */
html {
  scroll-behavior: smooth;
}

/* Verhindere Text-Selection bei Buttons */
button,
.btn,
a.btn {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* Optimiere Font-Rendering auf Mobile */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Größerer Spacing zwischen tappable Elementen */
.btn + .btn,
button + button {
  margin-left: 0.5rem;
}

/* Material Symbols sollten immer gut lesbar sein */
.material-symbols-outlined {
  font-size: 24px !important;
  min-width: 24px;
  min-height: 24px;
}

/* ============================================
   LAYOUT FIXES
   ============================================ */

/* Reset margin for vertical stacks using Flexbox/Grid with gap */
.flex-col > .btn + .btn,
.flex-col > button + button,
.grid > .btn + .btn,
.grid > button + button {
  margin-left: 0;
}

/* Fix: Margin Reset für Full-Width Buttons (z.B. Game Setup) */
button.w-full + button.w-full,
.w-full + .w-full {
  margin-left: 0;
}

/* ============================================
   DEBUGGING HELPER (bei Bedarf aktivieren)
   ============================================ */

/*
.debug-overflow * {
  outline: 1px solid red;
}

.debug-overflow *:hover {
  outline: 2px solid yellow;
}
*/
