/* ============================================
   CodeDivs - Apple-Inspired Dark Theme
   Modern, sleek, minimalist design
   ============================================ */

/* CSS Variables for consistent theming */
:root {
  --bg-primary: #1d1d1f;
  --bg-secondary: #161617;
  --bg-elevated: #2d2d30;
  --accent-blue: #0071e3;
  --accent-blue-hover: #0077ed;
  --text-primary: #f5f5f7;
  --text-secondary: #a1a1a6;
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-medium: rgba(255, 255, 255, 0.18);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "Segoe UI", Roboto, sans-serif;

  /* Fluid Typography Scale */
  /* Mobile (320px): base 12px, h1 16px */
  /* Tablet (600px): base 13px, h1 18px */
  /* Desktop (1024px+): base 14px, h1 21px */
  --font-base: clamp(12px, 2.2vw, 14px);
  --font-sm: clamp(11px, 2vw, 13px);
  --font-lg: clamp(14px, 2.5vw, 16px);
  --font-xl: clamp(16px, 3vw, 18px);
  --font-2xl: clamp(18px, 3.5vw, 20px);
  --font-3xl: clamp(20px, 4vw, 21px);
  --heading-h1: clamp(16px, 4.5vw, 21px);
  --heading-h2: clamp(18px, 3.5vw, 20px);
  --heading-h3: clamp(16px, 3vw, 18px);
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-elevated: #e8e8ed;
  --accent-blue: #0071e3;
  --accent-blue-hover: #0077ed;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --border-subtle: rgba(0, 0, 0, 0.1);
  --border-medium: rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.15);
}

*,
body,
html {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-system);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  padding: 0 clamp(0.75rem, 2vw, 2rem) clamp(0.75rem, 2vw, 2rem);
  box-sizing: border-box;
  font-size: var(--font-base);
  line-height: 1.5;
}

/* ============================================
   Header / Navigation Bar
   ============================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(29, 29, 31, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 clamp(0.75rem, 2vw, 2rem);
  height: auto;
  min-height: clamp(48px, 12vw, 52px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  border-radius: 8px 8px 0 0;
  margin-bottom: 0;
  flex-wrap: wrap;
  row-gap: 0.75rem;
}

@media (max-width: 600px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    min-height: auto;
    padding: 0.75rem 0.75rem;
  }

  /* Create a button row that wraps */
  .header > .saveButton,
  .header > .export-dropdown,
  .header > #importLibrary,
  .header > #shareBtn,
  .header > #saveToFile {
    flex: 1;
    min-width: 90px;
    margin-bottom: 0.5rem;
    margin-right: 0.5rem;
  }

  .header > .saveButton:nth-last-of-type(1),
  .header > .saveButton:nth-last-of-type(2),
  .header > #saveToFile {
    margin-bottom: 0;
  }
}

/* Logo Section */
#logo {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-shrink: 0;
  margin-right: 2rem;
}

#logo h1 {
  font-size: var(--heading-h1);
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin: 0;
  padding-right: 1rem;
  border-right: 1px solid var(--border-subtle);
  line-height: 1.2;
}

#logo-sub {
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-left: 0.25rem;
  line-height: 1.2;
}

@media (max-width: 600px) {
  #logo {
    margin-right: 0;
    gap: 0.75rem;
    width: 100%;
    justify-content: center;
  }

  #logo h1 {
    border-right: none;
    padding-right: 0;
    font-size: 2.25rem;
  }

  #logo-sub {
    display: none;
  }
}

#logo-me {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 400;
  display: none;
}

@media (max-width: 600px) {
  #logo-me {
    display: none !important;
  }
}

/* Theme Switcher */
.themeWrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: capitalize;
  margin-right: 1.5rem;
}

@media (max-width: 600px) {
  .themeWrapper {
    margin-right: 0;
    order: 2;
  }
}

.theme-selector {
  padding: 6px 12px;
  font-size: var(--font-sm);
  font-weight: 500;
  font-family: var(--font-system);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1.5px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
  outline: none;
}

.theme-selector:hover {
  border-color: var(--accent-blue);
  background: var(--bg-secondary);
}

.theme-selector:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.2);
}

.theme-selector option {
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 8px;
}

/* Toggle View Switch */
.toggleWrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: capitalize;
  margin-right: 1.5rem;
}

@media (max-width: 600px) {
  .toggleWrapper {
    margin-right: 0;
    display: none;
  }
}

#toggle-view-box {
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--bg-elevated);
  position: relative;
  cursor: pointer;
  transition: var(--transition-smooth);
  border: 1.5px solid var(--border-subtle);
}

#toggle-view-box:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

#toggler {
  position: absolute;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--text-primary);
  top: 2px;
  left: 2px;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

.toggled {
  transform: translateX(20px);
}

/* Panel Selector Buttons */
.buttonContainer {
  display: flex;
  gap: 0.5rem;
  margin: 0 auto;
}

