@import url('./tokens.css');

/* Shared production foundation. Legacy mode internals remain scoped until migrated. */
body.uw-active {
  min-width: 0;
  color: var(--bk-text);
  background:
    radial-gradient(circle at 50% -18%, rgba(123, 216, 196, .08), transparent 34rem),
    linear-gradient(180deg, var(--bk-bg-raised), var(--bk-bg));
  font-family: var(--bk-ui);
  text-rendering: optimizeLegibility;
}

body.uw-active::before {
  opacity: .08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)' opacity='.35'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

body.uw-active .uw-root,
body.uw-active .uw-root button,
body.uw-active .uw-root input,
body.uw-active .uw-root textarea,
body.uw-active .uw-root select {
  font-family: var(--bk-ui);
}

body.uw-booting #UW_ROOT {
  visibility: hidden;
  pointer-events: none;
}

body.uw-active .uw-chrome {
  border-bottom: 1px solid var(--bk-line);
  background: rgba(7, 10, 11, .92);
  box-shadow: 0 16px 42px rgba(0, 0, 0, .24);
  backdrop-filter: blur(20px) saturate(115%);
}

body.uw-active .uw-primary {
  min-height: 72px;
  gap: var(--bk-space-6);
  padding: var(--bk-space-3) var(--bk-space-6);
}

body.uw-active .uw-brand {
  min-width: 168px;
  color: var(--bk-text);
}

body.uw-active .uw-brand span {
  font-family: var(--bk-display);
  font-size: 1.78rem;
  font-weight: 600;
  letter-spacing: -.025em;
}

body.uw-active .uw-brand small,
body.uw-active .uw-studio-copy small,
body.uw-active .uw-contextbar small,
body.uw-active .uw-tool-menu small,
body.uw-active .uw-panel small,
body.uw-active .uw-command footer {
  color: var(--bk-muted);
  font-family: var(--bk-mono);
  font-size: var(--bk-text-xs);
  letter-spacing: .1em;
  text-transform: uppercase;
}

body.uw-active .uw-studios {
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--bk-line);
  border-radius: var(--bk-radius-pill);
  background: rgba(255, 255, 255, .025);
}

body.uw-active .uw-studio {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--bk-radius-pill);
  color: var(--bk-muted);
  transition: color var(--bk-duration) var(--bk-ease), background var(--bk-duration) var(--bk-ease), transform var(--bk-duration) var(--bk-ease);
}

body.uw-active .uw-studio:hover,
body.uw-active .uw-studio:focus-visible {
  color: var(--bk-text-soft);
  background: rgba(123, 216, 196, .08);
  transform: translateY(-1px);
}

body.uw-active .uw-studio.active {
  color: var(--bk-text);
  border-color: color-mix(in srgb, var(--accent, var(--bk-accent)) 56%, transparent);
  background: color-mix(in srgb, var(--accent, var(--bk-accent)) 13%, transparent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .07);
}

body.uw-active .uw-icon,
body.uw-active .uw-tool-current,
body.uw-active .uw-reader-toggle,
body.uw-active .uw-truth-button {
  border-color: var(--bk-line);
  border-radius: var(--bk-radius-md);
  color: var(--bk-text-soft);
  background: rgba(255, 255, 255, .035);
  transition: border-color var(--bk-duration) var(--bk-ease), background var(--bk-duration) var(--bk-ease), transform var(--bk-duration) var(--bk-ease);
}

body.uw-active .uw-icon:hover,
body.uw-active .uw-icon:focus-visible,
body.uw-active .uw-tool-current:hover,
body.uw-active .uw-tool-current:focus-visible,
body.uw-active .uw-reader-toggle:hover,
body.uw-active .uw-reader-toggle:focus-visible,
body.uw-active .uw-truth-button:hover,
body.uw-active .uw-truth-button:focus-visible {
  border-color: var(--bk-line-strong);
  background: rgba(213, 179, 108, .1);
  transform: translateY(-1px);
}

body.uw-active .uw-contextbar {
  min-height: 64px;
  border-top: 1px solid rgba(255, 255, 255, .035);
  background: rgba(16, 24, 23, .72);
}

body.uw-active .uw-ref-form,
body.uw-active .uw-focus-summary {
  border-color: var(--bk-line);
  background: rgba(0, 0, 0, .16);
}

body.uw-active .uw-ref-form input,
body.uw-active .uw-note-form input,
body.uw-active .uw-note-form textarea,
body.uw-active .uw-note-form select,
body.uw-active .uw-command header input {
  color: var(--bk-text);
  border-color: var(--bk-line);
  background: var(--bk-surface-inset);
}

