/* ───────────────────────────── fonts ─────────────────────────────
   Inter is self-hosted and declared with a Latin-only unicode-range, so DIGITS AND LATIN ALWAYS COME FROM
   INTER and Japanese glyphs fall through to the JP system fonts in --font-ui. This is deliberate: every
   Japanese font (Noto Sans JP, 游ゴシック, メイリオ, ヒラギノ) draws the digit "1" with a horizontal foot,
   the Japanese numeral convention. Without this split the browser picks the JP font for the whole run
   under <html lang="ja"> and every price renders with footed ones. Do not remove the unicode-range. */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/inter-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
                 U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/inter-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
                 U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113,
                 U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/fonts/inter-500-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
                 U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/fonts/inter-500-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
                 U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113,
                 U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/inter-600-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
                 U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/inter-600-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
                 U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113,
                 U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/inter-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
                 U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/inter-700-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
                 U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113,
                 U+2C60-2C7F, U+A720-A7FF;
}

/* Design tokens — docs/ui-spec.md §1. Colours are defined per theme on <html data-theme="dark|light">
   (settings.js resolves "system"), re-pointed by <html data-colors="mt5|exchange|inverted|cvd">.
   Components only ever reference these variables; never hard-code a colour in a module.
   Breakpoints (CSS variables cannot be used inside @media — keep these numbers in sync with
   ui/layout.js BREAKPOINTS):  phone < 768 (or a touch screen < 500 tall = phone landscape) · tablet 768–1023 ·
   pc ≥ 1024 · wide ≥ 1440 · short PC height < 820. Use :root[data-layout] / [data-orient], not width queries. */

