/* ============================================================
   styles/layout.css
   ============================================================ */

/*
 * WHAT: Responsive art-first application layout.
 * WHY: Support desktop, tablet, and mobile using one DOM.
 *
 * REQ: Artwork MUST precede editing controls visually.
 * REQ: Preserve canvas aspect ratio and image orientation.
 * REQ: CSS resizing MUST NOT change computational dimensions.
 * REQ: Support both portrait and landscape orientations.
 */

body {
  font-family: var(--ui-font-family);
  background: var(--ui-background);
  color: var(--ui-text);
}

/* Keep the header in the normal document flow. */
header {
  position: sticky;
  top: 0;
  background: var(--ui-surface);
  min-height: auto;
  box-shadow: none;
  border-bottom: 1px solid var(--ui-border);
}

/* Artwork-first workspace. */
main#container {
  display: grid;
  grid-template-columns:
    minmax(0, 1fr)
    var(--ui-editor-width);
  align-items: start;
  gap: var(--ui-space-lg);
  padding: var(--ui-space-lg);
}

/* Display artwork first without duplicating the canvas. */
#canvasSection {
  grid-column: 1;
  grid-row: 1;

  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;

  background: var(--ui-canvas-background);
  box-shadow: none;
}

/* Preserve intrinsic canvas dimensions. */
#canvasContainer {
  width: 100%;
  min-width: 0;
}

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

/* Place editing controls beside the artwork. */
#colorEditor {
  grid-column: 2;
  grid-row: 1;

  width: 100%;
  min-width: 0;
  max-width: none;
  max-height: none;
  margin: 0;

  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  box-shadow: none;
}

/*
 * WHY: Available workspace width determines the layout,
 *      rather than device names or browser identification.
 */
@media screen and (max-width: 900px) {
  main#container {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--ui-space-md);
    padding: var(--ui-space-md);
  }

  #canvasSection {
    grid-column: 1;
    grid-row: 1;
  }

  #colorEditor {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
  }

  .url-modal {
    min-width: 0;
    max-width: calc(100vw - 24px);
  }
}

/* Provide adequate targets for touch interaction. */
@media (pointer: coarse) {
  button,
  select,
  input[type="color"] {
    min-height: var(--ui-target-size);
  }

  button {
    min-width: var(--ui-target-size);
  }
}
/* ============================================================
   DEVICE SAFE AREAS
   ============================================================ */

/*
 * WHY: Accommodate device cutouts, rounded display corners,
 *      and installed PWA window boundaries.
 */

@media screen {
  body {
    min-height: 100vh;
    min-height: 100dvh;
  }

  header {
    padding-top: max(var(--ui-space-md), env(safe-area-inset-top));
  }

  main#container {
    padding-left: max(var(--ui-space-md), env(safe-area-inset-left));

    padding-right: max(var(--ui-space-md), env(safe-area-inset-right));
  }

  #appFooter {
    padding-bottom: max(var(--ui-space-xl), env(safe-area-inset-bottom));
  }
}
