/* ============================================
   MOBILE-FIRST RESPONSIVE DESIGN
   Phone (320px-480px) | Tablet (480px-768px) | iPad (768px-1024px) | Desktop (1024px+)
   ============================================ */

/* Mobile Menu Hamburger */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle:active {
  transform: scale(0.95);
}

.mobile-menu-toggle span {
  width: 22px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 1px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translateY(8px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translateY(-8px);
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  animation: fadeIn 0.3s ease-out;
}

.sidebar-overlay.active {
  display: block;
}

/* Phone Layout (320px - 480px) */
@media (max-width: 480px) {
  .mobile-menu-toggle {
    display: flex;
  }

  .header {
    padding: 10px 50px 10px 10px;
    flex-wrap: nowrap;
  }

  .logo {
    order: 1;
    flex: 1;
  }

  .logo-text {
    font-size: 13px;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-tabs {
    display: none;
  }

  .header-right {
    order: 2;
    margin-left: 0;
  }

  .task-sidebar {
    position: fixed;
    left: -280px;
    top: 60px;
    width: 280px;
    height: calc(100vh - 60px);
    z-index: 1000;
    background: var(--bg);
    border-right: 1px solid var(--border);
    border-left: none;
    padding: 1rem;
    transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
  }

  .task-sidebar.mobile-open {
    left: 0;
  }

  #tab-practice {
    flex-direction: column;
  }

  .editor-area {
    flex: 1;
    order: 2;
  }

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

  .toolbar-label {
    padding: 0 0.25rem;
  }

  .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .btn {
    flex: 1;
    min-width: 70px;
    padding: 0.35rem 0.5rem;
    font-size: 0.7rem;
  }

  .btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.65rem;
  }

  .snippet-select {
    min-width: 100%;
    height: 32px;
    font-size: 0.7rem;
  }

  .code-editor .CodeMirror {
    font-size: 12px;
    line-height: 1.5;
  }

  .code-editor .CodeMirror-linenumber {
    font-size: 10px;
    padding: 0 4px 0 2px;
  }

  .output-panel {
    height: 140px;
  }

  .output-tabs {
    overflow-x: auto;
  }

  .output-tab {
    padding: 0.3rem 0.7rem;
    font-size: 0.7rem;
    flex-shrink: 0;
  }

  .console-text {
    font-size: 0.65rem;
  }

  .skill-coach-body {
    max-height: 150px !important;
  }

  .skill-coach-list {
    gap: 0.5rem;
  }

  .coach-card {
    padding: 0.5rem 0.65rem;
  }

  .coach-card-desc {
    font-size: 0.7rem;
  }

  /* Files Tab Mobile */
  #tab-files {
    padding: 0.75rem;
  }

  .files-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .drop-zone {
    padding: 1.5rem 1rem;
  }

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

  .file-list {
    gap: 0.25rem;
  }

  .file-item {
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
  }

  .file-preview-panel {
    min-height: 200px;
  }

  .file-preview {
    min-height: 180px;
    padding: 0.75rem;
  }

  .file-preview pre {
    font-size: 0.65rem;
  }

  .preview-table {
    font-size: 0.7rem;
  }

  .preview-table th,
  .preview-table td {
    padding: 0.25rem 0.4rem;
  }
}

/* Tablet Layout (480px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .header {
    padding: 12px 40px 12px 12px;
    gap: 1.5rem;
  }

  .logo-text {
    font-size: 14px;
  }

  .task-sidebar {
    width: 260px;
  }

  .editor-toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

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

  .snippet-select {
    min-width: 120px;
    font-size: 0.75rem;
  }

  .code-editor .CodeMirror {
    font-size: 13px;
    line-height: 1.55;
  }

  .output-panel {
    height: 160px;
  }

  .console-text {
    font-size: 0.7rem;
  }

  .files-layout {
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .file-preview-panel {
    grid-column: 1 / -1;
  }

  .drop-zone {
    padding: 2rem 1.25rem;
  }

  .file-item {
    font-size: 0.8rem;
  }

  .file-preview pre {
    font-size: 0.7rem;
  }
}

/* iPad Layout (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .header {
    padding: 14px 32px;
    gap: 2rem;
  }

  .task-sidebar {
    width: 280px;
  }

  .editor-toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.78rem;
  }

  .snippet-select {
    min-width: 130px;
    font-size: 0.78rem;
  }

  .code-editor .CodeMirror {
    font-size: 13.5px;
    line-height: 1.6;
  }

  .output-panel {
    height: 180px;
  }

  .files-layout {
    grid-template-columns: 1fr 250px 1fr;
    gap: 1.25rem;
  }

  .drop-zone {
    padding: 2.25rem 1.5rem;
  }

  .file-item {
    font-size: 0.8rem;
  }
}

/* Desktop Layout (1024px+) */
@media (min-width: 1025px) {
  .header {
    padding: 18px 48px;
    gap: 2.25rem;
  }

  .task-sidebar {
    width: 320px;
  }

  .editor-toolbar {
    gap: 0.5rem;
  }

  .toolbar-actions {
    gap: 0.5rem;
  }

  .btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.8rem;
  }

  .snippet-select {
    min-width: 136px;
  }

  .code-editor .CodeMirror {
    font-size: 14.5px;
    line-height: 1.65;
  }

  .output-panel {
    height: 220px;
  }

  .files-layout {
    grid-template-columns: 1fr 280px 1fr;
    gap: 1.5rem;
  }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .tab,
  .file-item,
  .task-card {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 1rem;
  }

  .btn-sm {
    min-height: 40px;
    padding: 0.4rem 0.8rem;
  }

  /* Remove hover effects on touch */
  .btn:hover:not(:disabled),
  .tab:hover,
  .file-item:hover {
    transform: none;
  }

  /* Add active state feedback */
  .btn:active:not(:disabled),
  .tab:active,
  .file-item:active {
    opacity: 0.8;
    transform: scale(0.98);
  }
}

/* Landscape Mode */
@media (max-height: 500px) and (orientation: landscape) {
  .header {
    padding: 8px 16px;
  }

  .output-panel {
    height: 100px;
  }

  .task-sidebar {
    padding: 0.5rem;
  }

  .editor-toolbar {
    padding: 0.35rem;
  }

  .btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.65rem;
  }
}

/* Notch/Safe Area Support (iPhone X and later) */
@supports (padding: max(0px)) {
  .header {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }

  .task-sidebar {
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
  .btn,
  .tab,
  .file-item {
    border-width: 0.5px;
  }

  .code-editor .CodeMirror-cursor {
    border-width: 1px;
  }
}

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
}

/* Better text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Prevent zoom on double tap */
@media (max-width: 768px) {
  input,
  button,
  select,
  textarea {
    font-size: 16px;
  }
}

/* Orientation Change Handling */
@media (orientation: portrait) {
  body {
    --viewport-height: 100vh;
  }
}

@media (orientation: landscape) {
  body {
    --viewport-height: 100svh;
  }
}
