/* Hide mobile elements on desktop by default */
.mobile-tab-bar,
.mobile-panels {
  display: none;
}

/* Mobile Tab Bar UI */
@media (max-width: 768px) {

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

  /* Hide any desktop shape library elements */
  .shape-palette,
  .shape-targets,
  .shape-category {
    display: none !important;
  }

  /* Canvas takes space above panels and tab bar */
  .canvas-container {
    width: 100%;
    height: calc(100vh - 50px);
    /* Leave room for tab bar */
    height: calc(100dvh - 50px);
    /* Dynamic viewport height for mobile */
    position: relative;
    z-index: 1;
  }

  /* Mobile Tab Bar - fixed at bottom */
  .mobile-tab-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--panel-bg);
    border-top: 1px solid var(--border-color);
    z-index: 9999;
  }

  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--panel-text);
    opacity: 0.6;
    padding: 4px;
    cursor: pointer;
    transition: opacity 0.2s, color 0.2s;
  }

  .tab-btn.active {
    opacity: 1;
    color: var(--primary-color);
  }

  .tab-btn svg {
    width: 22px;
    height: 22px;
  }

  .tab-btn span {
    font-size: 10px;
    font-weight: 500;
  }

  /* Mobile Panels - above tab bar */
  .mobile-panels {
    display: block !important;
    position: fixed;
    bottom: 50px;
    bottom: calc(50px + env(safe-area-inset-bottom, 0));
    left: 0;
    right: 0;
    max-height: 45vh;
    background: var(--panel-bg);
    border-top: 1px solid var(--border-color);
    z-index: 9998;
    overflow: hidden;
  }

  .mobile-panel {
    display: none;
    padding: 12px 16px;
    overflow-y: auto;
    max-height: 45vh;
  }

  .mobile-panel.active {
    display: block;
  }

  /* Panel collapsed state */
  .mobile-panels.collapsed {
    display: none !important;
  }

  /* Mobile control styles within panels */
  .mobile-panel .control-group {
    margin-bottom: 12px;
  }

  .mobile-panel label {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--panel-text);
  }

  .mobile-panel input[type="range"] {
    width: 100%;
    height: 36px;
  }

  .mobile-panel input[type="number"] {
    width: 70px;
    padding: 8px;
    font-size: 16px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--panel-text);
  }

  .mobile-panel input[type="color"] {
    width: 50px;
    height: 36px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }

  .mobile-panel .radio-group {
    display: flex;
    gap: 16px;
  }

  .mobile-panel .radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
  }

  .mobile-panel .button-group {
    display: flex;
    gap: 8px;
  }

  .mobile-panel .btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 16px;
    min-height: 44px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--panel-text);
    cursor: pointer;
  }

  .mobile-panel .btn-primary {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
  }

  /* Checkbox styling */
  .mobile-panel input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 8px;
  }

  /* Select dropdown styling */
  .mobile-select {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--panel-text);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23e0e0e0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
  }

  .mobile-select:focus {
    outline: none;
    border-color: var(--primary-color);
  }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-panels {
    max-height: 60vh;
  }

  .mobile-panel {
    max-height: 60vh;
  }
}

/* Compact row layout for mobile density (Global mobile styles) */
.mobile-panel .control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  /* Reduced from default 12px */
}

.mobile-panel .control-row label {
  margin-bottom: 0;
  white-space: nowrap;
  min-width: 80px;
  /* Ensure labels align nicely */
  font-size: 13px;
}

.mobile-panel .control-row input[type="range"] {
  flex: 1;
  height: 32px;
  /* Slightly reduced height */
}

.mobile-panel .control-row input[type="color"] {
  height: 32px;
}

/* Compact divider */
.mobile-panel .control-divider {
  height: 1px;
  background: var(--border-color);
  margin: 8px 0;
  opacity: 0.5;
}

.mobile-panel .control-header {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary-color);
  margin-bottom: 6px;
  font-weight: 600;
}

/* Super Density Styles */

/* Grid layout for side-by-side controls */
.mobile-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

/* Inline input row (e.g. Color + Slider) */
.mobile-row-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0 8px;
  /* Padding inside the container */
}

.mobile-row-inline label {
  margin: 0;
  font-size: 13px;
  white-space: nowrap;
  min-width: auto;
  color: var(--panel-text);
}

/* Small color square */
.mobile-color-compact {
  width: 24px !important;
  height: 24px !important;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

/* Remove border/background from inputs inside inline row to blend in */
.mobile-row-inline input[type="range"] {
  border: none;
  background: transparent;
  height: 28px;
  /* Even smaller */
  padding: 0;
  margin: 0;
}

/* tighter vertical rhythm */
.mobile-panel .control-row {
  margin-bottom: 4px;
  /* Reduced further */
  gap: 8px;
}

.mobile-panel .control-header {
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  opacity: 0.8;
}

/* Reduce divider size */
.mobile-panel .control-divider {
  margin: 4px 0;
}

/* Shape properties visibility */
.shape-props-row {
  display: none;
}

.shape-props-row.active {
  display: grid;
  /* for mobile-2col */
}

/* Ensure single column rows show up as block/flex when active */
.control-row.shape-props-row.active {
  display: flex;
}