body.uw-active .uw-ref-form input:focus-visible,
body.uw-active .uw-note-form input:focus-visible,
body.uw-active .uw-note-form textarea:focus-visible,
body.uw-active .uw-note-form select:focus-visible,
body.uw-active .uw-command header input:focus-visible {
  border-color: var(--bk-focus);
  box-shadow: 0 0 0 3px rgba(123, 216, 196, .16);
  outline: none;
}

body.uw-active :is(.uw-panel, .uw-command, .uw-compare, .uw-presentation, .uw-tool-menu, .uw-utility-menu) {
  border-color: var(--bk-line);
  background: linear-gradient(160deg, rgba(21, 32, 30, .98), rgba(10, 16, 15, .99));
  box-shadow: var(--bk-shadow-panel);
}

body.uw-active .uw-panel-head,
body.uw-active .uw-command header,
body.uw-active .uw-compare > header,
body.uw-active .uw-presentation > header {
  border-bottom-color: var(--bk-line);
}

body.uw-active .uw-panel h2,
body.uw-active .uw-compare h2,
body.uw-active .uw-presentation h1 {
  color: var(--bk-text);
  font-family: var(--bk-display);
  font-weight: 600;
  letter-spacing: -.02em;
}

body.uw-active .uw-panel p,
body.uw-active .uw-compare p,
body.uw-active .uw-presentation p {
  color: var(--bk-text-soft);
  font-family: var(--bk-reading);
  line-height: var(--bk-leading-copy);
}

body.uw-active :is(button, a, input, textarea, select):focus-visible {
  outline: 2px solid var(--bk-focus);
  outline-offset: 3px;
}

body.uw-active .uw-domain-status {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  align-items: center;
  margin: var(--bk-space-4);
  padding: var(--bk-space-4) var(--bk-space-5);
  border: 1px solid var(--bk-line);
  border-radius: var(--bk-radius-md);
  color: var(--bk-text-soft);
  background: color-mix(in srgb, var(--bk-surface) 94%, transparent);
  box-shadow: var(--bk-shadow-panel);
}

body.uw-active .uw-domain-status strong {
  color: var(--bk-text);
  font-family: var(--bk-ui);
  font-size: var(--bk-text-sm);
}

body.uw-active .uw-domain-status span,
body.uw-active .uw-domain-status small {
  grid-column: 2;
  color: var(--bk-muted);
  font-family: var(--bk-reading);
  font-size: var(--bk-text-sm);
  line-height: 1.45;
}

body.uw-active .uw-domain-status i {
  grid-row: 1 / span 2;
  width: 10px;
  height: 10px;
  border-radius: var(--bk-radius-pill);
  background: var(--bk-accent);
  box-shadow: 0 0 0 5px rgba(123, 216, 196, .1);
  animation: uwStatusPulse 1.35s var(--bk-ease) infinite;
}

body.uw-active .uw-domain-status-error {
  border-color: color-mix(in srgb, var(--bk-danger) 52%, var(--bk-line));
  background: color-mix(in srgb, var(--bk-danger) 8%, var(--bk-surface));
}

body.uw-active .uw-domain-status-error strong {
  color: var(--bk-danger);
}

@keyframes uwStatusPulse {
  0%, 100% { opacity: .45; transform: scale(.82); }
  50% { opacity: 1; transform: scale(1); }
}

@media (max-width: 900px) {
  body.uw-active .uw-primary {
    min-height: 60px;
    gap: var(--bk-space-3);
    padding: var(--bk-space-2) var(--bk-space-3);
  }

  body.uw-active .uw-brand {
    min-width: 0;
  }

  body.uw-active .uw-brand span {
    font-size: 1.48rem;
  }

  body.uw-active .uw-brand small,
  body.uw-active .uw-studio-copy small {
    display: none;
  }

  body.uw-active .uw-studio-copy strong {
    font-size: .7rem;
  }

  body.uw-active .uw-studios {
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
  }

  body.uw-active .uw-studio {
    flex: 0 0 auto;
    min-height: 36px;
    padding-inline: 10px;
  }

  body.uw-active .uw-contextbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--bk-space-2);
    padding: var(--bk-space-2) var(--bk-space-3);
  }

  body.uw-active .uw-focus-summary {
    grid-column: 1 / -1;
    min-width: 0;
  }

  body.uw-active .uw-domain-status {
    margin: var(--bk-space-3);
    padding: var(--bk-space-3) var(--bk-space-4);
  }
}