.toggleButton {
  padding: clamp(6px, 1.5vw, 8px) clamp(12px, 2vw, 16px);
  font-size: var(--font-sm);
  font-weight: 500;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: 980px;
  cursor: pointer;
  transition: var(--transition-smooth);
  white-space: nowrap;
  user-select: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggleButton:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.toggleButton.selected {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

/* Save Button */
.saveButton {
  padding: clamp(6px, 1.5vw, 8px) clamp(12px, 2vw, 16px);
  font-size: var(--font-sm);
  font-weight: 500;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 980px;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition-smooth);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
}

@media (max-width: 600px) {
  .saveButton {
    flex: 1;
    min-width: 100px;
    margin-right: 0.5rem !important;
  }

  .saveButton:last-of-type {
    margin-right: 0 !important;
  }
}

.saveButton:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-medium);
  transform: translateY(-1px);
}

.saveButton:active {
  transform: translateY(0);
}

/* ============================================
   Tab Bar
   ============================================ */
.tab-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 clamp(0.75rem, 1vw, 1rem);
  height: clamp(40px, 10vw, 42px);
  gap: 1rem;
  overflow-x: auto;
  overflow-y: hidden;
}

.tabs-container {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.tab-bar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.tabs-container::-webkit-scrollbar {
  height: 4px;
}

.tabs-container::-webkit-scrollbar-track {
  background: transparent;
}

.tabs-container::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 2px;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: clamp(6px, 1vw, 8px) clamp(12px, 1.5vw, 16px);
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  transition: var(--transition-smooth);
  white-space: nowrap;
  position: relative;
  user-select: none;
  min-height: 44px;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.tab.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-bottom: 2px solid var(--accent-blue);
}

.tab-icon {
  flex-shrink: 0;
  color: var(--accent-blue);
}

.tab-name {
  flex: 1;
}

.tab-close {
  opacity: 0;
  padding: 2px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.tab:hover .tab-close {
  opacity: 1;
}

.tab-close:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* Split-view tab indicators */
.tab.panel-1::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: rgba(100, 200, 255, 0.3);
  border-radius: 6px 0 0 0;
}

.tab.panel-2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: rgba(255, 150, 100, 0.3);
  border-radius: 6px 0 0 0;
}

.tab.active.panel-1::before {
  background: rgba(100, 200, 255, 0.8);
}

.tab.active.panel-2::before {
  background: rgba(255, 150, 100, 0.8);
}

.popout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 1.5vw, 12px);
  font-size: var(--font-sm);
  font-weight: 500;
  font-family: var(--font-system);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
}

.popout-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

/* Export Dropdown */
.export-dropdown {
  position: relative;
  display: inline-block;
  margin-right: 0.5rem;
  flex: 1;
  min-width: 100px;
}

@media (max-width: 600px) {
  .export-dropdown {
    margin-right: 0.5rem;
  }
}

/* Make export button match saveButton style */
#exportBtn {
  padding: clamp(6px, 1.5vw, 8px) clamp(12px, 2vw, 16px);
  font-size: var(--font-sm);
  font-weight: 500;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 980px;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition-smooth);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
}

#exportBtn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-medium);
  transform: translateY(-1px);
}

#exportBtn:active {
  transform: translateY(0);
}

.export-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  min-width: 150px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@media (max-width: 600px) {
  .export-menu {
    right: auto;
    left: 0;
    min-width: 100%;
  }
}

.export-menu a {
  display: block;
  padding: clamp(8px, 1.5vw, 10px) clamp(12px, 2vw, 16px);
  color: var(--text-primary);
  text-decoration: none;
  font-size: var(--font-sm);
  font-weight: 500;
  transition: var(--transition-smooth);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.export-menu a:last-child {
  border-bottom: none;
}

.export-menu a:hover {
  background: var(--accent-blue);
  color: white;
}

.export-dropdown.active .export-menu {
  display: block;
}

/* ============================================
   Content / Editor Area
   ============================================ */
.contentWrapper {
  width: calc(100vw - 16px);
  height: calc(100vh - 110px);
  display: flex;
  background: var(--bg-secondary);
  gap: 8px;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  padding-right: 4rem;
}

.wrapperToggled {
  flex-direction: column;
}

/* When wrapper is toggled (vertical layout), file explorer should overlay when collapsed */
.wrapperToggled .file-explorer {
  width: 100%;
  max-width: none;
  border-right: none;
  border-bottom: 1px solid var(--border-medium);
  position: relative;
}

.wrapperToggled .file-explorer.collapsed {
  width: 100%;
  height: 4px;
  min-height: 4px;
  border-bottom: 1px solid var(--border-medium);
  border-right: none;
  overflow: hidden;
}

@media (max-width: 600px) {
  .contentWrapper {
    width: 100vw;
    height: calc(100vh - 52px);
    padding-right: 0;
    gap: 0;
    flex-direction: column;
    position: relative;
  }
}

/* Unified Editor Container */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
  border-radius: 0 0 0 8px;
}

