/* ============================================================================
   Smart Taala Tracker — design tokens
   ----------------------------------------------------------------------------
   Every colour, size, duration and hue in the interface is named here, and
   nowhere else. A rule in another stylesheet that needs a value takes it from
   this file; if the value it needs does not exist yet, it is added here first.
   That is what lets the whole app change theme, text size or tempo at once.

   Four things are tuned at runtime, by js/appearance.js and js/app.js:

     data-theme="light|dark"   on <html> — resolved from the saved choice, or
                                from the operating system when it is "auto".
     --scale                   text density: 1, 1.25 or 1.5. For a patient with
                               low vision this is the difference between using
                               the tool and not, so it is a control, not a
                               setting buried in a menu.
     --beat-ms                 the length of one beat at the current tempo.
                               Motion is derived FROM it, so the interface moves
                               in time with the thala rather than against it.
     --swara-*                 the twelve semitone hues (see below).
   ========================================================================= */

:root {
    /* ── Type ────────────────────────────────────────────────────────────
       Source Sans 3 for the interface, Source Serif 4 for headings and large
       numerals: one superfamily, so the metrics already agree.

       The tokens are named for their size in pixels at 100% density, because
       that is unambiguous to read in a rule and impossible to misorder. They
       are declared in rem, so --scale moves every one of them together. This
       is the vocabulary the app actually uses, not a geometric scale invented
       on paper; adding a size means adding it here first. */
    --font: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-display: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

    --text-11: 0.6875rem;   /* diagnostics only */
    --text-12: 0.75rem;
    --text-13: 0.8125rem;   /* captions, chip labels */
    --text-14: 0.875rem;    /* secondary text, field labels */
    --text-15: 0.9375rem;
    --text-16: 1rem;
    --text-17: 1.0625rem;   /* body — the reading size */
    --text-18: 1.125rem;
    --text-20: 1.25rem;
    --text-22: 1.375rem;
    --text-24: 1.5rem;
    --text-26: 1.625rem;
    --text-28: 1.75rem;
    --text-36: 2.25rem;     /* the one display size */

    --scale: 1;               /* density, set by js/appearance.js */

    /* ── Shape and rhythm of the layout ──────────────────────────────── */
    --r: 10px;
    --r-sm: 6px;
    --r-pill: 999px;
    --panel-w: calc(380px * var(--scale));
    --top-h: calc(56px * var(--scale));
    --hit: 44px;              /* smallest target anything may be */

    /* ── Motion, in musical time ─────────────────────────────────────────
       --beat-ms is written from the live tempo (js/app.js). Everything that
       moves derives from it and is clamped, so a 30 BPM exercise does not
       leave the interface wading through treacle, and 240 BPM does not make
       it twitch. A patient entraining to a pulse should not have to filter
       out an interface moving against it. */
    --beat-ms: 600ms;
    --motion-fast:  clamp(70ms,  calc(var(--beat-ms) * 0.15), 160ms);
    --motion:       clamp(110ms, calc(var(--beat-ms) * 0.25), 320ms);
    --motion-slow:  clamp(200ms, calc(var(--beat-ms) * 0.5),  700ms);
    --ease: cubic-bezier(.2, .7, .3, 1);

    /* ── Light theme ─────────────────────────────────────────────────────
       Warm paper rather than white: it is the tone of a practice room, and it
       is kinder than a lit page to someone looking at a screen for an hour. */
    --paper: #f6f4ef;
    --surface: #ffffff;
    --sunken: #efece5;
    --raised: #ffffff;
    --ink: #1c1b19;
    --ink-2: #57534e;
    --ink-3: #6b665e;
    --line: #e2ddd3;
    --line-strong: #cbc4b7;

    --accent: #1f6b57;
    --accent-hover: #185646;
    --accent-ink: #ffffff;
    --accent-soft: #e2efe9;
    --beat: #b45309;
    --beat-soft: #fbeedd;
    --warn: #a15c07;
    --warn-deep: #5c3b06;
    --bad: #b42318;
    --bad-soft: #fbe9e7;
    --violet: #6d5bb5;
    --good: #00a65a;
    --near: #e58a16;

    /* Surfaces that are not paper: the camera area before video arrives, the
       scrim over the page, the inverted chrome (toasts, stop button). */
    --stage: #e9e5dc;
    --scrim: rgba(246, 244, 239, .86);
    --invert-bg: #1c1b19;
    --invert-ink: #ffffff;
    --invert-bg-hover: #000000;

    /* The chevron drawn on a <select>. It is a background image, so it cannot
       read a custom property from inside; there is one per theme instead. */
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2357534e' stroke-width='1.6'/%3E%3C/svg%3E");

    --shadow-1: 0 1px 2px rgba(28, 27, 25, .12);
    --shadow-2: 0 8px 24px rgba(28, 27, 25, .10);
    --shadow-3: 0 12px 32px rgba(28, 27, 25, .12);

    /* The melakarta chakra keeps its manuscript colouring — it is a drawing of
       a traditional figure, not a piece of interface. */
    --chakra-half-a: #f5efe6;
    --chakra-half-b: #ede4d6;
    --chakra-sector-a: #c8b996;
    --chakra-sector-b: #b9a882;
    --chakra-ring: #5b1a17;
    --chakra-label: #8a7a62;
    --chakra-name: #4a3a28;
    --chakra-branch: #a87a70;
    --chakra-node: #b3261e;
    --chakra-node-mid: #7d9a5a;
    --chakra-dot: #e9a49b;
    --chakra-ink: #2a1d14;

    /* ── Swara hues ──────────────────────────────────────────────────────
       Twelve semitone positions, twelve hues, one full turn of the colour
       wheel: Sa warm, Pa opposite it and cool, tara Sa home to Sa again. The
       hue is the PITCH, so the same colour means the same note in the dial,
       the hand map and the raga picker — learn it once.
       Lightness and saturation are per-theme; the hues are not. */
    --swara-h-0:   25;   /* Sa        */
    --swara-h-1:   55;   /* Ri1 / komal */
    --swara-h-2:   85;   /* Ri2       */
    --swara-h-3:  115;   /* Ga1       */
    --swara-h-4:  145;   /* Ga2       */
    --swara-h-5:  175;   /* Ma1       */
    --swara-h-6:  205;   /* Ma2       */
    --swara-h-7:  235;   /* Pa        */
    --swara-h-8:  265;   /* Dha1      */
    --swara-h-9:  295;   /* Dha2      */
    --swara-h-10: 325;   /* Ni1       */
    --swara-h-11: 355;   /* Ni2       */
    --swara-s: 52%;
    --swara-l: 38%;
    --swara-soft-s: 58%;
    --swara-soft-l: 90%;

    color-scheme: light;
}

