/* Compact layout: locked to the screen. Canvas on top, one tab of controls under it, three actions at the bottom.
   Sections dissolve into the panel grid so every control keeps a single home in the markup. */

.panel-tabs {
  display: none;
}

@media (max-width: 860px) {
  :root {
    --text-m: 15px;
    --text-l: 16px;
    --text-xl: 18px;
    --control-h: 44px;
    --radius-m: 14px;
    --radius-l: 24px;
    --gutter-left: max(16px, env(safe-area-inset-left, 0px));
    --gutter-right: max(16px, env(safe-area-inset-right, 0px));
    --tab-content-h: 120px;
  }

  .app {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  /* Stage */

  .stage {
    flex: 1;
    min-height: 0;
  }

  .stage-bar {
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: var(--gutter-left);
    gap: 6px;
  }

  .stage-bar .chip {
    height: 38px;
    padding: 0 12px;
    font-size: 14px;
  }

  .stage-bar .icon-button {
    width: 38px;
    height: 38px;
  }

  .stage-bar .icon-button svg {
    width: 20px;
    height: 20px;
  }

  .stage-viewport {
    inset: calc(62px + env(safe-area-inset-top, 0px)) var(--gutter-right) 16px var(--gutter-left);
  }

  .frame {
    border-radius: 10px;
  }

  .toast {
    bottom: 16px;
    padding: 10px 18px;
    font-size: 14px;
  }

  /* Panel: tabs, one tab of controls, actions */

  .panel {
    flex: none;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    grid-template-rows: auto var(--tab-content-h) auto;
    grid-template-areas:
      "tabs tabs tabs"
      "content content content"
      "copy shape save";
    gap: 0 8px;
    overflow: visible;
    padding: 0 var(--gutter-right) calc(12px + env(safe-area-inset-bottom, 0px)) var(--gutter-left);
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .panel::after {
    content: "";
    grid-row: 3;
    grid-column: 1 / -1;
    align-self: start;
    margin: 0 calc(-1 * var(--gutter-right)) 0 calc(-1 * var(--gutter-left));
    border-top: 1px solid var(--line);
    pointer-events: none;
  }

  .panel-actions,
  .section {
    display: contents;
  }

  .section-title {
    display: none;
  }

  .panel-tabs {
    grid-area: tabs;
    display: flex;
    gap: 22px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .panel-tabs::-webkit-scrollbar {
    display: none;
  }

  .panel-tabs button {
    position: relative;
    flex: none;
    height: 46px;
    color: var(--ink-3);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    transition: color 0.2s var(--ease);
  }

  .panel-tabs button::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 10px;
    left: 0;
    height: 1.5px;
    border-radius: 1px;
    background: currentColor;
    transform: scaleX(0);
    transition: transform 0.3s var(--ease);
  }

  .panel-tabs button[aria-selected="true"] {
    color: var(--ink);
  }

  .panel-tabs button[aria-selected="true"]::after {
    transform: none;
  }

  [data-panel] {
    grid-area: content;
    align-self: center;
    min-width: 0;
    animation: tab-in 0.28s var(--ease);
  }

  .panel[data-tab="colors"] [data-panel]:not([data-panel="colors"]),
  .panel[data-tab="shape"] [data-panel]:not([data-panel="shape"]),
  .panel[data-tab="grain"] [data-panel]:not([data-panel="grain"]),
  .panel[data-tab="reference"] [data-panel]:not([data-panel="reference"]) {
    display: none;
  }

  @keyframes tab-in {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
  }

  .stack {
    gap: 8px;
  }

  /* Actions */

  #copy-button,
  #shape-button,
  #save-button {
    height: 48px;
    margin-top: 12px;
  }

  #copy-button {
    grid-area: copy;
    width: 48px;
    padding: 0;
  }

  #shape-button {
    grid-area: shape;
    border-radius: 999px;
  }

  #save-button {
    grid-area: save;
    width: 48px;
    padding: 0;
  }

  #copy-button .button-label,
  #save-button .button-label {
    display: none;
  }

  /* Colors */

  .swatches {
    display: flex;
    gap: 10px;
    margin: 0 calc(-1 * var(--gutter-right)) 0 calc(-1 * var(--gutter-left));
    padding: 6px var(--gutter-right) 6px var(--gutter-left);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .swatches::-webkit-scrollbar {
    display: none;
  }

  .swatch-item,
  .swatch-tool {
    flex: none;
    width: 40px;
  }

  .swatch-tool svg {
    width: 20px;
    height: 20px;
  }

  /* Sliders and segmented */

  .slider {
    padding: 0 18px;
  }

  .slider-fill::after {
    top: 13px;
    bottom: 13px;
  }

  .slider:hover .slider-fill::after,
  .slider.is-dragging .slider-fill::after {
    top: 9px;
    bottom: 9px;
  }

  .slider-value {
    font-size: 14px;
  }

  .segmented {
    padding: 4px;
    border-radius: var(--radius-m);
  }

  .segmented-indicator {
    top: 4px;
    bottom: 4px;
    border-radius: 10px;
  }

  .segmented button {
    height: 36px;
    border-radius: 10px;
  }

  /* Reference */

  .reference-empty {
    min-height: 72px;
    gap: 14px;
    padding: 10px 16px;
  }

  .reference-empty-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .reference-empty-icon svg {
    width: 20px;
    height: 20px;
  }

  .reference-empty-text {
    gap: 2px;
    font-size: 14px;
  }

  .reference-card {
    grid-template-columns: 56px minmax(0, 1fr) auto;
    gap: 12px;
    padding: 8px 4px 8px 8px;
  }

  .reference-thumb {
    width: 56px;
    height: 56px;
    border-radius: 10px;
  }

  .reference-meta {
    gap: 8px;
  }

  .reference-dot {
    width: 16px;
    height: 16px;
  }

  .reference-actions .icon-button {
    width: 40px;
    height: 40px;
  }

  /* Popovers become bottom sheets */

  .popover {
    top: auto !important;
    right: 0;
    bottom: 0;
    left: 0 !important;
    width: auto;
    padding: 16px var(--gutter-right) calc(16px + env(safe-area-inset-bottom, 0px)) var(--gutter-left);
    border-radius: var(--radius-l) var(--radius-l) 0 0;
  }

  .picker {
    gap: 12px;
  }

  .picker-area {
    height: 168px;
    border-radius: 12px;
  }

  .picker-thumb {
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
  }

  .picker-hue {
    height: 26px;
    margin: 0 13px;
  }

  .picker-hue::before,
  .picker-hue::after {
    width: 13px;
  }

  .picker-hue::before {
    left: -13px;
    border-radius: 13px 0 0 13px;
  }

  .picker-hue::after {
    right: -13px;
    border-radius: 0 13px 13px 0;
  }

  .picker-hue-thumb {
    width: 26px;
    height: 26px;
    margin: -13px 0 0 -13px;
  }

  .picker-row {
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 8px;
  }

  .picker-hex {
    padding: 0 16px;
  }

  .composition {
    gap: 14px;
  }

  .popover-head {
    margin: -4px -6px 0 0;
  }

  .popover-head .icon-button {
    width: 40px;
    height: 40px;
  }

  .ratio {
    gap: 8px;
    padding: 10px 0 8px;
    border-radius: 14px;
    font-size: 14px;
  }

  .ratio-frame {
    width: 34px;
    height: 34px;
  }

  .ratio-shape {
    transform: scale(0.8);
  }

  .text-button {
    font-size: 15px;
  }

  .size-field {
    padding: 0 14px;
  }

  .format-label {
    font-size: 15px;
  }
}
