/*
 * Attakei theme variables — the site's own house color (not a fallback or
 * baseline value set; see `.claude/CLAUDE.md`, "Website architecture").
 *
 * Ships a light default plus a `[data-theme="dark"]` dark variant (see the
 * dark block at the end of the mixin). Inherits Bulma defaults for radius /
 * shadow / spacing; only colors (primary / link / admonitions / scheme tint)
 * are customized.
 *
 * This file is compiled by `build.ts` into a single CSS artifact per theme
 * (the directory name is used as the theme name):
 *   - dist/<theme>/theme.min.css  (Bulma bundle + variables on :root)
 *
 * Downstream consumers can also `@use` this file with `with (...)` to
 * override individual values and run their own build.
 */

// --- scheme / text (align to primary hue at low saturation) ---
$scheme-h: 200 !default;
$scheme-s: 14% !default;
$text-h: 200 !default;
$text-s: 14% !default;

// --- primary / link ---
$primary-h: 200 !default;
$primary-s: 70% !default;
$primary-l: 30% !default;
$primary-invert-l: 100% !default;
$link-h: 168 !default;
$link-s: 76% !default;
$link-l: 30% !default;
$link-invert-l: 100% !default;
$link-on-scheme-l: $link-l !default;

// --- secondary (library extension colour paired with primary; see the
// "Choosing a theme's secondary" policy in .claude/themes-authoring.md).
// Default has no distinct supporting colour, so secondary aliases primary
// — a valid outcome, not a special case. The base colour is injected into
// Bulma's colour map via $custom-colors (entry.scss), which generates the
// full .is-secondary / .has-*-secondary surface and the --bulma-secondary-*
// palette; only invert-l is pinned here (mirroring the primary pin). ---
$secondary-h: $primary-h !default;
$secondary-s: $primary-s !default;
$secondary-l: $primary-l !default;
$secondary-invert-l: $primary-invert-l !default;
$custom-colors: ("secondary": (hsl($secondary-h, $secondary-s, $secondary-l))) !default;

// --- admonition palette (Pitfall 3: every admonition L sits at ≤50%, so
// white text reads cleanly on the saturated fill — pin invert-l to 100%
// instead of relying on the SCSS palette generator's default choice) ---
$info-h: 218 !default;
$info-s: 70% !default;
$info-l: 45% !default;
$info-invert-l: 100% !default;
$success-h: 145 !default;
$success-s: 70% !default;
$success-l: 36% !default;
$success-invert-l: 100% !default;
$warning-h: 40 !default;
$warning-s: 80% !default;
$warning-l: 50% !default;
$warning-invert-l: 100% !default;
$danger-h: 6 !default;
$danger-s: 70% !default;
$danger-l: 45% !default;
$danger-invert-l: 100% !default;

// --- radius (matches Bulma's --bulma-radius default; only declared so
// the Pitfall 6 control-radius pin can interpolate a literal value) ---
$radius: 0.375rem !default;

