/*
  PugOS Mobile is a second shell over the same application DOM. Everything in
  this file is either mobile-only furniture or scoped below the phone cutoff,
  so the desktop room and window manager keep their authored behaviour.
*/

.mobile-launcher,
.mobile-app__bar,
.mobile-system-nav,
.window--mobile-radio,
.mobile-wide-screen-note {
  display: none;
}

@media (max-width: 760px) {
  :root {
    --mobile-topbar: calc(44px + env(safe-area-inset-top));
    --mobile-appbar: 54px;
    --mobile-nav: calc(58px + env(safe-area-inset-bottom));
    --mobile-chassis-rail: clamp(8px, 2.5vw, 12px);
    --mobile-chassis: var(--surface-sunken);
    --mobile-chassis-raised: var(--surface-raised);
    --mobile-chassis-edge: var(--edge-strong);
    --mobile-display: var(--screen);
    --mobile-deck: var(--surface);
    --mobile-signal: var(--accent);
  }

  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--screen);
  }

  .os-shell {
    min-height: 100vh;
    height: 100dvh;
    background: var(--screen);
    box-shadow:
      inset var(--mobile-chassis-rail) 0 0 var(--mobile-chassis),
      inset calc(-1 * var(--mobile-chassis-rail)) 0 0 var(--mobile-chassis),
      inset calc(var(--mobile-chassis-rail) + 1px) 0 0 var(--mobile-chassis-edge),
      inset calc(-1 * (var(--mobile-chassis-rail) + 1px)) 0 0 var(--mobile-chassis-edge);
  }

  .os-shell::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
      linear-gradient(180deg, rgba(13, 14, 16, .1), rgba(13, 14, 16, .26)),
      url("./assets/wallpaper/mobile-workshop.webp") center / cover no-repeat;
    pointer-events: none;
  }

  .os-shell::after {
    content: "";
    position: fixed;
    inset: var(--mobile-topbar) 0 var(--mobile-nav);
    z-index: 200;
    border-inline: var(--mobile-chassis-rail) solid var(--mobile-chassis);
    box-shadow:
      inset 1px 0 0 var(--relief-light),
      inset -1px 0 0 var(--relief-dark);
    pointer-events: none;
  }

  .topbar {
    z-index: 210;
    height: var(--mobile-topbar);
    padding:
      env(safe-area-inset-top)
      max(calc(var(--mobile-chassis-rail) + 8px), env(safe-area-inset-right))
      0
      max(calc(var(--mobile-chassis-rail) + 8px), env(safe-area-inset-left));
    border-bottom-color: var(--mobile-chassis-edge);
    background: var(--mobile-chassis);
    box-shadow:
      inset 0 1px 0 var(--relief-light),
      inset 0 -2px 0 var(--relief-dark);
  }

  .topbar::before,
  .topbar::after {
    content: "";
    position: absolute;
    bottom: 6px;
    width: 4px;
    height: 4px;
    border: 1px solid var(--edge-soft);
    background: var(--screen);
    box-shadow: inset 1px 1px 0 var(--relief-light);
    transform: rotate(45deg);
    pointer-events: none;
  }

  .topbar::before {
    left: calc(var(--mobile-chassis-rail) / 2 - 2px);
  }

  .topbar::after {
    right: calc(var(--mobile-chassis-rail) / 2 - 2px);
  }

  .brand-chip {
    min-height: 36px;
    padding: 0;
    pointer-events: none;
  }

  .brand-chip__sigil {
    width: 27px;
    height: 27px;
  }

  .brand-chip span:last-child {
    font-size: 17px;
    letter-spacing: .06em;
  }

  .topbar__module,
  .status-pill {
    display: none;
  }

  .topbar__status {
    grid-column: 3;
    gap: 8px;
    font-size: 12px;
  }

  #clock {
    min-width: 44px;
    color: var(--ink-soft);
  }

  .mobile-launcher {
    position: fixed;
    inset:
      var(--mobile-topbar)
      var(--mobile-chassis-rail)
      var(--mobile-nav);
    z-index: 20;
    overflow-y: auto;
    padding:
      16px
      max(10px, env(safe-area-inset-right))
      24px
      max(10px, env(safe-area-inset-left));
    border-inline: 1px solid var(--edge-soft);
    background:
      linear-gradient(
        90deg,
        rgba(14, 15, 18, .32),
        transparent 12px,
        transparent calc(100% - 12px),
        rgba(14, 15, 18, .32)
      ),
      var(--mobile-chassis);
    box-shadow:
      inset 1px 0 0 var(--relief-light),
      inset -1px 0 0 var(--relief-dark);
    scrollbar-width: thin;
    scrollbar-color: var(--edge) transparent;
  }

  .is-mobile-shell.is-mobile-launcher .mobile-launcher {
    display: block;
  }

  .mobile-launcher__intro {
    position: relative;
    max-width: 38rem;
    margin: 3px auto 15px;
    padding: 13px 15px 14px 18px;
    border: 1px solid var(--mobile-chassis-edge);
    border-left: 3px solid var(--mobile-signal);
    background: var(--mobile-display);
    box-shadow:
      -3px 0 0 var(--mobile-chassis-raised),
      3px 0 0 var(--mobile-chassis-raised),
      0 -3px 0 var(--mobile-chassis-raised),
      0 4px 0 var(--relief-dark),
      inset 3px 3px 0 rgba(14, 15, 18, .68),
      inset -2px -2px 0 var(--relief-light);
  }

  .mobile-launcher__system {
    margin: 0 0 5px;
    color: var(--accent-lit);
    font-family: var(--font-terminal);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: .12em;
  }

  .mobile-launcher__intro h1 {
    margin: 0 0 5px;
    color: var(--ink);
    font-family: var(--font-brand);
    font-size: clamp(23px, 7vw, 31px);
    font-weight: 650;
    line-height: 1.08;
  }

  .mobile-launcher__intro h1:focus {
    outline: 0;
  }

  .mobile-launcher__intro > p:last-child {
    max-width: 34rem;
    margin: 0;
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.42;
  }

  .mobile-launcher__grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px 4px;
    max-width: 38rem;
    margin: 0 auto 4px;
    padding: 14px 10px 16px;
    border: 1px solid var(--mobile-chassis-edge);
    background: var(--mobile-deck);
    box-shadow:
      -3px 0 0 var(--mobile-chassis-raised),
      3px 0 0 var(--mobile-chassis-raised),
      0 -3px 0 var(--mobile-chassis-raised),
      0 4px 0 var(--relief-dark),
      inset 3px 3px 0 rgba(14, 15, 18, .44),
      inset -2px -2px 0 var(--relief-light);
  }

  .mobile-launcher__grid::before,
  .mobile-launcher__grid::after {
    content: "";
    position: absolute;
    left: 50%;
    width: 12px;
    height: 2px;
    background: var(--edge-soft);
    opacity: .62;
    transform: translateX(-50%);
    pointer-events: none;
  }

  .mobile-launcher__grid::before {
    top: 7px;
  }

  .mobile-launcher__grid::after {
    bottom: 7px;
  }

  .mobile-module {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 118px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 9px 7px 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink);
    text-decoration: none;
    transition:
      transform 160ms var(--ease-mechanical),
      border-color 160ms var(--ease-mechanical),
      background 160ms var(--ease-mechanical);
  }

  .mobile-module--priority {
    color: var(--ink);
  }

  .mobile-module::after {
    content: "";
    position: absolute;
    inset: auto 18% 4px;
    height: 2px;
    background: var(--mobile-signal);
    opacity: 0;
    transform: scaleX(.25);
    transition: opacity 160ms ease-out, transform 160ms ease-out;
  }

  .mobile-module:active,
  .mobile-module.is-launching {
    transform: translateY(2px);
    border-color: var(--edge-strong);
    background: var(--mobile-chassis-raised);
  }

  .mobile-module:active::after,
  .mobile-module.is-launching::after {
    opacity: 1;
    transform: scaleX(1);
  }

  .mobile-module:focus-visible {
    outline: var(--focus-width) solid var(--focus-color);
    outline-offset: -3px;
  }

  .mobile-module img,
  .mobile-module__radio-glyph {
    width: clamp(58px, 17vw, 68px);
    height: clamp(58px, 17vw, 68px);
    flex: 0 0 auto;
    margin-bottom: 5px;
    object-fit: contain;
  }

  .mobile-module strong {
    max-width: 100%;
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 650;
    line-height: 1.12;
    text-align: center;
  }

  .mobile-module > span:last-child {
    padding-top: 4px;
    color: var(--ink-dim);
    font-family: var(--font-terminal);
    font-size: 8px;
    letter-spacing: .08em;
    text-align: center;
  }

  .mobile-module__radio-glyph {
    display: grid;
    place-items: center;
    border: 1px solid var(--phosphor);
    background:
      repeating-linear-gradient(0deg, rgba(127, 174, 155, .16) 0 2px, transparent 2px 5px),
      var(--console);
    color: var(--phosphor);
    font-family: var(--font-terminal);
    border-width: 2px 1px;
    font-size: 15px;
    letter-spacing: .08em;
  }

  .mobile-app__bar {
    position: fixed;
    inset:
      var(--mobile-topbar)
      var(--mobile-chassis-rail)
      auto;
    z-index: 205;
    height: var(--mobile-appbar);
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: stretch;
    padding-inline:
      max(0px, env(safe-area-inset-left))
      max(0px, env(safe-area-inset-right));
    border-bottom: 1px solid var(--mobile-chassis-edge);
    background: var(--surface-sunken);
    color: var(--ink);
  }

  .is-mobile-shell:not(.is-mobile-launcher) .mobile-app__bar {
    display: grid;
  }

  .mobile-app__back {
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-right: 1px solid var(--edge-soft);
    background: transparent;
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 20px;
    cursor: pointer;
  }

  .mobile-app__back span {
    font-size: 11px;
    font-weight: 600;
  }

  .mobile-app__back:focus-visible {
    outline: var(--focus-width) solid var(--focus-color);
    outline-offset: -3px;
  }

  .mobile-app__identity {
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    margin: 0;
    padding: 0 13px;
    border-left: 2px solid var(--accent);
  }

  .mobile-app__identity span {
    color: var(--ink-dim);
    font-family: var(--font-terminal);
    font-size: 8px;
    letter-spacing: .1em;
  }

  .mobile-app__identity strong {
    min-width: 0;
    overflow: hidden;
    color: var(--ink);
    font-family: var(--font-brand);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.15;
    letter-spacing: .03em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-app__identity strong:focus {
    outline: 0;
  }

  .mobile-system-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 210;
    height: var(--mobile-nav);
    align-items: flex-start;
    justify-content: space-between;
    padding:
      7px
      max(10px, env(safe-area-inset-right))
      env(safe-area-inset-bottom)
      max(10px, env(safe-area-inset-left));
    border-top: 1px solid var(--mobile-chassis-edge);
    background: var(--mobile-chassis);
    box-shadow: inset 0 2px 0 var(--relief-light);
  }

  .is-mobile-shell .mobile-system-nav {
    display: flex;
  }

  .mobile-system-nav a {
    display: inline-flex;
    min-width: 88px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    border: 1px solid var(--edge-soft);
    background: var(--surface);
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 650;
    text-decoration: none;
  }

  .mobile-system-nav a:focus-visible {
    outline: var(--focus-width) solid var(--focus-color);
    outline-offset: -2px;
  }

  .mobile-system-nav__home {
    min-width: 48px !important;
    width: 48px;
    padding: 0 !important;
  }

  .mobile-system-nav__home .brand-chip__sigil {
    width: 29px;
    height: 29px;
  }

  .is-mobile-launcher .mobile-system-nav {
    justify-content: flex-end;
  }

  .is-mobile-launcher [data-mobile-contact] {
    display: none;
  }

  .is-mobile-shell .dock,
  .is-mobile-shell .room-layer,
  .is-mobile-shell .signal-feed {
    display: none;
  }

  .is-mobile-shell .desktop {
    inset:
      calc(var(--mobile-topbar) + var(--mobile-appbar))
      var(--mobile-chassis-rail)
      var(--mobile-nav);
    z-index: 30;
    background: var(--surface);
    border-inline: 1px solid var(--mobile-chassis-edge);
    box-shadow:
      inset 3px 0 0 var(--relief-dark),
      inset -2px 0 0 var(--relief-light);
  }

  .is-mobile-shell.is-mobile-launcher .desktop {
    display: none;
  }

  .is-mobile-shell .window-layer {
    position: absolute;
    inset: 0;
    background: var(--surface);
  }

  .is-mobile-shell .window-layer::before {
    display: none;
  }

  .is-mobile-shell .window {
    position: absolute;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    max-height: none;
    grid-template-rows: minmax(0, 1fr);
    border: 0;
    border-radius: 0;
    background: var(--surface);
    box-shadow: none;
    animation: mobile-app-in 170ms var(--ease-mechanical) both;
  }

  .is-mobile-shell .window:not(.is-focused),
  .is-mobile-shell .window[hidden],
  .is-mobile-shell .window.is-minimized {
    display: none;
  }

  .is-mobile-shell .window--mobile-radio.is-focused:not([hidden]) {
    display: grid;
  }

  .is-mobile-shell .window__bar {
    display: none;
  }

  .is-mobile-shell .window__body {
    min-height: 0;
    border: 0;
    background: var(--surface);
  }

  .is-mobile-shell .window__content {
    inset: 0;
    padding:
      18px
      max(16px, env(safe-area-inset-right))
      24px
      max(16px, env(safe-area-inset-left));
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--edge) var(--surface-sunken);
  }

  .is-mobile-shell .window__content h1 {
    font-size: clamp(34px, 10vw, 44px);
  }

  .is-mobile-shell .window__content h2 {
    font-size: clamp(27px, 8vw, 35px);
  }

  .is-mobile-shell .window--welcome {
    display: none !important;
  }

  .is-mobile-shell .button,
  .is-mobile-shell button,
  .is-mobile-shell input,
  .is-mobile-shell .reader__section,
  .is-mobile-shell .manual__tool,
  .is-mobile-shell [data-manual-goto] {
    min-height: 44px;
  }

  .is-mobile-shell .detail-strip {
    min-height: 72px;
  }

  .is-mobile-shell .mail__send-row {
    position: sticky;
    top: 0;
    z-index: 4;
    background: var(--surface-sunken);
  }

  .is-mobile-shell .mail__format-key {
    min-width: 44px;
    min-height: 44px;
  }

  .is-mobile-shell .mail__editor {
    min-height: max(190px, 30dvh);
  }

  .is-mobile-shell .reader__pane {
    padding: 18px 16px 24px;
  }

  .is-mobile-shell .reader__sections {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .is-mobile-shell .reader__section {
    justify-content: center;
    padding: 8px;
    border-left: 0;
    border-bottom: 2px solid transparent;
    font-size: 12px;
  }

  .is-mobile-shell .reader__section.is-current {
    border-bottom-color: var(--accent);
  }

  .is-mobile-shell .reader__count {
    display: none;
  }

  .is-mobile-shell .reader__sheet {
    padding: 18px 16px 22px;
  }

  .window--mobile-radio .window__content {
    display: grid;
    place-items: center;
    overflow-y: auto;
    background:
      repeating-linear-gradient(0deg, rgba(127, 174, 155, .025) 0 1px, transparent 1px 5px),
      var(--console);
  }

  .mobile-radio-slot {
    width: min(100%, 430px);
  }

  .window--mobile-radio .signal-radio {
    position: static;
    display: block;
    width: 100%;
    border-color: var(--edge-strong);
    background: var(--surface);
    box-shadow:
      inset 1px 1px 0 var(--relief-light),
      inset -1px -1px 0 var(--relief-dark),
      6px 7px 0 rgba(0, 0, 0, .28);
  }

  .window--mobile-radio .signal-radio__header {
    padding: 15px 16px 13px;
  }

  .window--mobile-radio .signal-radio__identity h2 {
    font-size: 16px;
  }

  .window--mobile-radio .signal-radio__stage {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 15px;
    padding: 18px 16px;
  }

  .window--mobile-radio .signal-radio .signal-radio__level {
    width: 60px;
  }

  .window--mobile-radio .signal-radio__ladder {
    height: 76px;
  }

  .window--mobile-radio .signal-radio__plate {
    padding: 13px 16px;
    overflow-x: auto;
  }

  .window--mobile-radio .signal-radio__line {
    font-size: 9px;
  }

  .window--mobile-radio .signal-radio__footer {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 12px 16px;
  }

  .window--mobile-radio .signal-radio__selector {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .window--mobile-radio .signal-radio__dial-bank {
    width: 74px;
    height: 74px;
  }

  .window--mobile-radio .signal-radio__dial {
    width: 58px;
    height: 58px;
  }

  .window--mobile-radio .signal-radio__detent {
    font-size: 7px;
  }

  .window--mobile-radio .signal-radio__detent--one,
  .window--mobile-radio .signal-radio__detent--four {
    top: 17px;
  }

  .window--mobile-radio .signal-radio__selection span {
    font-size: 8px;
  }

  .window--mobile-radio .signal-radio__selection a {
    font-size: 10px;
  }

  .window--mobile-radio .signal-radio__toggle {
    min-width: 84px;
    min-height: 48px;
  }

  .is-mobile-shell .window--terminal .console-module {
    display: none;
  }

  .is-mobile-shell .window--terminal .window__content {
    overflow-y: auto;
    padding: 20px 18px;
    background: var(--surface);
  }

  .is-mobile-shell .mobile-wide-screen-note {
    display: block;
    max-width: 34rem;
    margin: 0 auto;
    padding: 22px 20px;
    border: 1px solid var(--edge);
    border-left: 3px solid var(--phosphor);
    background: var(--surface-raised);
  }

  .is-mobile-shell .mobile-wide-screen-note h2 {
    margin-bottom: 12px;
    font-size: clamp(28px, 8vw, 36px);
  }

  @keyframes mobile-app-in {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

@media (min-width: 560px) and (max-width: 760px) {
  .mobile-launcher__grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mobile-launcher__grid::before,
  .mobile-launcher__grid::after {
    display: none;
  }
}

@media (max-width: 350px) {
  .mobile-launcher {
    padding-inline: 10px;
  }

  .mobile-module {
    min-height: 110px;
    padding-inline: 5px;
  }

  .mobile-module img,
  .mobile-module__radio-glyph {
    width: 56px;
    height: 56px;
  }
}

@media (max-width: 760px) and (hover: hover) and (pointer: fine) {
  .mobile-module:hover {
    border-color: var(--edge-soft);
    background: rgba(58, 62, 68, .72);
  }

  .mobile-system-nav a:hover,
  .mobile-app__back:hover {
    border-color: var(--edge-strong);
    background: var(--surface-raised);
    color: var(--ink);
  }
}

@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
  .is-mobile-shell .window,
  .mobile-module,
  .mobile-module::after {
    animation: none;
    transition: none;
  }
}

@media (max-width: 760px) and (hover: none) {
  .mobile-module:hover,
  .mobile-system-nav a:hover,
  .mobile-app__back:hover {
    transform: none;
  }
}
