/**
 * Responsive Design Enhancements
 * Mobile-first responsive improvements for the hacking game
 */

/* ====================================
   MOBILE OPTIMIZATIONS
   ==================================== */

/* Touch-friendly sizes */
@media (max-width: 768px) {
  /* Larger touch targets */
  .btn,
  button,
  a {
    min-height: 44px;
    min-width: 44px;
  }

  /* Improved button spacing */
  .btn {
    padding: 12px 16px;
    font-size: 11px;
  }

  /* Stack buttons vertically */
  .row {
    flex-direction: column;
    gap: 10px;
  }

  /* Full-width buttons on mobile */
  .btn {
    width: 100%;
  }

  /* Larger text for readability */
  body {
    font-size: 14px;
  }

  /* Terminal adjustments */
  .terminal {
    height: 150px;
    font-size: 11px;
    padding: 10px;
  }

  .cmdline input {
    font-size: 14px;
    padding: 12px;
  }

  /* Stats adjustments */
  .stat .val {
    font-size: 22px;
  }

  .stat .label {
    font-size: 10px;
  }

  /* Mission items */
  .op {
    padding: 12px;
  }

  .mission-title {
    font-size: 13px;
  }

  .mission-meta {
    font-size: 11px;
  }

  /* Panel padding */
  .panel {
    padding: 16px;
  }

  /* Map controls */
  #advancedMapControls {
    bottom: 10px;
    left: 10px;
  }

  #mapSearchControl {
    top: 10px;
    width: calc(100% - 20px);
  }

  /* Notification positioning */
  .notification {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }

  /* View toggle */
  .view-toggle {
    top: 10px;
    right: 10px;
  }

  .view-toggle button {
    padding: 6px 8px;
    font-size: 12px;
  }

  /* Theme switcher */
  .theme-switcher {
    top: 10px;
    left: 10px;
  }

  .theme-switcher button {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }
}

/* ====================================
   SMALL MOBILE DEVICES
   ==================================== */

@media (max-width: 480px) {
  /* Even smaller spacing */
  .app {
    padding: 8px;
    gap: 10px;
  }

  /* Compact panel */
  .panel {
    padding: 12px;
    border-radius: 6px;
  }

  /* Section headers */
  .section-title {
    font-size: 11px;
  }

  /* Stats grid */
  .hud-row {
    flex-direction: column;
    gap: 8px;
  }

  .stat {
    padding: 12px;
  }

  .stat .val {
    font-size: 20px;
  }

  .stat .label {
    font-size: 9px;
  }

  /* Logo */
  .logo {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  /* Terminal */
  .terminal {
    height: 120px;
    font-size: 10px;
    padding: 8px;
  }

  .cmdline {
    flex-direction: column;
  }

  .cmdline input {
    font-size: 13px;
  }

  /* Buttons */
  .btn {
    padding: 10px 14px;
    font-size: 10px;
  }

  /* Mission items */
  .op {
    padding: 10px;
  }

  .mission-title {
    font-size: 12px;
  }

  .mission-meta {
    font-size: 10px;
  }

  /* Map controls - stack vertically */
  #advancedMapControls {
    flex-direction: row;
    flex-wrap: wrap;
    max-width: calc(100vw - 40px);
  }

  .map-control-btn {
    width: 32px !important;
    height: 32px !important;
    font-size: 14px !important;
  }

  /* Search control */
  #mapSearchControl {
    top: 60px;
    width: calc(100% - 20px);
  }

  /* Keyboard shortcuts button */
  #keyboardShortcutsHelp {
    bottom: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
  }

  /* Modal adjustments */
  #shortcutsModal {
    max-width: calc(100vw - 40px);
    padding: 16px;
  }

  /* Filter panel */
  #missionFilterPanel {
    right: 10px;
    left: 10px;
    max-width: none;
    transform: translateY(-50%);
  }
}

/* ====================================
   LANDSCAPE MOBILE
   ==================================== */

@media (max-width: 900px) and (orientation: landscape) {
  .app {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }

  .center {
    order: 1;
    grid-column: 1 / 3;
  }

  .left {
    order: 2;
  }

  .right {
    order: 3;
  }

  /* Reduce heights in landscape */
  .terminal {
    height: 100px;
  }

  .left,
  .right {
    max-height: calc(100vh - 60px);
  }
}

/* ====================================
   TABLET OPTIMIZATIONS
   ==================================== */

@media (min-width: 769px) and (max-width: 1024px) {
  .app {
    grid-template-columns: 280px 1fr 280px;
    gap: 12px;
  }

  .panel {
    padding: 18px;
  }

  .stat .val {
    font-size: 22px;
  }

  .terminal {
    height: 180px;
  }

  /* Optimize map controls for tablet */
  #advancedMapControls {
    bottom: 20px;
    left: 20px;
  }

  #mapSearchControl {
    top: 70px;
    max-width: 450px;
  }
}