@mixin variables {
  --bulma-scheme-h: #{$scheme-h};
  --bulma-scheme-s: #{$scheme-s};
  --bulma-text-h: #{$text-h};
  --bulma-text-s: #{$text-s};
  --bulma-primary-h: #{$primary-h};
  --bulma-primary-s: #{$primary-s};
  --bulma-primary-l: #{$primary-l};
  --bulma-primary-invert-l: #{$primary-invert-l};
  --bulma-secondary-invert-l: #{$secondary-invert-l};
  --bulma-link-h: #{$link-h};
  --bulma-link-s: #{$link-s};
  --bulma-link-l: #{$link-l};
  --bulma-link-invert-l: #{$link-invert-l};
  --bulma-link-on-scheme-l: #{$link-on-scheme-l};
  --bulma-info-h: #{$info-h};
  --bulma-info-s: #{$info-s};
  --bulma-info-l: #{$info-l};
  --bulma-info-invert-l: #{$info-invert-l};
  --bulma-success-h: #{$success-h};
  --bulma-success-s: #{$success-s};
  --bulma-success-l: #{$success-l};
  --bulma-success-invert-l: #{$success-invert-l};
  --bulma-warning-h: #{$warning-h};
  --bulma-warning-s: #{$warning-s};
  --bulma-warning-l: #{$warning-l};
  --bulma-warning-invert-l: #{$warning-invert-l};
  --bulma-danger-h: #{$danger-h};
  --bulma-danger-s: #{$danger-s};
  --bulma-danger-l: #{$danger-l};
  --bulma-danger-invert-l: #{$danger-invert-l};

  // Pitfall 6: pin every --bulma-control-* on the shared control selector
  // group so bare `.button` / `.input` / `.textarea` / `.select select` /
  // `.pagination-*` and their icons resolve padding, border, height, and
  // radius correctly. `.is-*` modifiers re-declare with higher
  // specificity, so per-modifier behaviour is preserved.
  .button,
  .control,
  .file-cta,
  .file-name,
  .input,
  .pagination,
  .pagination-ellipsis,
  .pagination-link,
  .pagination-next,
  .pagination-previous,
  .select,
  .select select,
  .textarea {
    --bulma-control-border-width: 1px;
    --bulma-control-height: 2.5em;
    --bulma-control-padding-vertical: calc(0.5em - 1px);
    --bulma-control-padding-horizontal: calc(0.75em - 1px);
    --bulma-control-radius: #{$radius};
  }

  // Pitfall 8: `--bulma-link-text` is set on :root via an hsl(var(...))
  // chain that can fall back to UA-default on `<a>`; pin literally.
  a {
    --bulma-link-text: hsl(#{$link-h}, #{$link-s}, #{$link-on-scheme-l});
  }

  // Pitfall 14: `.breadcrumb a` reads `--bulma-breadcrumb-item-color`
  // (= var(--bulma-link-text)), whose hsl(var(), var(), var()) chain fails
  // at the child and drops the brand colour to the UA default. Pin the
  // literal link colour on the parent `.breadcrumb` (base colour only — a
  // hover lightness cannot be hard-coded generically and a base-only pin
  // does not regress hover).
  .breadcrumb {
    --bulma-breadcrumb-item-color: hsl(#{$link-h}, #{$link-s}, #{$link-on-scheme-l});
  }

  // Pitfall 4: burger icon on .navbar.is-primary follows primary-invert.
  .navbar.is-primary {
    --bulma-navbar-burger-color: var(--bulma-primary-invert);
  }

  // Pitfall 9: pin <use>-pattern SVG icons inside .panel-icon to 1em so
  // they sit in the icon slot instead of overflowing rightward.
  .panel-icon svg {
    width: 1em;
    height: 1em;
  }

  .panel-icon svg use {
    width: 100%;
    height: 100%;
  }

  // Pitfall 10: --bulma-shadow's hsl(var(--bulma-shadow-h), ...) chain
  // on :root fails to resolve at the shadowed containers (.box / .card /
  // .panel); they end up with neither the drop shadow nor the inner 1px
  // ring. Pin a fully resolved two-stop shadow on those selectors (matches
  // Bulma's light-mode computed value). `.dropdown` uses a two-level
  // indirection (parent `.dropdown` registers `--bulma-dropdown-content-
  // shadow: var(--bulma-shadow)`, child `.dropdown-content` reads it), so
  // per Pitfall 1's eager-substitution behaviour, the pin must go on the
  // parent `.dropdown` selector — pinning on `.dropdown-content` is too
  // late.
  .box,
  .card,
  .dropdown,
  .modal-card-head,
  .panel {
    --bulma-shadow:
      0 0.5em 1em -0.125em hsl(221deg 14% 4% / 10%),
      0 0 0 1px hsl(221deg 14% 4% / 2%);
  }

  // Pitfall 11: separator borders on `.card-footer` / `.panel-block` /
  // `.panel-tabs` / `.dropdown-divider` chain through --bulma-border-weak,
  // and `.tabs a` / `.tabs ul` chain through --bulma-border. Both share
  // the same `hsl(var(--bulma-scheme-h), var(--bulma-scheme-s), var(...-l))`
  // shape on :root and fail to resolve at the descendants — separator /
  // tab underlines disappear and the components look flat/floating. Pin
  // literal hsl on the parents (register happens on `.card` / `.dropdown`
  // / `.panel` / `.tabs`; children inherit the resolved value). Also pin
  // --bulma-card-header-shadow on .card, since its hsla(var(--bulma-
  // scheme-h), ...) chain (for the visual separator under `.card-header`)
  // is affected by the same failure.
  .card,
  .dropdown,
  .panel {
    --bulma-border-weak: hsl(#{$scheme-h}, #{$scheme-s}, 93%);
  }

  .tabs {
    --bulma-border: hsl(#{$scheme-h}, #{$scheme-s}, 86%);

    // Same Pitfall 12 shape: Bulma registers
    // `--bulma-tabs-boxed-link-active-background-color: var(--bulma-scheme-main)`
    // on `.tabs`, and `.scheme-main` on :root is
    // `hsl(var(...-h), var(...-s), var(...-main-l))`. The inner
    // hsl(var(), var(), var()) chain fails at the descendant
    // `.tabs.is-boxed li.is-active a`, leaving its background transparent
    // — the ul's continuous bottom border then bleeds through and reads
    // as an unwanted underline on the active is-boxed tab. Pin literal
    // hsl matching Bulma's light-mode `--bulma-scheme-main-l` (100%).
    --bulma-tabs-boxed-link-active-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 100%);
  }

  .card {
    --bulma-card-header-shadow: 0 0.125em 0.25em hsla(#{$scheme-h}, #{$scheme-s}, 4%, 10%);

    // Pitfall 13: `--bulma-card-radius` is Bulma's SCSS-default 0.75rem,
    // hardcoded in card.scss and NOT tied to any --bulma-radius token,
    // and Bulma re-declares it directly on `.card` in its register-vars
    // block. Emitting `--bulma-card-radius` on `:root` alone is shadowed
    // by that direct `.card` declaration, so the pin must be scoped to
    // `.card` too — inside the mixin, `.card { ... }` compiles to
    // `:root .card { ... }` and wins on specificity (0,2,0 vs 0,1,0).
    --bulma-card-radius: #{$radius};
  }

  // Same class of chain failure as Pitfall 11: `.modal` registers
  // `--bulma-modal-card-{head,body,foot}-background-color:
  // var(--bulma-scheme-{main,main-bis})`, which on :root is
  // `hsl(var(--bulma-scheme-h), var(--bulma-scheme-s),
  // var(--bulma-scheme-main{-bis}-l))`. The compound `hsl(var(), var(),
  // var())` fails at the descendant `.modal-card-{head,body,foot}` and
  // leaves the backgrounds transparent — the dark overlay bleeds
  // through and the modal becomes unreadable. Pin literal hsl on the
  // parent `.modal` per Pitfall 1's eager-substitution behaviour.
  // 100% / 98% match Bulma's light-mode `--bulma-scheme-main-l` and
  // `--bulma-scheme-main-bis-l`.
  .modal {
    --bulma-modal-card-head-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 100%);
    --bulma-modal-card-body-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 100%);
    --bulma-modal-card-foot-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 98%);
  }

  // Pitfall 13 (continued): Bulma's `.card-image:first-child img` /
  // `:last-child img` rule only rounds `<img>` children. A
  // background-styled `<figure>` (e.g. the gradient placeholders used in
  // the Showcase and card demo) has no img target and its top/bottom
  // corners visibly poke past the card's rounded silhouette. Mirror
  // Bulma's rule for figure children so gradient placeholders and other
  // non-img card-image content stay clipped to the card radius.
  .card-image:first-child > figure {
    border-start-start-radius: var(--bulma-card-radius);
    border-start-end-radius: var(--bulma-card-radius);
  }

  .card-image:last-child > figure {
    border-end-start-radius: var(--bulma-card-radius);
    border-end-end-radius: var(--bulma-card-radius);
  }

  // Widen the active tab's underline from Bulma's 1px to 3px so it
  // reads as a clear accent under plain `.tabs`. Under `.tabs.is-boxed`,
  // Bulma sets `border-bottom-color: transparent !important` on the
  // active tab, so this width change stays invisible there — the pin
  // surfaces in the non-boxed variant where a stronger active marker is
  // wanted. Cancel the compensating margin so the tab row does not
  // shift. Exclude `.is-toggle` because its active tab has an all-four
  // border and a 3px bottom would leave the active toggle 2px taller
  // than the neighbouring hover state.
  .tabs:not(.is-toggle) li.is-active a {
    border-bottom-width: 3px;
    margin-bottom: -3px;
  }

  // Bulma registers `--bulma-code` on :root as the danger/red colour
  // (hsl(danger-h, danger-s, danger-on-scheme-l)), so inline <code> reads
  // as an error state and clashes with the theme tone. Repoint both text and
  // background into the brand primary hue: a deep, dark primary tone for the
  // text (L=25%, below primary-l so it stays legible on the tint) over a
  // pale primary-hued chip (L=94%), so <code> reads as part of the palette
  // rather than Bulma's red-on-neutral default. Scope to the `code` selector
  // (0,1,1) so both win over Bulma's own :root registration regardless of
  // load order.
  code {
    --bulma-code: hsl(#{$primary-h}, #{$primary-s}, 25%);
    --bulma-code-background: hsl(#{$primary-h}, #{$primary-s}, 94%);
  }

  // --- Dark mode (Bulma neutral dark canvas + brand accents; driven by
  // [data-theme="dark"]) ---
  // default pins no scheme/text L, so Bulma's own [data-theme=dark] theme sets
  // the canvas; only the light-only literal pins above need dark counterparts.
  // `&` is :root, so this compiles to `:root[data-theme="dark"] …`.
  &[data-theme="dark"] {
    .box,
    .card,
    .dropdown,
    .modal-card-head,
    .panel {
      --bulma-shadow:
        0 0.5em 1em -0.125em hsl(0deg 0% 0% / 40%),
        0 0 0 1px hsl(0deg 0% 100% / 10%);
    }

    .card,
    .dropdown,
    .panel {
      --bulma-border-weak: hsl(#{$scheme-h}, #{$scheme-s}, 21%);
    }

    .tabs {
      --bulma-border: hsl(#{$scheme-h}, #{$scheme-s}, 24%);
      --bulma-tabs-boxed-link-active-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 9%);
    }

    .card {
      --bulma-card-header-shadow: 0 0.125em 0.25em hsl(0deg 0% 0% / 30%);
    }

    .modal {
      --bulma-modal-card-head-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 9%);
      --bulma-modal-card-body-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 9%);
      --bulma-modal-card-foot-background-color: hsl(#{$scheme-h}, #{$scheme-s}, 11%);
    }

    code {
      --bulma-code: hsl(#{$primary-h}, #{$primary-s}, 78%);
      --bulma-code-background: hsl(#{$primary-h}, #{$primary-s}, 16%);
    }

    // default's light link lightness (30%) is too dim on the dark canvas — lift
    // the body-link and breadcrumb tones for legibility. (The `.is-link` button
    // is a solid fill, so it stays legible without a restyle.)
    a {
      --bulma-link-text: hsl(#{$link-h}, #{$link-s}, 70%);
    }

    .breadcrumb {
      --bulma-breadcrumb-item-color: hsl(#{$link-h}, #{$link-s}, 70%);
    }
  }
}
