.tag-suffix { white-space: pre; }

/* Mobile layout matches the approved dark / amber gallery concept.
   Desktop styles remain in styles.css; overrides apply only up to 700px. */
.mobile-detail-header,
.mobile-sort-icon {
  display: none;
}

@media (max-width: 700px) {
  .site-header {
    height: 64px;
  }

  .header-inner,
  .page-shell {
    width: calc(100% - 24px);
  }

  .brand {
    gap: 10px;
    font-size: 26px;
  }

  .brand-mark {
    width: 36px;
    height: 40px;
  }

  .page-shell {
    padding-top: 12px;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 12px 10px;
  }

  .search-field {
    grid-column: 1 / -1;
    height: 46px;
    gap: 10px;
    padding-inline: 14px;
  }

  .search-field input {
    /* 16px prevents automatic input zoom in iOS Safari. */
    font-size: 16px;
  }

  .search-field input::placeholder {
    font-size: 14px;
  }

  .search-icon {
    width: 21px;
    height: 21px;
  }

  .type-switch {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 44px;
    padding: 4px;
    gap: 2px;
  }

  .type-button {
    min-width: 0;
    padding: 7px 5px;
    font-size: 12px;
    letter-spacing: -.15px;
  }

  .sort-field {
    width: 44px;
    min-width: 44px;
    height: 44px;
    border-color: rgba(255, 177, 29, .45);
    border-radius: 12px;
    background: rgba(255, 179, 28, .025);
  }

  .sort-field select {
    position: relative;
    z-index: 1;
    padding: 0;
    color: transparent;
    font-size: 16px;
    cursor: pointer;
  }

  .sort-field option {
    color: var(--text);
    font-size: 14px;
    background: var(--surface);
  }

  .sort-field > .icon:not(.mobile-sort-icon) {
    display: none;
  }

  .sort-field .mobile-sort-icon {
    display: block;
    top: 10px;
    right: 10px;
    width: 22px;
    height: 22px;
    color: #e2d7b8;
  }

  .material-filters {
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 12px;
    padding: 2px 1px 4px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    mask-image: linear-gradient(to right, #000 95%, transparent);
  }

  .material-button {
    min-height: 36px;
    padding: 8px 14px;
    font-size: 11px;
  }

  .gallery-section {
    margin-top: 22px;
  }

  .gallery-heading {
    gap: 10px;
    margin-bottom: 14px;
  }

  .gallery-heading h1 {
    font-size: 21px;
    letter-spacing: -.55px;
  }

  .result-count {
    flex-shrink: 0;
    font-size: 10px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .effect-card {
    border-radius: 12px;
  }

  .card-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    grid-template-rows: 22px 18px;
    align-items: center;
    gap: 4px 6px;
    min-height: 64px;
    padding: 8px;
  }

  .card-name {
    grid-column: 1;
    grid-row: 1;
    max-width: 100%;
    margin: 0;
    padding: 2px 0;
    font-size: 13px;
    letter-spacing: -.3px;
  }

  .card-tags {
    grid-column: 1;
    grid-row: 2;
    align-items: center;
    gap: 4px;
    min-width: 0;
  }

  .card-tags .tag {
    padding: 4px 5px;
    font-size: 8px;
    line-height: 1.15;
  }

  .copy-icon {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .copy-icon .icon {
    width: 21px;
    height: 21px;
  }

  .copy-icon::before {
    display: none;
  }

  .site-footer {
    margin: 18px 0 20px;
    font-size: 10px;
  }

  .empty-state,
  .error-state {
    padding: 50px 16px;
  }

  dialog {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--bg);
  }

  .mobile-detail-header {
    display: flex;
    align-items: center;
    height: calc(58px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 68px 0 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: #0e1012;
  }

  .mobile-detail-header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -.4px;
  }

  .detail-layout {
    display: block;
    height: calc(100% - 58px - env(safe-area-inset-top, 0px));
    padding-bottom: calc(126px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-padding-bottom: calc(126px + env(safe-area-inset-bottom, 0px));
    scrollbar-width: thin;
    scrollbar-color: #45464d transparent;
  }

  .image-panel {
    position: relative;
    padding-top: 0;
    background: #050506;
  }

  .viewer-stage {
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .viewer-arrow {
    width: 40px;
    height: 40px;
  }

  .viewer-arrow.previous {
    left: 10px;
  }

  .viewer-arrow.next {
    right: 10px;
  }

  .image-caption {
    position: absolute;
    right: 12px;
    bottom: 12px;
    height: auto;
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    background: rgba(8, 9, 10, .78);
  }

  #image-caption {
    display: none;
  }

  .image-caption #image-counter {
    color: #d8d9dd;
    font-size: 11px;
  }

  .prompt-panel {
    position: static;
    padding: 22px 18px 20px;
    overflow: visible;
    border: 0;
    background: radial-gradient(ellipse at 100% 0, rgba(255, 164, 36, .025), transparent 50%), #0e1012;
  }

  .close-dialog {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: 12px;
    width: 42px;
    height: 42px;
    z-index: 1;
    border-radius: 12px;
    background: #1b1d20;
  }

  .breadcrumb {
    display: none;
  }

  .detail-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }

  .prompt-panel h2 {
    min-width: 0;
    max-width: 100%;
    margin: 0;
    padding: 0;
    overflow-wrap: anywhere;
    font-size: 25px;
    letter-spacing: -.7px;
  }

  .detail-tags {
    gap: 6px;
  }

  .detail-tags .tag {
    padding: 7px 10px;
    font-size: 10px;
  }

  .effect-description {
    margin: 18px 0 25px;
    font-size: 12px;
    line-height: 1.8;
    color: #b9bbc2;
  }

  .prompt-heading {
    margin-bottom: 12px;
  }

  .prompt-box {
    height: clamp(170px, 24dvh, 220px);
    padding: 16px;
    font-size: 12px;
    line-height: 1.8;
    background: #111316;
  }

  .copy-dock {
    /* Its containing block is dialog, outside the scrolling detail layout. */
    position: absolute;
    inset: auto 0 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, .12);
    background: rgba(19, 21, 24, .97);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .2);
    backdrop-filter: blur(16px);
  }

  .copy-dock .prompt-hint {
    order: -1;
    margin: 0;
    text-align: center;
    font-size: 10px;
    line-height: 1.6;
  }

  .copy-dock .copy-full {
    position: static;
    flex-shrink: 0;
    width: 100%;
    min-height: 52px;
    margin: 0;
    font-size: 15px;
    border-radius: 12px;
  }

  .how-to {
    margin-top: 18px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, .018);
  }

  .how-to summary {
    min-height: 50px;
    padding: 12px 15px;
    font-size: 12px;
  }

  .how-to ol {
    margin: 0;
    padding: 0 20px 0 34px;
  }

  .how-to p {
    margin: 10px 16px 16px;
  }

  .dialog-toast {
    position: absolute;
    bottom: calc(120px + env(safe-area-inset-bottom, 0px));
    width: max-content;
    max-width: calc(100% - 32px);
    font-size: 11px;
    text-align: center;
  }
}

@media (max-width: 360px) {
  .type-button {
    font-size: 11px;
    padding-inline: 2px;
  }

  .gallery-heading h1 {
    font-size: 19px;
  }

  .card-tags .tag-suffix {
    display: none;
  }

  .card-tags .tag {
    padding-inline: 4px;
  }

  .card-name {
    font-size: 12px;
  }

  .detail-tags .tag {
    font-size: 9px;
    padding: 6px 8px;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .copy-dock {
    background: #181a1e;
    backdrop-filter: none;
  }
}

@media (max-width: 700px) and (orientation: landscape) {
  .viewer-stage { height: 42dvh; aspect-ratio: auto; }
  .detail-art { width: min(100%, 74.667dvh); margin-inline: auto; }
}

/* Keep the modal close control outside the scrolling content in both layouts. */
.close-dialog { z-index: 1; }
