/*
 * Canary framework base layer.
 *
 * Generic, reusable layout for the standard Canary shell (header/nav/#app/
 * footer) ONLY -- widget styling does NOT live here. It used to (downloads/
 * slideshow rules were baked in directly), which quietly broke the widget
 * system's own "built-in and site-authored are discovered identically, no
 * special-casing" promise: a site-authored widget had nowhere to put its
 * CSS, while the two built-ins got free styling nobody else could get.
 * Fixed by giving widgets a third discovered file type alongside .html/.js
 * -- see runtime/widgets/downloads.css, slideshow.css, and SiteBuilder's
 * {{widgetStyles}} placeholder. Every visual property that's actually a
 * brand decision (colors, logo sizing, wordmark typography) is a CSS custom
 * property or isolated in a rule a theme layer is expected to override --
 * this file should never need per-site edits.
 *
 * A site's theme.css loads after this file and overrides the :root tokens
 * below (and, if it wants a different logo/title treatment, the .site-logo
 * / .site-title rules) with its own branding. See templates/default/css in
 * the Canary repo for how this pairs with a theme layer, and PLAN.md's
 * "CSS framework/theme split" note for the reasoning.
 */

:root {
  color-scheme: dark;
  --bg: #17181c;
  --bg-elevated: #1f2126;
  --text: #e8e9eb;
  --text-dim: #9aa0a8;
  --accent: #4f8cff;
  --border: #2b2d33;
  --max-width: 860px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

blockquote {
  margin: 1rem 0 1rem 1.5rem;
  padding: 0.2rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}

blockquote p {
  margin: 0.4rem 0;
}

.site-header {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.site-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: nowrap;
  padding-bottom: 0.75rem;
}

.site-nav {
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.site-tagline {
  flex: 1 1 auto;
  min-width: 0;
}

.site-tagline p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: right;
}

/* Generic wordmark treatment -- a theme layer overrides font-family/size for
   its own brand identity (see PLAN.md: consoland's is a large monospace
   wordmark, which is a theme decision, not a framework default). */
.site-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
  font-family: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

/* Generic safe default -- a theme layer overrides sizing/aspect-ratio/border
   for its own actual logo asset (see PLAN.md: logo sizing is explicitly a
   branding decision, not a framework default). */
.site-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.site-nav-list {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  position: relative;
}

.nav-item.has-dropdown {
  /* Extends the item's actual hover box down into the visual gap below the
     label, so crossing that gap doesn't drop out of :hover before reaching
     the dropdown. The negative margin cancels the padding's layout push. */
  padding-bottom: 0.6rem;
  margin-bottom: -0.6rem;
}

.nav-label {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.95rem;
}

a.nav-label {
  text-decoration: none;
}

.nav-label:hover,
.nav-item:focus-within .nav-label {
  color: var(--accent);
}

.nav-item.active > .nav-label {
  color: var(--accent);
  font-weight: 600;
}

.nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 160px;
  padding: 0.4rem 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  z-index: 20;
}

/* ">" not a descendant selector: hovering the top-level item must only
   reveal ITS OWN immediate dropdown, not every .nav-dropdown nested inside
   it -- a nested submenu (see .nav-dropdown-nested below) has its own,
   separately-gated hover rule and would otherwise pop open regardless of
   whether its own row is actually hovered. */
.nav-item.has-dropdown:hover > .nav-dropdown,
.nav-item.has-dropdown:focus-within > .nav-dropdown {
  display: block;
}

.nav-dropdown a {
  display: block;
  padding: 0.4rem 0.9rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  white-space: nowrap;
}

.nav-dropdown a:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  text-decoration: none;
}

.nav-dropdown a.active {
  color: var(--accent);
  font-weight: 600;
}

/* nav.depth > 1: a dropdown child that itself has children (see
   Canary.Core.Config.NavConfig, runtime/ts/nav.ts's renderNavChild) renders
   as a .nav-subitem with its own nested flyout submenu instead of a plain
   link -- a depth-1 site never produces any of this markup, so none of it
   changes how a depth-1 site's nav looks or behaves. */
.nav-subitem {
  position: relative;
}

/* ".nav-dropdown .nav-dropdown-label", not just ".nav-dropdown-label": this
   element is always inside a .nav-dropdown, and ".nav-dropdown a"'s
   specificity (0,1,1) beats a bare ".nav-dropdown-label" (0,1,0) -- that
   rule was silently winning and forcing display:block here regardless of
   this rule's own `display: flex`, which is the actual reason `gap` never
   visibly separated the label text from its chevron (a non-flex container
   has no gap to apply at all). Found by inspecting the live computed
   style, not by re-guessing at the CSS -- two previous attempts at this
   same visual fix (justify-content, then a real span instead of ::after)
   both looked right on paper and neither actually worked, which is
   specifically why this one was verified against getComputedStyle instead
   of just eyeballing another screenshot. */
.nav-dropdown .nav-dropdown-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  white-space: nowrap;
  text-decoration: none;
  cursor: default;
}

a.nav-dropdown-label {
  cursor: pointer;
}

.nav-dropdown-chevron {
  /* A real element (see runtime/ts/nav.ts), not ::after. The actual,
     confirmed bug that motivated this (see .nav-dropdown-label above) was
     a plain CSS specificity fight, not anything about pseudo-elements --
     a ::after chevron might have worked fine once display:flex was
     actually winning. Left as a real span anyway since it's already built,
     confirmed working, and no less clear than a CSS-content icon. */
  font-size: 0.7rem;
  opacity: 0.6;
}

.nav-dropdown-label:hover,
.nav-subitem:focus-within > .nav-dropdown-label {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  text-decoration: none;
}

.nav-dropdown-label.active {
  color: var(--accent);
  font-weight: 600;
}

.nav-dropdown-nested {
  /* Flies out to the side of its own row rather than below the whole
     parent dropdown -- top:100%/left:0 (the top-level .nav-dropdown's own
     positioning) would place it under the entire menu instead of next to
     the specific row that opened it. */
  top: -0.4rem;
  left: 100%;
  margin-left: 0.25rem;
}

.nav-subitem.has-subdropdown:hover > .nav-dropdown-nested,
.nav-subitem.has-subdropdown:focus-within > .nav-dropdown-nested {
  display: block;
}

#app {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

#app img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
}
