/* nurr-mobile.css
   External responsive layer for NURR.
   This file only changes layout on small screens. It does not touch generator logic.
*/

@media (max-width: 820px), (max-height: 650px) {
  html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
  }

  #root {
    width: 100svw;
    height: 100svh;
    overflow: hidden;
  }

  canvas.stage,
  .nature-fallback-img,
  .placeholder-overlay {
    width: 100svw !important;
    height: 100svh !important;
  }

  .nurr-brand {
    left: 18px;
    top: 18px;
    font-size: clamp(30px, 11vw, 46px);
    line-height: 0.9;
    z-index: 9;
    opacity: 0.92;
  }

  .corner-mark {
    right: 16px;
    bottom: 78px;
    opacity: 0.55;
  }

  .corner-mark .big {
    font-size: 17px;
  }

  .corner-mark .small {
    display: none;
  }

  /* Mode rail becomes a compact bottom tab bar */
  .rail {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    height: 58px;
    z-index: 21;
    padding: 0 max(12px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
    background: rgba(8, 1, 95, 0.42);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid rgba(244, 237, 224, 0.22);
    pointer-events: auto;
    justify-content: center;
  }

  .rail-group {
    width: 100%;
    height: 100%;
    flex-direction: row;
    justify-content: space-between;
    gap: 0;
  }

  .rail-item {
    writing-mode: horizontal-tb;
    transform: none;
    flex: 1;
    height: 100%;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(13px, 3.6vw, 17px);
    line-height: 1;
    letter-spacing: 0.02em;
    color: rgba(244, 237, 224, 0.78);
    text-shadow: none;
  }

  .rail-item.active {
    color: #fffaf0;
  }

  .rail-item:hover {
    color: #fffaf0;
  }

  /* Control panel becomes a bottom sheet */
  .panel {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    top: auto !important;
    bottom: calc(58px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-height: min(72svh, 620px);
    z-index: 20;
    border-radius: 18px 18px 0 0;
    overflow: hidden;
    transform: translateY(calc(100% - 66px));
    transition: transform 0.28s cubic-bezier(.2,.8,.2,1), box-shadow 0.28s ease;
    box-shadow: 0 -18px 54px rgba(8, 1, 95, 0.22);
  }

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

  .panel-header {
    min-height: 66px;
    padding: 13px 16px 10px;
    align-items: center;
    cursor: pointer;
  }

  .panel-eyebrow {
    font-size: 9px;
    margin-bottom: 5px;
  }

  .panel-title {
    font-size: 19px;
    line-height: 0.94;
    max-width: 190px;
  }

  .header-actions {
    align-items: center;
  }

  .icon-btn {
    width: 28px;
    height: 28px;
  }

  .mobile-panel-handle {
    position: absolute;
    left: 50%;
    top: 7px;
    transform: translateX(-50%);
    width: 42px;
    height: 4px;
    border: 0;
    border-radius: 999px;
    background: rgba(10,5,64,0.22);
    padding: 0;
    cursor: pointer;
  }

  .panel-body {
    max-height: calc(min(72svh, 620px) - 66px);
    padding: 12px 16px 18px;
    -webkit-overflow-scrolling: touch;
  }

  .section {
    margin-top: 14px;
  }

  .section-label .name {
    font-size: 15px;
  }

  .section-label .value {
    font-size: 9px;
  }

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

  .palette-grid {
    grid-template-columns: repeat(5, 1fr);
    max-height: 96px;
    gap: 5px;
  }

  .palette-card {
    height: 28px;
  }

  .layout-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .formation-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .nature-grid {
    grid-template-columns: repeat(4, 1fr);
    max-height: 128px;
  }

  .btn {
    padding: 8px 10px;
    font-size: 11px;
  }

  .btn-italic {
    font-size: 15px;
  }

  .help {
    font-size: 12px;
    margin-top: 14px;
    padding-top: 12px;
  }

  /* Color picker: centered and finger-safe */
  .color-wheel-card {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    top: 50% !important;
    width: min(88vw, 320px);
    padding: 20px;
    transform: translate(-50%, -50%);
    border-radius: 22px;
    z-index: 60;
  }

  .color-wheel-surface {
    height: 150px;
    border-radius: 28px;
  }

  .color-readout div {
    font-size: 12px;
    padding: 6px 0;
  }

  .eyedropper-follow {
    width: 50px;
    height: 50px;
    transform: translate3d(-25px, -25px, 0);
  }

  .eyedropper-color {
    width: 42px;
    height: 42px;
  }

  .eyedropper-follow svg {
    width: 26px;
    height: 26px;
  }

  .collection-drawer {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(58px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 170px;
    z-index: 19;
    border-radius: 14px 14px 0 0;
  }

  body.mobile-panel-open .collection-drawer {
    display: none;
  }

  .collection-grid {
    grid-template-columns: repeat(4, 1fr);
    max-height: 78px;
  }

  .snapshot-toast {
    bottom: calc(76px + env(safe-area-inset-bottom));
    font-size: 15px;
    padding: 10px 18px;
  }
}

/* Very narrow phones */
@media (max-width: 420px) {
  .nurr-brand {
    left: 14px;
    top: 14px;
    font-size: 34px;
  }

  .panel {
    left: 0 !important;
    right: 0 !important;
    bottom: calc(56px + env(safe-area-inset-bottom)) !important;
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
  }

  .rail {
    height: 56px;
  }

  .rail-item {
    font-size: 14px;
  }

  .palette-grid {
    grid-template-columns: repeat(4, 1fr);
  }

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

  .nature-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
