/* Mobile navigation: the same destinations, with readable labels and touch feedback. */
.ec-mobile-menu-head { display: none; }

@media (max-width: 900px) {
  body.drawer-open { overflow: hidden; }

  #mainSidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    max-width: 340px;
    height: 100vh;
    height: 100dvh;
    flex-basis: auto;
    padding: 0 14px calc(20px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-right: 1px solid #E4EAF3;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 70;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform .22s ease, visibility .22s;
    box-shadow: 8px 0 30px rgba(23, 35, 60, .12);
  }
  #mainSidebar.open { visibility: visible; transform: translateX(0); }
  #mainSidebar .ec-mobile-menu-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 0 10px;
    background: #fff;
    border-bottom: 1px solid #E4EAF3;
    color: #17233C;
    font-size: 1.14rem;
    font-weight: 800;
  }
  #mainSidebar .ec-mobile-menu-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 68px;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid #E4EAF3;
    border-radius: 12px;
    background: #F7F9FC;
    color: #17233C;
    font: inherit;
    font-size: .93rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
  }
  #mainSidebar .ec-mobile-menu-close svg { width: 20px; height: 20px; }
  #mainSidebar .ec-mobile-menu-close:active { transform: scale(.96); background: #EEF0FF; }
  #mainSidebar .side-brand { padding: 16px 8px; gap: 8px; }
  #mainSidebar .side-logo-img { width: 56px; height: 56px; max-width: 56px; }
  #mainSidebar .side-brand-tx { display: flex; font-size: 1.2rem; }
  #mainSidebar .side-brand-tx small { color: #65738A; font-size: .9rem; }
  #mainSidebar .side-nav, #mainSidebar .side-foot { gap: 6px; }
  #mainSidebar .side-item {
    min-height: 48px;
    padding: 12px;
    justify-content: flex-start;
    border-radius: 12px;
    font-size: 1rem;
    line-height: 1.45;
    touch-action: manipulation;
    transition: background .14s ease, transform .14s ease;
  }
  #mainSidebar .side-item .nav-label { display: flex; flex-wrap: wrap; align-items: center; }
  #mainSidebar .side-item .nav-label::before { width: 6px; height: 6px; flex-basis: 6px; }
  #mainSidebar .side-item:active { transform: scale(.98); background: #EEF0FF; }
  #mainSidebar .side-item[aria-current="page"] { box-shadow: inset 3px 0 0 #4F72F2; font-weight: 800; }
  #mainSidebar .side-item:focus-visible, #mainSidebar .ec-mobile-menu-close:focus-visible {
    outline: 3px solid #4F72F2;
    outline-offset: 2px;
  }
  #sidebarBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(23, 35, 60, .42);
    touch-action: none;
  }
  #sidebarBackdrop[hidden] { display: none; }

  #tabbar {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    position: fixed;
    inset: auto 0 0;
    z-index: 60;
    gap: 5px;
    padding: 8px max(8px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    background: rgba(255, 255, 255, .98);
    border-top: 1px solid #E4EAF3;
    box-shadow: 0 -4px 20px rgba(20, 40, 80, .06);
  }
  #tabbar .tabbar-item {
    --ec-tab-accent: #4F72F2;
    --ec-tab-soft: #EEF0FF;
    --ec-tab-ink: #304EA8;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 66px;
    margin: 0;
    padding: 8px 2px 7px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: #F7F9FC;
    color: #65738A;
    font-family: inherit;
    font-size: .86rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform .13s ease, background .13s ease, border-color .13s ease;
  }
  #tabbar .tabbar-item[data-view="board"] { --ec-tab-accent: #159A68; --ec-tab-soft: #E9F6EF; --ec-tab-ink: #116944; }
  #tabbar .tabbar-item[data-view="store"] { --ec-tab-accent: #B66B13; --ec-tab-soft: #FFF4DF; --ec-tab-ink: #85500F; }
  #tabbar .tabbar-item[data-view="logic"] { --ec-tab-accent: #6366E8; --ec-tab-soft: #EEF0FF; --ec-tab-ink: #484AB0; }
  #tabbar .tabbar-item[data-view="game"] { --ec-tab-accent: #B13C72; --ec-tab-soft: #FCECF3; --ec-tab-ink: #862D56; }
  #tabbar #tabbarMore { --ec-tab-accent: #65738A; --ec-tab-soft: #EDF1F6; --ec-tab-ink: #17233C; }
  #tabbar .tabbar-item .ic { width: 30px; height: 30px; flex: 0 0 30px; color: var(--ec-tab-accent); }
  #tabbar .tabbar-item > span { color: inherit; white-space: nowrap; letter-spacing: -.04em; }
  #tabbar .tabbar-item.active,
  #tabbar .tabbar-item[aria-current="page"],
  #tabbar #tabbarMore.active,
  #tabbar #tabbarMore.is-current-section {
    background: var(--ec-tab-soft);
    color: var(--ec-tab-ink);
    border-color: var(--ec-tab-accent);
    font-weight: 800;
    box-shadow: 0 2px 6px rgba(20, 40, 80, .06);
  }
  #tabbar .tabbar-item.active::before,
  #tabbar #tabbarMore.is-current-section::before {
    content: "";
    position: absolute;
    top: 3px;
    width: 16px;
    height: 3px;
    border-radius: 4px;
    background: var(--ec-tab-accent);
  }
  #tabbar .tabbar-item:active { transform: translateY(2px) scale(.95); background: var(--ec-tab-soft); }
  #tabbar .tabbar-item:focus-visible { outline: 3px solid var(--ec-tab-accent); outline-offset: 2px; }
  .app-body .container { padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 640px) {
  #tabbar { gap: 4px; padding-left: max(6px, env(safe-area-inset-left, 0px)); padding-right: max(6px, env(safe-area-inset-right, 0px)); }
  #tabbar .tabbar-item { font-size: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  #mainSidebar, #mainSidebar .side-item, #tabbar .tabbar-item { transition: none; }
  #mainSidebar .side-item:active, #mainSidebar .ec-mobile-menu-close:active, #tabbar .tabbar-item:active { transform: none; }
}

/* The desktop studio hides its sidebar; mobile uses the same accessible drawer. */
@media (max-width: 900px) {
  .app-shell.nn-studio-mode #mainSidebar { width: min(88vw, 340px); flex-basis: auto; height: 100dvh; padding: 0 14px calc(20px + env(safe-area-inset-bottom, 0px)); border-right-color: #E4EAF3; overflow-x: hidden; overflow-y: auto; opacity: 1; pointer-events: auto; }
  .app-shell.nn-studio-mode .nn-sidebar-toggle { display: none !important; }
}