@media (max-width: 600px) {
  .editor-container {
    min-height: 200px;
    flex: 1;
    border-radius: 0;
    border-bottom: 1px solid var(--border-medium);
  }
}

/* Editor Header with Controls */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2vw, 12px);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  min-height: 44px;
}

.format-btn,
.split-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 1.5vw, 12px);
  font-size: var(--font-sm);
  font-weight: 500;
  font-family: var(--font-system);
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
  min-height: 44px;
}

.format-btn:hover,
.split-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.format-btn:active,
.split-toggle-btn:active {
  opacity: 0.7;
}

/* Dual Editor Panels Layout */
.editor-panels-wrapper {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

.editor-panels-wrapper.split-horizontal {
  grid-template-columns: 1fr auto 1fr;
}

.editor-panels-wrapper.split-vertical {
  grid-template-rows: 1fr auto 1fr;
  grid-template-columns: 1fr;
}

/* Editor Panel */
.editor-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
  min-height: 0;
}

/* Explicit grid positioning */
#editor-panel-1 {
  grid-row: 1;
  grid-column: 1;
}

.editor-panels-wrapper.split-horizontal #editor-panel-2 {
  grid-row: 1;
  grid-column: 3;
}

.editor-panels-wrapper.split-vertical #editor-panel-2 {
  grid-row: 3;
  grid-column: 1;
}

.editor-panels-wrapper.split-horizontal .editor-divider {
  grid-row: 1;
  grid-column: 2;
}

.editor-panels-wrapper.split-vertical .editor-divider {
  grid-row: 2;
  grid-column: 1;
}

/* Text Area Styling */
.editor-panel .text-area {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: clamp(8px, 1.5vw, 12px);
  background: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  border-radius: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: var(--font-base);
  resize: none;
  outline: none;
  overflow: auto;
}

.editor-panel .text-area:focus {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
}

/* Resizable Divider */
.editor-divider {
  background: var(--border-medium);
  user-select: none;
  transition: background 0.2s ease;
  display: none;
  z-index: 10;
}

.editor-divider:hover {
  background: var(--accent-blue);
}

/* Prevent text selection during divider drag */
body.resizing-divider {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

body.resizing-divider textarea {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Horizontal divider (between columns) - span all rows */
.editor-panels-wrapper.split-horizontal .editor-divider {
  display: block;
  width: 4px;
  cursor: col-resize;
}

/* Vertical divider (between rows) - span all columns */
.editor-panels-wrapper.split-vertical .editor-divider {
  display: block;
  height: 4px;
  cursor: row-resize;
}

/* Split Toggle Button Active State */
.split-toggle-btn.active {
  background: rgba(0, 113, 227, 0.2);
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

@media (max-width: 600px) {
  .editor-header {
    flex-direction: column;
    align-items: stretch;
  }

  .format-btn,
  .split-toggle-btn {
    flex: 1;
    width: 100%;
  }

  .split-toggle-btn {
    display: none;
  }
}

.output-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-medium);
  position: relative;
  overflow: hidden;
  border-radius: 0 0 8px 0;
}

.output-container.hidden {
  display: none;
}

@media (max-width: 600px) {
  .output-container {
    min-height: 200px;
    flex: 1;
    border-left: none;
    border-radius: 0 0 8px 8px;
  }
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2vw, 12px);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  min-height: 44px;
}

.output-close-btn {
  padding: clamp(4px, 1vw, 6px);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  min-width: 44px;
  min-height: 44px;
}

.output-close-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

/* ============================================
   File Explorer Sidebar
   ============================================ */
.file-explorer {
  width: 250px;
  min-width: 200px;
  max-width: 400px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-medium);
  border-radius: 8px 0 0 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition-smooth);
}

.file-explorer.collapsed {
  width: 4px;
  min-width: 4px;
  border-right: none;
  overflow: hidden;
}

/* On desktop, collapsed state shows 4px sliver */
@media (min-width: 601px) {
  .file-explorer.collapsed {
    width: 4px;
    min-width: 4px;
    display: flex;
    border-right: 1px solid var(--border-medium);
    overflow: hidden;
  }
}

@media (max-width: 600px) {
  .file-explorer {
    width: 100%;
    max-width: none;
    min-width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-medium);
    border-radius: 0;
    max-height: 250px;
    min-height: 120px;
    position: absolute;
    top: 52px;
    left: 0;
    z-index: 40;
    margin: 0;
    overflow-y: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  /* On mobile, collapsed state hides the file explorer */
  .file-explorer.collapsed {
    width: 100%;
    display: none;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    border-bottom: none;
    border-right: none;
  }
}

.file-explorer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.file-explorer-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.explorer-toggle {
  padding: clamp(4px, 1vw, 6px);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  min-width: 44px;
  min-height: 44px;
}