/* ───────────────────────────── theme-independent ───────────────────────────── */
:root {
  /* typography */
  /* Inter (self-hosted, Latin+digits only) → system UI font → Japanese. The JP fonts are ordered lightest
     first: ヒラギノ角ゴ on Apple, Noto Sans JP / 游ゴシック on Windows; メイリオ is last — it is heavy and
     poorly hinted at small sizes. Inter never serves Japanese (unicode-range), so order is safe. */
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
             "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic",
             Meiryo, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --fs-2xs: 11px;  --lh-2xs: 1.2;    /* badges, tab-bar labels (600) */
  --fs-xs: 12px;   --lh-xs: 1.3;     /* captions, column headers, account labels (500) */
  --fs-sm: 13px;   --lh-sm: 1.35;    /* dense tables, toolbox, Market Watch rows */
  --fs-md: 14px;   --lh-md: 1.4;     /* PC base text, menus, inputs */
  --fs-lg: 15px;   --lh-lg: 1.4;     /* phone base, panel titles, buttons (500) */
  --fs-xl: 17px;   --lh-xl: 1.3;     /* phone list symbol, sheet titles, ALL phone inputs (600) */
  --fs-2xl: 22px;  --lh-2xl: 1.2;    /* chart header bid, phone trade-button prices (600) */
  --fs-3xl: 28px;  --lh-3xl: 1.15;   /* phone equity hero, one-click big digits (700) */
  --fs-4xl: 36px;  --lh-4xl: 1.1;    /* phone New Order big digits (700) */
  --fw-regular: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;

  /* spacing */
  --sp-1: 2px; --sp-2: 4px; --sp-3: 6px; --sp-4: 8px; --sp-5: 12px; --sp-6: 16px;
  --sp-7: 20px; --sp-8: 24px; --sp-9: 32px; --sp-10: 40px;

  /* radii */
  --r-xs: 2px;     /* badges */
  --r-sm: 4px;     /* chips, table action buttons, TF buttons */
  --r-md: 6px;     /* buttons, inputs */
  --r-lg: 8px;     /* cards, menus, popovers, toasts, one-click panel */
  --r-xl: 12px;    /* modals, PC dialogs */
  --r-2xl: 16px;   /* phone bottom-sheet top corners */
  --r-pill: 999px;

  /* z-index layers (never invent other values; see docs/frontend-conventions.md) */
  --z-base: 0; --z-sticky: 10; --z-chart-overlay: 20; --z-header: 30; --z-dropdown: 40; --z-drawer: 50;
  --z-scrim: 60; --z-modal: 70; --z-toast: 80; --z-tooltip: 90; --z-lock: 100;

  /* motion — only transform and opacity animate */
  --dur-fast: 120ms;  --dur-base: 180ms;  --dur-slow: 260ms;  --dur-sheet-out: 200ms;
  --dur-toast-in: 220ms;  --dur-toast-out: 160ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  /* shell geometry (PC sizes are overridden at runtime by ui/layout.js from the splitters) */
  --hdr-h: 48px;           /* PC header */
  --tape-h: 32px;          /* ticker tape (phone: 28) */
  --mw-w: 320px;           /* Market Watch column   (240–440) */
  --op-w: 320px;           /* order panel column    (288–400) */
  --tb-h: 248px;           /* Toolbox height incl. tabs (36 … 60vh) */
  --tb-tabs-h: 36px;       /* Toolbox tab row */
  --chart-min-w: 480px;
  --rail-w: 40px;          /* chart drawing rail */
  --topbar-h: 44px;        /* phone top bar (+ safe-top) */
  --tabbar-h: 56px;        /* phone tab bar (+ safe-bottom) */
  --banner-h: 32px;
  --row-h: 28px;           /* PC table row (comfortable: 32) */
  --row-h-phone: 60px;     /* phone list row baseline (comfortable +4) */
  --ctl-h: 32px;           /* PC control height: inputs, buttons (phone: 44) */
  --ctl-h-sm: 28px;
  --icon-btn: 28px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

:root[data-density="comfortable"] { --row-h: 32px; --row-h-phone: 64px; }
:root[data-layout="phone"] { --tape-h: 28px; --ctl-h: 44px; --ctl-h-sm: 36px; --icon-btn: 40px; }

/* ───────────────────────────── dark (default) — §1.2 ───────────────────────────── */
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  /* layers */
  --bg-0: #0B0E11;  --bg-1: #12161C;  --bg-2: #181C23;  --bg-3: #20252D;  --bg-4: #2A303A;
  --scrim: rgba(5, 7, 10, 0.64);
  /* lines */
  --border: #262B33;  --border-strong: #363D48;  --divider: #1D2229;
  /* text */
  --text-1: #EAECEF;  --text-2: #A5ADBA;  --text-3: #7D8695;  --text-4: #545C68;
  --text-3-raised: #919AA9;   /* text-3 inside menus / popovers / toasts: 5.4:1 on bg-3, 4.7:1 on bg-4 */
  /* monochrome primary */
  --primary: #EAECEF;  --primary-hover: #FFFFFF;  --on-primary: #0B0E11;
  /* trade colours (MT5: Buy blue, Sell red) */
  --buy: #1F66F0;  --buy-hover: #1B5DE6;  --buy-press: #1957D1;  --on-buy: #FFFFFF;
  --buy-text: #5C9DFF;  --buy-soft: rgba(31, 102, 240, 0.16);
  --sell: #D9304A; --sell-hover: #CC2C45; --sell-press: #BF2740; --on-sell: #FFFFFF;
  --sell-text: #FF5C70; --sell-soft: rgba(217, 48, 74, 0.16);
  /* outcome colours */
  --up: #2EBD85;   --up-soft: rgba(46, 189, 133, 0.14);
  --down: #F85468; --down-soft: rgba(248, 84, 104, 0.14);
  --warning-text: #F0B90B; --warning-fill: #F0B90B; --on-warning: #11151B;
  --warning-soft: rgba(240, 185, 11, 0.14);
  --danger-fill: #D9304A; --on-danger: #FFFFFF;
  /* destructive text (menu items, lock errors): independent of the up/down colour style */
  --danger-text: #FF5C70; --danger-soft: rgba(217, 48, 74, 0.16);
  --info: #5C9DFF;  --link: #5C9DFF;  --focus: #5C9DFF;
  --selection: rgba(92, 157, 255, 0.28);
  /* status dots */
  --live: #2EBD85; --stale: #F0B90B; --offline: #7D8695; --error: #F85468;
  /* --live is a dot colour; as 11-13px TEXT on a --live tint it falls below 4.5:1.
     Resolves per theme because --live and --text-1 are redefined in each. */
  --live-raised: color-mix(in srgb, var(--live) 85%, var(--text-1));
  /* chart */
  --chart-bg: #12161C;  --chart-grid: #1C2129;  --chart-axis-text: #8A93A3;  --chart-border: #262B33;
  --chart-crosshair: #6B7482;  --chart-crosshair-label: #2A303A;
  --candle-up: #2EBD85; --candle-down: #F6465D;
  --volume-up: rgba(46, 189, 133, 0.35); --volume-down: rgba(246, 70, 93, 0.35);
  --chart-bid-line: #A5ADBA;  --chart-ask-line: #F6465D;
  --chart-line: #5C9DFF; --chart-area-top: rgba(92, 157, 255, 0.28); --chart-area-bottom: rgba(92, 157, 255, 0);
  --chart-pos-buy: #5C9DFF; --chart-pos-sell: #FF5C70; --chart-sl: #F85468; --chart-tp: #2EBD85;
  --chart-alert: #F0B90B; --chart-watermark: rgba(234, 236, 239, 0.04);
  --chart-legend-bg: rgba(18, 22, 28, 0.86);
  /* indicator palette — fixed slot order (§1.6) */
  --ind-1: #3987E5; --ind-2: #D95926; --ind-3: #9085E9; --ind-4: #C98500; --ind-5: #D55181;
  /* elevation */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.40);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --skeleton: #20252D;
  --seg-thumb: var(--bg-4);  --seg-thumb-shadow: none;
}

