/* CT Investments: a subsite of PermitParser with its own register.
   The parent is a blueprint; this is a trading desk at dawn. Light and dark
   follow the system through light-dark(), and a toggle pins either one.
   Colour is oklch throughout so the up/down hues hold equal weight in both. */

@import url('/fonts/fonts.css');

@layer reset, tokens, base, layout, components, motion;

@layer tokens {
  :root {
    color-scheme: light dark;
    &[data-theme="light"] { color-scheme: light; }
    &[data-theme="dark"] { color-scheme: dark; }

    --bg: light-dark(oklch(98.4% 0.006 260), oklch(16.5% 0.022 268));
    --bg-2: light-dark(oklch(96% 0.01 260), oklch(19.5% 0.025 268));
    --surface: light-dark(oklch(100% 0 0 / 0.78), oklch(23% 0.026 268 / 0.72));
    --surface-solid: light-dark(oklch(100% 0 0), oklch(22% 0.026 268));
    --ink: light-dark(oklch(22% 0.03 268), oklch(96.5% 0.008 260));
    --ink-2: light-dark(oklch(42% 0.025 265), oklch(78% 0.02 262));
    --ink-3: light-dark(oklch(56% 0.02 262), oklch(64% 0.02 262));
    --line: light-dark(oklch(22% 0.03 268 / 0.1), oklch(100% 0 0 / 0.09));
    --line-2: light-dark(oklch(22% 0.03 268 / 0.18), oklch(100% 0 0 / 0.16));

    --accent: light-dark(oklch(62% 0.16 50), oklch(80% 0.13 62));
    --accent-2: light-dark(oklch(55% 0.18 300), oklch(76% 0.13 300));
    --up: light-dark(oklch(55% 0.15 155), oklch(80% 0.17 155));
    --down: light-dark(oklch(57% 0.2 25), oklch(73% 0.17 25));
    --amber: light-dark(oklch(64% 0.15 75), oklch(84% 0.15 85));
    --cyan: light-dark(oklch(56% 0.11 215), oklch(80% 0.11 210));
    --blue: light-dark(oklch(55% 0.16 260), oklch(76% 0.12 260));
    --neutral: light-dark(oklch(55% 0.01 260), oklch(70% 0.01 260));

    --display: 'Space Grotesk', 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
    --body: 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

    --r-lg: 22px;
    --r-md: 14px;
    --r-sm: 9px;
    --shadow: 0 1px 0 light-dark(oklch(100% 0 0 / 0.9), oklch(100% 0 0 / 0.05)) inset,
              0 12px 40px -18px light-dark(oklch(30% 0.05 268 / 0.25), oklch(0% 0 0 / 0.6));
    --ease: cubic-bezier(.2, .8, .2, 1);
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { interpolate-size: allow-keywords; scroll-behavior: smooth; scroll-padding-top: 88px; }
  body, h1, h2, h3, p, ul { margin: 0; }
  ul { padding: 0; list-style: none; }
  button, select, input { font: inherit; color: inherit; }
  @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
}

@layer base {
  body {
    background:
      radial-gradient(60rem 36rem at 85% -10%, color-mix(in oklch, var(--accent) 22%, transparent), transparent 70%),
      radial-gradient(50rem 30rem at -10% 10%, color-mix(in oklch, var(--accent-2) 16%, transparent), transparent 70%),
      var(--bg);
    background-attachment: fixed;
    color: var(--ink);
    font: 400 16px/1.6 var(--body);
    -webkit-font-smoothing: antialiased;
    font-variant-numeric: tabular-nums;
    min-height: 100dvh;
  }
  h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; line-height: 1.08; text-wrap: balance; }
  p { text-wrap: pretty; }
  a { color: inherit; text-underline-offset: 3px; text-decoration-color: color-mix(in oklch, currentColor 35%, transparent); }
  a:hover { text-decoration-color: currentColor; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
  ::selection { background: color-mix(in oklch, var(--accent) 40%, transparent); }
  .skip-link {
    position: absolute; left: 12px; top: -60px; z-index: 100;
    background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r-sm);
    &:focus { top: 12px; }
  }
}

@layer layout {
  .shell { width: min(1200px, 100% - 32px); margin-inline: auto; }
  .band { padding-block: clamp(56px, 8vw, 104px); border-top: 1px solid var(--line); }
  .section-head {
    display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 20px 32px;
    margin-bottom: 28px;
    h2 { font-size: clamp(30px, 4.4vw, 48px); font-weight: 600; }
  }
  .section-sub { color: var(--ink-2); max-width: 62ch; margin-top: 10px; }
  .eyebrow {
    font: 500 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
    margin-bottom: 14px;
  }
}

