/* ============================================================
   styles/map.css
   ============================================================ */

/*
 * WHAT: Responsive interactive MandArt map presentation.
 *
 * WHY: Support mathematical discovery while preserving
 *      Bruce H. Johnson's original map.
 *
 * REQ: Preserve the original image aspect ratio.
 * REQ: Keep SVG overlays aligned with original image pixels.
 * REQ: Use existing neutral surfaces and accent colors.
 * REQ: Support desktop, tablet, and phone interactions.
 * REQ: Provide accessible region selection controls.
 *
 * OBS: The map can be embedded in Gallery or Explore.
 */

/* ============================================================
   MAP CONTAINER
   ============================================================ */

@media screen {
  .mandart-map {
    display: flex;
    flex-direction: column;

    min-width: 0;
    width: 100%;
    box-sizing: border-box;

    gap: var(--ui-space-md);
    padding: var(--ui-space-md);

    background: var(--ui-surface);
    color: var(--ui-text);

    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
  }

  .mandart-map-heading {
    margin: 0;

    color: var(--ui-text);
    font-size: 1.125rem;
    font-weight: 500;
    text-align: left;
  }

  .mandart-map-instructions {
    margin: 0;

    color: var(--ui-text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
    text-align: left;
  }

  /* ==========================================================
     ORIGINAL MAP IMAGE AND OVERLAY
     ========================================================== */

  .mandart-map-viewport {
    position: relative;

    width: 100%;
    max-width: 900px;

    margin-inline: auto;

    overflow: hidden;

    cursor: default;
    user-select: none;
  }

  .mandart-map-viewport.is-selectable {
    cursor: crosshair;
  }

  /*
   * REQ: Preserve original image dimensions and proportions.
   * WHY: The SVG overlay uses original image pixel coordinates.
   */

  .mandart-map-image {
    display: block;

    width: 100%;
    max-width: none;
    height: auto;

    margin: 0;
    padding: 0;

    border: 0;
    border-radius: 0;

    user-select: none;
  }

  .mandart-map-overlay {
    position: absolute;
    inset: 0;

    display: block;

    width: 100%;
    height: 100%;

    /*
     * WHY: Pointer coordinates are interpreted relative
     *      to the original map image.
     */
    pointer-events: none;
  }

  /* ==========================================================
     MATHEMATICAL REGION OVERLAYS
     ========================================================== */

  /*
   * WHY: Highlight regions containing matching artwork
   *      without hiding the original mathematical map.
   */

  .mandart-map-region-available {
    fill: var(--ui-accent);
    fill-opacity: 0.4;

    stroke: var(--ui-accent);
    stroke-width: 1;
    stroke-opacity: 0.9;

    vector-effect: non-scaling-stroke;
  }

  /*
   * WHY: The selected region needs greater visual emphasis
   *      than surrounding available regions.
   */

  .mandart-map-region-selected {
    fill: var(--ui-accent);
    fill-opacity: 0.75;

    stroke: #ffffff;
    stroke-width: 2;

    vector-effect: non-scaling-stroke;
  }

  .mandart-map-region-hovered {
    fill: none;

    stroke: var(--ui-accent);
    stroke-width: 2;

    vector-effect: non-scaling-stroke;
  }

  /* ==========================================================
     MATHEMATICAL LOCATION MARKER
     ========================================================== */

  .mandart-map-crosshair {
    stroke: var(--ui-accent);
    stroke-width: 2;

    vector-effect: non-scaling-stroke;
  }

  .mandart-map-marker {
    fill: none;

    stroke: var(--ui-accent);
    stroke-width: 2;

    vector-effect: non-scaling-stroke;
  }

  /* ==========================================================
     MAP LEGEND
     ========================================================== */

  .mandart-map-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;

    gap: var(--ui-space-md);

    color: var(--ui-text-secondary);
    font-size: 0.75rem;
  }

  .mandart-map-legend-item {
    display: inline-flex;
    align-items: center;

    gap: var(--ui-space-xs);
  }

  .mandart-map-swatch {
    display: inline-block;

    width: 14px;
    height: 14px;
    box-sizing: border-box;

    flex-shrink: 0;
  }

  .mandart-map-swatch-available {
    background: var(--ui-accent);
    border: 1px solid var(--ui-accent);
    opacity: 0.6;
  }

  .mandart-map-swatch-selected {
    background: var(--ui-accent);
    border: 2px solid #ffffff;
  }

  /* ==========================================================
     ACCESSIBLE REGION CONTROLS
     ========================================================== */

  .mandart-map-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;

    gap: var(--ui-space-md);
  }

  .mandart-map-controls[hidden] {
    display: none;
  }

  .mandart-map-region-label {
    display: flex;
    flex-direction: column;

    min-width: 0;

    gap: var(--ui-space-xs);

    color: var(--ui-text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
  }

  .mandart-map-region-select {
    width: 100%;
    min-width: 0;
    min-height: var(--ui-target-size);
    box-sizing: border-box;

    margin: 0;
    padding: var(--ui-space-sm) var(--ui-space-md);

    background: var(--ui-surface-raised);
    color: var(--ui-text);

    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);

    font-family: inherit;
    font-size: 0.9375rem;
  }

  .mandart-map-clear {
    min-height: var(--ui-target-size);

    padding: var(--ui-space-sm) var(--ui-space-md);

    background: var(--ui-accent);
    color: var(--ui-accent-text);

    border: 1px solid transparent;
    border-radius: var(--ui-radius-sm);

    font-weight: 600;
    white-space: nowrap;
  }

  .mandart-map-clear:hover:not(:disabled) {
    background: var(--ui-accent-hover);
  }

  .mandart-map-clear:disabled {
    background: var(--ui-surface);
    color: var(--ui-text-secondary);

    border-color: var(--ui-border);

    opacity: 0.45;
    cursor: default;
  }

  .mandart-map-region-select:focus-visible,
  .mandart-map-clear:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }

  /* ==========================================================
     MAP SELECTION INFORMATION
     ========================================================== */

  .mandart-map-status {
    min-height: 1.5em;
    margin: 0;

    color: var(--ui-text);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;

    overflow-wrap: anywhere;
  }

  .mandart-map-hover-status {
    min-height: 1.5em;
    margin: 0;

    color: var(--ui-text-secondary);
    font-size: 0.8125rem;
    text-align: left;
  }

  /* ==========================================================
     TABLET AND PHONE
     ========================================================== */

  @media (max-width: 600px) {
    .mandart-map {
      padding: var(--ui-space-sm);
      gap: var(--ui-space-sm);
    }

    .mandart-map-heading {
      font-size: 1rem;
    }

    .mandart-map-legend {
      gap: var(--ui-space-sm);
      font-size: 0.6875rem;
    }

    .mandart-map-controls {
      gap: var(--ui-space-sm);
    }

    .mandart-map-region-select {
      font-size: 1rem;
    }

    .mandart-map-clear {
      font-size: 0.8125rem;
    }

    /*
     * WHY: Touch devices do not have a persistent hover
     *      interaction. Avoid reserving unnecessary space.
     */

    .mandart-map-hover-status {
      display: none;
    }
  }
}
