/**
 * Materyaal Ders Oyunu Hazırlayıcı - Mobile & Small Tablet Stylesheet
 */

html, body {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

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

@media (max-width: 768px) {
  .app-header {
    padding: 0.65rem 0.85rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    padding-top: max(0.65rem, env(safe-area-inset-top));
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow: visible;
  }

  .header-brand-wrap {
    min-width: 0;
    flex: 1 1 auto;
  }

  .brand-link {
    min-width: 0;
    gap: 0.5rem;
  }

  .brand-title {
    font-size: clamp(1rem, 3.5vw, 1.25rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-subtitle {
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-nav-tabs {
    display: none;
    width: 100%;
    flex-direction: column;
    background: #172554;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    gap: 0.5rem;
    order: 3;
    margin-top: 0.5rem;
    max-height: min(70vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .header-nav-tabs.mobile-open {
    display: flex;
  }

  .mobile-menu-toggle {
    display: flex;
    flex-shrink: 0;
  }

  .header-search-wrap {
    flex: 0 1 140px;
    min-width: 70px;
  }

  .header-search-input {
    width: 100%;
    max-width: 140px;
    min-height: 38px;
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
  }

  .header-search-input:focus {
    width: 100%;
    max-width: 170px;
  }

  .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .brand-icon {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
    border-radius: 10px;
  }

  .modal-overlay {
    align-items: flex-start;
    overflow-y: auto;
    padding: max(.65rem, env(safe-area-inset-top)) .65rem max(.65rem, env(safe-area-inset-bottom));
  }

  .modal-content {
    width: 95vw !important;
    max-width: min(580px, 95vw) !important;
    max-height: calc(90vh - 1.5rem) !important;
    max-height: calc(90dvh - 1.5rem) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin: auto !important;
    padding: 1.25rem 1rem !important;
    border-radius: 16px !important;
    box-sizing: border-box !important;
  }

  #profile-setup-modal { overflow:hidden!important; padding:.4rem!important; }
  #profile-setup-modal .profile-settings-content { width:calc(100vw - .8rem)!important; height:calc(100dvh - .8rem)!important; max-height:calc(100dvh - .8rem)!important; margin:0 auto!important; touch-action:pan-y!important; }
  #profile-setup-modal .settings-nav-tabs { position:sticky; top:-1.25rem; z-index:3; padding:.65rem 0 .5rem; background:#fff; }
  .settings-admin-groups { grid-template-columns:1fr; }

  #auth-qr-code-box {
    min-width: 148px!important;
    min-height: 148px!important;
  }

  /* Mobile Bottom Sheet for Teacher Profile Menu */
  .header-profile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .header-profile-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  .header-profile-dropdown {
    position: fixed !important;
    top: calc(max(0.5rem, env(safe-area-inset-top)) + 64px) !important;
    bottom: auto !important;
    right: 0.5rem !important;
    left: auto !important;
    width: min(340px, calc(100vw - 1rem)) !important;
    max-width: calc(100vw - 1rem) !important;
    min-width: 0 !important;
    border-radius: 18px !important;
    padding: 0.85rem 1rem !important;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35) !important;
    border: 1px solid #cbd5e1 !important;
    background: #ffffff !important;
    z-index: 1060 !important;
    max-height: calc(100vh - 76px - max(0.5rem, env(safe-area-inset-bottom))) !important;
    max-height: calc(100dvh - 76px - max(0.5rem, env(safe-area-inset-bottom))) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    transform: none !important;
  }

  .header-profile-dropdown:not(.hidden) {
    display: flex !important;
  }

  .mobile-sheet-handle {
    display: none !important;
  }

  .mobile-user-sheet-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    background: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    border-radius: 14px;
    margin-bottom: 0.85rem;
    flex-shrink: 0;
  }

  .mobile-avatar-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #0284c7;
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(2, 132, 199, 0.2);
  }

  .mobile-user-details {
    flex: 1;
    min-width: 0;
    text-align: left;
    display: flex;
    flex-direction: column;
  }

  .mobile-user-name {
    font-size: 1rem;
    font-weight: 800;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-user-email {
    font-size: 0.8rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-active-badge {
    background: #10b981;
    color: #ffffff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    flex-shrink: 0;
  }

  .header-profile-dropdown .dropdown-item {
    padding: 0.85rem 1rem;
    font-size: 1rem;
    min-height: 52px;
    border-radius: 12px;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
  }

  .header-profile-dropdown .dropdown-item-smartboard {
    margin-bottom: 0.5rem;
    border: 1.5px solid #38bdf8;
    background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
  }

  .mobile-sheet-close-btn {
    display: block;
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.85rem;
    font-size: 0.95rem;
    font-weight: 700;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    cursor: pointer;
    text-align: center;
  }
  .mobile-sheet-close-btn:active {
    background: #e2e8f0;
  }

  .app-header button,
  .mobile-menu-toggle,
  .header-auth-btn,
  .header-user-badge-btn,
  .nav-tab-btn,
  .catalog-grade-pill {
    min-width: 36px;
    min-height: 36px;
  }

  .main-layout {
    padding: 0.75rem;
    padding-bottom: 7.5rem;
    padding-bottom: calc(max(7.5rem, 160px));
    gap: 1rem;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .card {
    padding: 1rem;
    max-width: 100%;
    overflow-x: hidden;
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* Mobile Games Grid: 2 or 3 columns as requested */
  body.catalog-mode .game-type-category-grid,
  .game-type-selector,
  .game-type-category-grid,
  .game-type-grid,
  .community-grid,
  .my-games-grade-folder-content {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
  }

  @media (min-width: 501px) and (max-width: 768px) {
    body.catalog-mode .game-type-category-grid,
    .game-type-selector,
    .game-type-category-grid,
    .game-type-grid,
    .community-grid,
    .my-games-grade-folder-content {
      grid-template-columns: repeat(3, 1fr) !important;
      gap: 0.75rem !important;
    }
  }

  /* Compact Game Type Cards */
  body.catalog-mode .game-type-card,
  .game-type-card {
    min-height: 135px !important;
    padding: 0.85rem 0.6rem !important;
    border-radius: 14px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
  }
  body.catalog-mode .type-card-icon,
  .game-type-card .type-card-icon,
  .game-type-card .type-icon {
    font-size: 2.1rem !important;
    margin-bottom: 0.3rem !important;
  }
  body.catalog-mode .type-card-title,
  .game-type-card .type-card-title,
  .game-type-card .type-title {
    font-size: 0.84rem !important;
    font-weight: 800 !important;
    line-height: 1.25 !important;
  }
  body.catalog-mode .game-type-card::after {
    font-size: 0.72rem !important;
    padding-top: 0.3rem !important;
  }

  /* Compact Community Cards for 2-3 Column Display */
  .community-card {
    border-radius: 14px !important;
    overflow: hidden !important;
  }
  .community-card-cover {
    height: 90px !important;
  }
  .community-card-body {
    padding: 0.65rem 0.55rem !important;
    gap: 0.25rem !important;
  }
  .community-card-title {
    font-size: 0.82rem !important;
    line-height: 1.25 !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
  }
  .community-card-meta {
    font-size: 0.68rem !important;
    gap: 0.25rem !important;
    flex-wrap: wrap !important;
  }
  .community-card-actions {
    padding: 0.45rem 0.55rem !important;
    gap: 0.3rem !important;
  }
  .community-card-actions .btn {
    font-size: 0.72rem !important;
    padding: 0.3rem 0.45rem !important;
    min-height: 32px !important;
    flex: 1 1 auto !important;
  }

  /* Compact My Games Cards for 2-3 Column Display */
  .my-game-card {
    padding: 0.75rem 0.55rem !important;
    border-radius: 12px !important;
    display: flex !important;
    flex-direction: column !important;
  }
  .my-game-card .game-card-title {
    font-size: 0.82rem !important;
    line-height: 1.25 !important;
  }
  .my-game-meta {
    font-size: 0.68rem !important;
    margin: 0.3rem 0 !important;
  }
  .my-game-card-actions {
    margin-top: auto !important;
    flex-wrap: wrap !important;
    gap: 0.3rem !important;
  }
  .my-game-card-actions .btn {
    font-size: 0.7rem !important;
    padding: 0.3rem 0.45rem !important;
    min-height: 30px !important;
    flex: 1 1 calc(50% - 0.2rem) !important;
  }

  .option-editor-row, .group-editor-row {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .option-editor-row .form-input {
    flex: 1 1 200px;
  }

  .modal-content {
    max-width: 95vw !important;
    max-width: min(580px, 95vw) !important;
    width: 95vw !important;
    max-height: calc(90vh - 1.5rem) !important;
    max-height: calc(90dvh - 1.5rem) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 1.25rem 1rem !important;
    margin: 1rem auto !important;
    box-sizing: border-box !important;
  }

  .qrcode-container canvas, .qrcode-container img {
    max-width: 100% !important;
    height: auto !important;
  }

  .editor-toolbar {
    padding: 0.65rem 0.85rem;
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-left, .toolbar-right {
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  /* Player Mobile */
  .player-top-bar {
    padding: 0.4rem 0.65rem;
    gap: 0.35rem;
    flex-wrap: nowrap;
  }

  .player-top-bar .ctrl-text {
    display: none;
  }

  .btn-player-ctrl {
    padding: 0.35rem 0.5rem;
    min-width: 36px;
    min-height: 36px;
    justify-content: center;
  }

  .player-title {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  }

  .player-meta {
    font-size: 0.72rem;
  }

  .player-arena {
    padding: 0.75rem;
  }

  .game-play-card {
    padding: 1.25rem;
  }

  .question-prompt {
    font-size: 1.25rem;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }

  .btn-option {
    min-height: 58px;
    font-size: 1.05rem;
    padding: 0.85rem 1rem;
  }

  .tf-statement-text {
    font-size: 1.4rem;
  }

  .btn-tf {
    min-height: 75px;
    font-size: 1.35rem;
  }

  .matching-columns-wrap {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .grouping-buckets-grid {
    grid-template-columns: 1fr;
  }

  .feedback-modal {
    width: 95%;
    padding: 1rem 1.25rem;
    bottom: 1rem;
  }

  .feedback-icon {
    font-size: 2rem;
  }

  .game-over-card {
    padding: 1.5rem;
  }

  .game-over-stats {
    flex-direction: column;
    gap: 0.75rem;
  }
}

@media (max-width: 480px) {
  .game-type-selector,
  .game-type-category-grid,
  .community-grid,
  .my-games-grade-folder-content {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.55rem !important;
  }

  #featured-teachers-container,
  #community-teachers-container,
  #community-games-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .brand-subtitle {
    display: none;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .app-header {
    padding: 0.5rem 0.65rem;
    gap: 0.4rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    gap: 0.35rem;
  }

  .header-search-wrap {
    flex: 1 1 auto;
    max-width: 100%;
    min-width: 60px;
  }

  .header-search-input {
    width: 100%;
    max-width: 100%;
    min-height: 36px;
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
  }

  .header-search-input:focus {
    width: 100%;
    max-width: 100%;
  }

  .header-auth-btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
    min-height: 36px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .mobile-menu-toggle {
    width: 36px;
    height: 36px;
    padding: 6px;
    flex-shrink: 0;
  }

  .main-layout {
    padding: 0.5rem;
    padding-bottom: 8rem;
    padding-bottom: calc(max(8rem, 210px));
  }

  .card {
    padding: 0.85rem 0.65rem;
  }

  .btn {
    padding: 0.55rem 0.75rem;
    font-size: 0.85rem;
  }

  .editor-toolbar {
    padding: 0.5rem;
  }

  .toolbar-btn {
    flex: 1 1 auto;
    font-size: 0.8rem;
    padding: 0.45rem 0.6rem;
    text-align: center;
  }

  .metrics-summary-table {
    grid-template-columns: 1fr;
  }

  .player-start-card {
    padding: 1.5rem 1rem;
  }

  .start-card-title {
    font-size: 1.5rem;
  }

  /* Mobile Grouping Builder */
  .group-builder-card {
    padding: 0.85rem;
    max-width: 100%;
    box-sizing: border-box;
  }

  .group-builder-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .group-header-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .concept-main-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  .concept-main-row .concept-text-input,
  .concept-main-row .concept-group-select {
    width: 100%;
    flex: 1 1 100%;
    max-width: 100%;
  }

  .concept-details-row {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .group-card-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .group-card-footer .btn {
    width: 100%;
  }
}
