:root {
  --mobile-nav-height: 66px;
  --mobile-viewport-height: 100dvh;
}

.mobile-session-status,
.mobile-bottom-nav {
  display: none;
}

@supports not (height: 100dvh) {
  :root { --mobile-viewport-height: 100vh; }
}

@media (max-width: 760px), (orientation: landscape) and (max-height: 520px) {
  html, body, #app {
    width: 100%;
    min-width: 0;
    min-height: var(--mobile-viewport-height);
    overflow-x: hidden;
  }

  :root { --header-height: 56px; }

  #app-header {
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
  }

  #app-header .header-inner {
    gap: 8px;
    padding: 0 10px;
  }

  #app-header .header-brand {
    flex: 0 0 auto;
    min-width: 0;
  }

  #app-header .header-version,
  #app-header .header-nav,
  #app-header .header-actions > :not(#mobile-session-status):not(#auth-header-area):not(#btn-admin) {
    display: none !important;
  }

  #app-header .header-actions {
    min-width: 0;
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 6px;
  }

  .mobile-session-status {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    min-height: 36px;
    gap: 6px;
    padding: 6px 9px;
    border: 1px solid #dbe4f0;
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
    font-size: 11px;
    font-weight: 800;
  }

  .mobile-session-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #94a3b8;
  }

  .mobile-session-status[data-state="student"] .mobile-session-dot { background: #22c55e; }
  .mobile-session-status[data-state="teacher"] .mobile-session-dot { background: #3b82f6; }
  .mobile-session-status[data-state="manager"] .mobile-session-dot { background: #8b5cf6; }
  .mobile-session-status[data-state="guest"] .mobile-session-dot { background: #f59e0b; }
  .mobile-session-label {
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #auth-header-area .auth-signup-btn { display: none !important; }
  #auth-header-area .auth-login-btn,
  #auth-header-area .auth-avatar-btn,
  #btn-admin {
    min-width: 44px !important;
    min-height: 44px !important;
  }
  #auth-header-area .auth-login-btn {
    width: 44px;
    padding: 0 !important;
    font-size: 0 !important;
  }
  #auth-header-area .auth-login-btn i { font-size: 18px; }

  #main-content {
    padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  .mobile-bottom-nav {
    position: fixed;
    z-index: 120;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
    padding: 6px max(6px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(6px, env(safe-area-inset-left, 0px));
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: start;
    border-top: 1px solid #dbe4f0;
    background: rgba(255,255,255,.97);
    box-shadow: 0 -8px 24px rgba(15,23,42,.08);
    backdrop-filter: blur(14px);
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    min-width: 0;
    min-height: 52px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font: inherit;
    font-size: 10px;
    font-weight: 800;
    touch-action: manipulation;
  }
  .mobile-bottom-nav i { font-size: 18px; }
  .mobile-bottom-nav [aria-current="page"] {
    color: #4f46e5;
    background: #eef2ff;
  }
  .mobile-bottom-nav [hidden] { display: none !important; }

  #floating-settings-btn,
  #floating-feedback-btn {
    display: none !important;
  }

  .auth-modal-overlay {
    align-items: flex-end !important;
    padding: env(safe-area-inset-top, 0px) 0 0 !important;
  }
  .auth-modal-box {
    width: 100% !important;
    max-width: none !important;
    max-height: min(92dvh, calc(var(--mobile-viewport-height) - env(safe-area-inset-top, 0px))) !important;
    border-radius: 18px 18px 0 0 !important;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    overscroll-behavior: contain;
  }

  body.puzzlelo-mobile-play .mobile-bottom-nav,
  body.puzzlelo-mobile-play .mobile-session-status {
    display: none !important;
  }
  body.puzzlelo-mobile-play #main-content {
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }

  @media (orientation: landscape) and (max-height: 520px) {
    :root { --mobile-nav-height: 54px; }
    .mobile-bottom-nav {
      grid-template-columns: repeat(5, minmax(64px, 1fr));
      overflow-x: auto;
    }
    .mobile-bottom-nav a,
    .mobile-bottom-nav button {
      min-height: 44px;
      flex-direction: row;
      font-size: 11px;
    }
    .mobile-bottom-nav i { font-size: 15px; }
    .auth-modal-box { max-height: 100dvh !important; }
  }
}

@media print {
  .mobile-session-status,
  .mobile-bottom-nav { display: none !important; }
}
