/*
 * Forward Korea UI 2.0 / Mobile shell polish — incremental opt-in stylesheet.
 * No navigation or feature removal. The current five destinations remain intact.
 * Keep semantic light/night tokens and the existing paper/ink editorial character.
 * Works without native plugins or device-specific APIs.
 */
@media (max-width: 760px) {
  :root {
    --fk-ui2-nav-offset: max(8px, env(safe-area-inset-bottom, 0px));
    --fk-ui2-nav-clearance: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  body:not(:has(#meme-forge)) {
    padding-bottom: var(--fk-ui2-nav-clearance);
  }

  /* The page must never finish behind the floating PWA tab bar. */
  .bottom-nav {
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: var(--fk-ui2-nav-offset);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    gap: 4px;
    padding: 7px;
    margin: 0;
    box-sizing: border-box;
    border: 2px solid var(--ui-border);
    border-radius: 16px;
    /* Colors come from the existing theme rules (paper/ink light, night palette). */
    box-shadow: var(--ui-shadow);
  }

  .bottom-nav a {
    min-width: 0;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    border-radius: 10px;
    font-size: 11px;
    line-height: 1.12;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .bottom-nav a > span,
  .bottom-nav a .fk-icon {
    color: inherit;
    flex: none;
  }

  .bottom-nav a.active {
    background: var(--ui-selected);
    color: var(--ui-on-selected);
    border-radius: 10px;
  }

  .bottom-nav a.active > span,
  .bottom-nav a.active .fk-icon {
    color: var(--ui-on-selected);
  }

  .bottom-nav a:focus-visible {
    outline: 3px solid var(--ui-focus);
    outline-offset: 2px;
  }

  /* Keep the logo and tactile toolbar; avoid an oversized first viewport. */
  .top-nav .nav-inner {
    height: 58px;
    min-height: 58px;
    gap: 8px;
  }

  .top-nav .utility-inner {
    min-height: 44px;
    padding-top: 2px;
    padding-bottom: 2px;
  }

  .top-nav .utility-right {
    min-width: 0;
    max-width: 100%;
    gap: 6px;
  }

  .top-nav .burger-btn {
    min-height: 44px;
    min-width: 44px;
    flex-shrink: 0;
  }

  .ticker .track {
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 11px;
  }

  #trend-bar,
  #trend-bar .trend-line {
    min-height: 40px;
  }

  /* PWA update controls must sit ABOVE navigation and stay legible at 320px. */
  .pwa-update-banner {
    left: 50%;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    box-sizing: border-box;
    width: min(420px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    max-height: min(48dvh, 360px);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 2px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface-raised);
    color: var(--ui-text);
    box-shadow: var(--ui-shadow);
    text-align: left;
    overflow-wrap: anywhere;
  }

  .pwa-update-banner > span,
  .pwa-update-banner > .pwa-update-summary,
  .pwa-update-banner > [data-pwa-release-pending] {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .pwa-update-banner > button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding: 8px 6px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .pwa-update-banner > button:focus-visible {
    outline: 3px solid var(--ui-focus);
    outline-offset: 2px;
  }
}

/* The full-screen Meme Forge retains ownership of the viewport on mobile. */
@media (max-width: 767px) {
  body:has(#meme-forge) .pwa-update-banner {
    display: none;
  }
}

@media (max-width: 390px) {
  .top-nav .logo-text small {
    display: none;
  }

  .bottom-nav a {
    font-size: 10px;
  }
}

@media (max-height: 540px) and (max-width: 760px) {
  .pwa-update-banner {
    max-height: 36dvh;
  }
}