/* Location Atlas: make asynchronous source state explicit on the visual stage. */
.mapstage-hud .map-data-state {
  display: grid;
  gap: .35rem;
  padding: .7rem .75rem;
  border: 1px solid color-mix(in srgb, var(--os-teal, #74e7d0) 24%, transparent);
  border-radius: .75rem;
  background: color-mix(in srgb, var(--os-teal, #74e7d0) 8%, transparent);
}

.mapstage-hud .map-data-state strong {
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: .7rem;
  line-height: 1.25;
}

.mapstage-hud .map-data-state span {
  color: var(--text-muted, #aab5c7);
  font-size: .66rem;
  line-height: 1.4;
}

.mapstage-hud .map-data-state i {
  width: .65rem;
  height: .65rem;
  border: 2px solid color-mix(in srgb, var(--os-teal, #74e7d0) 30%, transparent);
  border-top-color: var(--os-teal, #74e7d0);
  border-radius: 50%;
  animation: uw-spin .8s linear infinite;
}

.mapstage-hud .map-data-state button {
  justify-self: start;
  min-height: 2rem;
  padding: .35rem .65rem;
  border: 1px solid color-mix(in srgb, var(--os-gold, #d5ad63) 40%, transparent);
  border-radius: .5rem;
  background: color-mix(in srgb, var(--os-gold, #d5ad63) 9%, transparent);
  color: var(--text-primary, #f3f0e8);
  cursor: pointer;
  font: 600 .66rem/1 var(--font-ui, system-ui, sans-serif);
}

.mapstage-hud .map-data-state button:focus-visible {
  outline: 2px solid var(--focus-ring, #8cf0df);
  outline-offset: 2px;
}

.mapstage-hud .map-data-state-error {
  border-color: color-mix(in srgb, var(--status-error, #e58e84) 48%, transparent);
  background: color-mix(in srgb, var(--status-error, #e58e84) 8%, transparent);
}

.mapstage-hud .map-data-state-empty {
  border-color: color-mix(in srgb, var(--os-gold, #d5ad63) 32%, transparent);
  background: color-mix(in srgb, var(--os-gold, #d5ad63) 7%, transparent);
}

.pt-data-state {
  display: grid;
  gap: .45rem;
  margin: .75rem;
  padding: 1rem;
  border: 1px solid var(--bk-line, rgba(255, 255, 255, .14));
  border-radius: var(--bk-radius-md, .75rem);
  background: var(--bk-surface-2, rgba(255, 255, 255, .04));
}

.pt-data-state strong { color: var(--bk-text, #f3f0e8); }
.pt-data-state span { color: var(--bk-text-muted, #aab5c7); font-size: var(--bk-text-sm, .8rem); line-height: 1.45; }
.pt-data-state button {
  justify-self: start;
  min-height: 34px;
  padding: 0 .75rem;
  border: 1px solid var(--bk-focus, #8cf0df);
  border-radius: var(--bk-radius-sm, .5rem);
  color: var(--bk-text, #f3f0e8);
  background: transparent;
  cursor: pointer;
}
.pt-data-state button:focus-visible { outline: 2px solid var(--bk-focus, #8cf0df); outline-offset: 2px; }
.pt-data-state-empty { border-color: color-mix(in srgb, var(--bk-gold, #d5ad63) 42%, transparent); }
.pt-data-state-error { border-color: color-mix(in srgb, var(--status-error, #e58e84) 52%, transparent); }

@keyframes uw-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .mapstage-hud .map-data-state i { animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  body.uw-active *,
  body.uw-active *::before,
  body.uw-active *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Production hardening: keep legacy mode affordances available while their
   internals are migrated into the shared shell. These rules intentionally sit
   in the final layer so older visual overrides cannot remove primary controls. */
body.uw-active .uw-contextbar > *,
body.uw-active .uw-contextbar .uw-ref-form,
body.uw-active .uw-contextbar .uw-focus-summary {
  min-width: 0;
}

body.uw-active .uw-focus-summary,
body.uw-active .uw-focus-summary strong,
body.uw-active .uw-focus-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.uw-active .timeline-overlay .tl-nav-stats {
  min-width: 0;
  overflow: hidden;
}

body.uw-active .timeline-overlay .tl-nav-stats > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 901px) {
  /* The metadata console floats over the canvas on wide screens. This keeps
     the research surface genuinely full-height while retaining its context
     controls as an anchored layer instead of spending a second grid row on
     them. */
  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-stage-shell {
    position: relative;
    display: block !important;
    grid-column: 2 !important;
    grid-row: 1 !important;
    height: 100% !important;
    min-height: 0 !important;
  }

  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-shell {
    grid-template-rows: 42px minmax(0, 1fr) !important;
  }

  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-workbench {
    grid-template-columns: 244px minmax(0, 1fr) 368px !important;
    grid-template-rows: minmax(0, 1fr) !important;
    height: 100% !important;
  }

  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-sidebar {
    grid-column: 1 !important;
    grid-row: 1 !important;
    height: 100% !important;
  }

  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-inspector {
    grid-column: 3 !important;
    grid-row: 1 !important;
    height: 100% !important;
  }

  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-stage-meta {
    position: absolute !important;
    z-index: 8;
    top: 0;
    right: 0;
    left: 0;
    width: auto !important;
    min-height: 106px !important;
    max-height: 106px !important;
  }

  body.uw-active.expert-ui-ready .app[data-active-mode="timeline"] .timeline-overlay .tl-stage {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
  }
}

body.uw-active .pt-tradition-switch button {
  min-height: 34px;
  min-width: 0;
  padding-inline: 10px;
  font-size: var(--bk-text-sm) !important;
  line-height: 1.2;
}

body.uw-active .uw-handoff {
  display: flex !important;
  min-width: 0;
  align-items: center;
  gap: var(--bk-space-2);
}

body.uw-active .uw-handoff:empty {
  display: none !important;
}

body.uw-active .uw-handoff button {
  min-width: 0;
  min-height: 34px;
  max-width: 160px;
  overflow: hidden;
  padding: 0 var(--bk-space-3);
  border: 1px solid var(--bk-line);
  border-radius: var(--bk-radius-md);
  color: var(--bk-text-soft);
  background: rgba(123, 216, 196, .07);
  font-size: var(--bk-text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.uw-active .uw-handoff button:hover,
body.uw-active .uw-handoff button:focus-visible {
  border-color: var(--bk-focus);
  color: var(--bk-text);
  background: rgba(123, 216, 196, .14);
}

body.uw-active :is(#GREEKORTHODOXMODE, #SYRIACORTHODOXMODE, #CATHOLICMODE) :is(.pt-tradition-switch button, .pt-view-tabs button) {
  font-size: var(--bk-text-sm) !important;
  line-height: 1.2 !important;
}

body.uw-active :is(#GREEKORTHODOXMODE, #SYRIACORTHODOXMODE, #CATHOLICMODE) .pt-search-row :is(.patristic-search, select) {
  min-height: 36px;
  font-size: var(--bk-text-sm) !important;
  line-height: 1.25 !important;
}

body.uw-active :is(#GREEKORTHODOXMODE, #SYRIACORTHODOXMODE, #CATHOLICMODE) .pt-library .patristic-list button > strong {
  font-size: var(--bk-text-sm) !important;
  line-height: 1.25 !important;
}

@media (max-width: 900px) {
  /* simple-ui-overhaul hides all study asides on phones. Urtext is the
     exception: the word index is the primary navigation for the mode and must
     remain the first stacked panel. */
  body.uw-active #ORIGINALMODE[aria-hidden="false"] #ORIGINALSUGGESTIONS {
    display: block !important;
    height: 390px !important;
    min-height: 390px !important;
    max-height: 390px !important;
    opacity: 1 !important;
    visibility: visible !important;
    overflow: auto !important;
  }

  body.uw-active #ORIGINALMODE[aria-hidden="false"] #ORIGINALSUGGESTIONS .original-word-card {
    display: grid !important;
    opacity: 1 !important;
    visibility: visible !important;
    animation: none !important;
  }

  body.uw-active #ORIGINALMODE[aria-hidden="false"] .original-main {
    grid-template-rows: 390px max-content max-content !important;
  }

  body.uw-active .uw-contextbar {
    overflow: hidden;
  }

  body.uw-active .uw-handoff {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  body.uw-active .uw-truth-button {
    width: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    overflow: hidden;
    justify-self: end;
  }

  body.uw-active .uw-contextbar:has(.uw-handoff:not(:empty)) {
    height: 80px !important;
    min-height: 80px !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 28px;
    grid-template-rows: 34px 34px;
    grid-template-areas: "tool ref truth" "handoff handoff handoff";
  }

  body.uw-active .uw-handoff:not(:empty) {
    grid-area: handoff;
    width: 100%;
    height: 34px;
    max-width: 100%;
  }

  body.uw-active .uw-contextbar .uw-ref-form,
  body.uw-active .uw-contextbar .uw-tool-current,
  body.uw-active .uw-contextbar .uw-truth-button {
    max-width: 100%;
  }
}
