/* ============================================================
   styles/studio.css
   ============================================================ */

/*
 * WHAT: MandArt artistic workspace presentation.
 * WHY: Keep the artwork visually dominant while providing
 *      consistent, accessible creative controls.
 *
 * REQ: Preserve the existing artwork palette and color mapping.
 * REQ: Use neutral interface surfaces.
 * REQ: Use lime green as the primary interactive accent.
 * REQ: Support mouse, keyboard, and touch interaction.
 * REQ: Preserve all existing functional DOM identifiers.
 */

@media screen {
  /* ==========================================================
     === EXISTING THEME INTEGRATION ===
     ========================================================== */

  :root {
    color-scheme: dark;

    --primary-color: var(--ui-accent);
    --primary-hover: var(--ui-accent-hover);
    --secondary-color: var(--ui-accent);
    --accent-color: var(--ui-accent);

    --background-color: var(--ui-background);
    --surface-color: var(--ui-surface);
    --header-bg: var(--ui-surface);
    --text-color: var(--ui-text);
    --text-light: var(--ui-text);
    --border-color: var(--ui-border);
  }

  button,
  input,
  select,
  textarea {
    font-family: inherit;
  }

  button,
  select,
  input[type="color"] {
    touch-action: manipulation;
  }

  button:focus-visible,
  select:focus-visible,
  input:focus-visible,
  textarea:focus-visible,
  a:focus-visible,
  [tabindex]:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 3px;
  }

  a {
    color: var(--ui-text-secondary);
    text-underline-offset: 3px;
  }

  a:hover {
    color: var(--ui-accent);
  }

  /* ==========================================================
     === APPLICATION HEADER ===
     ========================================================== */

  header {
    gap: var(--ui-space-md);
    padding: var(--ui-space-md) var(--ui-space-lg);
  }

  header #appTitle {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  /* Primary workspace navigation. */
