/* The Appearance controls (js/lx/appearance.js), shared by Settings and the /design page. In the components layer,
 * so a person's own CSS still wins over it. */

@layer lx.components {
  .ds-states { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
  .ds-status { display: flex; align-items: center; gap: var(--space-1); min-height: 1.5em; color: var(--ink-2); }
  .ds-status:empty { display: none; }
  .ds-status[data-tone="right"] .lx-icon { color: var(--m-right); }
  .ds-status[data-tone="wrong"] .lx-icon { color: var(--m-wrong); }
  .ds-status[data-tone="slipping"] .lx-icon { color: var(--m-slipping); }
  .ds-status .lx-icon { flex: none; }

  .ds-group { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4) 0; border-top: 1px solid var(--hair); }
  .ds-group-title { color: var(--ink-3); font-weight: 500; }
  .ds-appearance [data-part="segmented"] { flex-wrap: wrap; }
  .ds-themes { display: flex; flex-direction: column; align-items: stretch; }
  .ds-themes [data-part="segment"] { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 0; padding: var(--space-2) var(--space-3); text-align: left; line-height: 1.3; }
  .ds-themes [data-part="segment"] strong { font-weight: 500; }

  .ds-token-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-2); }
  .ds-token-label { display: flex; flex-direction: column; min-width: 0; }
  .ds-token-row[data-changed] .ds-token-label > span::after { content: " · changed"; color: var(--ink-3); }
  .ds-token-controls { display: flex; align-items: center; gap: 6px; }
  .ds-token-input { width: 136px; min-height: 32px; padding: 0 var(--space-2); font: 400 var(--size-12) / 1 var(--type-mono); }
  /* 16px on a touch screen: a smaller field makes an iPhone zoom in when it's focused. And a finger's full control height there (32 px was
     under the 44 a tap needs: the image name, any token's name and value). */
  @media (pointer: coarse) { .ds-token-input { min-height: var(--control); font-size: 16px; } }
  .ds-token-any { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: var(--space-1); }
  .ds-colour { flex: none; width: 32px; height: 32px; padding: 0; border: 1px solid var(--edge); border-radius: var(--radius-8); background: none; cursor: pointer; }
  .ds-colour::-webkit-color-swatch-wrapper { padding: 3px; }
  .ds-colour::-webkit-color-swatch { border: 0; border-radius: 5px; }
  .ds-colour::-moz-color-swatch { border: 0; border-radius: 5px; }
  .ds-css { width: 100%; min-height: 200px; resize: vertical; font: 400 var(--size-12) / 1.5 var(--type-mono); white-space: pre; tab-size: 2; }
  .ds-image-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
  .ds-image-label { display: flex; flex: 1; flex-direction: column; min-width: 110px; }
  .ds-image-row .ds-token-input { flex: 1; min-width: 90px; }
  .ds-thumb { flex: none; width: 40px; height: 40px; border: 1px solid var(--hair); border-radius: var(--radius-8); background: var(--fill); object-fit: cover; }

  /* Colors: a chip that opens the color picker (over a checkerboard, so see-through colors read as such), the
   * value as text you can edit, and a reset once it's changed. */
  .lx-colour-probe { position: fixed; width: 0; height: 0; overflow: hidden; visibility: hidden; pointer-events: none; }
  .lx-colour-row { display: flex; align-items: center; gap: var(--space-3); }
  .lx-colour-pick { position: relative; flex: none; width: 34px; height: 34px; cursor: pointer; }
  .lx-colour-chip {
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border: 1px solid var(--edge);
    border-radius: var(--radius-8);
    background: repeating-conic-gradient(var(--fill) 0 25%, var(--well) 0 50%) 0 0 / 10px 10px;
  }
  .lx-colour-chip > span { display: block; width: 100%; height: 100%; }
  .lx-colour-picker { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; opacity: 0; cursor: pointer; }
  .lx-colour-pick:has(.lx-colour-picker:focus-visible) .lx-colour-chip { outline: 2px solid var(--ring); outline-offset: 2px; }
  /* The value reads as a line under its name, and answers a tap the control's full height: its box reaches --reach up over the name (words,
     not a control; a tap there means this color too), given back by its top margin, so nothing moves and only a tap feels it. Up, never down:
     the next row lies just under the line and paints over anything reaching into it (the even reach measured 39 px). Focused, it's a field
     drawn at the line's own height, the same room. */
  .lx-colour-row .lx-colour-value {
    --reach: max(0px, var(--control) - 1.4em - 4px);
    width: 100%;
    min-height: 0;
    margin-top: calc(-1 * var(--reach));
    padding: calc(1px + var(--reach)) 0 1px;
    border: 1px solid transparent;
    border-radius: var(--radius-8);
    background: transparent;
    color: var(--ink-3);
    font: 400 var(--size-12) / 1.4 var(--type-mono);
  }
  .lx-colour-row .lx-colour-value:focus { margin-top: 0; padding: 1px var(--space-2); border-color: var(--edge); background: var(--well); color: var(--ink-1); outline: none; }
  @media (pointer: coarse) { .lx-colour-row .lx-colour-value { font-size: 16px; } }
  .lx-colour-row[data-changed] .lx-row-title::after { content: " · changed"; color: var(--ink-3); }
  .lx-colour-row [data-part="icon-button"][hidden] { display: none; }

  /* A sample of the app in your colors, kept in view under the header while you scroll the colors below it. */
  .lx-colour-preview {
    position: sticky;
    top: calc(var(--space-3) * 2 + 36px);
    z-index: 4;
    padding: var(--space-1) 0 var(--space-3);
    background: var(--canvas);
  }
  .lx-colour-sample { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3); }
  .lx-colour-sample-target { font: 500 var(--size-16) / 1.35 var(--type-read); }
  /* The moved word as the literal line marks it: the highlighter and its dotted underline. */
  .lx-colour-sample-moved { padding: 0 3px; border-radius: 4px; background: var(--m-moved-mark); color: var(--m-moved-ink); text-decoration: underline dotted var(--m-moved-line); text-underline-offset: 3px; }
  .lx-colour-sample-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: var(--space-2); }
  .lx-colour-sample-row [data-part="strength-meter"] { width: 48px; }
  .lx-colour-sample-row [data-part="button"] { margin-left: auto; }

  /* Images */
  .lx-image-row { flex-wrap: wrap; }
  .lx-image-row .lx-row-text { min-width: 120px; }
  .lx-image-add { flex-wrap: wrap; gap: var(--space-2); }
  .lx-image-add .ds-token-input { flex: 1; min-width: 100px; width: auto; }
  /* Each section: a section showing another's background has that one's thumbnail, faded. */
  .lx-section-row .ds-thumb[data-borrowed] { opacity: 0.4; }

  /* Custom CSS: the parts it can target */
  .lx-parts { display: flex; flex-direction: column; gap: var(--space-2); }
  /* Shut, its hidden contents take no gap: the summary's row is the whole box. */
  .lx-parts:not([open]) { gap: 0; }
  .lx-parts-list .lx-row-title { font: 400 var(--size-14) / 1.4 var(--type-mono); }

  /* Toasts sit above the tabs (or at the foot of the page beside the sidebar), and never take a press meant for the
   * page: only the toast itself is pressable. */
  .lx-toasts {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(68px + env(safe-area-inset-bottom) + var(--space-3));
    z-index: 40;
    display: flex;
    justify-content: center;
    /* Each toast at its own height, at the edge its layer is anchored to: never stretched to the layer's (12 Nov 2026: a session's toast
       drew 490 px tall when its layer was given a top and a bottom). */
    align-items: flex-end;
    padding: 0 var(--space-4);
    pointer-events: none;
  }
  .lx-toasts > * { flex: none; pointer-events: auto; max-width: 100%; }
  .lx-toasts [data-part="toast"] [data-part="button"] { margin: -4px -8px -4px var(--space-1); }
  /* On a computer (frame.md §0): at the foot, centered on the page beside the sidebar while the sidebar is shown (its 232 px, then the same
     16 px either side, so a toast's middle is the page's), on the window while a session or the reader covers it (it stood 124 px right of a
     session's middle, 11 Nov 2026). */
  @media (min-width: 1024px) {
    .lx-toasts { bottom: var(--space-5); }
    :root:has([data-part="app"] > [data-part="tab-bar"]):not(:has([data-part="app"] > :is([data-part="session"], [data-part="reader"]))) .lx-toasts { padding-left: calc(232px + var(--space-4)); }
  }

  .lx-safe-banner { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3) 0; }
}
