/* =========================================================
   CHROMA — responsive layout
   Desktop → compact rail → touch bottom sheet
   ========================================================= */

@media (max-width: 1320px) {
  .stage-plate {
    width: min(360px, 30vw);
  }

  .sector {
    display: none;
  }
}

@media (max-width: 1180px) {
  .panel {
    width: 374px;
  }

  .stage-plate {
    left: 202px;
    width: 300px;
  }

  .actionbar {
    grid-template-columns: minmax(150px, 1fr) auto;
  }

  .actionbar-note {
    display: none;
  }

  .view-bar {
    bottom: 94px;
  }

  .gesture-hint {
    bottom: 142px;
  }
}

@media (max-width: 1120px) {
  .rail {
    width: 58px;
    gap: 5px;
  }

  .rail-item {
    grid-template-columns: 1fr;
    place-items: center;
    min-height: 46px;
    padding: 9px 0;
    border-radius: 12px;
  }

  .rail-index,
  .rail-label,
  .rail-glow {
    display: none;
  }

  .rail-item.is-active {
    background: color-mix(in srgb, var(--item-accent, var(--accent)) 12%, rgba(13, 7, 25, 0.5));
  }

  .rail-icon {
    width: 20px;
    height: 20px;
  }

  .rail-divider {
    margin: 8px 8px;
  }

  .rail-focus {
    justify-content: center;
    padding: 10px 0;
  }

  .rail-focus span {
    display: none;
  }

  .stage-plate {
    left: 96px;
    width: min(310px, 33vw);
  }

  .panel {
    width: 360px;
  }
}

/* =========================================================
   Touch / small-screen lobby
   ========================================================= */