#workspaceNav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--ui-space-sm);
}

  /* File opening and export controls. */
  #controlsContainer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: var(--ui-space-sm);
    width: 100%;
  }

  .header-btn {
    min-height: 40px;
    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-size: 0.875rem;
  }

  .header-btn:hover {
    background: var(--ui-border);
  }

  /* Primary discovery action. */

  #openCatalogBtn {
    background: var(--ui-accent);
    color: var(--ui-accent-text);
    border-color: var(--ui-accent);
    font-weight: 600;
  }

  #openCatalogBtn:hover {
    background: var(--ui-accent-hover);
  }

  /* ==========================================================
     === ARTWORK CANVAS ===
     ========================================================== */

  #canvasSection {
    gap: var(--ui-space-sm);
    background: transparent;
  }

  #canvasSection h2 {
    width: 100%;
    margin: 0;
    padding-block: var(--ui-space-xs);

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

  #canvasContainer {
    background: var(--ui-canvas-background);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
  }

  /*
   * REQ: Display scaling must preserve the canvas aspect ratio.
   * REQ: Do not modify intrinsic computational dimensions.
   */

  #canvas {
    display: block;
    max-width: 100%;
    height: auto;
  }

  #drawingName {
    font-size: 1rem;
    font-weight: 500;
    color: var(--ui-text-secondary);
  }

  #download-container,
  #download-container-mandart {
    min-height: 0;
    margin: 0;
    overflow-wrap: anywhere;
  }

  #download-container:empty,
  #download-container-mandart:empty {
    display: none;
  }

  /* ==========================================================
     === COLOR EDITOR ===
     ========================================================== */

  #colorEditor {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;

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

  #colorEditor h2 {
    margin: 0;

    font-size: 1.125rem;
    font-weight: 600;
    text-align: left;
  }

  #mandColorContainer {
    display: flex;
    align-items: center;
    justify-content: space-between;

    margin: 0;
    padding-block: var(--ui-space-sm);
    border-bottom: 1px solid var(--ui-border);
  }

  #mandColorPicker,
  .color-picker {
    width: 44px;
    height: 44px;

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

    background: transparent;
    flex-shrink: 0;
  }

  .color-picker:hover {
    transform: none !important;
  }

  #addColorBtn {
    width: 100%;
    max-width: none;
    min-height: 44px;
    margin: 0;

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

    font-weight: 600;
    border-radius: var(--ui-radius-sm);
  }

  #addColorBtn:hover {
    background: var(--ui-accent-hover);
    opacity: 1;
  }

  #hueList {
    width: 100%;
    min-width: 0;
  }

  .hue-row {
    display: flex;
    align-items: center;

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

    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-border);
  }

  .hue-row:hover {
    background: var(--ui-surface-raised);
  }

  .hue-row .color-picker {
    flex: 1;
    min-width: 44px;
    width: auto;
  }

  .drag-handle {
    align-items: center;
    justify-content: center;

    width: 36px;
    min-width: 36px;
    height: 44px;

    margin: 0;
    opacity: 1;
  }

  .grip-line {
    background: var(--ui-text-muted);
  }

  .delete-btn {
    width: 44px;
    max-width: none;
    height: 44px;
    margin: 0;

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

    border: 1px solid var(--ui-border);
    flex-shrink: 0;
  }

  .delete-btn:hover {
    background: var(--ui-border) !important;
    color: var(--ui-text) !important;
  }

  /* ==========================================================
     === PALETTE REORDERING ===
     ========================================================== */

  /*
   * WHY: Override temporary debugging colors in the legacy
   *      stylesheet while preserving the existing behavior.
   */

  /* ==========================================================
     === PALETTE DIRECT MANIPULATION ===
     ========================================================== */

  .drag-handle {
    touch-action: none;
    user-select: none;

    padding: 0;

    background: transparent;
    border: 0;
    border-radius: var(--ui-radius-sm);
  }

  .drag-handle:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }

  .palette-reordering .hue-row {
    position: relative;
    transition: transform 160ms ease-out;
  }

  .palette-reordering .hue-row.palette-reorder-lifted {
    z-index: 10;

    background: var(--ui-surface-raised);
    outline: 2px solid var(--ui-accent);

    box-shadow: 0 6px 16px rgb(0 0 0 / 25%);

    transition: none;
    will-change: transform;
  }

  .palette-reorder-lifted .drag-handle {
    cursor: grabbing;
  }

  .palette-move-controls {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .palette-move-controls button {
    min-width: 44px;
    min-height: 24px;

    margin: 0;
    padding: 0;

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

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

    font-size: 0.875rem;
    cursor: pointer;
  }

  .palette-move-controls button:hover:not(:disabled) {
    border-color: var(--ui-accent);
  }

  .palette-move-controls button:disabled {
    opacity: 0.35;
    cursor: default;
  }

  /* ==========================================================
     === PALETTE EDITING ACTIONS ===
     ========================================================== */

  .palette-edit-controls {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;

    gap: 2px;
  }

  .palette-edit-controls button {
    box-sizing: border-box;

    width: 44px;
    min-width: 44px;
    max-width: none;

    height: 24px;
    min-height: 24px;

    margin: 0;
    padding: 0;

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

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

    font-size: 0.875rem;
    cursor: pointer;
  }

  .palette-edit-controls button:hover {
    background: var(--ui-surface-raised) !important;
    color: var(--ui-text) !important;

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

  .palette-edit-controls button:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
  }

  @media (prefers-reduced-motion: reduce) {
    .palette-reordering .hue-row {
      transition: none;
    }
  }

  /* ==========================================================
     === ADVANCED COLOR SETTINGS ===
     ========================================================== */

  #colorSettings {
    min-width: 0;
    margin: 0;
    padding: var(--ui-space-md);

    color: var(--ui-text-secondary);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
  }

  #colorSettings legend {
    padding-inline: var(--ui-space-sm);
    font-size: 0.875rem;
    text-align: left;
  }

  #colorSettingsControls label {
    font-size: 0.875rem;
  }

  #colorSettingsControls input[type="range"] {
    display: block;
    width: 100%;
    margin-block: var(--ui-space-sm) var(--ui-space-lg);
    accent-color: var(--ui-accent);
  }

  input:checked + .slider {
    background: var(--ui-accent);
  }

  .slider {
    background: var(--ui-border-strong);
  }

  .switch:focus-within {
    outline: 2px solid var(--ui-accent);
    outline-offset: 3px;
  }

  /* ==========================================================
     === EXISTING DIALOG CONTROLS ===
     ========================================================== */

  .url-modal {
    background: var(--ui-surface);
    color: var(--ui-text);
    border: 1px solid var(--ui-border-strong);
  }

  .url-input {
    background: var(--ui-background);
    color: var(--ui-text);
    border-color: var(--ui-border);
  }

  .url-input:focus {
    border-color: var(--ui-accent);
    box-shadow: none;
  }

  .btn-primary {
    background: var(--ui-accent);
    color: var(--ui-accent-text);
  }

  .btn-primary:hover {
    background: var(--ui-accent-hover);
  }

  .btn-secondary {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
  }

  .btn-secondary:hover {
    background: var(--ui-border);
  }

  /* ==========================================================
     === PROJECT ATTRIBUTION AND HELP ===
     ========================================================== */

  #appFooter {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--ui-space-sm);

    padding: var(--ui-space-xl);
    border-top: 1px solid var(--ui-border);

    color: var(--ui-text-muted);
    font-size: 0.8125rem;
    text-align: center;
  }

  #appFooter p {
    margin: 0;
  }

  #appFooter nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: var(--ui-space-lg);
  }

  #appFooter #githubIcon {
    width: 20px;
    height: 20px;
    margin: 0;

    /*
     * OBS: Existing GitHub image is dark on a light background.
     * WHY: Preserve the existing asset while adapting it
     *      to the dark interface.
     */

    filter: grayscale(1) invert(1);
  }

  /* ==========================================================
     === SMALL SCREENS ===
     ========================================================== */

  @media (max-width: 600px) {
    header {
      position: static;
      padding: var(--ui-space-sm);
    }

    header #appTitle {
      font-size: 1.25rem;
    }

    #controlsContainer {
      gap: var(--ui-space-xs);
    }

    .header-btn {
      min-height: 44px;
      font-size: 0.8125rem;
    }

    #colorEditor {
      padding: var(--ui-space-md);
    }
  }

  /* ==========================================================
     === TOUCH DEVICES ===
     ========================================================== */

  @media (pointer: coarse) {
    .header-btn,
    .btn,
    .modal-close-btn {
      min-height: 44px;
    }

    .drag-handle {
      min-width: 44px;
    }
  }

  /* ==========================================================
     === REDUCED MOTION ===
     ========================================================== */

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ============================================================
   === ARTWORK COMPUTATION STATUS ===
   ============================================================ */

