/* Mobile app layer: edge-to-edge safe areas, phone header, touch sizing, install tip. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }

/* Edge to edge: content runs under the notch / home bar, controls stay clear of them.
   The strip behind the status bar stays brand-black so the phone's white status text is always readable. */
.topbar {
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(to bottom, #0B0B0C env(safe-area-inset-top), var(--ink) env(safe-area-inset-top));
}
.wrap { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
footer.site { padding-bottom: calc(36px + env(safe-area-inset-bottom)); }
.mini-bar { bottom: calc(12px + env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }
@media (max-width: 899px) { body.form-active footer.site { padding-bottom: calc(90px + env(safe-area-inset-bottom)); } }
.toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
.modal-backdrop { padding-top: calc(24px + env(safe-area-inset-top)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Installed app: no rubber-band reveal behind the page, no accidental text selection on buttons. */
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } }
.is-app .btn, .is-app .topnav button, .is-app .theme-switch { -webkit-user-select: none; user-select: none; }

/* Phone header: brand + theme switch on one row, menu as a single swipeable row below. */
@media (max-width: 640px) {
  .topbar .wrap { gap: 6px 10px; min-height: 54px; padding-top: 8px; }
  .top-actions { display: contents; }
  .brand { order: 0; }
  .theme-switch { order: 1; margin-left: auto; }
  .topnav { order: 2; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * max(16px, env(safe-area-inset-left))) 0; padding: 0 max(16px, env(safe-area-inset-left)) 8px; scroll-snap-type: x proximity; }
  .topnav::-webkit-scrollbar { display: none; }
  .topnav button, .topnav a { white-space: nowrap; scroll-snap-align: start; }
  .topnav.hidden { display: none !important; }
}

/* Touch screens: comfortable 44–48px tap targets. */
@media (pointer: coarse) {
  .btn { min-height: 48px; }
  .topnav button, .topnav a { min-height: 44px; display: inline-flex; align-items: center; }
  .theme-switch { min-height: 40px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
}

/* Phones: full-width primary actions, sheet-style dialogs. */
@media (max-width: 520px) {
  .form-actions .btn, .modal-foot .btn { flex: 1 1 auto; }
  .modal-backdrop { padding-left: 0; padding-right: 0; padding-bottom: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: calc(100dvh - 24px - env(safe-area-inset-top)); overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
}

/* Install tip */
.install-wrap { margin-top: 14px; }
.install-tip { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; border: 1px solid var(--jade); border-radius: 14px;
  background: color-mix(in srgb, var(--jade) 10%, var(--surface)); box-shadow: var(--shadow); animation: rise .3s ease both; }
.install-tip img { flex: none; border-radius: 10px; }
.install-text { flex: 1; min-width: 0; display: grid; gap: 2px; font-size: 14px; color: var(--muted); }
.install-text strong { color: var(--fg); font-size: 15px; }
.install-go { flex: none; padding: 10px 16px; }
.install-x { flex: none; width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; border-radius: 50%; cursor: pointer; }
.install-x:hover { background: var(--line-soft); color: var(--fg); }
body:has(#view-home.hidden) .install-wrap { display: none; }
.ios-share { display: inline-block; width: 13px; height: 16px; vertical-align: -2px; margin: 0 2px;
  border: 2px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; position: relative; }
.ios-share::before { content: ""; position: absolute; left: 50%; top: -7px; width: 2px; height: 11px; background: currentColor; transform: translateX(-50%); }
.ios-share::after { content: ""; position: absolute; left: 50%; top: -8px; width: 6px; height: 6px; border-left: 2px solid currentColor; border-top: 2px solid currentColor; transform: translateX(-50%) rotate(45deg); }

@media print { .install-wrap { display: none !important; } }
