/* Things Tailwind utilities can't express cleanly. Colors come from the theme tokens only. */

html { background: var(--bg); }
body { background: var(--bg); color: var(--fg); }

/* ---- Icons ---- */
.icon {
  font-family: 'Material Symbols Rounded';
  font-size: 1.25rem; line-height: 1;
  font-variation-settings: 'opsz' 20, 'wght' 400, 'FILL' 0, 'GRAD' 0;
  color: currentColor;
  user-select: none;
  flex: none;
}

/* ---- Focus: the --focus ring, plus a --fg edge so it stays visible in every theme ---- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 6px var(--fg);
}
:focus:not(:focus-visible) { outline: none; }
tr:focus, li:focus { outline: none; }
tr:focus-visible, li:focus-visible { box-shadow: none; outline-offset: -3px; }

.skip-link {
  position: absolute; left: 0.5rem; top: -4rem; z-index: 60;
  padding: 0.75rem 1rem; border-radius: 0.375rem;
  background: var(--accent); color: var(--accent-fg); font-weight: 600;
}
.skip-link:focus { top: 0.5rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  min-height: 44px; min-width: 44px; padding: 0 0.875rem;
  border: 1px solid var(--border); border-radius: 0.375rem;
  background: var(--surface-2); color: var(--fg);
  font: inherit; font-weight: 500; line-height: 1.2; cursor: pointer;
}
.btn:hover { border-color: var(--fg); }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { border-color: var(--fg); }
.btn[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; }
.btn[aria-disabled='true']:hover { border-color: var(--border); }
.btn-icon { padding: 0; width: 44px; }
.tap { min-height: 44px; }

/* ---- Links: --fg text so contrast holds in every theme, accent used for the underline ---- */
.link { color: var(--fg); text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.link:hover { text-decoration-thickness: 3px; }

/* ---- Messages: icon carries the status colour, text stays readable ---- */
.msg { display: flex; align-items: flex-start; gap: 0.375rem; font-size: 0.875rem; color: var(--fg); }
.msg[hidden] { display: none; }
.msg .icon { margin-top: 1px; color: var(--accent); }
.msg[data-kind='error'] .icon { color: var(--danger); }
.field[aria-invalid='true'] { border-color: var(--danger); box-shadow: inset 3px 0 0 var(--danger); }

/* ---- Join brackets: one style at every level; fill alternates with depth ---- */
.bracket {
  display: flex; align-items: center; justify-content: center; gap: 2px;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0.375rem;
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer;
}
.bracket[data-parity='1'] { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
/* 18% instead of 25%: --fg stays at 4.5:1 on the hover tint in every bundled theme. */
.bracket:hover, .bracket:focus-visible { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); border-left-width: 5px; }
.join-cell { position: relative; min-width: 3.5rem; padding: 2px; }
.join-cell > .bracket { position: absolute; inset: 2px; flex-direction: column; }
.bracket-inline { min-height: 44px; padding: 0 0.625rem; font-size: 0.875rem; gap: 0.25rem; }
.bracket-inline .icon { font-size: 1.125rem; }

/* ---- Tooltip (icon-only buttons) ---- */
.tooltip {
  position: fixed; z-index: 50; max-width: 18rem;
  padding: 0.25rem 0.5rem; border-radius: 0.25rem;
  background: var(--fg); color: var(--bg);
  font-size: 0.8125rem; line-height: 1.3; white-space: nowrap;
}
.tooltip[hidden] { display: none; }

/* ---- Compact density: wide windows with a mouse or trackpad. Touch and narrow screens keep 44px targets. ---- */
@media (min-width: 40rem) and (pointer: fine) {
  .tap { min-height: 32px; }
  .btn { min-height: 32px; min-width: 32px; padding: 0 0.625rem; }
  .btn-icon { width: 32px; padding: 0; }
  .join-cell { min-width: 3rem; }
}

/* ---- Theme picker: a palette icon button on narrow screens (same look as the help button) ----
   The <select> stays in place but invisible on top of the icon, so a tap opens the native option list. */
@media (max-width: 39.999rem) {
  .theme-picker { position: relative; }
  .theme-label {
    justify-content: center; width: 44px; min-height: 44px; gap: 0;
    border: 1px solid var(--border); border-radius: 0.375rem;
    background: var(--surface-2); color: var(--fg);
  }
  .theme-label .label-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .theme-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
  .theme-select:focus-visible { outline: none; box-shadow: none; }
  .theme-picker:has(.theme-select:focus-visible) .theme-label {
    outline: 3px solid var(--focus); outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 6px var(--fg);
  }
}

/* ---- Collapsible panels and the help dialog ---- */
.disclosure > summary { list-style: none; }
.disclosure > summary::-webkit-details-marker { display: none; }
.help-dialog {
  margin: auto; padding: 0;
  width: calc(100% - 2rem); max-width: 34rem; max-height: calc(100dvh - 2rem); overflow: auto;
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); border-radius: 0.5rem;
}
.help-dialog::backdrop { background: color-mix(in srgb, var(--bg) 75%, transparent); }

/* ---- Size bar: how much of the whole network a subnet covers (decorative; the mask already says it in text) ----
   In the table it starts in the row's first data cell and runs across all the data columns, up to the Split column.
   --bar-span (set from JavaScript on the table) is that distance in px; 100% of the first cell is the fallback. */
:root { --bar-h: 3.6px; }
.size-cell { position: relative; }
.size-cell::before { content: ''; position: absolute; left: 0; bottom: 0; height: var(--bar-h); width: var(--bar-span, 100%); background: var(--border); }
.size-cell > .size-bar { position: absolute; left: 0; bottom: 0; height: var(--bar-h); width: max(var(--bar-h), calc(var(--bar-span, 100%) * var(--share))); background: var(--accent); }
.size-track { position: relative; height: var(--bar-h); border-radius: 2px; background: var(--border); overflow: hidden; }
/* 100% is the card's content box; add its padding and indent to get the full list width. */
.size-track > .size-bar { position: absolute; left: 0; top: 0; bottom: 0; width: max(var(--bar-h), min(100%, calc((100% + 1.25rem + var(--indent, 0rem)) * var(--share)))); background: var(--accent); }

/* ---- Cards (narrow screens) ---- */
.card-title { overflow-wrap: anywhere; }

/* ---- Forced colors (Windows High Contrast) ---- */
@media (forced-colors: active) {
  .btn, .bracket, .field, .card, .theme-label { border: 1px solid ButtonText; }
  .bracket { border-left-width: 3px; }
  .tooltip { border: 1px solid CanvasText; }
  .size-bar { background: Highlight; forced-color-adjust: none; }
  .size-cell::before, .size-track { background: GrayText; forced-color-adjust: none; }
  :focus-visible { outline: 3px solid Highlight; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
