/* ═══════════════════════════════════════════════
   ASCII Studio — Mobile Experience
   Full-screen tab navigation, floating FAB,
   bottom sheet exports, touch-optimized controls
   ═══════════════════════════════════════════════ */

/* ── Hide mobile-only elements on desktop ── */
#mobile-nav,
#mobile-render-fab,
.mobile-sheet {
  display: none;
}

@media (max-width: 800px) {

  /* ── Layout: full-height tabs instead of cramped split ── */
  html, body { overflow: hidden; height: 100%; }

  #app {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  #sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    min-width: 100%;
    height: 100%;
    max-height: 100%;
    z-index: 100;
    border-right: none;
    border-top: none;
    transform: translateX(-100%);
    transition: transform 0.35s var(--ease-out-expo);
    padding-bottom: 72px; /* space for bottom nav */
  }

  #sidebar.mobile-visible {
    transform: translateX(0);
  }

  #sidebar::after {
    display: none; /* remove accent strip on mobile */
  }

  #sidebar-header {
    display: flex !important;
    padding: 14px 16px 12px;
  }

  #main {
    flex: 1;
    height: 100%;
    min-height: 0;
    padding-bottom: 72px; /* space for bottom nav */
  }

  /* ── Topbar: slimmer, hide export buttons (moved to sheet) ── */
  #topbar {
    height: 44px;
    padding: 0 12px;
    flex-wrap: nowrap;
    gap: 8px;
  }

  #topbar-actions {
    display: none; /* exports are in the bottom sheet now */
  }

  #status {
    font-size: 10px;
  }

  #thumb-wrap {
    padding: 8px 12px 0;
  }

  #thumb-inner {
    padding: 5px 8px;
    width: 100%;
  }

  #thumb {
    width: 44px;
    height: 30px;
  }

  #thumb-name {
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
  }

  /* ── Preview: full available height ── */
  #preview-wrap {
    padding: 8px;
    flex: 1;
    min-height: 0;
  }

  #dropzone {
    padding: 40px 20px;
    max-width: 100%;
    border-radius: 12px;
  }

  .dz-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
  }

  .dz-icon svg { width: 18px; height: 18px; }
  .dz-main { font-size: 12px; }

  /* ── Controls: bigger touch targets ── */
  #controls-scroll {
    padding: 8px 14px 100px; /* extra bottom padding for FAB clearance */
  }

  .section {
    margin-bottom: 8px;
  }

  .section-head {
    padding: 12px 14px;
    min-height: 48px;
  }

  .section-icon {
    width: 28px;
    height: 28px;
  }

  .section-title {
    font-size: 11px;
  }

  .section-body {
    padding: 12px 14px 16px;
  }

  .ctrl {
    margin-bottom: 16px;
  }

  .ctrl-label {
    font-size: 12px;
    margin-bottom: 8px;
  }

  .ctrl-val {
    font-size: 11px;
    padding: 3px 8px;
  }

  /* Bigger slider thumb for touch */
  input[type=range] {
    height: 6px;
  }

  input[type=range]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  /* Bigger toggle switches */
  input[type=checkbox] {
    width: 38px;
    height: 20px;
  }

  input[type=checkbox]::after {
    width: 16px;
    height: 16px;
    top: 1px;
    left: 1px;
  }

  input[type=checkbox]:checked::after {
    left: 19px;
  }

  .toggle-row {
    padding: 6px 0;
    min-height: 40px;
  }

  .toggle-row label {
    font-size: 12px;
  }

  select {
    padding: 10px 30px 10px 12px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Render button in sidebar */
  .btn-render {
    margin-top: 16px;
    padding: 14px;
    font-size: 13px;
    border-radius: 12px;
  }

  /* ── Mobile Bottom Navigation ── */
  #mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(10, 10, 16, 0.92);
    backdrop-filter: blur(24px) saturate(1.8);
    -webkit-backdrop-filter: blur(24px) saturate(1.8);
    border-top: 1px solid var(--glass-border);
    z-index: 200;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-3);
    font-family: 'Geist', system-ui, sans-serif;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.25s, transform 0.25s var(--ease-spring);
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }

  .mobile-tab svg {
    width: 20px;
    height: 20px;
    transition: stroke 0.25s, filter 0.25s;
  }

  .mobile-tab.active {
    color: var(--accent);
  }

  .mobile-tab.active svg {
    stroke: var(--accent);
    filter: drop-shadow(0 0 6px var(--accent-glow));
  }

  .mobile-tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background: var(--accent);
    border-radius: 0 0 2px 2px;
    box-shadow: 0 0 8px var(--accent-glow);
  }

  .mobile-tab:active {
    transform: scale(0.92);
  }

  /* ── Floating Render FAB ── */
  #mobile-render-fab {
    display: flex;
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #b8e63c);
    border: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 150;
    box-shadow:
      0 4px 20px var(--accent-glow),
      0 8px 32px rgba(0, 0, 0, 0.4);
    transition: transform 0.25s var(--ease-spring), box-shadow 0.25s;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-render-fab svg {
    width: 22px;
    height: 22px;
    stroke: #000;
  }

  #mobile-render-fab:active {
    transform: scale(0.88);
  }

  /* ── Mobile Export Sheet ── */
  .mobile-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(14, 14, 22, 0.96);
    backdrop-filter: blur(32px) saturate(1.8);
    -webkit-backdrop-filter: blur(32px) saturate(1.8);
    border-top: 1px solid var(--glass-border);
    border-radius: 20px 20px 0 0;
    z-index: 300;
    transform: translateY(0);
    transition: transform 0.35s var(--ease-out-expo), opacity 0.25s;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-sheet.hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
  }

  .sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.3px;
  }

  .sheet-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.12);
  }

  .sheet-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--surface-3);
    border-radius: 50%;
    color: var(--text-2);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
  }

  .sheet-close:active {
    background: rgba(255, 255, 255, 0.1);
  }

  .sheet-body {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px 20px 24px;
  }

  .sheet-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 8px;
    background: var(--surface-3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text);
    font-family: 'Geist Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease-spring);
    -webkit-tap-highlight-color: transparent;
  }

  .sheet-btn-icon {
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
  }

  .sheet-btn-icon svg {
    width: 20px;
    height: 20px;
  }

  .sheet-btn:active {
    transform: scale(0.95);
    background: var(--accent-dim);
    border-color: var(--accent-border);
  }

  /* ── Toast: bottom-center on mobile ── */
  #toast {
    bottom: 80px;
    right: 50%;
    transform: translateX(50%) translateY(16px) scale(0.95);
    max-width: calc(100vw - 32px);
  }

  #toast.show {
    transform: translateX(50%) translateY(0) scale(1);
  }

  /* ── Zoom controls in topbar ── */
  .btn {
    padding: 6px 10px;
    font-size: 11px;
    min-height: 36px;
  }
}

/* ── Extra small phones (< 380px) ── */
@media (max-width: 380px) {
  .sheet-body {
    grid-template-columns: repeat(2, 1fr);
  }

  #mobile-render-fab {
    width: 50px;
    height: 50px;
    bottom: 76px;
    right: 12px;
  }

  #mobile-render-fab svg {
    width: 18px;
    height: 18px;
  }
}