/*
 * WHAT: Indeterminate artwork computation indicator.
 * WHY: Communicate progress without estimating completion time.
 * REQ: Preserve visibility of the artwork and palette.
 * REQ: Respect reduced-motion accessibility preferences.
 */

@media screen {
  .artwork-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: var(--ui-space-md);
    width: 100%;
    min-height: 32px;
  }

  #canvasSection .artwork-heading h2 {
    width: auto;
    flex: 1;
  }

  #artworkStatus {
    color: var(--ui-accent);
    font-size: 0.875rem;
    text-align: right;
  }

  #artworkProgress {
    width: 100%;
    height: 3px;

    overflow: hidden;
    background: var(--ui-surface-raised);
    border-radius: var(--ui-radius-sm);
  }

  #artworkProgress[hidden] {
    /* WHY: Preserve the artwork position during computation. */
    /* REQ: Reserve progress indicator space even when idle. */
    display: block;
    visibility: hidden;
  }

  #artworkProgress[hidden] span {
    animation-play-state: paused;
  }

  #artworkProgress span {
    display: block;

    width: 35%;
    height: 100%;

    background: var(--ui-accent);
    border-radius: var(--ui-radius-sm);

    animation: artwork-progress 1.2s ease-in-out infinite;
  }

  @keyframes artwork-progress {
    from {
      transform: translateX(-100%);
    }

    to {
      transform: translateX(290%);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    #artworkProgress span {
      width: 100%;
      animation: none;
    }
  }
}