/* ── Dark theme ──────────────────────────────────────────────────────────
   One block, because js/appearance.js always resolves the choice to a literal
   light or dark before the first paint — "auto" never reaches the stylesheet.
   Warm near-black rather than grey: the same room, lights down. */
:root[data-theme="dark"], .theme-dark {
    --paper: #14130f;
    --surface: #1c1a15;
    --sunken: #24211b;
    --raised: #272319;
    --ink: #f1ede3;
    --ink-2: #bdb6a6;
    --ink-3: #948d7e;
    --line: #2e2a23;
    --line-strong: #46402f;

    --accent: #58bb9c;
    --accent-hover: #6fcfb0;
    --accent-ink: #06231c;
    --accent-soft: #17352c;
    --beat: #e8903a;
    --beat-soft: #3a2a15;
    --warn: #e0a43c;
    --warn-deep: #f0c070;
    --bad: #f28b7d;
    --bad-soft: #3a1f1c;
    --violet: #a89ae8;
    --good: #35d08c;
    --near: #f0a94a;

    --stage: #1a1813;
    --scrim: rgba(12, 11, 8, .88);
    --invert-bg: #f1ede3;
    --invert-ink: #14130f;
    --invert-bg-hover: #ffffff;

    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23bdb6a6' stroke-width='1.6'/%3E%3C/svg%3E");

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, .55);
    --shadow-3: 0 12px 32px rgba(0, 0, 0, .6);

    --chakra-half-a: #241f17;
    --chakra-half-b: #2c261c;
    --chakra-sector-a: #5d5340;
    --chakra-sector-b: #6e6349;
    --chakra-ring: #8c3a33;
    --chakra-label: #a2947b;
    --chakra-name: #ece3d2;
    --chakra-branch: #c29a90;
    --chakra-node: #e2665a;
    --chakra-node-mid: #9dbd72;
    --chakra-dot: #f0b1a8;
    --chakra-ink: #f3ece0;

    --swara-s: 62%;
    --swara-l: 66%;
    --swara-soft-s: 30%;
    --swara-soft-l: 22%;

    color-scheme: dark;
}

/* The twelve resolved swara colours. Written once against the theme's own
   lightness, and re-resolved inside a scoped dark region so they follow it
   too (the sign-in screen is a dark room on an otherwise light page). */
:root, .theme-dark {
    --swara-0:  hsl(var(--swara-h-0)  var(--swara-s) var(--swara-l));
    --swara-1:  hsl(var(--swara-h-1)  var(--swara-s) var(--swara-l));
    --swara-2:  hsl(var(--swara-h-2)  var(--swara-s) var(--swara-l));
    --swara-3:  hsl(var(--swara-h-3)  var(--swara-s) var(--swara-l));
    --swara-4:  hsl(var(--swara-h-4)  var(--swara-s) var(--swara-l));
    --swara-5:  hsl(var(--swara-h-5)  var(--swara-s) var(--swara-l));
    --swara-6:  hsl(var(--swara-h-6)  var(--swara-s) var(--swara-l));
    --swara-7:  hsl(var(--swara-h-7)  var(--swara-s) var(--swara-l));
    --swara-8:  hsl(var(--swara-h-8)  var(--swara-s) var(--swara-l));
    --swara-9:  hsl(var(--swara-h-9)  var(--swara-s) var(--swara-l));
    --swara-10: hsl(var(--swara-h-10) var(--swara-s) var(--swara-l));
    --swara-11: hsl(var(--swara-h-11) var(--swara-s) var(--swara-l));
}

/* ── Higher contrast ─────────────────────────────────────────────────────
   Honour the system request rather than offering a separate theme nobody
   finds: lines darken, secondary text stops being secondary. */
@media (prefers-contrast: more) {
    :root {
        --ink-2: #332f2b;
        --ink-3: #443f39;
        --line: #b9b1a3;
        --line-strong: #8d8577;
    }
    :root[data-theme="dark"] {
        --ink-2: #e6e0d2;
        --ink-3: #cfc8b8;
        --line: #5a5243;
        --line-strong: #7d7461;
    }
}

/* Motion is a nicety; never a requirement. */
@media (prefers-reduced-motion: reduce) {
    :root {
        --motion-fast: 0.01ms;
        --motion: 0.01ms;
        --motion-slow: 0.01ms;
    }
}