.explorer-toggle:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.file-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.file-action-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 1.5vw, 12px);
  font-size: var(--font-sm);
  font-weight: 500;
  font-family: var(--font-system);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
  width: 100%;
  text-align: left;
  min-height: 44px;
}

.file-action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.file-item,
.folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 2px 0;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition-smooth);
  user-select: none;
  position: relative;
}

.file-item:hover,
.folder-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.file-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

/* Split-view file-item indicators */
.file-item.active-panel-1::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: rgba(100, 200, 255, 0.8);
  border-radius: 50%;
}

.file-item.active-panel-2::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: rgba(255, 150, 100, 0.8);
  border-radius: 50%;
}

.file-item.active-panel-1.active-panel-2::after {
  background: linear-gradient(
    90deg,
    rgba(100, 200, 255, 0.8) 50%,
    rgba(255, 150, 100, 0.8) 50%
  );
}

.file-item svg,
.folder-item svg {
  flex-shrink: 0;
}

.file-icon {
  color: var(--accent-blue);
}

.folder-icon {
  color: #fbbf24;
}

.folder-item.open .folder-icon {
  color: #f59e0b;
}

.folder-toggle {
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  color: var(--text-secondary);
  width: 16px;
  text-align: center;
  transition: var(--transition-smooth);
}

.folder-toggle:hover {
  color: var(--text-primary);
}

.folder-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.folder-delete {
  opacity: 0;
  padding: 2px 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition-smooth);
}

.folder-item:hover .folder-delete {
  opacity: 1;
}

.folder-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.file-children {
  padding-left: 1.5rem;
  display: none;
}

.folder-item.open + .file-children {
  display: block;
}

.file-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-delete {
  opacity: 0;
  padding: 2px 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition-smooth);
}

.file-item:hover .file-delete,
.folder-item:hover .file-delete {
  opacity: 1;
}

.file-delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* Legacy Editor Panels - kept for backwards compatibility */
.html,
.css,
.javascript {
  display: none;
}

/* Format Button */
.format-btn {
  position: absolute;
  top: clamp(6px, 1vw, 8px);
  right: clamp(6px, 1vw, 8px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: clamp(6px, 1.5vw, 8px) clamp(10px, 1.5vw, 12px);
  font-size: var(--font-sm);
  font-weight: 500;
  font-family: var(--font-system);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-smooth);
  outline: none;
  opacity: 0.7;
  min-height: 44px;
  min-width: 44px;
}

.format-btn:hover {
  opacity: 1;
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.format-btn:active {
  transform: translateY(0);
}

.format-btn svg {
  flex-shrink: 0;
}

.html {
  border-left: none;
}

.javascript {
  border-right: 1px solid var(--border-medium);
}

.output {
  flex: 1;
  background: white;
  border: none;
  display: block;
  border-radius: 8px;
}

/* Textareas */
.text-area {
  width: 100%;
  height: 100%;
  padding: clamp(1rem, 2vw, 1.5rem);
  font-size: clamp(12px, 2vw, 14px);
  line-height: 1.6;
  font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Code", "Consolas",
    monospace;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  outline: none;
  resize: none;
  caret-color: var(--accent-blue);
  letter-spacing: 0.3px;
  tab-size: 4;
  -moz-tab-size: 4;
  flex: 1;
}

@media (max-width: 600px) {
  .text-area {
    padding: 0.75rem;
    font-size: 13px;
  }
}

.text-area:disabled {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

.text-area:focus {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
}

.text-area::selection {
  background: rgba(0, 113, 227, 0.3);
}

.text-area::-webkit-scrollbar {
  width: 12px;
}

.text-area::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.text-area::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 6px;
  border: 3px solid var(--bg-secondary);
}

.text-area::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Autocomplete Dropdown */
#autocomplete-dropdown {
  background: rgba(45, 45, 48, 0.95);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

#autocomplete-dropdown div {
  padding: 8px 12px;
  font-family: "SF Mono", monospace;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s ease;
  border-left: 2px solid transparent;
}

#autocomplete-dropdown div:hover {
  background: rgba(0, 113, 227, 0.2);
  border-left-color: var(--accent-blue);
}

/* Light Theme Specific Overrides */
[data-theme="light"] #autocomplete-dropdown {
  background: rgba(255, 255, 255, 0.95);
}

[data-theme="light"] .header {
  background: rgba(255, 255, 255, 0.72);
}

[data-theme="light"] .output {
  background: white;
}

[data-theme="light"] .text-area {
  color: #1d1d1f;
}

[data-theme="light"] #toggle-view-box:hover {
  border-color: rgba(0, 0, 0, 0.3);
}

/* ============================================
   States & Utilities
   ============================================ */
.hidden {
  display: none !important;
}