@media print {
  #artworkStatus,
  #artworkProgress {
    display: none !important;
  }
}

/* ============================================================
   === CREATIVE PALETTE ACTIONS ===
   ============================================================ */

/*
 * WHAT: Primary artistic experimentation controls.
 * WHY: Make recoloring inviting, immediate, and reversible.
 * REQ: Preserve neutral surfaces and lime-green accents.
 * REQ: Provide accessible keyboard and touch controls.
 */

@media screen {
  #paletteActions {
    display: flex;
    flex-direction: column;
    gap: var(--ui-space-sm);
  }

  #paletteActions button {
    width: 100%;
    min-height: var(--ui-target-size);

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

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

    font-size: 0.9375rem;
    font-weight: 500;
  }

  #colorSurpriseBtn {
    background: var(--ui-accent);
    color: var(--ui-accent-text);
    border-color: var(--ui-accent);
    font-weight: 600;
  }

  #colorSurpriseBtn:not(:disabled):hover {
    background: var(--ui-accent-hover);
  }

  #restoreOriginalColorsBtn {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
  }

  #restoreOriginalColorsBtn:not(:disabled):hover {
    background: var(--ui-border);
  }

  #paletteActions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  #paletteActions button i {
    margin-inline-end: var(--ui-space-xs);
  }
}
/* ============================================================
   === INDIVIDUAL PALETTE LOCKS ===
   ============================================================ */

/*
 * WHAT: Accessible palette lock controls.
 * WHY: Protect selected colors during artistic randomization.
 * REQ: Distinguish lock state using both icon and color.
 * REQ: Maintain adequate touch target dimensions.
 */

@media screen {
  .color-lock-btn {
    display: flex;
    align-items: center;
    justify-content: center;

    width: var(--ui-target-size);
    min-width: var(--ui-target-size);
    height: var(--ui-target-size);

    padding: 0;
    margin: 0;
    flex-shrink: 0;

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

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

  .color-lock-btn:hover {
    background: var(--ui-border);
    color: var(--ui-text);
  }

  .color-lock-btn[aria-pressed="true"] {
    color: var(--ui-accent);
    border-color: var(--ui-accent);
  }
}

/* ============================================================
   === ARTISTIC HISTORY CONTROLS ===
   ============================================================ */

@media screen {
  #colorHistoryActions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ui-space-sm);
  }

  #colorHistoryActions button {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
  }

  #colorHistoryActions button:not(:disabled):hover {
    background: var(--ui-border);
  }
}
/* ============================================================
   === CURATED ARTISTIC PALETTES ===
   ============================================================ */

/*
 * WHAT: Accessible curated palette previews.
 * WHY: Encourage artistic experimentation while keeping
 *      the artwork and active palette visible.
 *
 * REQ: Preserve actual palette preview colors.
 * REQ: Preserve neutral interface surfaces.
 * REQ: Use the existing lime-green interaction accent.
 * REQ: Bound the gallery height to avoid displacing the
 *      primary artistic controls.
 */

@media screen {
  #curatedPaletteSection {
    min-width: 0;
    padding: var(--ui-space-md);

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

  #curatedPaletteSection summary {
    min-height: var(--ui-target-size);
    padding-block: var(--ui-space-sm);

    cursor: pointer;
    color: var(--ui-text);

    font-size: 0.9375rem;
    font-weight: 500;
  }

  #curatedPaletteSection summary:hover {
    color: var(--ui-accent);
  }

  #curatedPaletteSection summary:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 3px;
  }

  #curatedPaletteList {
    display: flex;
    flex-direction: column;

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

    max-height: min(280px, 35vh);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .curated-palette-btn {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;

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

    width: 100%;
    min-height: var(--ui-target-size);
    padding: var(--ui-space-sm);

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

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

    text-align: left;
  }

  .curated-palette-btn:not(:disabled):hover {
    border-color: var(--ui-accent);
  }

  .curated-palette-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .curated-palette-name {
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
  }

  .curated-palette-swatches {
    display: flex;

    height: 28px;
    min-width: 0;

    overflow: hidden;

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

  .curated-palette-swatch {
    flex: 1;
    min-width: 0;
  }
}
/* ============================================================
   === GLOBAL ARTISTIC ADJUSTMENTS ===
   ============================================================ */