/* ───────────────────────────── light — §1.3 (tuned, not inverted) ───────────────────────────── */
:root[data-theme="light"] {
  color-scheme: light;
  --bg-0: #F3F4F6;  --bg-1: #FFFFFF;  --bg-2: #F7F8FA;  --bg-3: #EEF0F3;  --bg-4: #E3E6EB;
  --scrim: rgba(17, 21, 27, 0.40);
  --border: #E2E5EA;  --border-strong: #C9CED6;  --divider: #EEF0F3;
  --text-1: #11151B;  --text-2: #474F5C;  --text-3: #646D7C;  --text-4: #9AA1AC;
  --text-3-raised: #5A6371;   /* 5.3:1 on bg-3, 4.9:1 on bg-4 */
  --primary: #11151B; --primary-hover: #2A303A; --on-primary: #FFFFFF;
  --buy: #1D5FD8;  --buy-hover: #2468E6;  --buy-press: #184FB5;  --on-buy: #FFFFFF;
  --buy-text: #1D5FD8;  --buy-soft: rgba(29, 95, 216, 0.10);
  --sell: #C8283F; --sell-hover: #D3304A; --sell-press: #AE2136; --on-sell: #FFFFFF;
  --sell-text: #C8283F; --sell-soft: rgba(200, 40, 63, 0.10);
  --up: #027A52;   --up-soft: rgba(2, 122, 82, 0.10);
  --down: #C42B42; --down-soft: rgba(196, 43, 66, 0.10);
  --warning-text: #9A5B00; --warning-fill: #F0B90B; --on-warning: #11151B; --warning-soft: #FFF4D6;
  --danger-fill: #C8283F; --on-danger: #FFFFFF;
  --danger-text: #C8283F; --danger-soft: rgba(200, 40, 63, 0.10);
  --info: #1D5FD8;  --link: #1D5FD8;  --focus: #1D5FD8;  --selection: rgba(29, 95, 216, 0.18);
  --live: #027A52; --stale: #9A5B00; --offline: #9AA1AC; --error: #C42B42;
  --chart-bg: #FFFFFF;  --chart-grid: #F0F2F5;  --chart-axis-text: #5F6876;  --chart-border: #E2E5EA;
  --chart-crosshair: #9AA1AC;  --chart-crosshair-label: #474F5C;
  --candle-up: #089981; --candle-down: #F23645;
  --volume-up: rgba(8, 153, 129, 0.30); --volume-down: rgba(242, 54, 69, 0.30);
  --chart-bid-line: #646D7C;  --chart-ask-line: #F23645;
  --chart-line: #1D5FD8; --chart-area-top: rgba(29, 95, 216, 0.20); --chart-area-bottom: rgba(29, 95, 216, 0);
  --chart-pos-buy: #1D5FD8; --chart-pos-sell: #C8283F; --chart-sl: #C42B42; --chart-tp: #027A52;
  --chart-alert: #B7791F; --chart-watermark: rgba(17, 21, 27, 0.04);
  --chart-legend-bg: rgba(255, 255, 255, 0.88);
  --ind-1: #2A78D6; --ind-2: #EB6834; --ind-3: #6250D6; --ind-4: #EDA100; --ind-5: #E87BA4;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-2: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-3: 0 16px 40px rgba(16, 24, 40, 0.14), 0 0 0 1px rgba(16, 24, 40, 0.06);
  --skeleton: #EEF0F3;
  --seg-thumb: var(--bg-1);  --seg-thumb-shadow: var(--shadow-1);
}

/* ───────────────────────────── colour styles — §1.4 ───────────────────────────── */
/* exchange: green Buy (both themes) */
:root[data-colors="exchange"] {
  --buy: #08875B; --buy-hover: #077A52; --buy-press: #06724D; --on-buy: #FFFFFF;
  --buy-text: var(--up); --buy-soft: rgba(8, 135, 91, 0.16); --chart-pos-buy: var(--up);
}

