/* ==========================================================================
   Story Craft Workbench — Compact App Bar & Unified Footer for /apps/<tool>/
   Built strictly on /styles/tokens.css (Direction A: Prompt Book):
   - Locked font sizes: 14px (--text-sm), 16px (--text-base), 18px (--text-lg), 30px (--text-2xl)
   - Locked spacing ladder: 0, 2, 4, 8, 12, 16, 24, 32, 40, 48, 64, 80, 96px
   - 0.5px closed hairlines (--hairline), concentric radii 6px (--r-outer) / 2px (--r-inner)
   ========================================================================== */

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  inline-size: 1px !important;
  block-size: 1px !important;
  margin: var(--sp-0) !important;
  padding: var(--sp-0) !important;
  border: var(--sp-0) !important;
  white-space: nowrap !important;
}

.app-skip-link:is(:focus, :focus-visible, :active) {
  position: fixed;
  inset-block-start: var(--sp-8);
  inset-inline-start: var(--sp-12);
  z-index: var(--z-drawer);
  padding: var(--sp-8) var(--sp-12);
  background-color: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--r-inner);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 600;
  text-decoration: none;
}

.app-shell-bar,
.app-shell-bar *,
.app-shell-bar *::before,
.app-shell-bar *::after,
.app-shell-footer,
.app-shell-footer *,
.app-shell-footer *::before,
.app-shell-footer *::after {
  box-sizing: border-box;
}

.app-shell-bar {
  position: sticky;
  inset-block-start: var(--sp-0);
  z-index: var(--z-header);
  flex-shrink: 0;
  inline-size: 100%;
  background-color: var(--bg-canvas);
  border-block-end: var(--hairline) solid var(--border-subtle);
  font-family: var(--font-sans);
  font-style: normal;
  view-transition-name: site-chrome-top;
}

.app-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-8) var(--sp-12);
  min-block-size: var(--appbar-min-h);
  padding: var(--sp-4) var(--sp-16);
}

.app-shell-bar.is-wide .app-bar-inner {
  flex-wrap: nowrap;
}

.app-bar-left,
.app-bar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-8);
}

.app-shell-bar.is-wide .app-bar-left,
.app-shell-bar.is-wide .app-bar-right {
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.app-brand {
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: var(--lh-base);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--motion-fast);
}

.app-brand:hover {
  color: var(--accent);
}

.app-act-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-4);
  min-block-size: var(--sp-24);
  padding: var(--sp-2) var(--sp-8);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  border: var(--hairline) solid var(--border-strong);
  border-radius: var(--r-inner);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 500;
  white-space: nowrap;
}

.app-act-tag[data-act="1"] {
  background-color: var(--act-1-bg);
  color: var(--act-1);
  border-color: var(--act-1-border);
}

.app-act-pips {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-4);
}

.app-act-pip {
  display: inline-block;
  inline-size: var(--sp-8);
  block-size: var(--sp-8);
  border-radius: var(--sp-0);
  flex-shrink: 0;
}

.app-act-pip.p1 {
  background-color: var(--act-1);
}

.app-act-pip.p2 {
  background-color: var(--act-2);
}

.app-act-pip.p3 {
  background-color: var(--act-3);
}

.app-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.app-slash {
  font-family: var(--font-mono);
  color: var(--border-focus);
}

.app-guide-link {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--sp-32);
  padding: var(--sp-4) var(--sp-8);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  border: var(--hairline) solid var(--border-strong);
  border-radius: var(--r-inner);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}

.app-guide-link:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.app-nav {
  display: flex;
  align-items: center;
}

.app-menu-btn {
  anchor-name: --app-menu-btn;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--sp-32);
  padding: var(--sp-4) var(--sp-12);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  border: var(--hairline) solid var(--border-strong);
  border-radius: var(--r-inner);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--motion-fast), transform var(--motion-fast);
}

.app-menu-btn:hover {
  background-color: var(--bg-hover);
}

/* Collapsed popover menu default */
.app-menu {
  position: fixed;
  inset: auto;
  inset-block-start: var(--sp-48);
  inset-block-start: anchor(--app-menu-btn bottom);
  inset-inline-end: var(--sp-16);
  inline-size: min(84dvw, 272px);
  max-inline-size: calc(100dvw - var(--sp-32));
  block-size: fit-content;
  max-block-size: calc(100dvh - var(--sp-64));
  margin: var(--sp-0);
  margin-block-start: var(--sp-8);
  padding: var(--sp-8);
  list-style: none;
  background-color: var(--bg-canvas);
  border: var(--hairline) solid var(--border-strong);
  border-radius: var(--r-outer);
  overflow: auto;
  z-index: var(--z-popover);
}

.app-shell-bar:not(.is-wide) .app-menu:not(:is(:popover-open, .\:popover-open)) {
  display: none;
}

