@media (min-width: 1800px) { html { font-size: 106.25%; } }
@media (min-width: 2200px) { html { font-size: 112.5%; } }
@media (min-width: 2500px) { html { font-size: 125%; } }
@media (min-width: 3000px) { html { font-size: 137.5%; } }
@media (min-width: 3600px) { html { font-size: 150%; } }

@media (max-width: 1280px) {
  .app { grid-template-columns: 15.625rem minmax(0, 1fr) 18.125rem; }
  .main-action-buttons .btn { flex-basis: 9.375rem; }
}

@media (max-width: 1100px) and (min-width: 901px) {
  .app { grid-template-columns: 13.75rem minmax(0, 1fr) 16.875rem; min-height: 32.5rem; }
  .panel { padding: 0.75rem; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); gap: 0.5rem; }
  .thumb-info-original { display: none; }
  .drop-area { padding: 0.75rem 0.625rem; }
  .drop-sub { display: none; }
  .main-action-buttons .btn { flex-basis: 40%; padding: 0 0.75rem; }
  .main-action-buttons kbd { display: none; }
  .group { padding: 0.75rem; }
  .chip { padding: 0 0.5625rem; }
}

@media (max-width: 900px) {
  :root { --gap: 0.625rem; --topbar-h: 3.375rem; --bar-h: 4.125rem; --strip-h: 5.25rem; }

  body { overscroll-behavior-y: none; }
  body.has-actions { padding-bottom: calc(var(--bar-h) + 1.25rem + env(safe-area-inset-bottom)); }
  body.sheet-open { overflow: hidden; }

  .topbar { width: calc(100% - 1.25rem); margin-top: 0.625rem; padding: 0 0.375rem 0 0.625rem; }
  .brand-mark { width: 2.125rem; height: 2.125rem; border-radius: 0.625rem; }
  .brand-text h1 { font-size: 1rem; }
  #settingsBtn { display: inline-grid; }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "stage" "library";
    width: calc(100% - 1.25rem);
    height: calc(100vh - var(--topbar-h) - 0.625rem - var(--gap) * 2 - var(--bar-h) - 1.25rem);
    height: calc(100dvh - var(--topbar-h) - 0.625rem - var(--gap) * 2 - var(--bar-h) - 1.25rem - env(safe-area-inset-bottom));
    min-height: 26.25rem;
  }
  body:not(.has-actions) .app { height: calc(100dvh - var(--topbar-h) - 0.625rem - var(--gap) * 2); }

  .panel { border-radius: 1.25rem; }
  .stage { padding: 0.5rem; gap: 0.5rem; }
  .stage-toolbar { align-self: stretch; justify-content: space-between; border-radius: 0.875rem; }
  .tool-btn { width: 2.5rem; height: 2.5rem; }
  #image-container { min-height: 0; border-radius: 0.875rem; }
  .empty-text { max-width: 17.5rem; }
  .progress { padding: 0 0.375rem 2px; }

  .library {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    height: var(--strip-h);
    padding: 0.5rem;
  }
  .library .panel-head, .drop-area { display: none; }
  .add-tile { display: grid; width: 4.25rem; height: 4.25rem; }
  .thumbs {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }
  .thumbs::-webkit-scrollbar { display: none; }
  .thumbs:empty::before { content: 'Chạm + để thêm ảnh'; display: flex; align-items: center; padding: 0 0.375rem; }
  .thumb { width: 4.25rem; height: 4.25rem; flex: none; padding: 0.1875rem; border-radius: 0.875rem; scroll-snap-align: start; }
  .thumb-media { border-radius: 0.6875rem; }
  .thumb-meta { display: none; }
  .thumb-index { top: 0.1875rem; left: 0.1875rem; min-width: 1.125rem; height: 1.125rem; font-size: 0.625rem; line-height: 1.125rem; padding: 0 0.3125rem; }
  .thumb-check { right: 0.1875rem; bottom: 0.1875rem; width: 1.125rem; height: 1.125rem; }
  .remove-thumb-btn { top: 0.1875rem; right: 0.1875rem; width: 1.375rem; height: 1.375rem; }
  .thumb:not(.active) .remove-thumb-btn { opacity: 0; pointer-events: none; }
  #clearAllImages { width: 2.75rem; min-height: 4.25rem; padding: 0; flex: none; border-radius: 0.875rem; }
  #clearAllImages .btn-text, #clearAllImages kbd { display: none; }

  .main-action-buttons {
    position: fixed;
    left: 0.625rem;
    right: 0.625rem;
    bottom: calc(0.625rem + env(safe-area-inset-bottom));
    z-index: 40;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 0.375rem;
    max-width: 42.5rem;
    margin: 0 auto;
    padding: 0.375rem;
    border-radius: 1.375rem;
    background: var(--panel-solid);
    border: 1px solid var(--glass-border);
    box-shadow: var(--highlight), var(--shadow-lg);
  }
  .main-action-buttons.is-empty { display: none; }
  .main-action-buttons .btn {
    position: relative;
    flex-direction: column;
    gap: 0.1875rem;
    min-height: 3.375rem;
    padding: 0.25rem;
    border-radius: 1rem;
    font-size: 0.7188rem;
    line-height: 1.15;
    white-space: normal;
    text-align: center;
    box-shadow: none;
  }
  .main-action-buttons .btn .ic { width: 1.3125rem; height: 1.3125rem; }
  .main-action-buttons .btn-tinted { background: transparent; }
  .main-action-buttons .btn-tinted:active { background: var(--accent-tint); }
  .main-action-buttons kbd { display: none; }
  .main-action-buttons .btn-count { position: absolute; top: 0.25rem; right: calc(50% - 1.625rem); min-width: 1.125rem; height: 1.125rem; line-height: 1.125rem; font-size: 0.6562rem; padding: 0 0.3125rem; }
  .main-action-buttons .spinner { width: 1.25rem; height: 1.25rem; }

  .inspector {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 76;
    width: min(100%, 42.5rem);
    max-height: 86vh;
    max-height: 86dvh;
    margin: 0 auto;
    padding: 0.375rem 0.875rem calc(0.875rem + env(safe-area-inset-bottom));
    border-radius: 1.5rem 1.5rem 0 0;
    background: var(--panel-solid);
    box-shadow: var(--shadow-lg);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform .35s var(--ease), visibility 0s linear .35s;
  }
  body.sheet-open .inspector { transform: none; visibility: visible; transition: transform .35s var(--ease), visibility 0s; }
  .sheet-handle { display: block; flex: none; width: 2.5rem; height: 0.3125rem; margin: 0.25rem auto 0.375rem; border-radius: 62.4375rem; background: var(--fill-hover); }
  .sheet-close { display: inline-grid; margin: -0.375rem -0.375rem -0.375rem 0; }
  .inspector .panel-head { padding-bottom: 0.625rem; }
  .inspector-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16.25rem, 1fr));
    align-content: start;
    overflow-y: auto;
  }
  .sheet-scrim:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 75;
    background: var(--scrim);
    animation: fade-in .25s ease both;
  }

  .input { height: 2.75rem; font-size: 1rem; }
  .link-button { width: 2.5rem; height: 2.75rem; }
  .chip { height: 2.125rem; padding: 0 0.8125rem; font-size: 0.8438rem; }
  .swatch { width: 1.875rem; height: 1.875rem; }
  .color-swatch { width: 2.75rem; height: 2.75rem; }
  .segmented span { padding: 0.5625rem 0; font-size: 0.875rem; }
  .btn { min-height: 2.875rem; }

  .toasts { top: calc(var(--topbar-h) + 1rem); right: 50%; align-items: center; transform: translateX(50%); }
  .shortcut-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 420px) {
  .brand-text p { display: none; }
  .tool-btn { width: 2.125rem; }
  .tool-counter { min-width: 2.75rem; font-size: 0.75rem; }
  .tool-sep { margin: 0 2px; }
  .main-action-buttons .btn { font-size: 0.6875rem; }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  :root { --strip-h: 4rem; --bar-h: 3.375rem; }
  .app { min-height: 17.5rem; }
  .add-tile, .thumb { width: 3rem; height: 3rem; }
  #clearAllImages { min-height: 3rem; }
  .main-action-buttons .btn { flex-direction: row; min-height: 2.625rem; font-size: 0.75rem; }
}

@media (hover: none) {
  kbd, .drop-sub { display: none; }
  .modal kbd { display: inline-flex; }
  #shortcutBtn { display: none; }
  .remove-thumb-btn { opacity: 1; }
}
