/* ui-v5.css
   Mobile-first hardening and tablet adaptation layer.
   Original features and interactions remain untouched. */

:root {
  --ui5-touch: 44px;
  --ui5-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ui5-safe-top: env(safe-area-inset-top, 0px);
  --ui5-safe-left: env(safe-area-inset-left, 0px);
  --ui5-safe-right: env(safe-area-inset-right, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  overflow-x: clip;
  overscroll-behavior-y: none;
}

button,
input,
label,
select,
textarea {
  touch-action: manipulation;
}

h1,
h2,
h3,
p {
  overflow-wrap: break-word;
}

/* Mobile quick nav for the standalone pages. */
.ui5-mobile-nav {
  display: none;
}

@media (max-width: 900px) {
  .ui5-mobile-nav {
    position: fixed;
    z-index: 1080;
    right: max(12px, var(--ui5-safe-right));
    bottom: max(12px, var(--ui5-safe-bottom));
    left: max(12px, var(--ui5-safe-left));
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
    border: 2px solid var(--v3-ink);
    border-radius: 18px;
    background: rgba(255, 253, 247, .92);
    box-shadow: 6px 6px 0 var(--v3-yellow), 0 18px 44px rgba(39, 49, 58, .16);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
  }

  .ui5-mobile-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 12px;
    color: var(--v3-ink);
    font: 800 12px/1 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
    text-decoration: none;
    transition: color .25s ease, background .25s ease, transform .25s ease;
  }

  .ui5-mobile-nav a:hover,
  .ui5-mobile-nav a:focus-visible {
    color: var(--v3-coral-deep);
    background: rgba(255, 142, 113, .14);
    transform: translateY(-1px);
  }

  .ui5-mobile-nav a[aria-current="page"] {
    color: #fff;
    background: var(--v3-ink);
    box-shadow: 0 5px 16px rgba(39, 49, 58, .2);
  }

  .standalone-page main {
    padding-bottom: calc(92px + var(--ui5-safe-bottom));
  }
}

@media (min-width: 901px) {
  .ui5-mobile-nav {
    display: none !important;
  }
}

/* Touch-first controls and hover cleanup on coarse pointers. */
@media (hover: none), (pointer: coarse) {
  .command-button,
  .icon-button,
  .gallery-dialog__actions button,
  .gallery-viewer__actions button,
  .segmented-control button {
    min-height: var(--ui5-touch);
  }

  .line-puppy-theme .atlas-photo:hover,
  .line-puppy-theme .reel-frame:hover,
  .line-puppy-theme .constellation-photo:hover,
  .line-puppy-theme .photo-slot__view:hover,
  .line-puppy-theme .letter-button:hover,
  .line-puppy-theme .goodnight__button:hover {
    transform: none !important;
  }

  .gallery-photo:hover,
  .gallery-photo__favorite:hover,
  .command-button:hover,
  .icon-button:hover {
    transform: none !important;
  }

  .gallery-photo:hover .gallery-photo__open img {
    transform: none !important;
  }

  .calendar-day:hover,
  .calendar-day[aria-pressed="true"] {
    transform: none !important;
  }

  .line-puppy-theme .photo-slot__view:hover {
    color: inherit;
    background: inherit;
  }
}

/* Landscape phones and very short viewports. */
@media (max-height: 560px) and (orientation: landscape) {
  .entry-login {
    top: 50%;
    max-height: calc(100svh - 12px);
    padding-top: 58px;
    padding-bottom: 18px;
  }

  .entry-login__lead {
    margin: 12px auto 16px;
    font-size: 13px;
  }

  .entry-field input {
    height: 42px;
  }

  .entry-login__submit {
    margin-top: 14px;
  }

  .film__scroll-cue {
    display: none;
  }

  .goodnight {
    min-height: 100svh;
    padding-top: 24vh;
    padding-bottom: var(--ui5-safe-bottom);
  }
}

