/* Shared look for the TMF Tools pages: sidebar, toolbar, grouped settings, controls. */
  /* Laid out like a Mac app: source list on the left, toolbar and canvas in
     the middle, inspector on the right. Follows the system's light or dark. */
  :root {
    color-scheme: light dark;
    --accent: #007aff;
    --window: #ffffff;
    --sidebar: #f2f2f4;
    --canvas: #ececee;
    --text: rgba(0, 0, 0, .86);
    --text2: rgba(0, 0, 0, .52);
    --text3: rgba(0, 0, 0, .3);
    --sep: rgba(0, 0, 0, .1);
    --group: rgba(0, 0, 0, .035);
    --control: rgba(0, 0, 0, .065);
    --control-hi: rgba(0, 0, 0, .11);
    --thumb: #ffffff;
    --thumb-shadow: 0 0 0 .5px rgba(0, 0, 0, .06), 0 1px 2.5px rgba(0, 0, 0, .18);
    --field: #ffffff;
    --field-edge: rgba(0, 0, 0, .14);
    --row-hover: rgba(0, 0, 0, .05);
    --check-a: #dcdce0; --check-b: #f4f4f6;
    --ease: cubic-bezier(.22, 1, .36, 1);
    font: 13px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --accent: #0a84ff;
      --window: #1e1e1f;
      --sidebar: #29292b;
      --canvas: #161617;
      --text: rgba(255, 255, 255, .88);
      --text2: rgba(255, 255, 255, .55);
      --text3: rgba(255, 255, 255, .28);
      --sep: rgba(255, 255, 255, .1);
      --group: rgba(255, 255, 255, .05);
      --control: rgba(255, 255, 255, .09);
      --control-hi: rgba(255, 255, 255, .16);
      --thumb: #636366;
      --thumb-shadow: 0 0 0 .5px rgba(0, 0, 0, .3), 0 1px 2px rgba(0, 0, 0, .35);
      --field: rgba(255, 255, 255, .07);
      --field-edge: rgba(255, 255, 255, .13);
      --row-hover: rgba(255, 255, 255, .06);
      --check-a: #232325; --check-b: #19191a;
    }
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; }
  body {
    color: var(--text);
    background: var(--window);
    display: grid;
    grid-template-columns: 212px minmax(0, 1fr) 272px;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    cursor: default;
    user-select: none;
  }
  button, input { font: inherit; color: inherit; }
  :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }

  /* ---------- source list ---------- */
  #sidebar {
    background: var(--sidebar);
    border-right: 1px solid var(--sep);
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
  }
  .app { display: flex; align-items: center; gap: 9px; padding: 2px 8px 14px; }
  .app b { font-size: 13px; font-weight: 600; letter-spacing: -.005em; }
  .heading { padding: 6px 8px 5px; font-size: 11px; font-weight: 600; color: var(--text2); }
  .item {
    display: flex; align-items: center; gap: 8px;
    width: 100%; height: 30px; padding: 0 8px;
    border: 0; border-radius: 6px; background: none;
    text-align: left; font-size: 13px;
  }
  .item:hover { background: var(--row-hover); }
  .item[aria-current="true"] { background: var(--accent); color: #fff; }
  .chip { width: 18px; height: 18px; border-radius: 5px; flex: none; background: #000; box-shadow: 0 0 0 .5px rgba(255, 255, 255, .25); }
  .chip.smoke   { background: radial-gradient(circle, #000 38%, #55555c 100%); }
  .chip.embers  { background: radial-gradient(circle, #000 42%, #ff7a1e 58%, #7a1400 100%); }
  .chip.horizon { background: radial-gradient(circle, #000 44%, #fff 52%, #2a2a2e 64%); }
  .chip.storm   { background: radial-gradient(circle at 70% 30%, #dfe8ff 0 10%, transparent 34%), radial-gradient(circle, #000 40%, #4b5160 100%); }
  /* sidebar dropdown: a family row with a chevron, variations indented beneath */
  .disclosure {
    display: flex; align-items: center; gap: 4px;
    width: 100%; height: 30px; padding: 0 6px;
    border: 0; border-radius: 6px; background: none;
    text-align: left; font-size: 13px; font-weight: 600;
  }
  .disclosure:hover { background: var(--row-hover); }
  .disclosure svg {
    width: 12px; height: 12px; flex: none;
    fill: none; stroke: var(--text2); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round;
    transition: transform 240ms var(--ease);
  }
  .disclosure[aria-expanded="true"] svg { transform: rotate(90deg); }
  .children { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 280ms var(--ease); }
  .children > div { overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
  .open > .children { grid-template-rows: 1fr; }
  .children .item { padding-left: 24px; }
  .group-list:not(.open) .item { visibility: hidden; }   /* closed: not reachable by Tab */
  .disclaimer { margin-top: auto; padding: 14px 8px 0; font-size: 10.5px; line-height: 1.4; color: var(--text2); opacity: .8; }
  @media (prefers-reduced-motion: reduce) { .children, .disclosure svg { transition: none; } }

  .count { margin-left: auto; font-size: 11px; color: var(--text3); font-variant-numeric: tabular-nums; }
  .item[aria-current="true"] .count { color: rgba(255, 255, 255, .7); }

  /* ---------- toolbar + canvas ---------- */
  #content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  #toolbar {
    height: 52px; flex: none;
    display: flex; align-items: center; gap: 12px;
    padding: 0 14px;
    border-bottom: 1px solid var(--sep);
  }
  .nav { display: flex; gap: 2px; }
  .tool {
    display: grid; place-items: center;
    width: 30px; height: 28px;
    border: 0; border-radius: 6px; background: none;
    color: var(--text2);
    transition: background-color 120ms, transform 100ms ease-out;
  }
  .tool:hover { background: var(--row-hover); color: var(--text); }
  .tool:active { background: var(--control-hi); transform: scale(.94); }
  .tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
  #title { min-width: 96px; flex: 1 1 0; }
  #title b { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.012em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #title small { display: block; font-size: 11px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* segmented control */
  .seg { position: relative; display: flex; background: var(--control); border-radius: 7px; padding: 2px; }
  .seg .thumb {
    position: absolute; top: 2px; bottom: 2px; left: 0; width: 0;
    border-radius: 5.5px;
    background: var(--thumb);
    box-shadow: var(--thumb-shadow);
    transition: transform 320ms var(--ease), width 320ms var(--ease);
    pointer-events: none;
  }
  .seg button {
    position: relative; flex: 1;
    height: 22px; padding: 0 11px;
    border: 0; border-radius: 5.5px; background: none;
    font-size: 12px; font-weight: 500; white-space: nowrap;
    transition: opacity 100ms;
  }
  .seg button:active { opacity: .55; }
  #inspector .seg button { padding: 0 4px; }   /* three labels share a narrow column */

  /* push buttons */
  .btn {
    height: 24px; padding: 0 12px;
    border: 0; border-radius: 6px;
    background: var(--control);
    box-shadow: inset 0 0 0 .5px var(--field-edge);
    font-size: 13px; font-weight: 500;
    transition: transform 100ms ease-out, background-color 120ms, filter 120ms;
  }
  .btn:active { transform: scale(.97); background: var(--control-hi); }
  .btn.primary { height: 28px; padding: 0 14px; background: var(--accent); color: #fff; box-shadow: inset 0 .5px 0 rgba(255, 255, 255, .25); font-weight: 600; }
  .btn.primary:active { filter: brightness(.85); }
  .btn.primary.done { background: #34c759; }
  .btn:disabled { opacity: .4; }

  #canvas {
    position: relative; flex: 1; min-height: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; padding: 22px 26px 16px;
    overflow: hidden;
    transition: background-color 250ms;
  }
  body[data-bg="check"] #canvas { background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 24px 24px; }
  body[data-bg="dark"]  #canvas { background: #050506; }
  body[data-bg="light"] #canvas { background: linear-gradient(135deg, #8fa4bd, #d3bf9b); }
  #stageWrap { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
  #stage {
    position: relative; flex: none;
    border-radius: 10px; overflow: hidden;
    box-shadow: 0 0 0 .5px rgba(128, 128, 128, .5), 0 12px 34px rgba(0, 0, 0, .28);
    will-change: transform, opacity;
  }
  /* color-scheme matches the overlay page's own, otherwise the browser paints
     the frame an opaque white instead of leaving it see-through */
  #stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; color-scheme: light; }
  #grab { position: absolute; inset: 0; cursor: grab; touch-action: pan-y; }
  #grab.dragging { cursor: grabbing; }

  /* page dots */
  #dots { flex: none; display: flex; gap: 7px; padding: 5px 9px; border-radius: 999px; background: rgba(60, 60, 67, .55); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
  #dots button { width: 7px; height: 7px; padding: 0; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .38); transition: background-color 200ms, transform 200ms var(--ease); }
  #dots button[aria-current="true"] { background: #fff; transform: scale(1.15); }

  /* ---------- inspector ---------- */
  #inspector {
    border-left: 1px solid var(--sep);
    padding: 14px 14px 18px;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 6px;
  }
  .group { background: var(--group); border-radius: 9px; box-shadow: inset 0 0 0 .5px var(--sep); margin-bottom: 10px; }
  .row { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 11px; }
  .row + .row { border-top: 1px solid var(--sep); }
  .row > span:first-child { margin-right: auto; white-space: nowrap; }
  .row .value { color: var(--text2); font-variant-numeric: tabular-nums; }
  .row.stack { flex-direction: column; align-items: stretch; gap: 7px; padding: 9px 11px 11px; }

  .textfield {
    display: flex; align-items: center;
    width: 132px; height: 24px; padding-left: 7px;
    border-radius: 6px; background: var(--field);
    box-shadow: inset 0 0 0 .5px var(--field-edge), 0 .5px 1px rgba(0, 0, 0, .06);
  }
  .textfield span { color: var(--text3); }
  .textfield input { flex: 1; min-width: 0; height: 100%; padding: 0 7px 0 2px; border: 0; outline: 0; background: none; user-select: text; }
  .textfield:focus-within { box-shadow: inset 0 0 0 .5px var(--accent), 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }

  /* colour well */
  input[type="color"] {
    width: 44px; height: 23px; padding: 0;
    border: 0; border-radius: 6px; background: none;
    box-shadow: inset 0 0 0 .5px var(--field-edge), 0 .5px 1px rgba(0, 0, 0, .12);
    overflow: hidden; cursor: default;
  }
  input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
  input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 3.5px; box-shadow: inset 0 0 0 .5px rgba(128, 128, 128, .5); }

  /* switch */
  .switch { position: relative; width: 38px; height: 22px; flex: none; }
  .switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; }
  .switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--control-hi); box-shadow: inset 0 0 0 .5px var(--field-edge); transition: background-color 200ms; pointer-events: none; }
  .switch i::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
    border-radius: 50%; background: #fff;
    box-shadow: 0 0 0 .5px rgba(0, 0, 0, .08), 0 1.5px 3px rgba(0, 0, 0, .28);
    transition: transform 300ms var(--ease);
  }
  .switch input:checked + i { background: var(--accent); }
  .switch input:checked + i::after { transform: translateX(16px); }
  .switch input:focus-visible + i { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }

  #link {
    width: 100%; padding: 6px 8px;
    border: 0; border-radius: 6px; outline: 0;
    background: var(--field);
    box-shadow: inset 0 0 0 .5px var(--field-edge);
    color: var(--text2);
    font: 11px/1.3 ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
    user-select: text;
  }
  .foot { padding: 0 4px; font-size: 11px; color: var(--text2); line-height: 1.4; }
  .right { display: flex; justify-content: flex-end; margin: -2px 0 10px; }

  /* ---------- narrow windows: stack the panes ---------- */
  /* Narrow windows and phones: the sidebar becomes a row of tool links across
     the top, and the panes stack. The long overlay list is dropped here; the
     Grid view, the arrows and the page dots pick an overlay instead. */
  @media (max-width: 860px) {
    body { grid-template-columns: 1fr; grid-template-rows: auto minmax(300px, 1fr) auto; overflow: auto; }
    #sidebar {
      flex-direction: row; flex-wrap: wrap; align-items: center; gap: 2px 4px;
      border-right: 0; border-bottom: 1px solid var(--sep); padding: 8px 10px; overflow: visible;
    }
    #sidebar .app { padding: 0 10px 0 6px; }
    #sidebar .heading, #sidebar #list, .count { display: none; }
    #sidebar .item { width: auto; white-space: nowrap; }
    #sidebar .disclaimer { flex-basis: 100%; margin: 0; padding: 6px 8px 0; }
    #toolbar { height: auto; min-height: 52px; flex-wrap: wrap; row-gap: 8px; padding: 8px 14px; }
    #title { flex: 1 1 160px; }
    #inspector { border-left: 0; border-top: 1px solid var(--sep); overflow: visible; }
  }
  @media (prefers-reduced-motion: reduce) {
    .seg .thumb, .switch i::after, .btn, .tool, #dots button { transition: none; }
  }
  @media (prefers-contrast: more) {
    :root { --sep: color-mix(in srgb, currentColor 45%, transparent); --field-edge: color-mix(in srgb, currentColor 60%, transparent); }
  }

  /* ---------- overlay picker: grid view (a row per family, a tile per variation) ---------- */
  #grid { position: absolute; inset: 0; overflow-y: auto; padding: 14px 20px 22px; }
  #grid[hidden] { display: none; }
  /* labels sit on a dark chip so they read on any backdrop (grid, dark or light) */
  #grid .heading, .mrow .fam, .tile span {
    width: fit-content; padding: 2px 7px; border-radius: 5px;
    background: rgba(20, 20, 24, .72); color: #fff;
  }
  #grid .heading { margin: 8px 0; }
  .mrow { display: grid; grid-template-columns: 104px repeat(4, minmax(0, 1fr)); gap: 10px; align-items: start; margin-bottom: 12px; }
  .mrow .fam { align-self: center; font-size: 12px; font-weight: 600; }
  .tile { display: block; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; transition: transform 100ms ease-out; }
  .tile:active { transform: scale(.98); }
  .tile canvas, .tile iframe {
    display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 8px;
    box-shadow: 0 0 0 .5px rgba(128, 128, 128, .55);
    pointer-events: none; color-scheme: light;
  }
  .tile:hover canvas, .tile:hover iframe { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .7); }
  .tile[aria-current="true"] canvas, .tile[aria-current="true"] iframe { box-shadow: 0 0 0 2.5px var(--accent); }
  .tile span { display: block; margin-top: 5px; font-size: 11px; }

  /* grid tiles: the player's data drawn over the effect, where the card sits.
     It is laid out at a fixed size and scaled by the script, as on the overlay. */
  .thumb { position: relative; }
  .mini { position: absolute; left: 22%; top: 32%; width: 56%; height: 36%; display: flex; align-items: center; justify-content: center; pointer-events: none; }
  .mfit { flex: none; display: flex; align-items: center; gap: 26px; font-size: 10px; font-weight: 700; text-transform: uppercase;
          white-space: nowrap; line-height: 1; --tc: 255, 255, 255; --sp: 0em; color: rgb(var(--tc)); transform-origin: center center; }
  .mbadge { --s: 19em; --slot: 0.96; flex: none;
            width: calc(var(--s) * var(--iw, 1)); height: calc(var(--s) * var(--ih, 1));
            margin-block: calc(var(--s) * (1 - var(--ih, 1)) / 2); margin-inline: calc(var(--s) * (var(--slot) - var(--iw, 1)) / 2); }
  .mini.mono .mbadge { filter: grayscale(1) contrast(1.15); }
  .mlines { display: flex; flex-direction: column; gap: 1.2em; }
  .mmode { font-size: 1.5em; letter-spacing: calc(.22em + var(--sp)); color: rgba(var(--tc), .6); }
  .mrank { font-size: 5em; letter-spacing: var(--sp); }
  .melo { font-size: 3.2em; letter-spacing: var(--sp); color: rgba(var(--tc), .8); }
  .mpeak { font-size: 1.7em; letter-spacing: calc(.08em + var(--sp)); color: rgba(var(--tc), .6); padding-top: .7em; border-top: 1px solid rgba(var(--tc), .2); }
  .mcells { display: none; gap: 3em; }
  .mini.cells .mcells { display: flex; }
  .mini.cells .mrank, .mini.cells .melo { display: none; }
  .mcell { display: flex; flex-direction: column; gap: .9em; }
  .mcell b { font-size: 4.6em; font-weight: 700; letter-spacing: var(--sp); }
  .mcell small { font-size: 1.4em; letter-spacing: calc(.16em + var(--sp)); color: rgba(var(--tc), .6); }
  .mcell.up b { color: #46e08a; }
  .mcell.down b { color: #ff6464; }
  .foot a { color: var(--accent); text-decoration: none; white-space: nowrap; }
  .foot a:hover { text-decoration: underline; }

  /* ---------- polish shared by every page ---------- */
  /* slim scrollbars that match the theme instead of the browser's chunky default */
  * { scrollbar-width: thin; scrollbar-color: var(--control-hi) transparent; }
  /* a control that currently has no effect (e.g. Monochrome while Tint is on) */
  .row.idle { opacity: .4; pointer-events: none; }
  /* text you may want to copy stays selectable even though the app chrome isn't */
  #link, .result, table, .head { user-select: text; cursor: auto; }
  input::placeholder { color: var(--text3); }
  button:disabled { cursor: default; }

  /* ---------- shared by every tool page ---------- */
  a.item { text-decoration: none; color: inherit; }
  #sidebar > * { flex: none; }            /* a long list scrolls; it never squashes the rows */
  .btn { white-space: nowrap; }
  body.two { grid-template-columns: 212px minmax(0, 1fr); }      /* tools with no inspector */
  @media (max-width: 860px) { body.two { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } }
