/* Colour layer: a colour pair per section, a shell that takes on the current section's colours and
   blends to the next, gradient banners, icon tiles with a sliding highlight, and motion that only
   loops for things that are live. Shared by the dashboard (index.html), story mode, the layers map and the admin page; the pages
   opt in with the cl-* classes and data-sec attributes, and colour.js drives the moving parts.
   Loaded after each page's own <style>, so equal-specificity rules here win. */

@property --sec  { syntax: "<color>"; inherits: true; initial-value: #0369a1; }
@property --sec2 { syntax: "<color>"; inherits: true; initial-value: #0f766e; }
@property --spot { syntax: "<number>"; inherits: false; initial-value: 0; }

/* ---- section colours: main and second gradient stop. Both carry white text at 4.5:1 or more. ---- */
[data-sec="map"]       { --c1: #0369a1; --c2: #0f766e; }   /* dashboard: Map (globe) */
[data-sec="stories"]   { --c1: #c2410c; --c2: #be123c; }   /* dashboard: Stories */
[data-sec="sources"]   { --c1: #4f46e5; --c2: #2563eb; }   /* dashboard: Sources */
[data-sec="briefs"]    { --c1: #9333ea; --c2: #be185d; }   /* dashboard: Briefs */
[data-sec="story"]     { --c1: #0369a1; --c2: #6d28d9; }   /* story mode, the front page */
[data-sec="layers"]    { --c1: #0e7490; --c2: #2563eb; }   /* the layers map */
[data-sec="overview"]  { --c1: #4338ca; --c2: #7e22ce; }   /* admin: Overview (key figures) */
[data-sec="traffic"]   { --c1: #0369a1; --c2: #0f766e; }   /* admin: Web traffic */
[data-sec="app"]       { --c1: #9333ea; --c2: #be185d; }   /* admin: iPhone app */
[data-sec="ops"]       { --c1: #b45309; --c2: #c2410c; }   /* admin: Operations */
/* admin key-figure cards */
[data-sec="visitors"]  { --c1: #0369a1; --c2: #0e7490; }
[data-sec="visits"]    { --c1: #0f766e; --c2: #0369a1; }
[data-sec="views"]     { --c1: #4f46e5; --c2: #2563eb; }
[data-sec="installs"]  { --c1: #9333ea; --c2: #4f46e5; }
[data-sec="active"]    { --c1: #be185d; --c2: #9333ea; }
[data-sec="members"]   { --c1: #2563eb; --c2: #0e7490; }

:root {
  --sec: var(--c1, #0369a1);
  --sec2: var(--c2, #0f766e);
  /* section colour used as text or an icon stroke: mixed toward white on dark, toward black on light */
  --tone-mix: 62%; --tone-to: #fff;
  --acc: color-mix(in srgb, var(--sec) var(--tone-mix), var(--tone-to));
  --r-panel: 16px;
  --spring: cubic-bezier(.34, 1.6, .5, 1);
  --spring-soft: cubic-bezier(.34, 1.4, .5, 1);
  --ease-out: cubic-bezier(.25, 1, .5, 1);   /* ease-out quart */
  transition: --sec .7s ease, --sec2 .7s ease;
}
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { --tone-mix: 82%; --tone-to: #000; } }
:root[data-theme="light"] { --tone-mix: 82%; --tone-to: #000; }

/* ---- shell: soft glows of the section's colours near the top, a gradient line under the bar ------ */
body {
  background:
    radial-gradient(ellipse min(60vw, 900px) 420px at 100% 0, color-mix(in srgb, var(--sec) 13%, transparent), transparent 72%),
    radial-gradient(ellipse min(50vw, 760px) 380px at 0 0, color-mix(in srgb, var(--sec2) 9%, transparent), transparent 72%),
    var(--abyss);
  background-repeat: no-repeat;
}
.bar { border-block-end: 2px solid transparent;
       border-image: linear-gradient(90deg, var(--sec), var(--sec2) 55%, transparent) 1; }
:root[dir="rtl"] .bar { border-image: linear-gradient(270deg, var(--sec), var(--sec2) 55%, transparent) 1; }
:focus-visible { outline-color: var(--acc); }
a:hover { text-decoration-color: var(--acc); }
.btn:hover { border-color: var(--acc); }

/* primary button: the section's gradient, lifts 1 px on hover */
.cl-primary { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--sec), var(--sec2)); }
.cl-primary:hover { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--sec), var(--sec2));
                    transform: translateY(-1px); box-shadow: 0 6px 16px -8px var(--sec); }

/* theme switch: the icon turns on hover */
#themeToggle .i { transition: transform .5s var(--spring); }
#themeToggle:hover .i { transform: rotate(160deg); }

/* ---- navigation: icon tiles, and one highlight that slides to the current item ------------------- */
.cl-nav { isolation: isolate; }   /* the page positions it (the slider measures against it) */
.cl-item { position: relative; z-index: 1; }
.cl-tile { flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
           background: color-mix(in srgb, var(--c1) 14%, transparent);
           color: color-mix(in srgb, var(--c1) var(--tone-mix), var(--tone-to));
           transition: transform .25s var(--spring), background-color .3s, color .3s, box-shadow .3s; }
.cl-tile .i { width: 16px; height: 16px; }
.cl-item:hover { background: color-mix(in srgb, var(--c1) 7%, transparent); }
.cl-item:hover .cl-tile { transform: scale(1.1) rotate(-6deg); }
.cl-item.is-on .cl-tile { background: linear-gradient(135deg, var(--c1), var(--c2)); color: #fff;
                          box-shadow: 0 4px 12px -3px color-mix(in srgb, var(--c1) 70%, transparent); }
.cl-item.is-on { color: color-mix(in srgb, var(--c1) var(--tone-mix), var(--tone-to)); font-weight: 650; }
.cl-pill { position: absolute; z-index: 0; left: 0; top: 0; width: 0; height: 0; pointer-events: none; opacity: 0;
           border-radius: 10px;
           background: linear-gradient(90deg, color-mix(in srgb, var(--sec) 16%, transparent), color-mix(in srgb, var(--sec2) 8%, transparent));
           box-shadow: inset 0 -3px 0 var(--sec), 0 8px 18px -12px var(--sec);
           transition: transform .45s var(--spring-soft), width .45s var(--spring-soft), height .45s var(--spring-soft), opacity .2s; }
.cl-pill.is-ready { opacity: 1; }
.cl-pill.is-vertical { box-shadow: inset 3px 0 0 var(--sec), 0 8px 18px -12px var(--sec); }
:root[dir="rtl"] .cl-pill.is-vertical { box-shadow: inset -3px 0 0 var(--sec), 0 8px 18px -12px var(--sec); }

/* ---- page banner ----------------------------------------------------------------------------------- */
.cl-banner { position: relative; isolation: isolate; overflow: hidden; display: flex; flex-wrap: wrap; align-items: center;
             gap: 14px 16px; padding: 20px 22px; border-radius: 18px; color: #fff;
             background: linear-gradient(120deg, var(--c1), var(--c2) 60%, var(--c1)); background-size: 220% 220%;
             box-shadow: 0 22px 44px -26px color-mix(in srgb, var(--c1) 90%, transparent); }
.cl-banner::before, .cl-banner::after { content: ""; position: absolute; z-index: -1; border-radius: 50%; pointer-events: none;
             background: radial-gradient(circle, rgb(255 255 255 / .22), transparent 68%); }
.cl-banner::before { width: 260px; height: 260px; inset-inline-end: -60px; top: -120px; }
.cl-banner::after { width: 200px; height: 200px; inset-inline-start: 30%; bottom: -130px; opacity: .7; }
.cl-banner-wave { position: absolute; z-index: -1; inset-inline: 0; bottom: 0; height: 34px; pointer-events: none; opacity: .07;
                  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 34'%3E%3Cpath d='M0 20 Q25 6 50 20 T100 20 T150 20 T200 20 V34 H0Z' fill='%23fff'/%3E%3C/svg%3E") 0 100% / 200px 34px repeat-x; }
.cl-banner-ico { flex: none; display: grid; place-items: center; width: 50px; height: 50px; border-radius: 14px;
                 background: rgb(255 255 255 / .2); box-shadow: inset 0 0 0 1px rgb(255 255 255 / .35);
                 backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.cl-banner-ico .i { width: 24px; height: 24px; color: #fff; }
.cl-banner-text { flex: 1 1 16rem; min-width: 0; display: grid; gap: 2px; }
.cl-kicker { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: rgb(255 255 255 / .85); }
.cl-banner h1, .cl-banner h2, .cl-banner .cl-title { margin: 0; font-size: 27px; line-height: 1.15; font-weight: 700; color: #fff; }
.cl-banner-sub { margin: 0; font-size: 13px; color: rgb(255 255 255 / .9); }
.cl-banner-sub b, .cl-banner-sub q { color: #fff; }
.cl-banner a { color: #fff; text-decoration-color: rgb(255 255 255 / .6); }
.cl-banner :focus-visible { outline-color: #fff; }
.cl-banner .i { color: inherit; }
/* controls inside a banner are frosted glass; a segmented control's white thumb slides */
.cl-banner .btn { color: #fff; background: rgb(255 255 255 / .14); border-color: rgb(255 255 255 / .35); }
.cl-banner .btn:hover { background: rgb(255 255 255 / .24); border-color: #fff; }
.cl-seg { position: relative; isolation: isolate; }
.cl-thumb { position: absolute; z-index: -1; left: 0; top: 0; width: 0; height: 0; border-radius: 7px; opacity: 0; pointer-events: none;
            transition: transform .35s var(--spring-soft), width .35s var(--spring-soft), opacity .2s; }
.cl-thumb.is-ready { opacity: 1; }
.cl-banner .cl-seg { background: rgb(255 255 255 / .14); border-color: rgb(255 255 255 / .3); }
.cl-banner .cl-seg button { color: rgb(255 255 255 / .92); background: none; }
.cl-banner .cl-seg button:hover { color: #fff; background: rgb(255 255 255 / .1); }
.cl-banner .cl-seg button[aria-pressed="true"] { color: var(--c1); background: none; box-shadow: none; }
.cl-banner .cl-seg button[aria-pressed="true"] .i { color: var(--c1); }
.cl-banner .cl-thumb { background: #fff; box-shadow: 0 2px 8px -2px rgb(0 0 0 / .3); }
/* outside a banner the thumb is the panel colour with a hint of the section */
.cl-seg:not(.cl-banner .cl-seg) button[aria-pressed="true"] { background: none; }
.cl-seg:not(.cl-banner .cl-seg) .cl-thumb { background: var(--glass-solid);
            box-shadow: 0 0 0 1px var(--rule-strong), inset 0 -2px 0 color-mix(in srgb, var(--sec) 70%, transparent); }

/* ---- panels, cards and depth -------------------------------------------------------------------- */
.cl-panel { border-radius: var(--r-panel); }
.cl-spot { background-image: radial-gradient(360px circle at var(--mx, 50%) var(--my, -400px),
             color-mix(in srgb, var(--c1, var(--sec)) calc(16% * var(--spot)), transparent), transparent 70%);
           transition: --spot .3s, border-color .3s, box-shadow .3s; }
.cl-spot:hover { --spot: 1; border-color: color-mix(in srgb, var(--c1, var(--sec)) 45%, var(--rule)); }
.cl-lift:hover { box-shadow: 0 14px 30px -20px color-mix(in srgb, var(--c1, var(--sec)) 80%, transparent); }

.cl-card { position: relative; overflow: hidden; border: 1px solid var(--rule); border-radius: var(--r-panel);
           background-color: var(--glass-solid);
           background-image:
             radial-gradient(360px circle at var(--mx, 50%) var(--my, -400px), color-mix(in srgb, var(--c1) calc(16% * var(--spot)), transparent), transparent 70%),
             linear-gradient(135deg, color-mix(in srgb, var(--c1) 11%, transparent), transparent 58%);
           transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
           transition: --spot .3s, transform .5s var(--ease-out), border-color .3s, box-shadow .3s; }
.cl-card:hover { --spot: 1; border-color: color-mix(in srgb, var(--c1) 45%, var(--rule));
                 box-shadow: 0 16px 34px -22px color-mix(in srgb, var(--c1) 85%, transparent); }
.cl-card.is-tilting { transition: --spot .3s, transform .12s linear, border-color .3s, box-shadow .3s; }
.cl-card::before { content: ""; position: absolute; inset: 0 0 auto; width: auto; height: 4px; opacity: 1;
                   background: linear-gradient(90deg, var(--c1), var(--c2)); }
.cl-card-ico { position: absolute; top: 12px; inset-inline-end: 12px; display: grid; place-items: center; width: 34px; height: 34px;
               border-radius: 10px; color: #fff; background: linear-gradient(135deg, var(--c1), var(--c2));
               box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--c1) 80%, transparent);
               transition: transform .3s var(--spring); }
.cl-card-ico .i { width: 17px; height: 17px; }
.cl-card:hover .cl-card-ico { transform: scale(1.12) rotate(8deg); }

/* section heading with its own icon tile */
.cl-head-tile { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-inline-end: 10px; border-radius: 8px;
                vertical-align: middle; color: #fff; background: linear-gradient(135deg, var(--c1), var(--c2));
                box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--c1) 70%, transparent); }
.cl-head-tile .i { width: 15px; height: 15px; margin: 0 !important; color: #fff !important; }

/* rows: indent and take a tint of the section on hover */
.cl-rows > li { transition: padding .25s var(--ease-out), background-color .25s, box-shadow .25s; }
.cl-rows > li:hover { padding-inline-start: 22px; background-color: color-mix(in srgb, var(--c1, var(--sec)) 6%, transparent);
                      box-shadow: inset 3px 0 0 color-mix(in srgb, var(--c1, var(--sec)) 80%, transparent); }
:root[dir="rtl"] .cl-rows > li:hover { box-shadow: inset -3px 0 0 color-mix(in srgb, var(--c1, var(--sec)) 80%, transparent); }

/* ---- live things: the only loops ------------------------------------------------------------------ */
.cl-live { display: inline-flex; align-items: center; gap: 7px; min-height: 26px; padding: 0 10px; border-radius: 999px;
           font-size: 12px; color: var(--frost); background: color-mix(in srgb, var(--phosphor) 10%, transparent);
           border: 1px solid color-mix(in srgb, var(--phosphor) 30%, transparent); }
.cl-live b { color: var(--phosphor-text); font-weight: 700; }
.cl-live time, .cl-live .ro { font-variant-numeric: tabular-nums; }
.cl-live[data-stale="true"] { background: color-mix(in srgb, var(--amber) 12%, transparent); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }
.cl-live[data-stale="true"] b { color: var(--amber-text); }
.cl-dot { position: relative; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--phosphor); }
.cl-live[data-stale="true"] .cl-dot { background: var(--amber); }
.cl-dot::after { content: ""; position: absolute; inset: 0; border-radius: inherit; border: 2px solid currentColor; color: var(--phosphor); opacity: 0; }
.cl-dot.is-ping::after { animation: cl-ping 1.1s var(--ease-out) 1; }
.cl-breathe { animation: cl-breathe 2.2s ease-in-out infinite; }

/* ---- entrances: once, on first show -------------------------------------------------------------- */
.cl-page-in { animation: cl-rise .45s var(--ease-out) both; }
.cl-banner.cl-page-in .cl-banner-ico { animation: cl-pop .55s var(--spring) .08s both; }
.cl-enter > * { animation: cl-slide-in .42s var(--ease-out) both; animation-delay: calc(min(var(--i, 0), 14) * 38ms); }
.cl-rise > * { animation: cl-rise .5s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms); }

@keyframes cl-rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes cl-slide-in { from { opacity: 0; transform: translateX(-10px); } }
@keyframes cl-pop { from { opacity: 0; transform: scale(.6) rotate(-14deg); } }
@keyframes cl-ping { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(3); } }
@keyframes cl-breathe { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 18%, transparent); }
                        50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--signal) 18%, transparent); } }
@keyframes cl-drift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes cl-orb-a { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-26px, 18px); } }
@keyframes cl-orb-b { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(30px, -14px); } }
@keyframes cl-wave { to { background-position-x: 200px; } }
@keyframes cl-grow-y { from { transform: scaleY(0); } }
@keyframes cl-grow-x { from { transform: scaleX(0); } }
@keyframes cl-draw { from { stroke-dashoffset: 1; } }
@keyframes cl-fade { from { opacity: 0; } }
@keyframes cl-shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }

/* the banner's slow drift: a genuine loop, but slow and only while motion is welcome */
.cl-banner { animation: cl-drift 14s ease-in-out infinite; }
.cl-banner::before { animation: cl-orb-a 9s ease-in-out infinite; }
.cl-banner::after { animation: cl-orb-b 11s ease-in-out infinite; }
.cl-banner-wave { animation: cl-wave 18s linear infinite; }

/* loading: a shimmer tinted by the section, never a blank page */
.cl-shimmer { background: linear-gradient(100deg, var(--tint) 30%, color-mix(in srgb, var(--sec) 16%, var(--tint)) 50%, var(--tint) 70%) 0 0 / 200% 100%;
              animation: cl-shimmer 1.5s linear infinite !important; }

/* ---- reduced motion: no animation or transition anywhere; numbers and charts are shown final ----- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .cl-card { transform: none !important; }
}
/* hover-only effects stay off on touch screens */
@media (hover: none) {
  .cl-item:hover .cl-tile, .cl-card:hover .cl-card-ico { transform: none; }
}