/* Vertical orientation (stacked panels) */
.wrapperToggled .html,
.wrapperToggled .css,
.wrapperToggled .javascript {
  border-right: none;
  border-bottom: 1px solid var(--border-medium);
}

.wrapperToggled .javascript {
  border-bottom: 1px solid var(--border-medium);
}

/* ============================================
   Responsive Design
   ============================================ */
@media screen and (max-width: 1300px) {
  #logo h1 {
    font-size: 19px;
  }

  #logo-sub {
    font-size: 11px;
  }
}

@media screen and (max-width: 1150px) {
  .header {
    padding: 0 1.5rem;
  }

  #logo-sub {
    display: none;
  }

  .toggleWrapper span {
    display: none;
  }
}

@media screen and (max-width: 980px) {
  .header {
    height: auto;
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .buttonContainer {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .saveButton {
    order: 2;
  }
}

@media screen and (max-width: 750px) {
  body {
    padding: 4px;
  }

  .contentWrapper {
    width: calc(100vw - 8px);
    height: calc(100vh - 64px);
    gap: 4px;
  }

  .header {
    margin-bottom: 4px;
  }

  /* File Explorer Mobile Styles */
  .file-explorer {
    width: 4px;
    min-width: 4px;
    max-width: none;
    border-right: 1px solid var(--border-medium);
    border-bottom: none;
    border-radius: 0;
    box-shadow: none;
    position: relative;
    transition: width 0.3s ease;
  }

  .file-explorer:not(.collapsed) {
    width: 80%;
    max-width: 300px;
  }

  .file-explorer.collapsed {
    width: 4px;
    min-width: 4px;
  }

  /* Force vertical layout on tablets and mobile */
  .contentWrapper {
    flex-direction: column !important;
  }

  .html,
  .css,
  .javascript {
    border-right: none;
    border-bottom: 1px solid var(--border-medium);
    min-height: 200px;
  }

  #logo h1 {
    font-size: 18px;
  }

  #logo-sub {
    display: none;
  }

  /* Hide orientation toggle on mobile - vertical layout is always best */
  .toggleWrapper {
    display: none;
  }

  /* Improve touch targets */
  .toggleButton {
    padding: 10px 16px;
    font-size: 13px;
    min-height: 44px;
  }

  .saveButton,
  #exportBtn {
    padding: 10px 16px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Better header layout for tablets */
  .header {
    padding: 0.75rem 1rem;
    height: auto;
  }

  #logo {
    margin-right: 1rem;
  }
}

@media screen and (max-width: 460px) {
  .header {
    padding: 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  #logo {
    width: 100%;
    margin-right: 0;
  }

  #logo h1 {
    font-size: 19px;
    border-right: none;
    padding-right: 0;
  }

  .buttonContainer {
    width: 100%;
    justify-content: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .toggleButton {
    padding: 8px 14px;
    font-size: 12px;
    min-height: 40px;
  }

  .saveButton,
  #exportBtn {
    padding: 8px 14px;
    font-size: 12px;
    min-height: 40px;
  }

  .saveButton {
    margin-left: auto;
  }

  /* Larger text for better readability on mobile */
  .text-area {
    font-size: 15px;
    padding: 1rem;
  }

  /* Ensure panels have adequate height */
  .html,
  .css,
  .javascript {
    min-height: 250px;
  }

  .output {
    min-height: 300px;
  }
}

/* Extra small devices */
@media screen and (max-width: 350px) {
  .header {
    padding: 0.5rem;
  }

  #logo h1 {
    font-size: 17px;
  }

  .buttonContainer {
    gap: 0.35rem;
  }

  .toggleButton,
  .saveButton,
  #exportBtn {
    padding: 7px 12px;
    font-size: 11px;
  }

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

/* ============================================
   Phase 2.3: Navigation Drawer & Hamburger Menu
   ============================================ */

/* Hamburger menu toggle button */
.hamburger-menu {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  transition: var(--transition-smooth);
  z-index: 101;
}

.hamburger-menu span {
  width: 24px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: var(--transition-smooth);
  transform-origin: center;
}

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

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

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

/* Mobile navigation drawer */
.mobile-drawer {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 102;
  animation: fadeIn 0.3s ease;
}

.mobile-drawer.show {
  display: block;
}

.drawer-content {
  position: absolute;
  top: 52px;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-top: none;
  border-radius: 0 0 0 12px;
  min-width: 280px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  overflow: hidden;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

.drawer-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-section:last-child {
  border-bottom: none;
}

.drawer-section-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  color: var(--text-primary);
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--font-sm);
  font-family: var(--font-system);
  width: 100%;
  text-align: left;
  transition: var(--transition-smooth);
  min-height: 44px;
}

.drawer-item:hover {
  color: var(--accent-blue);
}

.drawer-item.theme-option {
  padding-left: 24px;
}