/* Tablet portrait and medium screens: tighter but still full-featured. */
@media (min-width: 621px) and (max-width: 1024px) {
  .line-puppy-theme .scene-copy--opening {
    top: 17%;
    max-width: min(58vw, 500px);
  }

  .line-puppy-theme .scene-copy--encounter {
    top: 24%;
    max-width: min(50vw, 440px);
  }

  .line-puppy-theme .scene-copy--ordinary {
    top: 52%;
    right: 8vw;
    max-width: min(50vw, 440px);
  }

  .line-puppy-theme .scene-copy--promise {
    top: 23%;
    left: 8vw;
    max-width: min(54vw, 480px);
  }

  .line-puppy-theme .scene-copy--ending {
    top: 27%;
    right: 8vw;
    max-width: min(54vw, 490px);
  }

  .line-puppy-theme .photo-card--main {
    width: min(42vw, 360px);
  }

  .line-puppy-theme .photo-card--second {
    width: min(19vw, 175px);
  }

  .line-puppy-theme .photo-card--third {
    width: min(18vw, 165px);
  }

  .line-puppy-theme .global-countdown--home {
    width: min(360px, 44vw);
  }

  .line-puppy-theme .atlas__masonry {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-flow: dense;
    height: auto !important;
    gap: 18px;
    margin-top: 72px;
  }

  .line-puppy-theme .atlas-photo {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: auto !important;
    aspect-ratio: .8 !important;
    transform: translate3d(0, 34px, 0) rotate(var(--tilt));
  }

  .line-puppy-theme .atlas-photo.is-visible {
    transform: translate3d(0, 0, 0) rotate(var(--tilt));
  }

  .line-puppy-theme .atlas-photo:nth-child(1),
  .line-puppy-theme .atlas-photo:nth-child(5),
  .line-puppy-theme .atlas-photo:nth-child(9) {
    grid-column: span 2;
    aspect-ratio: 1.2 !important;
  }

  .line-puppy-theme .atlas__little-line {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    grid-column: span 3;
    margin: 6px 0;
  }

  .line-puppy-theme .atlas__afterword {
    width: min(560px, 80%);
    margin-right: 8%;
  }

  .line-puppy-theme .goodnight__ring {
    width: min(82vw, 720px);
  }

  .gallery-wall {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 118px;
  }

  .calendar-workspace {
    grid-template-columns: minmax(0, 1fr) 280px;
  }

  .calendar-main {
    padding-right: 22px;
  }

  .calendar-rail {
    padding-left: 22px;
  }
}

@media (max-width: 900px) {
  body.line-puppy-theme .memory-mark {
    padding-right: max(18px, var(--ui5-safe-right));
    padding-left: max(18px, var(--ui5-safe-left));
  }

  .standalone-page .global-nav {
    padding-right: max(14px, var(--ui5-safe-right));
    padding-left: max(14px, var(--ui5-safe-left));
  }
}

/* Small phones: reduce empty space and keep every control tappable. */
@media (max-width: 480px) {
  .line-puppy-theme .entry-login {
    width: calc(100% - 24px);
    padding: 60px 18px 20px;
  }

  .line-puppy-theme .entry-login__lead {
    font-size: 13px;
  }

  .line-puppy-theme .entry-field input {
    height: 46px;
  }

  .line-puppy-theme .entry-login__submit {
    min-height: 48px;
  }

  .line-puppy-theme .global-countdown--home {
    top: 55vh;
    width: calc(100vw - 20px);
  }

  .line-puppy-theme .scene-copy--opening {
    top: 17%;
  }

  .line-puppy-theme .scene-copy--encounter,
  .line-puppy-theme .scene-copy--promise {
    top: 16%;
  }

  .line-puppy-theme .scene-copy--ordinary,
  .line-puppy-theme .scene-copy--ending {
    top: 17%;
  }

  .line-puppy-theme .photo-card--main {
    width: min(58vw, 270px);
  }

  .line-puppy-theme .photo-card--second {
    width: min(38vw, 160px);
  }

  .line-puppy-theme .photo-card--third {
    width: min(36vw, 150px);
  }

  .line-puppy-theme .atlas__masonry {
    gap: 12px;
  }

  .reel-frame {
    width: min(62vw, 230px);
  }

  .photo-reel__track {
    gap: 10vw;
  }

  .calendar-hero__clock {
    font-size: 27px;
  }

  .calendar-day {
    min-height: 46px;
    padding: 4px;
  }

  .calendar-day__number {
    width: 25px;
    height: 25px;
    font-size: 10px;
  }

  .calendar-day__markers {
    right: 3px;
    bottom: 3px;
    gap: 2px;
  }

  .calendar-day__marker {
    width: 6px;
    height: 6px;
  }

  .calendar-event,
  .upcoming-event {
    padding: 11px 10px;
  }

  .gallery-empty {
    padding: 18px 16px;
  }

  .gallery-empty img {
    width: min(220px, 62vw);
  }

  .gallery-viewer__side {
    min-height: 220px;
    padding: 26px 16px 18px;
  }
}

/* Dialogs must never escape the small viewport. */
dialog {
  max-height: calc(100svh - 16px);
  overflow: auto;
}

.gallery-viewer__panel {
  max-height: calc(100svh - 16px);
}

@media (max-width: 620px) {
  .gallery-viewer__image {
    min-height: 46svh;
  }

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

/* Light mobile performance pass: fewer stacked paint layers. */
@media (max-width: 620px) {
  body.line-puppy-theme .memory-atmosphere::before {
    background-image: none;
  }

  body.line-puppy-theme .ambient-petals {
    display: none;
  }

  body.line-puppy-theme .film__grain {
    opacity: .18;
  }

  body.line-puppy-theme .halo {
    display: none;
  }

  body.line-puppy-theme .journey-line {
    opacity: .38;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ui5-mobile-nav,
  .ui5-mobile-nav a {
    transition: none;
  }
}