/* inverted (red up) */
:root[data-colors="inverted"]:not([data-theme="light"]) {
  --up: #F85468;   --up-soft: rgba(248, 84, 104, 0.14);
  --down: #2EBD85; --down-soft: rgba(46, 189, 133, 0.14);
  --candle-up: #F6465D; --candle-down: #2EBD85;
  --volume-up: rgba(246, 70, 93, 0.35); --volume-down: rgba(46, 189, 133, 0.35);
  --chart-tp: #F85468; --chart-sl: #2EBD85;
}
:root[data-colors="inverted"][data-theme="light"] {
  --up: #C42B42;   --up-soft: rgba(196, 43, 66, 0.10);
  --down: #027A52; --down-soft: rgba(2, 122, 82, 0.10);
  --candle-up: #F23645; --candle-down: #089981;
  --volume-up: rgba(242, 54, 69, 0.30); --volume-down: rgba(8, 153, 129, 0.30);
  --chart-tp: #C42B42; --chart-sl: #027A52;
}

/* cvd (colour-vision friendly): blue / orange */
:root[data-colors="cvd"]:not([data-theme="light"]) {
  --sell: #C2570C; --sell-hover: #B85209; --sell-press: #A84A0A;
  --sell-text: #FF8A3D; --sell-soft: rgba(194, 87, 12, 0.18);
  --up: #5C9DFF;   --up-soft: rgba(92, 157, 255, 0.14);
  --down: #FF8A3D; --down-soft: rgba(255, 138, 61, 0.14);
  --candle-up: #3987E5; --candle-down: #D95926;
  --volume-up: rgba(57, 135, 229, 0.35); --volume-down: rgba(217, 89, 38, 0.35);
  --chart-pos-sell: #FF8A3D; --chart-sl: #FF8A3D; --chart-tp: #5C9DFF; --chart-ask-line: #D95926;
  --danger-fill: #C2570C; --danger-text: #FF8A3D; --danger-soft: rgba(194, 87, 12, 0.18);
}
:root[data-colors="cvd"][data-theme="light"] {
  --sell: #B4500B; --sell-hover: #C2570C; --sell-press: #9A4409;
  --sell-text: #B4500B; --sell-soft: rgba(180, 80, 11, 0.10);
  --up: #1D5FD8;   --up-soft: rgba(29, 95, 216, 0.10);
  --down: #B4500B; --down-soft: rgba(180, 80, 11, 0.10);
  --candle-up: #2A78D6; --candle-down: #D4561F;
  --volume-up: rgba(42, 120, 214, 0.30); --volume-down: rgba(212, 86, 31, 0.30);
  --chart-pos-sell: #B4500B; --chart-sl: #B4500B; --chart-tp: #1D5FD8; --chart-ask-line: #D4561F;
  --danger-fill: #B4500B; --danger-text: #B4500B; --danger-soft: rgba(180, 80, 11, 0.10);
}

/* ───────────────────────────── raised surfaces ───────────────────────────── */
/* Menus and popovers sit on bg-3 and highlight rows with bg-4, where the plain tone colours drop under 4.5:1
   for 11–12 px text (dark Sell red on bg-4: 4.1:1). app.css points --up / --down / … at these inside .menu and
   .pop: 15 % toward text-1 (lighter in dark, darker in light) keeps the hue and every colour style at ≥ 4.5:1.
   Declared on :root after the colour styles, so they follow the theme and data-colors. */
:root {
  --up-raised: color-mix(in srgb, var(--up) 85%, var(--text-1));
  --down-raised: color-mix(in srgb, var(--down) 85%, var(--text-1));
  --buy-text-raised: color-mix(in srgb, var(--buy-text) 85%, var(--text-1));
  --sell-text-raised: color-mix(in srgb, var(--sell-text) 85%, var(--text-1));
  --danger-text-raised: color-mix(in srgb, var(--danger-text) 85%, var(--text-1));
  --warning-text-raised: color-mix(in srgb, var(--warning-text) 85%, var(--text-1));
}

/* ── per-locale UI font stacks ──────────────────────────────────────────────
   --font-ui ends in Japanese faces, which is deliberate for ja (see the note at the top of this
   file about footed digits) but wrong for the other locales: Japanese fonts carry no Hangul at
   all, draw Simplified Chinese with Japanese glyph forms, and have no Vietnamese diacritics. The
   browser then resolves those glyphs per-character into a different face, so one word is drawn in
   two fonts and the spacing goes uneven. Give each locale a stack that covers its whole script.
   ja is untouched. */
:root[lang="zh"] {
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
             "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
:root[lang="ko"] {
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
             "Malgun Gothic", "Noto Sans KR", sans-serif;
}
/* Vietnamese: the Inter subsets here declare unicode-ranges that skip U+1EA0-U+1EF1 - exactly the
   toned vowels (ế ề ố ồ ắ) - and no bundled font file contains them, so they fell through to the
   Japanese faces, which draw them as a base letter plus a detached accent ("Tiê´ng Viê.t").
   Inter still draws everything it does cover; the toned vowels resolve to a latin UI face with
   compatible metrics instead of a CJK one. */
:root[lang="vi"] {
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