/* Show hamburger on mobile */
@media (max-width: 600px) {
  .hamburger-menu {
    display: flex;
    order: -1;
    margin-right: auto;
  }

  /* Hide desktop-only buttons on mobile */
  .desktop-only {
    display: none !important;
  }

  /* Show mobile-only elements */
  #mobile-file-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition-smooth);
    margin-right: 0.5rem;
    min-height: 44px;
    min-width: 44px;
    flex-shrink: 0;
  }

  #mobile-file-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--accent-blue);
  }

  #mobile-file-toggle:active {
    opacity: 0.7;
  }
}

/* File explorer toggle button in tab bar */
#file-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition-smooth);
  min-height: 44px;
  min-width: 44px;
  flex-shrink: 0;
}

#file-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

#file-toggle-btn:active {
  opacity: 0.7;
}

/* ============================================
   Library Import Modal
   ============================================ */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: var(--bg-primary);
  margin: 5% auto;
  padding: 0;
  border: 1px solid var(--border-medium);
  border-radius: 12px;
  width: min(90vw, 700px);
  max-height: 80vh;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

@media (max-width: 600px) {
  .modal-content {
    width: min(90vw, 500px);
    margin: 10% auto;
    max-height: 85vh;
    border-radius: 8px;
  }
}

@media (max-width: 414px) {
  .modal-content {
    width: min(95vw, 480px);
    margin: 15% auto;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.modal-header h2 {
  margin: 0;
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 600;
  color: var(--text-primary);
}

@media (max-width: 600px) {
  .modal-header {
    padding: 1rem 1.25rem;
  }

  .modal-header h2 {
    font-size: 18px;
  }
}

.close {
  color: var(--text-secondary);
  font-size: 32px;
  font-weight: 300;
  cursor: pointer;
  transition: var(--transition-smooth);
  line-height: 1;
}

.close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: clamp(1rem, 3vw, 2rem);
  overflow-y: auto;
  flex: 1;
}

@media (max-width: 600px) {
  .modal-body {
    padding: 1rem 1.25rem;
  }
}

.search-box {
  margin-bottom: 1.5rem;
}

.search-box input {
  width: 100%;
  padding: clamp(10px, 2vw, 12px) clamp(12px, 2vw, 16px);
  font-size: var(--font-sm);
  font-family: var(--font-system);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  outline: none;
  transition: var(--transition-smooth);
  min-height: 44px;
}

.search-box input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.2);
}

.library-categories h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 1rem 0;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

@media (max-width: 600px) {
  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
  }
}

@media (max-width: 414px) {
  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
  }
}

