/* responsive.css — breakpoints. Order matters: later rules override earlier.
   Desktop-first base; mobile opts in via max-width. The bottom-sheet behavior
   activates under body.studio-enhanced (added by MobileSheet component). */

@media (max-width: 980px) {
  body.studio-enhanced {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .studio-layout {
    grid-template-columns: 1fr;
  }

  .studio-right,
  .content-block {
    min-width: 0;
  }

  .preview-panel {
    min-height: auto;
    position: static;
  }

  .canvas-stage {
    min-height: clamp(330px, 54vh, 430px);
  }

  .canvas-frame {
    width: min(58vw, 330px);
  }
}

@media (max-width: 720px) {
  .content,
  .font-page .content {
    padding: 12px;
  }

  .site-header,
  .header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .identity-row,
  .font-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: stretch;
    min-width: 0;
    width: 100%;
  }

  .theme-toggle,
  .nav-menu summary {
    width: 100%;
  }

  .nav-submenu {
    position: static;
    width: 100%;
  }

  .canvas-stage {
    gap: 8px;
    position: relative;
    min-height: clamp(260px, 48vh, 360px);
  }

  .arrow-button,
  .button-left,
  .button-right {
    font-size: 22px;
    height: 44px;
    width: 44px;
    z-index: 2;
  }

  .canvas-stage .button-left {
    left: 6px;
  }

  .canvas-stage .button-right {
    right: 6px;
  }

  .arrow-button:hover,
  .button-left:hover,
  .button-right:hover {
    transform: translateY(calc(-50% - 2px));
  }

  .canvas-frame {
    max-width: 290px;
    padding: 0;
    width: min(74vw, 290px);
  }

  #final-canvas {
    width: 100%;
  }

  .panel-card,
  .options-card,
  .preview-panel,
  .font-page main {
    padding: 12px;
  }

  .preview-panel {
    gap: 12px;
  }

  .brand-cube {
    height: 52px;
    width: 52px;
  }

  h1 {
    font-size: 30px;
  }

  .button-container {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .features-grid,
  .howto-grid {
    grid-template-columns: 1fr;
  }
}

/* Bottom-sheet mode for the control panel on tablet/phone widths. */
@media (max-width: 980px) {
  .studio-layout {
    gap: 12px;
  }

  .studio-layout > .preview-panel {
    order: 1;
  }

  .studio-right > .preview-panel {
    order: 0;
  }

  .studio-right > .content-block {
    order: 1;
  }

  .control-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    bottom: 0;
    box-shadow: 0 -18px 70px rgba(43, 52, 103, 0.18);
    left: 0;
    max-height: min(78vh, 680px);
    overflow: auto;
    overscroll-behavior: contain;
    padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    transform: translateY(100%);
    transition: transform 0.22s ease;
    z-index: 900;
  }

  body.sheet-open .control-panel {
    transform: translateY(0);
  }

  .sheet-handle {
    align-items: center;
    background: transparent;
    border: 0;
    color: var(--ink);
    cursor: pointer;
    display: flex;
    font-family: var(--body-font);
    font-weight: 700;
    gap: 8px;
    justify-content: center;
    min-height: 42px;
    width: 100%;
  }

  .sheet-handle::before {
    background: rgba(109, 76, 255, 0.35);
    border-radius: 999px;
    content: "";
    display: block;
    height: 4px;
    left: 50%;
    position: absolute;
    top: 8px;
    transform: translateX(-50%);
    width: 54px;
  }

  .mobile-tune-button {
    align-items: center;
    background: linear-gradient(135deg, var(--violet), var(--violet-2));
    border: 0;
    border-radius: 999px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    box-shadow: var(--pixel-shadow);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font-family: var(--body-font);
    font-weight: 700;
    justify-content: center;
    min-height: 52px;
    padding: 0 20px;
    position: fixed;
    right: 18px;
    z-index: 950;
  }

  body.sheet-open .mobile-tune-button {
    opacity: 0;
    pointer-events: none;
  }

  .identity-card,
  .preset-card,
  .options-card {
    box-shadow: none;
  }

  .section-tabs {
    grid-template-columns: repeat(4, minmax(92px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .button-container {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
  }

  .render-frame-card,
  .render-ornament-card,
  .render-background-card {
    flex: 0 0 144px;
    scroll-snap-align: start;
  }

  .download-row {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--line);
    border-radius: 14px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 14px;
    padding: 8px;
    position: fixed;
    right: 14px;
    z-index: 850;
  }

  body[data-theme="dark"] .download-row {
    background: rgba(20, 25, 42, 0.92);
  }
}

@media (max-width: 720px) {
  body.studio-enhanced {
    padding-bottom: calc(142px + env(safe-area-inset-bottom));
  }

  .app-shell {
    min-height: auto;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .preview-toolbar {
    align-items: stretch;
    display: grid;
    gap: 12px;
  }

  .studio-action-bar {
    justify-content: stretch;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .download-row {
    grid-template-columns: 1fr;
    left: 10px;
    right: 10px;
  }

  .secondary-download {
    display: none;
  }

  .studio-action-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .studio-icon-button {
    padding-left: 6px;
    padding-right: 6px;
  }

  .preset-bar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .preset-chip {
    flex: 0 0 auto;
  }
}

@media (max-width: 520px) {
  .site-header,
  .header {
    gap: 12px;
    margin-bottom: 14px;
  }

  .brand-subtitle {
    font-size: 14px;
  }

  .top-actions {
    grid-template-columns: minmax(0, 1fr) 44px 44px;
  }

  .theme-toggle,
  .language-menu .darkbuttonboxes,
  .language-menu summary {
    width: 44px;
  }

  .tools-menu {
    min-width: 0;
  }

  .tools-menu summary {
    width: 100%;
  }

  .preview-panel {
    border-radius: 14px;
    padding: 10px;
  }

  .canvas-stage {
    min-height: clamp(240px, 46vh, 320px);
  }

  .canvas-stage::before,
  .canvas-stage::after {
    display: none;
  }

  .canvas-frame {
    max-width: 250px;
    width: min(72vw, 250px);
  }

  .arrow-button,
  .button-left,
  .button-right {
    height: 40px;
    width: 40px;
  }

  .summary-grid {
    gap: 8px;
  }

  .summary-grid span {
    border-radius: 10px;
    padding: 10px;
  }

  .summary-grid b {
    font-size: 13px;
  }

  .control-panel {
    max-height: min(82vh, 640px);
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel-card,
  .options-card {
    border-radius: 14px;
  }

  .step-card {
    gap: 12px;
  }

  .step-heading {
    gap: 10px;
  }

  .section-tabs {
    grid-template-columns: repeat(4, minmax(84px, 1fr));
  }

  .mobile-tune-button {
    min-height: 48px;
    padding: 0 16px;
    right: 12px;
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 26px;
  }

  .brand-cube {
    height: 46px;
    width: 46px;
  }

  .canvas-frame {
    max-width: 224px;
    width: min(70vw, 224px);
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .studio-action-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Touch targets >= 44px on coarse pointers (phones). */
@media (pointer: coarse) {
  .button-small,
  .section-tab,
  .preset-chip,
  .studio-icon-button,
  .secondary-download,
  .lang-flag {
    min-height: 44px;
    min-width: 44px;
  }
  .canvas-frame {
    touch-action: none;
  }
}