@layer components {
  /* ---- header + ticker tape ---- */
  .top {
    position: sticky; top: 0; z-index: 20;
    background: color-mix(in oklch, var(--bg) 72%, transparent);
    backdrop-filter: blur(18px) saturate(1.4);
    border-bottom: 1px solid var(--line);
  }
  .top-bar { display: flex; align-items: center; gap: 20px; height: 60px; }
  .brand {
    display: flex; align-items: center; gap: 10px; text-decoration: none;
    font: 600 17px/1 var(--display); letter-spacing: -0.01em;
  }
  .brand-mark {
    width: 28px; height: 28px;
    rect { fill: var(--ink); }
    path { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
  }
  .brand-sub { font: 500 11px/1 var(--mono); color: var(--ink-3); letter-spacing: .04em; }
  .top-nav {
    display: flex; gap: 4px; margin-left: auto;
    a {
      text-decoration: none; color: var(--ink-2); font-size: 14px; font-weight: 500;
      padding: 7px 12px; border-radius: 999px; transition: background .2s, color .2s;
      &:hover { background: var(--line); color: var(--ink); }
    }
  }
  .theme-toggle {
    width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--surface);
    display: grid; place-items: center; cursor: pointer;
    svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
    &:hover { border-color: var(--accent); }
  }
  @media (width < 760px) {
    .top-nav { display: none; }
    .theme-toggle { margin-left: auto; }
    .brand-sub { display: none; }
  }

  .tape {
    overflow: hidden; border-top: 1px solid var(--line); height: 34px;
    mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
  }
  .tape-track {
    display: flex; width: max-content; height: 100%; align-items: center;
    font: 500 12.5px/1 var(--mono);
    &:hover { animation-play-state: paused; }
  }
  .tape-item { display: inline-flex; gap: 8px; padding-inline: 18px; white-space: nowrap; }
  .tape-item b { font-weight: 600; }

  /* ---- hero ---- */
  .hero { padding-block: clamp(48px, 8vw, 96px) clamp(48px, 6vw, 72px); }
  .kicker {
    display: inline-flex; align-items: center; gap: 10px;
    font: 500 12.5px/1 var(--mono); color: var(--ink-2);
    padding: 8px 14px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface);
  }
  .pulse {
    width: 8px; height: 8px; border-radius: 50%; background: var(--up);
    box-shadow: 0 0 0 0 color-mix(in oklch, var(--up) 60%, transparent);
  }
  h1 {
    font-size: clamp(46px, 9vw, 112px); font-weight: 700; letter-spacing: -0.045em; line-height: .95;
    margin-top: 26px;
  }
  .grad {
    background: linear-gradient(100deg, var(--accent) 10%, var(--accent-2) 90%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  .lede { font-size: clamp(17px, 2vw, 20px); color: var(--ink-2); max-width: 58ch; margin-top: 22px; }

  .bento {
    display: grid; gap: 14px; margin-top: clamp(36px, 5vw, 56px);
    grid-template-columns: repeat(4, 1fr);
    .brief { grid-column: span 2; grid-row: span 2; }
    #tile-mortgage { grid-row: span 2; }
    @media (width < 900px) { grid-template-columns: repeat(2, 1fr); }
    @media (width < 900px) { #tile-mortgage { grid-row: auto; grid-column: span 2; } }
    @media (width < 560px) { grid-template-columns: 1fr; .brief, #tile-mortgage { grid-column: auto; grid-row: auto; } }
  }
  .tile, .card, .channel {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    box-shadow: var(--shadow); backdrop-filter: blur(12px);
  }
  .tile { padding: 22px; display: flex; flex-direction: column; gap: 10px; min-height: 160px; }
  .tile-label { font: 500 12px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
  .tile-note { color: var(--ink-3); font-size: 13px; margin-top: auto; }
  .big { font: 600 clamp(34px, 4vw, 44px)/1 var(--display); letter-spacing: -0.03em; }
  .brief-list {
    display: grid; gap: 14px; margin-top: 6px; counter-reset: b;
    li {
      counter-increment: b; display: grid; grid-template-columns: 28px 1fr; gap: 10px;
      font-size: clamp(16px, 1.6vw, 18px); line-height: 1.45;
      &::before {
        content: counter(b, decimal-leading-zero); font: 500 12px/1.9 var(--mono); color: var(--accent);
      }
    }
  }

  @property --p { syntax: '<number>'; inherits: false; initial-value: 0; }
  .ring {
    --size: 92px;
    width: var(--size); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
    background:
      radial-gradient(closest-side, var(--surface-solid) 78%, transparent 80% 100%),
      conic-gradient(var(--up) calc(var(--p) * 1%), color-mix(in oklch, var(--down) 55%, transparent) 0);
    transition: --p 1.2s var(--ease);
    span { font: 600 22px/1 var(--display); }
  }

  .spark-wrap svg { width: 100%; height: 44px; display: block; overflow: visible; }
  #tile-mortgage .spark-wrap { flex: 1; min-height: 44px; svg { height: 100%; } }
  .spark-line { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
  .spark-fill { fill: currentColor; opacity: .12; }

  /* ---- controls ---- */
  .controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
  .chips {
    display: flex; flex-wrap: wrap; gap: 6px;
    label { cursor: pointer; }
    input { position: absolute; opacity: 0; pointer-events: none; }
    span {
      display: inline-block; padding: 7px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
      border: 1px solid var(--line-2); color: var(--ink-2); background: var(--surface); transition: all .2s;
    }
    label:hover span { border-color: var(--ink-3); color: var(--ink); }
    input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
    input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
  }
  .sort {
    display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3);
    select {
      appearance: none; padding: 7px 30px 7px 12px; border-radius: 999px;
      border: 1px solid var(--line-2); background: var(--surface-solid); font-size: 13.5px; font-weight: 500; color: var(--ink);
      background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
      background-position: right 15px center, right 10px center; background-size: 5px 5px; background-repeat: no-repeat;
    }
  }

  .legend {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 20px;
  }
  .legend-note { color: var(--ink-3); font-size: 13px; }

  .sig {
    --c: var(--neutral);
    display: inline-flex; align-items: center; gap: 6px;
    font: 500 12px/1 var(--mono); padding: 6px 10px; border-radius: 999px;
    color: var(--c); background: color-mix(in oklch, var(--c) 13%, transparent);
    border: 1px solid color-mix(in oklch, var(--c) 28%, transparent);
    &::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
  }
  .sig-uptrend, .sig-sellers { --c: var(--up); }
  .sig-extended, .sig-softening { --c: var(--amber); }
  .sig-turning { --c: var(--cyan); }
  .sig-pullback, .sig-balanced { --c: var(--blue); }
  .sig-downtrend { --c: var(--down); }
  .sig-buyers { --c: var(--cyan); }

  /* ---- stock cards ---- */
  .cards {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  }
  .card { container-type: inline-size; position: relative; }
  .stock {
    display: grid; gap: 12px; padding: 20px; width: 100%; height: 100%; text-align: left; cursor: pointer;
    background: none; border: 0; border-radius: inherit;
    transition: transform .3s var(--ease);
    &:hover { transform: translateY(-2px); }
  }
  .card:has(.stock:hover) { border-color: var(--line-2); }
  .stock-top { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
  .ticker { font: 600 13px/1 var(--mono); letter-spacing: .04em; color: var(--ink-3); }
  .stock-name { font: 600 19px/1.15 var(--display); margin-top: 6px; letter-spacing: -0.01em; }
  .stock-tie { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
  .px { text-align: right; }
  .px-val { font: 600 22px/1 var(--display); letter-spacing: -0.02em; }
  .chg { font: 500 13px/1 var(--mono); margin-top: 6px; display: inline-block; }
  .pos { color: var(--up); }
  .neg { color: var(--down); }
  .stock .spark-wrap svg { height: 52px; }
  .stock-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
  .rets { display: flex; gap: 12px; font: 500 12px/1 var(--mono); color: var(--ink-3); b { font-weight: 500; } }
  .action { font-size: 14px; color: var(--ink-2); line-height: 1.5; border-top: 1px dashed var(--line-2); padding-top: 12px; }
  @container (width < 330px) {
    .rets { display: none; }
    .stock-name { font-size: 17px; }
  }

  .empty, .error {
    grid-column: 1 / -1; padding: 28px; border: 1px dashed var(--line-2); border-radius: var(--r-lg);
    color: var(--ink-2); text-align: center;
  }

  /* ---- metros ---- */
  .metros { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
  .metro { padding: 22px; display: grid; gap: 16px; }
  .metro-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
  .metro h3 { font-size: 22px; font-weight: 600; }
  .metro .big { margin-top: 4px; }
  .kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .kv div {
    background: var(--bg-2); border-radius: var(--r-sm); padding: 10px 12px;
    dt { font-size: 11.5px; color: var(--ink-3); }
    dd { margin: 4px 0 0; font: 600 16px/1.1 var(--display); }
    small { display: block; font: 500 11.5px/1 var(--mono); margin-top: 5px; }
  }
  .metro .spark-wrap { color: var(--accent); }

  /* ---- towns ---- */
  .towns { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
  .town { padding: 18px; display: grid; gap: 10px; }
  .town-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
  .town h3 { font-size: 17px; font-weight: 600; }
  .bars { display: flex; align-items: end; gap: 3px; height: 54px; }
  .bars span {
    flex: 1; min-height: 3px; border-radius: 3px 3px 1px 1px;
    background: color-mix(in oklch, var(--accent) 55%, transparent);
    &:last-child { background: var(--accent); }
  }
  .town-note { font-size: 13px; color: var(--ink-3); }
  .callout {
    margin-top: 22px; padding: 18px 22px; border-radius: var(--r-md);
    background: color-mix(in oklch, var(--accent) 10%, transparent);
    border: 1px solid color-mix(in oklch, var(--accent) 30%, transparent);
    a { font-weight: 600; }
  }
  .btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 999px;
    font-weight: 500; font-size: 14px; text-decoration: none; background: var(--ink); color: var(--bg);
    &.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line-2); }
    &:hover { border-color: var(--accent); }
  }

  /* ---- startups ---- */
  .channels { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
  .channel {
    padding: 24px; display: flex; flex-direction: column; gap: 12px;
    h3 { font-size: 21px; font-weight: 600; }
    > p:not(.channel-kind):not(.act) { color: var(--ink-2); font-size: 15px; }
    > a { margin-top: auto; font: 500 13px/1 var(--mono); color: var(--accent); text-decoration: none; }
  }
  .channel-kind { font: 500 11.5px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent-2); }
  .act {
    font-size: 14.5px; padding: 12px 14px; border-radius: var(--r-sm); background: var(--bg-2);
    span { font: 600 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-right: 6px; }
  }

  /* ---- detail popover ---- */
  .detail {
    width: min(640px, 100% - 24px); max-height: min(88dvh, 820px); overflow: auto;
    padding: 28px; border: 1px solid var(--line-2); border-radius: var(--r-lg);
    background: var(--surface-solid); color: var(--ink); box-shadow: 0 40px 120px -20px oklch(0% 0 0 / .5);
    &::backdrop { background: oklch(10% 0.02 268 / .45); backdrop-filter: blur(6px); }
    h3 { font-size: 28px; font-weight: 600; margin-top: 6px; }
    .spark-wrap svg { height: 150px; }
  }
  .detail-close {
    position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid var(--line-2); background: var(--surface); font-size: 22px; line-height: 1; cursor: pointer;
  }
  .detail-px { display: flex; align-items: baseline; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
  .detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px;
    @media (width < 520px) { grid-template-columns: repeat(2, 1fr); } }
  .range { margin-top: 18px; }
  .range-bar { position: relative; height: 8px; border-radius: 99px; margin-top: 8px;
    background: linear-gradient(90deg, var(--down), var(--amber), var(--up)); opacity: .85; }
  .range-dot { position: absolute; top: 50%; width: 16px; height: 16px; border-radius: 50%; translate: -50% -50%;
    background: var(--surface-solid); border: 3px solid var(--ink); }
  .range-labels { display: flex; justify-content: space-between; font: 500 12px/1 var(--mono); color: var(--ink-3); margin-top: 8px; }
  .detail .action { margin-top: 18px; font-size: 15px; }

  /* ---- footer ---- */
  .foot { border-top: 1px solid var(--line); padding-block: 40px 56px; color: var(--ink-3); font-size: 14px; }
  .foot-grid { display: grid; gap: 12px; max-width: 900px; strong { color: var(--ink); } }

  /* ---- loading ---- */
  .skeleton, .skeleton-card {
    background: linear-gradient(90deg, var(--line) 25%, var(--line-2) 50%, var(--line) 75%);
    background-size: 300% 100%;
  }
  .skeleton { height: 22px; border-radius: 6px; }
  .skeleton-card { min-height: 220px; border: 0; }
  .skeleton-card.tall { min-height: 320px; }
}

@layer motion {
  @media (prefers-reduced-motion: no-preference) {
    .tape-track { animation: tape 70s linear infinite; }
    @keyframes tape { to { translate: -50% 0; } }

    .pulse { animation: pulse 2.4s ease-out infinite; }
    @keyframes pulse { 70% { box-shadow: 0 0 0 9px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

    .skeleton, .skeleton-card { animation: shimmer 1.6s linear infinite; }
    @keyframes shimmer { to { background-position: -150% 0; } }

    /* Sections rise in as they scroll into view, where the browser can tie
       an animation to scroll; elsewhere they are simply there. */
    @supports (animation-timeline: view()) {
      .section-head, .card, .channel, .callout {
        animation: rise linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 60%;
      }
      @keyframes rise { from { opacity: 0; translate: 0 28px; scale: .98; } }
    }

    .detail {
      transition: opacity .25s var(--ease), translate .3s var(--ease), display .3s allow-discrete, overlay .3s allow-discrete;
      opacity: 0; translate: 0 16px;
      &:popover-open { opacity: 1; translate: 0 0; }
      @starting-style { &:popover-open { opacity: 0; translate: 0 16px; } }
    }

    ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .3s; }
  }
}