/* ====================================
   TOUCH DEVICE ENHANCEMENTS
   ==================================== */

@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .btn:hover,
  .stat:hover,
  .op:hover {
    transform: none;
  }

  /* Use active states instead */
  .btn:active {
    transform: scale(0.95);
  }

  .stat:active {
    transform: translateY(-2px);
  }

  .op:active {
    transform: translateX(4px);
  }

  /* Larger tap targets */
  button,
  a,
  .btn,
  .map-control-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Remove small hover tooltips on touch */
  .tooltip::before,
  .tooltip::after {
    display: none;
  }

  /* Use tap-based tooltips instead */
  .tooltip {
    position: relative;
  }

  .tooltip.active::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    display: block;
  }

  /* Increase scrollbar size for touch */
  ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
  }

  ::-webkit-scrollbar-thumb {
    border-radius: 6px;
  }
}

/* ====================================
   FOLDABLE DEVICES
   ==================================== */

@media (min-width: 280px) and (max-width: 653px) and (orientation: portrait) {
  /* Ultra-narrow phones */
  .app {
    padding: 6px;
    gap: 8px;
  }

  .panel {
    padding: 10px;
  }

  .stat .val {
    font-size: 18px;
  }

  .terminal {
    height: 100px;
    font-size: 9px;
  }

  .btn {
    font-size: 9px;
    padding: 8px 12px;
  }
}

/* ====================================
   HIGH DPI DISPLAYS
   ==================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Sharper borders */
  .panel,
  .btn,
  .stat,
  .op {
    border-width: 0.5px;
  }

  /* Crisper text */
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* ====================================
   REDUCED MOTION
   ==================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  /* Keep essential animations but reduce them */
  .loading-spinner {
    animation: spin 2s linear infinite !important;
  }
}

/* ====================================
   DARK MODE PREFERENCE
   ==================================== */

@media (prefers-color-scheme: dark) {
  /* Already dark by default, but ensure consistency */
  body {
    background: var(--bg);
    color: var(--muted);
  }
}

/* ====================================
   PRINT STYLES
   ==================================== */

@media print {
  /* Hide interactive elements */
  .btn,
  button,
  .view-toggle,
  .theme-switcher,
  #advancedMapControls,
  #mapSearchControl,
  #keyboardShortcutsHelp,
  .notification {
    display: none !important;
  }

  /* Optimize layout for printing */
  .app {
    display: block;
    padding: 0;
  }

  .panel {
    page-break-inside: avoid;
    border: 1px solid #000;
    box-shadow: none;
    margin-bottom: 20px;
  }

  /* Print-friendly colors */
  body {
    background: white;
    color: black;
  }

  .stat .val,
  .mission-title {
    color: black;
  }
}

/* ====================================
   ACCESSIBILITY ENHANCEMENTS
   ==================================== */

/* High contrast mode */
@media (prefers-contrast: high) {
  body {
    --border-color: #fff;
    --muted: #fff;
  }

  .panel,
  .btn,
  .stat {
    border-width: 2px;
  }

  button:focus,
  a:focus,
  input:focus {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
  }
}

/* Larger text preference */
@media (prefers-reduced-transparency: reduce) {
  .panel,
  .modal-backdrop,
  #advancedMapControls,
  #mapSearchControl {
    backdrop-filter: none;
    background: var(--panel);
  }
}

/* ====================================
   SAFE AREA INSETS (iOS)
   ==================================== */

@supports (padding-top: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .view-toggle {
    top: calc(10px + env(safe-area-inset-top));
  }

  .theme-switcher {
    top: calc(10px + env(safe-area-inset-top));
  }

  #advancedMapControls {
    bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .notification {
    top: calc(20px + env(safe-area-inset-top));
  }
}

/* ====================================
   CONTAINER QUERIES (Future-proof)
   ==================================== */

@container (max-width: 400px) {
  .panel {
    padding: 12px;
  }

  .stat .val {
    font-size: 18px;
  }
}

/* ====================================
   ORIENTATION SPECIFIC
   ==================================== */

/* Portrait mode optimizations */
@media (orientation: portrait) and (max-width: 768px) {
  /* Stack all panels vertically */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  /* Full-width map */
  .center {
    min-height: 50vh;
  }

  /* Scrollable side panels */
  .left,
  .right {
    max-height: none;
    overflow-y: visible;
  }
}

/* Landscape mode optimizations */
@media (orientation: landscape) and (max-height: 500px) {
  /* Compact header */
  .brand {
    font-size: 16px;
  }

  .logo {
    width: 36px;
    height: 36px;
  }

  /* Minimize vertical space */
  .panel {
    padding: 10px;
  }

  .section-header {
    margin-bottom: 8px;
  }

  /* Compact terminal */
  .terminal {
    height: 80px;
    font-size: 9px;
  }

  /* Hide non-essential elements in very short landscape */
  #visualPolishUI {
    display: none;
  }
}