.library-item {
  padding: clamp(0.75rem, 2vw, 1rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 100px;
}

.library-item:hover {
  border-color: var(--accent-blue);
  background: var(--bg-secondary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.library-item.selected {
  border-color: var(--accent-blue);
  background: rgba(0, 113, 227, 0.1);
}

@media (max-width: 600px) {
  .library-item {
    padding: 0.75rem;
    min-height: 90px;
  }
}

@media (max-width: 414px) {
  .library-item {
    min-height: 80px;
  }
}

.library-name {
  font-weight: 600;
  font-size: clamp(12px, 2vw, 14px);
  color: var(--text-primary);
}

.library-desc {
  font-size: clamp(10px, 1.8vw, 12px);
  color: var(--text-secondary);
  line-height: 1.3;
}

.library-version {
  font-size: clamp(9px, 1.5vw, 11px);
  color: var(--accent-blue);
  font-family: "SF Mono", monospace;
  word-break: break-word;
}

/* Share Modal Specific Styles */
.share-url-container {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-direction: column;
}

@media (min-width: 600px) {
  .share-url-container {
    flex-direction: row;
  }
}

.share-url-input {
  flex: 1;
  padding: clamp(10px, 1.5vw, 12px) clamp(12px, 2vw, 16px);
  font-size: var(--font-sm);
  font-family: "SF Mono", monospace;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  outline: none;
  min-height: 44px;
}

.copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: clamp(10px, 1.5vw, 12px) clamp(16px, 2vw, 20px);
  font-size: var(--font-sm);
  font-weight: 500;
  font-family: var(--font-system);
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
}

.copy-btn:hover {
  background: var(--accent-blue-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.copy-btn:active {
  transform: translateY(0);
}

.copy-success {
  display: none;
  padding: 12px 16px;
  background: rgba(52, 199, 89, 0.15);
  color: #34c759;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  margin-bottom: 1rem;
  animation: fadeIn 0.3s ease;
}

.copy-success.show {
  display: block;
}

.share-social {
  border-top: 1px solid var(--border-subtle);
  padding-top: 1.5rem;
}

.social-buttons {
  display: flex;
  gap: clamp(0.5rem, 2vw, 1rem);
  flex-direction: column;
}

@media (min-width: 600px) {
  .social-buttons {
    flex-direction: row;
  }
}

.social-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: clamp(10px, 2vw, 12px) clamp(16px, 2vw, 20px);
  font-size: var(--font-sm);
  font-weight: 500;
  color: white;
  text-decoration: none;
  border-radius: 8px;
  transition: var(--transition-smooth);
  flex: 1;
  justify-content: center;
  min-height: 44px;
  white-space: nowrap;
}

.social-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

@media (max-width: 600px) {
  .social-btn {
    padding: 12px 16px;
  }
}

.social-btn.twitter {
  background: #1da1f2;
}

.social-btn.twitter:hover {
  background: #1a8cd8;
}

.social-btn.linkedin {
  background: #0077b5;
}

.social-btn.linkedin:hover {
  background: #006399;
}

/* ============================================
   Smooth Animations
   ============================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#autocomplete-dropdown {
  animation: fadeIn 0.15s ease;
}

/* Panel transitions */
.html,
.css,
.javascript,
.output {
  transition: flex 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover effects for interactive elements */
.toggleButton,
.saveButton,
#exportBtn,
#toggle-view-box,
#toggler {
  will-change: transform;
}

/* ============================================
   Phase 2.1: Touch Interaction Improvements
   For devices without hover capability
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover states from dropdowns - they don't work on touch */
  .export-dropdown:hover,
  .social-btn:hover,
  .copy-btn:hover,
  .library-item:hover,
  .theme-selector:hover,
  .modal-content button:hover,
  input:hover,
  textarea:hover {
    /* Override hover background/border changes */
    background-color: inherit;
    border-color: inherit;
    transform: none;
    box-shadow: none;
  }

  /* Add active/tap states for touch feedback */
  button,
  .copy-btn,
  .social-btn,
  .library-item,
  .theme-selector,
  input,
  textarea,
  select {
    transition: background-color 0.15s ease, border-color 0.15s ease;
  }

  /* Provide visible feedback on touch/tap */
  button:active,
  .copy-btn:active,
  .social-btn:active,
  .library-item:active,
  .theme-selector:active,
  input:active,
  textarea:active,
  select:active {
    background: var(--bg-elevated);
    opacity: 0.8;
  }

  /* Focus states are critical for touch interaction */
  button:focus,
  .copy-btn:focus,
  .social-btn:focus,
  .library-item:focus,
  .theme-selector:focus,
  input:focus,
  textarea:focus,
  select:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
  }

  /* Remove transform hover effects on touch */
  .copy-btn:hover,
  .social-btn:hover,
  .library-item:hover {
    transform: none;
  }

  /* Touch-friendly export dropdown - no hover reveal */
  .export-dropdown.dropdown-menu {
    /* Always accessible, not hidden by default on hover */
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .export-dropdown.dropdown-menu.show {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
  }

  /* Tab buttons get active state */
  .tab:active {
    background: rgba(0, 113, 227, 0.2);
    border-color: var(--accent-blue);
  }

  .tab:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: -2px;
  }

  /* Format button touch feedback */
  .format-btn:active {
    background: rgba(0, 113, 227, 0.15);
  }

  /* Output close button touch feedback */
  .output-close-btn:active {
    opacity: 0.7;
  }

  /* File explorer toggle touch feedback */
  .explorer-toggle:active {
    opacity: 0.8;
  }

  /* Autocomplete dropdown - ensure it's tappable */
  #autocomplete-dropdown {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-medium);
  }

  #autocomplete-dropdown div:active {
    background: var(--bg-elevated);
  }

  /* Modal interactions */
  .modal-content button:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
  }

  /* Remove pointer cursors where not actionable */
  .modal-header,
  .library-desc,
  .library-version {
    cursor: auto;
  }
}

/* ============================================
   Focus Visible Improvements
   Better keyboard and touch navigation
   ============================================ */
/* Only show focus outline for keyboard navigation, not mouse clicks */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.tab:focus-visible,
.library-item:focus-visible,
.copy-btn:focus-visible,
.social-btn:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Remove default focus styles on mouse click */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================
   High Contrast Mode Support
   Better visibility on touch devices
   ============================================ */
@media (prefers-contrast: more) {
  button,
  .copy-btn,
  .social-btn,
  .tab {
    border: 2px solid var(--border-medium);
  }

  button:active,
  .copy-btn:active,
  .social-btn:active,
  .tab:active {
    border-color: var(--accent-blue);
  }
}

/* ============================================
   Phase 2.4: Editor Controls Optimization
   Format button, tabs, and output controls
   ============================================ */

/* Format Button Mobile Optimization */
@media (max-width: 600px) {
  .format-btn {
    top: 0.5rem;
    right: 0.5rem;
    padding: 8px 12px;
    font-size: 12px;
    gap: 4px;
  }

  .format-btn span {
    display: none;
  }
}

/* Tab Bar Responsiveness */
.tabs-container {
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
}

