/* =============================================
   PHONE CHAT (mockup-mobile-chat.html, built in)
   Same query as the phone layout in css/responsive.css and MOBILE_QUERY
   in js/mobile-nav.js. Edge to edge: the link status and [SET-UP] along
   the top, the SISTERS / OBSERVER FEED switch under it, the composer
   with paperclip, gift and send keys, and the folders as an icon bar
   along the bottom. The header, menu and icons are built by
   js/mobile-nav.js and stay hidden outside the phone layout.

   The site sets every font size with !important through an id-heavy
   selector (css/terminal.css), so the few size overrides here are
   prefixed with three ids to outrank it.
   ============================================= */
#m-hdr,
#m-setup-menu,
.dash-folders .m-ico {
  display: none;
}

@media (max-width: 768px), (max-height: 520px) and (pointer: coarse) {

  /* ---- Edge to edge ---- */
  #terminal-container {
    padding: 0;
  }

  .dashboard-grid,
  .dash-right {
    gap: 0;
  }

  .dash-main {
    position: relative;
    padding: 0;
    border: 0 !important;
    box-shadow: none !important;
    background: var(--bg) !important;
  }

  /* The header replaces the status strip, the icon bar replaces DIR,
     and sound lives in [SET-UP] */
  #mobile-status-strip,
  #mobile-dir-tab,
  #terminal-container:has(#facility-map[style*="flex"]) #sys-keys {
    display: none !important;
  }

  /* ---- Header: link status, [SET-UP] ---- */
  #m-hdr {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    padding: 6px 12px;
    padding-top: max(6px, env(safe-area-inset-top));
  }

  .m-hdr-side {
    display: none;
  }

  .m-hdr-status {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--fg);
  }

  #m-setup {
    justify-self: end;
    padding: 2px 0;
    border: 0;
    background: transparent;
    color: var(--fg);
    white-space: nowrap;
    cursor: var(--cur-hand);
  }

  #m-setup[aria-expanded="true"] {
    background: var(--fg);
    color: var(--bg);
    text-shadow: none;
  }

  /* ---- [SET-UP] menu, dropped under the header ---- */
  #m-setup-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    position: absolute;
    top: 38px;
    right: 8px;
    z-index: 70;
    width: min(300px, calc(100% - 16px));
    box-sizing: border-box;
    padding: 10px;
    border: 1px solid var(--fg);
    background: var(--bg);
    color: var(--fg);
  }

  #m-setup-menu[hidden] {
    display: none;
  }

  .m-setup-title {
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(var(--fg-rgb), 0.28);
  }

  .m-setup-row {
    display: grid;
    grid-template-columns: 76px 1fr 1fr;
    align-items: center;
    gap: 6px;
  }

  .m-setup-opt,
  .m-setup-act {
    padding: 6px 4px;
    border: 1px solid rgba(var(--fg-rgb), 0.45);
    background: transparent;
    color: var(--fg);
    text-align: center;
    cursor: var(--cur-hand);
  }

  .m-setup-opt.is-on,
  .m-setup-opt:active,
  .m-setup-act:active {
    background: var(--fg);
    color: var(--bg);
    border-color: var(--fg);
    text-shadow: none;
  }

  .m-setup-act {
    text-align: left;
    border: 0;
    padding: 6px 2px;
  }

  /* ---- SISTERS / OBSERVER FEED: one boxed switch, chat only ---- */
  .dash-main > .encom-header {
    display: none !important;
  }

  body[data-room="subscriber-zone"] .dash-main > .encom-header {
    display: block !important;
    flex: 0 0 auto;
    margin: 0 !important;
    padding: 0 12px 8px !important;
    border: 0 !important;
    border-bottom: 1px solid rgba(var(--fg-rgb), 0.28) !important;
    background: transparent !important;
    min-height: 0 !important;
  }

  body[data-room="subscriber-zone"] .dash-main > .encom-header > :not(#visualization-header) {
    display: none !important;
  }

  .vis-title,
  .tab-br {
    display: none !important;
  }

  body[data-room="subscriber-zone"] #visualization-header {
    display: flex !important;
    width: 100%;
    border: 1px solid var(--fg);
    color: var(--fg) !important;
  }

  #header-tab-sisters,
  #header-tab-observer {
    flex: 1 1 0;
    margin: 0 !important;
    padding: 6px 0 !important;
    border: 0 !important;
    background: transparent !important;
    color: var(--fg) !important;
    text-align: center;
    text-decoration: none !important;
    box-shadow: none !important;
  }

  #header-tab-sisters.active-tab,
  #header-tab-observer.active-tab {
    background: var(--fg) !important;
    color: var(--bg) !important;
    text-shadow: none !important;
  }

  /* ---- The conversation, full width ---- */
  #premium-view-sisters {
    padding: 0 !important;
  }

  /* CONNECTED / translation bridge / exchanges: now the header line */
  #premium-view-sisters > div:first-child {
    display: none !important;
  }

  #sisters-chat-container {
    padding: 12px 12px 8px !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  #sisters-status-row {
    margin-bottom: 6px !important;
    padding: 0 12px;
  }

  #sisters-lockout-banner,
  #sisters-attach-status-container {
    margin: 0 10px 8px !important;
  }

  /* ---- Composer: paperclip, gift, TRANSMISSION, [NUDGE], send ---- */
  #sisters-input-bar {
    display: grid !important;
    grid-template-columns: auto auto 1fr auto auto;
    align-items: center;
    gap: 8px !important;
    padding: 8px 10px !important;
    border: 0 !important;
    border-top: 1px solid rgba(var(--fg-rgb), 0.28) !important;
    background: transparent !important;
  }

  #sisters-input-bar:has(#sisters-sock-thief-btn:not([style*="display: none"])) {
    grid-template-columns: auto auto auto 1fr auto auto;
    gap: 6px !important;
  }

  #sisters-input-bar:has(#sisters-user-nudge-btn:not([style*="display: none"])) {
    grid-template-columns: auto auto 1fr auto auto auto;
    gap: 6px !important;
  }

  #sisters-input-bar:has(#sisters-sock-thief-btn:not([style*="display: none"])):has(#sisters-user-nudge-btn:not([style*="display: none"])) {
    grid-template-columns: auto auto auto 1fr auto auto auto;
    gap: 5px !important;
  }

  #terminal-container #sisters-input-bar #sisters-user-nudge-btn {
    height: 40px;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
    padding: 0 7px !important;
    font-size: 15px !important;
    white-space: nowrap;
  }

  #sisters-input-bar > span {
    display: none !important;
  }

  #terminal-container #sisters-input-bar #sisters-attach-btn,
  #terminal-container #sisters-input-bar #sisters-credits-btn,
  #terminal-container #sisters-input-bar #sisters-sock-thief-btn,
  #terminal-container #sisters-input-bar #sisters-send {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    box-sizing: border-box;
    padding: 0 !important;
    border: 1px solid rgba(var(--fg-rgb), 0.45) !important;
    background: transparent !important;
    color: var(--fg) !important;
    font-size: 0 !important;
    box-shadow: none !important;
  }

  #terminal-container #sisters-input-bar #sisters-sock-thief-btn[style*="display: none"] {
    display: none !important;
  }

  #sisters-credits-btn .sisters-gift-label,
  #sisters-sock-thief-btn .sisters-sock-label,
  #sisters-send-icon {
    display: none !important;
  }

  #sisters-attach-btn .sisters-pic-icon,
  #sisters-credits-btn .sisters-gift-icon,
  #sisters-sock-thief-btn .sisters-sock-icon {
    width: 20px;
    height: 20px;
  }

  /* Return arrow, drawn in the key's own colour */
  #sisters-send::before {
    content: '';
    display: block;
    width: 20px;
    height: 20px;
    background: currentColor;
    -webkit-mask: var(--m-key-icon) center / contain no-repeat;
    mask: var(--m-key-icon) center / contain no-repeat;
  }

  #sisters-send {
    --m-key-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 5v7.5H6M10 8.5l-4 4 4 4' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }

  #terminal-container #sisters-input-bar #sisters-send {
    border-color: var(--fg) !important;
    background: var(--fg) !important;
    color: var(--bg) !important;
  }

  #sisters-attach-btn:disabled,
  #sisters-send:disabled {
    opacity: 0.45;
  }

  #sisters-input {
    height: 40px;
    box-sizing: border-box;
    padding: 0 10px !important;
    border: 1px solid rgba(var(--fg-rgb), 0.45) !important;
    background: transparent !important;
  }

  #sisters-input::placeholder {
    color: var(--fg) !important;
    opacity: 1;
  }

  /* The thinner DEC block for typing on a phone */
  #vt-block-caret {
    width: 6px !important;
  }

  /* ---- Folders: an icon bar along the bottom ---- */
  .dash-folders {
    gap: 0 !important;
    border-top: 1px solid rgba(var(--fg-rgb), 0.28);
    background: var(--bg);
  }

  .dash-folders .folder-tab,
  .dash-folders .folder-tab:not([data-target="subscriber-zone"]):not([data-target="products"]) {
    display: flex !important;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    position: relative;
    height: 44px;
    margin: 0;
    padding: 0;
    cursor: var(--cur-hand);
  }

  .dash-folders .folder-tab .folder-name,
  .dash-folders .folder-tab .folder-icon {
    display: none !important;
  }

  .dash-folders .m-ico {
    display: block;
    width: 20px;
    height: 20px;
    overflow: visible;
    color: var(--fg);
  }

  .dash-folders .folder-tab.active-folder {
    background: var(--fg);
  }

  .dash-folders .folder-tab.active-folder .m-ico {
    color: var(--bg);
  }

  html[data-display="standard"] .dash-folders .m-ico {
    filter: drop-shadow(-1px 0 0 rgba(40, 255, 110, 0.39)) drop-shadow(1px 0 0 rgba(200, 40, 255, 0.42));
  }

  /* Unread: a small blinking block beside the icon */
  .dash-folders .folder-tab.has-new-messages::after {
    content: '';
    position: absolute;
    top: 9px;
    left: calc(50% + 11px);
    width: 6px;
    height: 6px;
    background: var(--fg);
    animation: blink 1s step-end infinite;
  }

  .dash-folders .folder-tab.active-folder.has-new-messages::after {
    background: var(--bg);
  }

  /* Icons sit still and play once when tapped, every pose stepped */
  .m-ico * {
    transform-box: fill-box;
  }

  .m-ico.play.i-bubble .d1 { animation: sistersBinaryBlink1 1.375s steps(1) 1; }
  .m-ico.play.i-bubble .d2 { animation: sistersBinaryBlink2 1.375s steps(1) 1; }
  .m-ico.play.i-bubble .d3 { animation: sistersBinaryBlink3 1.375s steps(1) 1; }
  .m-ico.play.i-term .cursor { animation: mIcoCursor 0.9s steps(1) 1; }
  .m-ico.i-grid .cell { opacity: 0; }
  .m-ico.play.i-grid .c1 { animation: mIcoCell 0.9s steps(1) 0s 1; }
  .m-ico.play.i-grid .c2 { animation: mIcoCell 0.9s steps(1) 0.15s 1; }
  .m-ico.play.i-grid .c3 { animation: mIcoCell 0.9s steps(1) 0.3s 1; }
  .m-ico.play.i-grid .c4 { animation: mIcoCell 0.9s steps(1) 0.45s 1; }
  .m-ico.play.i-beacon .rays { animation: mIcoRays 0.8s steps(1) 1; }
  .m-ico.i-vend .carton { opacity: 0; }
  .m-ico.play.i-vend .carton { animation: mIcoDrop 0.8s steps(1) 1; }
}

@keyframes mIcoCursor {
  0%, 33% { opacity: 0; }
  34%, 66% { opacity: 1; }
  67%, 99% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes mIcoCell {
  0% { opacity: 1; }
  60% { opacity: 0; }
}

@keyframes mIcoRays {
  0%, 24% { opacity: 0; }
  25%, 49% { opacity: 1; }
  50%, 74% { opacity: 0; }
  75%, 100% { opacity: 1; }
}

@keyframes mIcoDrop {
  0% { opacity: 1; transform: translateY(0); }
  20% { opacity: 1; transform: translateY(3px); }
  40% { opacity: 1; transform: translateY(7px); }
  60% { opacity: 1; transform: translateY(11px); }
  85%, 100% { opacity: 0; transform: translateY(11px); }
}

@media (prefers-reduced-motion: reduce) {
  .m-ico.play * {
    animation: none !important;
  }
}
