/* Mobile-only styles for oachkatzlschwoaf.bayern – desktop layout unchanged */

@media (max-width: 900px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    overflow-x: clip;
    max-width: 100vw;
  }

  img,
  video,
  iframe,
  embed,
  object,
  svg:not(.no-mobile-scale) {
    max-width: 100%;
    height: auto;
  }

  table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  pre,
  code,
  .code-block {
    max-width: 100%;
    overflow-x: auto;
    word-break: break-word;
  }

  nav {
    width: calc(100% - 24px) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
    box-sizing: border-box;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
  }

  nav button:not(.menu-toggle):not(.mobile-nav-auto) {
    font-size: 0.82em;
    padding: 8px 10px;
  }

  .main-container,
  .wrap,
  .content,
  .container,
  main,
  header,
  section,
  article,
  .password-form {
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .main-container,
  .wrap,
  .content {
    padding-left: max(12px, env(safe-area-inset-left)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
  }

  .left-column,
  .right-column,
  [class*="column"],
  [id*="panel"] {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  h1 {
    font-size: clamp(1.45rem, 6.5vw, 2.5rem) !important;
    line-height: 1.2;
  }

  h2 {
    font-size: clamp(1.2rem, 5.5vw, 2rem) !important;
  }

  input,
  select,
  textarea {
    font-size: max(16px, 1em) !important;
  }

  a,
  button,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  select,
  .btn,
  .hub-btn,
  .game-action-btn,
  .board-action-menu-btn {
    min-height: 44px;
  }

  /* Auto-injected mobile nav (pages without own hamburger rules) */
  nav.mobile-nav-enhanced {
    position: sticky;
  }

  nav.mobile-nav-enhanced .menu-toggle.mobile-nav-auto {
    display: block;
    font-size: 1.65em;
    line-height: 1;
    cursor: pointer;
    border: none;
    background: transparent;
    padding: 6px 10px;
    margin-right: auto;
    color: inherit;
  }

  nav.mobile-nav-enhanced > ul {
    display: none;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 6px);
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 14px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    border-radius: 12px;
    z-index: 2000;
    gap: 4px;
  }

  nav.mobile-nav-enhanced > ul.open {
    display: flex;
  }

  nav.mobile-nav-enhanced > ul li a {
    display: block;
    padding: 10px 12px;
  }

  /* Button nav rows (e.g. games.html) */
  nav:has(> button) {
    justify-content: center;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }

  nav > button {
    flex: 1 1 calc(50% - 8px);
    min-width: calc(50% - 8px);
    max-width: 100%;
    white-space: normal !important;
    line-height: 1.25;
  }

  /* Schach archive / hub buttons */
  .hub-btn {
    width: 100%;
    min-width: 0 !important;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch !important;
  }

  .toolbar select,
  .toolbar button {
    width: 100%;
  }

  /* Schach app – also for solo/computer mode */
  #game-layout:not(.online) {
    --board-ui-x: 16px;
    --board-ui-y: 118px;
  }

  #board-action-row {
    --board-size: min(
      calc(100vw - 16px - 2 * var(--board-capture-strip, 40px)),
      calc(100dvh - 118px),
      100%
    );
  }

  #action-rail {
    width: 72px;
    min-width: 72px;
    max-height: 38dvh;
  }

  #game-actions-popup {
    left: max(4px, env(safe-area-inset-left));
  }

  #game-actions-menu {
    min-width: 156px;
    max-width: calc(100vw - 72px);
  }

  #top-bar {
    padding: 6px 8px;
    gap: 4px;
  }

  #top-bar button,
  #top-bar select {
    font-size: 0.76em;
    padding: 6px 8px;
  }

  #game-status {
    width: 100%;
    order: 10;
    white-space: normal;
    text-overflow: unset;
  }

  #chat-panel {
    right: 6px;
    left: 6px;
    width: auto;
    bottom: max(6px, env(safe-area-inset-bottom));
    height: min(280px, calc(100dvh - 88px));
  }

  #mode-overlay .mode-card,
  .modal-card,
  .color-card {
    width: calc(100% - 24px);
    max-width: 420px;
  }

  .list-panel {
    max-height: 42dvh;
  }
}

@media (max-width: 900px) {
  #game-layout.online {
    flex-direction: column;
  }

  #game-layout.online #players-panel {
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: none;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid #333;
  }

  #game-layout.online .panel-body {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0;
  }

  #game-layout.online .panel-section.grow {
    flex: 1 1 45%;
    min-width: 140px;
    max-height: 22dvh;
  }

  #game-layout.online .panel-section.compact-actions {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  #game-layout.online .panel-section.compact-actions .game-action-btn {
    margin-top: 0;
  }

  #game-layout.online #board-action-row {
    --board-size: min(
      calc(100vw - 24px - 2 * var(--board-capture-strip, 40px)),
      calc(100dvh - 230px),
      100%
    );
  }

  #game-layout.online.panel-collapsed #board-action-row {
    --board-size: min(
      calc(100vw - 24px - 2 * var(--board-capture-strip, 40px)),
      calc(100dvh - 180px),
      100%
    );
  }

  #game-layout.online:not(.panel-collapsed) #panel-toggle-btn {
    left: 0;
    top: 8px;
    transform: none;
    border-radius: 8px;
    border-left: 1px solid #444;
  }

  #panel-toggle-btn {
    display: none !important;
  }

  #board-action-row {
    flex-direction: row;
    flex-wrap: nowrap;
  }
}

@media (max-width: 480px) {
  nav > button {
    flex: 1 1 100%;
    min-width: 100%;
  }

  #game-actions-menu {
    left: 0;
    right: auto;
    top: calc(100% + 8px);
    transform: none;
  }

  .replay-controls {
    flex-wrap: wrap;
    justify-content: center;
  }
}