@media (max-width: 600px) {
  .tabs-container {
    min-height: 44px;
    max-height: 44px;
  }

  .tab {
    padding: 6px 10px;
    gap: 4px;
    min-width: 100px;
  }

  .tab-name {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tab-icon {
    display: none;
  }

  .tab-close {
    min-width: 20px;
    min-height: 20px;
  }
}

/* Output Container Mobile Optimization */
#output-container {
  display: flex;
  flex-direction: column;
}

@media (max-width: 600px) {
  #output-container {
    min-height: 200px;
    max-height: calc(100vh - 52px);
  }
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(0.75rem, 2vw, 1rem);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 44px;
}

.output-header h3 {
  margin: 0;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.output-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition-smooth);
  font-size: 18px;
  min-height: 44px;
  min-width: 44px;
}

.output-close-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

/* File Explorer Toggle Mobile */
.explorer-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: clamp(6px, 1.5vw, 10px) clamp(12px, 2vw, 16px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: var(--font-sm);
  cursor: pointer;
  transition: var(--transition-smooth);
  min-height: 44px;
}

.explorer-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: rgba(255, 255, 255, 0.05);
}

/* Responsive Editor Container */
.content-wrapper {
  display: flex;
  flex: 1;
}

@media (max-width: 600px) {
  .content-wrapper {
    flex-direction: column;
  }
}

/* Editor Panels Mobile */
.editor-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 200px;
  position: relative;
}

@media (max-width: 600px) {
  .editor-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-medium);
    max-height: 300px;
  }

  .editor-panel:last-child {
    border-bottom: none;
  }
}

/* ============================================
   Phase 3: Advanced Optimizations
   ============================================ */

/* 3.2 Landscape Mode Handling */
@media (max-height: 500px) and (orientation: landscape) {
  /* Compact header for landscape */
  .header {
    min-height: auto;
    padding: 0.5rem 0.75rem;
    row-gap: 0.25rem;
  }

  /* Hide logo subtitle in landscape */
  #logo-sub {
    display: none !important;
  }

  /* Reduce icon and button sizing in landscape */
  .hamburger-menu {
    width: 40px;
    height: 40px;
  }

  .theme-selector {
    padding: 4px 10px;
    font-size: 11px;
  }

  .saveButton {
    padding: 6px 12px;
    font-size: 11px;
    min-height: 36px;
  }

  /* Compact editor panels */
  .editor-panel {
    min-height: 150px;
    max-height: 200px;
  }

  #output-container {
    max-height: 200px;
  }

  /* Reduce tab height in landscape */
  .tabs-container {
    min-height: 36px;
    max-height: 36px;
  }

  .tab {
    padding: 4px 8px;
    min-height: 36px;
  }

  /* Hide drawer on landscape (side-by-side is better) */
  .mobile-drawer {
    display: none !important;
  }

  .hamburger-menu {
    display: none !important;
  }
}

/* Very small landscape (max-height: 400px) */
@media (max-height: 400px) {
  .header {
    min-height: auto;
    padding: 0.5rem 0.5rem;
  }

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

  .editor-panel {
    min-height: 120px;
  }

  .tab {
    padding: 3px 6px;
    font-size: 10px;
  }
}

/* 3.3 Dark/Light Theme Mobile Optimization */
[data-theme="light"] {
  /* Increase contrast for light theme on small screens */
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
}

@media (prefers-color-scheme: light) and (max-width: 600px) {
  body {
    /* Slightly darker background for readability on small displays */
    --bg-primary: #f5f5f7;
  }
}

/* Improve contrast for outdoor viewing */
@media (prefers-contrast: more) {
  .header {
    border-bottom: 2px solid var(--border-medium);
  }

  .tab.active {
    border-bottom: 3px solid var(--accent-blue);
  }

  .modal-content {
    border: 2px solid var(--border-medium);
  }
}

/* 3.4 Accessibility Improvements */

/* Enhanced focus indicators */
:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Reduced motion for users with vestibular disorders */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .hamburger-menu span {
    transition: none;
  }

  .mobile-drawer {
    animation: none !important;
  }

  .drawer-content {
    animation: none !important;
  }

  #autocomplete-dropdown {
    animation: none !important;
  }
}

/* ARIA live regions for screen readers */
[role="status"],
[role="alert"],
[aria-live],
[aria-label] {
  outline: none;
}

/* Better keyboard navigation for touch devices */
@media (hover: none) and (pointer: coarse) {
  /* Show keyboard indicator for non-mouse users */
  :focus:not(:focus-visible) {
    outline: none;
  }

  :focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 1px;
  }
}

/* Ensure sufficient color contrast */
.text-primary {
  color: var(--text-primary);
}

.text-secondary {
  color: var(--text-secondary);
}

/* Improve readability with line-height on mobile */
@media (max-width: 600px) {
  p,
  .library-desc,
  .modal-body {
    line-height: 1.6;
    letter-spacing: 0.3px;
  }
}