@media (max-width: 900px) {
  :root {
    --sheet-collapsed: 138px;
  }

  body {
    font-size: 13.5px;
  }

  .topbar {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    gap: 10px;
  }

  .topbar::before {
    height: 100px;
    background: linear-gradient(180deg, rgba(5, 2, 10, 0.8), transparent);
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 29px;
    height: 29px;
  }

  .brand-word {
    font-size: 14px;
    letter-spacing: 0.13em;
  }

  .brand-sub,
  .sector {
    display: none;
  }

  .top-actions {
    gap: 6px;
  }

  .status-pill {
    height: 32px;
    padding: 0 9px;
    font-size: 7px;
    letter-spacing: 0.1em;
  }

  .fps-chip {
    display: none !important;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .rail {
    display: none;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(var(--sheet-collapsed) + env(safe-area-inset-bottom));
    max-height: none;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 22px 22px 0 0;
    background: linear-gradient(165deg, rgba(31, 18, 56, 0.97), rgba(11, 6, 22, 0.99));
    box-shadow: 0 -24px 70px rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(20px);
    transition: height 380ms cubic-bezier(0.22, 1, 0.36, 1), transform 300ms ease, opacity 300ms ease;
  }

  .panel::before {
    background: linear-gradient(90deg, transparent, rgba(95, 245, 255, 0.5), rgba(255, 79, 216, 0.5), transparent);
  }

  .panel::after {
    display: none;
  }

  .panel.is-closed {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  .panel.is-open {
    height: min(68vh, 620px);
  }

  .sheet-grab {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 17px;
    flex: none;
    cursor: grab;
  }

  .sheet-grab span {
    width: 31px;
    height: 3px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
  }

  .mobile-tabs {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: none;
    padding: 0 9px 5px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-tab {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    height: 46px;
    padding: 3px 2px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--faint);
    font-size: 7.5px;
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
    transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
  }

  .mobile-tab svg {
    width: 16px;
    height: 16px;
  }

  .mobile-tab.is-active {
    color: var(--paper);
    border-color: var(--line);
    background: rgba(255, 255, 255, 0.045);
  }

  .mobile-tab[data-tab="character"].is-active {
    color: var(--cyan);
  }

  .mobile-tab[data-tab="outfits"].is-active {
    color: var(--magenta);
  }

  .mobile-tab[data-tab="abilities"].is-active {
    color: var(--coral);
  }

  .mobile-tab[data-tab="profile"].is-active {
    color: var(--violet);
  }

  .sheet-expand {
    display: grid;
    place-items: center;
    width: 30px;
    height: 38px;
    flex: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--faint);
  }

  .sheet-expand svg {
    width: 16px;
    height: 16px;
    transition: transform 250ms ease;
  }

  .panel.is-open .sheet-expand svg {
    transform: rotate(180deg);
  }

  .panel-head {
    display: none;
    padding: 12px 16px 9px;
  }

  .panel.is-open .panel-head {
    display: block;
  }

  .panel-title {
    font-size: 21px;
  }

  .panel-sub {
    max-width: none;
    font-size: 10.5px;
  }

  .panel-ghost,
  .panel-collapse {
    display: none;
  }

  .panel-body {
    display: none;
    padding: 13px 16px 18px;
  }

  .panel.is-open .panel-body {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  .sheet-actions {
    display: grid;
    grid-template-columns: 1fr 1.25fr;
    gap: 7px;
    flex: none;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(9, 4, 18, 0.6);
  }

  .sheet-actions .btn {
    min-height: 42px;
    font-size: 11.5px;
  }

  .panel-reopen {
    display: none !important;
  }

  .panel-heading {
    padding-right: 0;
  }

  .actionbar {
    display: none;
  }

  .view-bar {
    display: none;
  }

  .gesture-hint {
    display: none;
  }

  .stage-plate {
    left: 16px;
    bottom: calc(var(--sheet-collapsed) + env(safe-area-inset-bottom) + 18px);
    width: calc(100vw - 32px);
    max-width: 440px;
    transition: opacity 220ms ease, transform 220ms ease;
  }

  body.sheet-open .stage-plate {
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
  }

  .plate-name {
    font-size: clamp(30px, 10vw, 44px);
  }

  .plate-tagline {
    max-width: 28ch;
    font-size: 11px;
  }

  .plate-meta {
    margin-top: 9px;
  }

  .plate-meta span {
    font-size: 6.2px;
    padding: 4px 6px;
  }

  .stage-loading {
    bottom: calc(var(--sheet-collapsed) + 28px + env(safe-area-inset-bottom));
  }

  .stage-error {
    padding: 16px;
    align-items: start;
    padding-top: 18vh;
  }

  .stage-error-card {
    padding: 20px;
  }

  .review-bar {
    top: calc(58px + env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    max-width: none;
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 10px 11px;
    transform: none;
  }

  .review-name {
    flex: 1;
    padding-left: 0;
    border-left: 0;
  }

  .review-name input {
    width: 100%;
    min-width: 80px;
  }

  .review-stats {
    order: 4;
    width: 100%;
  }

  .review-actions {
    margin-left: 0;
  }

  .review-actions .btn {
    min-height: 34px;
  }

  .toasts {
    bottom: calc(var(--sheet-collapsed) + env(safe-area-inset-bottom) + 12px);
    width: calc(100vw - 20px);
  }

  .dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 20px);
  }

  .dialog-card {
    max-height: calc(100dvh - 20px);
    border-radius: 19px;
  }

  .dialog-head {
    padding: 17px 16px 10px;
  }

  .dialog-title {
    font-size: 22px;
  }

  .dialog-sub {
    font-size: 10.5px;
  }

  .dialog-body {
    padding: 2px 16px 14px;
  }

  .dialog-foot {
    padding: 11px 16px calc(13px + env(safe-area-inset-bottom));
  }

  .dialog-foot .btn {
    min-height: 42px;
  }

  .dropzone {
    min-height: 186px;
    padding: 20px 14px;
  }

  .dropzone-notes {
    grid-template-columns: 1fr;
  }

  .dropzone-note {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 9px;
  }

  .dropzone-note strong {
    display: inline;
    margin: 0;
  }

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

  .publish-cell:last-child {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-column: 1 / -1;
  }

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

  .toasts {
    z-index: 260;
  }

  body.is-focus-mode .panel,
  body.is-focus-mode .topbar,
  body.is-focus-mode .stage-plate {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  .focus-exit {
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
  }

  .stage-empty {
    top: 40%;
  }
}

@media (max-width: 640px) {
  .panel.is-open {
    height: min(70vh, 600px);
  }

  .avatar-grid {
    gap: 6px;
  }

  .rig-cell {
    padding: 8px 8px;
  }

  .category-tabs {
    margin-right: -16px;
    padding-right: 16px;
  }

  .item-art {
    height: 78px;
  }

  .section-title {
    font-size: 14.5px;
  }

  .ability-feature {
    padding: 12px;
  }

  .feature-icon {
    width: 43px;
    height: 43px;
  }

  .publish-summary {
    padding: 10px;
  }

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

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

  .review-stats span {
    font-size: 6.2px;
  }

  .stage-loading {
    font-size: 7px;
  }
}

@media (max-width: 380px) {
  .brand-word {
    font-size: 13px;
  }

  .status-pill {
    padding: 0 7px;
  }

  .top-actions {
    gap: 4px;
  }

  .icon-button {
    width: 32px;
    height: 32px;
  }

  .panel.is-open {
    height: min(73vh, 590px);
  }

  .item-art {
    height: 72px;
  }

  .item-name {
    font-size: 10px;
  }

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

  .publish-cell {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .publish-cell:first-child {
    border-top: 0;
  }
}

/* short landscape screens */
@media (max-width: 900px) and (max-height: 520px) {
  .panel.is-open {
    height: 88vh;
  }

  .panel-head {
    padding-top: 8px;
    padding-bottom: 6px;
  }

  .panel-sub {
    display: none;
  }

  .stage-plate {
    display: none;
  }

  .sheet-grab {
    height: 12px;
  }

  .mobile-tab {
    height: 38px;
  }

  .panel {
    height: 118px;
  }
}

/* pointer-coarse ergonomics */
@media (pointer: coarse) {
  .mobile-tab,
  .category-tab,
  .motion-pill,
  .ability-link,
  .text-button {
    -webkit-tap-highlight-color: transparent;
  }

  .swatch {
    width: 34px;
    height: 34px;
  }

  .item-card:active,
  .avatar-card:active {
    transform: scale(0.985);
  }
}