/*
 * WHAT: Global palette and color spacing controls.
 * WHY: Refine artistic interpretation without modifying
 *      mathematical geometry.
 * REQ: Preserve accessible labels and focus indicators.
 * REQ: Preserve neutral interface surfaces.
 * REQ: Use the existing lime-green interaction accent.
 */

@media screen {
  #paletteAdjustmentSection,
  #colorSettings {
    min-width: 0;
    padding: var(--ui-space-md);

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

  #paletteAdjustmentSection summary,
  #colorSettings summary {
    min-height: var(--ui-target-size);
    padding-block: var(--ui-space-sm);

    cursor: pointer;
    font-size: 0.9375rem;
    font-weight: 500;
  }

  #paletteAdjustmentSection summary:hover,
  #colorSettings summary:hover {
    color: var(--ui-accent);
  }

  #paletteAdjustmentSection summary:focus-visible,
  #colorSettings summary:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 3px;
  }

  #paletteAdjustmentControls {
    display: flex;
    flex-direction: column;
    gap: var(--ui-space-md);
  }

  .palette-adjustment-label {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: var(--ui-space-sm);
    font-size: 0.875rem;
  }

  .palette-adjustment-label output {
    color: var(--ui-text-secondary);
    font-variant-numeric: tabular-nums;
  }

  #paletteAdjustmentControls input[type="range"] {
    width: 100%;
    min-height: 32px;
    margin: 0;

    accent-color: var(--ui-accent);
  }

  .palette-adjustment-description {
    margin: 0;

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

  #resetColorSpacingBtn,
  #resetPaletteAdjustmentsBtn {
    width: 100%;
    min-height: var(--ui-target-size);
    padding: var(--ui-space-sm);

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

    font-size: 0.875rem;
    font-weight: 500;
  }

  #resetColorSpacingBtn,
  #resetPaletteAdjustmentsBtn {
    background: var(--ui-surface-raised);
    color: var(--ui-text);
  }

  #resetColorSpacingBtn:not(:disabled):hover,
  #resetPaletteAdjustmentsBtn:not(:disabled):hover {
    background: var(--ui-border);
  }

  #paletteAdjustmentControls button:disabled,
  #resetColorSpacingBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  #colorSettingsControls input[type="number"] {
    display: block;

    width: 100%;
    min-height: var(--ui-target-size);

    margin-block: var(--ui-space-sm) var(--ui-space-lg);

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

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

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

  #colorSettingsControls input:invalid {
    border-color: var(--ui-border-strong);
    outline: 2px dashed var(--ui-text-secondary);
  }
}

/* ============================================================
   === MATHEMATICAL VIEWPORT NAVIGATION ===
   ============================================================ */

/*
 * WHY: Provide immediate spatial feedback during gestures
 *      without modifying intrinsic computational dimensions.
 *
 * REQ: Restrict touch gesture interception to Explore.
 * REQ: Preserve ordinary scrolling in other workspaces.
 * REQ: Clip temporary translations within the canvas container.
 */

@media screen {
  .viewport-navigation-instructions {
    width: 100%;
    margin: 0;

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

  .viewport-navigation-instructions[hidden] {
    display: none;
  }

  #canvas.viewport-navigation-enabled {
    cursor: grab;
    touch-action: none;
    user-select: none;

    /* REQ: Match the image-local transformation mathematics. */
    transform-origin: 0 0;
  }

  #canvas.viewport-panning {
    cursor: grabbing;

    will-change: transform;
    transition: none;
  }

  #canvas.viewport-zooming {
    cursor: zoom-in;

    will-change: transform;
    transition: none;
  }

  #canvas.viewport-render-pending {
    cursor: progress;

    will-change: transform;
    transition: none;
  }

  #canvasContainer {
    overflow: hidden;
  }
}

@media print {
  .viewport-navigation-instructions {
    display: none !important;
  }

  #canvas {
    transform: none !important;
  }
}