.app-shell-bar:not(.is-wide) .app-menu:is(:popover-open, .\:popover-open) {
  display: grid;
  gap: var(--sp-4);
}

.app-menu a {
  display: flex;
  align-items: center;
  min-block-size: var(--sp-32);
  padding: var(--sp-4) var(--sp-12);
  color: var(--text-muted);
  border-radius: var(--r-inner);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--motion-fast), color var(--motion-fast);
}

.app-menu a:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.app-menu a[aria-current="page"],
.app-menu a[data-active-section="true"] {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
}

.app-shell-bar:not(.is-wide) .app-theme-inline {
  display: none;
}

.app-menu-theme-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-12);
  margin-block-start: var(--sp-4);
  padding: var(--sp-8) var(--sp-12) var(--sp-4);
  border-block-start: var(--hairline) solid var(--border-subtle);
}

.app-menu-theme-label {
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  color: var(--text-muted);
}

/* Wide inline mode */
.app-shell-bar.is-wide .app-menu-btn,
.app-shell-bar.is-wide .app-menu-theme-item {
  display: none;
}

.app-shell-bar.is-wide .app-menu {
  position: static;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  inline-size: auto;
  max-inline-size: none;
  block-size: auto;
  max-block-size: none;
  margin: var(--sp-0);
  padding: var(--sp-0);
  border: var(--sp-0);
  border-radius: var(--sp-0);
  background: transparent;
  overflow: visible;
}

.app-shell-bar.is-wide .app-menu::backdrop {
  display: none;
}

.app-shell-bar.is-measuring *,
.app-shell-bar.is-measuring *::before,
.app-shell-bar.is-measuring *::after {
  transition: none !important;
}

/* Segmented controls (outer 6px, padding 4px -> inner 2px) */
.app-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-8);
}

.app-seg-group {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4);
  background-color: var(--bg-subtle);
  border: var(--hairline) solid var(--border-subtle);
  border-radius: var(--r-outer);
}

.app-seg-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--sp-24);
  padding: var(--sp-2) var(--sp-8);
  background: transparent;
  color: var(--text-muted);
  border: var(--sp-0);
  border-radius: var(--r-inner);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}

.app-seg-item:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}

@media (prefers-reduced-motion: no-preference) {
  .app-guide-link:active,
  .app-menu-btn:active,
  .app-seg-item:active {
    transform: scale(0.98);
  }
}

:is(.app-guide-link, .app-menu-btn, .app-seg-item):is(:disabled, [aria-disabled="true"]) {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.app-seg-item[aria-current="true"],
.app-seg-item[aria-pressed="true"] {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
}

/* Fallback language status strip (rendered only when EN falls back to ZH dataset) */
.app-fallback-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4) var(--sp-16);
  background-color: var(--accent-soft);
  color: var(--text-primary);
  border-block-start: var(--hairline) solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 500;
  text-align: center;
}

/* Unified Compact Footer */
.app-shell-footer {
  flex-shrink: 0;
  inline-size: 100%;
  background-color: var(--bg-subtle);
  border-block-start: var(--hairline) solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  color: var(--text-muted);
  view-transition-name: site-chrome-bottom;
}

.app-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-8) var(--sp-16);
  padding: var(--sp-8) var(--sp-16);
}

.app-footer-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-12);
}

.app-footer-home {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--motion-fast);
}

.app-footer-home:hover {
  color: var(--text-primary);
}

.app-footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-12);
  margin: var(--sp-0);
  padding: var(--sp-0);
  list-style: none;
}

.app-footer-links a {
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 4px;
  transition: color var(--motion-fast);
}

.app-footer-links a:hover {
  color: var(--text-primary);
}

.app-shell-bar :where(a:any-link, button):focus-visible,
.app-shell-footer :where(a:any-link, button):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .app-shell-bar:not(.is-wide) .app-act-tag {
    display: none;
  }

  .app-bar-inner {
    gap: var(--sp-4) var(--sp-8);
    padding: var(--sp-4) var(--sp-12);
  }

  .app-bar-left,
  .app-bar-right {
    gap: var(--sp-8);
  }

  .app-fallback-strip {
    padding: var(--sp-4) var(--sp-12);
  }
}

@media (pointer: coarse) {
  .app-guide-link,
  .app-menu-btn,
  .app-menu a {
    min-block-size: var(--sp-40);
  }
  .app-seg-item {
    min-block-size: var(--sp-32);
    padding-inline: var(--sp-8);
  }
}

@media (forced-colors: active) {
  .app-menu a[aria-current="page"],
  .app-menu a[data-active-section="true"],
  .app-seg-item[aria-current="true"],
  .app-seg-item[aria-pressed="true"] {
    outline: 1px solid CanvasText;
    text-decoration: underline;
  }
}
