/* MapFun — skins rail (#skinbar), per-group flyout, tooltip, status line. Loaded after components.css (overrides its
   placeholder rules). The rail reads as what it is: a strip of group buttons with a submenu. #skinbar itself carries no
   panel chrome — the strip, the flyout, the status line and the sea-level slot each carry their own — because a
   backdrop-filter on the root would become a containing block for the position:fixed flyout inside it. */

/* ---------- Rail geometry ------------------------------------------------- */
#skinbar.skinbar {
  --rail-strip-w: var(--rail-w);
  --fly-w: 244px;
  /* The top half of the left column. #toolbox takes the bottom half (--tools-h, published by
     src/ui/truesize.js), so the strip may grow only into what is left between the top bar and the floor;
     past that the group grid scrolls rather than pushing the tools off the screen. */
  max-height: calc(100dvh - var(--topbar-h) - 12px - var(--tools-h, 380px) - 8px - var(--rail-floor));
  /* the status card hangs in a strip reserved at the foot of the group panel (see .rail-groups'
     padding-bottom): absolute, so a transient "loading 8k…" never moves #toolbox, and reserved, so it can
     never draw on top of it either */
  /* above #infocard (z 14 in css/base.css): on a phone the card is a 60dvh sheet sitting exactly where the flyout
     opens, and #skinbar's own z-index is the stacking context the flyout is trapped in. */
  z-index: 15;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  width: auto; padding: 0; overflow: visible;
  background: none; border: 0; box-shadow: none;
  backdrop-filter: none; -webkit-backdrop-filter: none;
}

/* the strip: one always-visible tile per group */
/* Two tiles per row: seven groups become four rows instead of seven, which is what lets the skins, the
   overlay toggles and the latitude ladder share one column on a 900-px screen. */
.skinbar .rail-groups {
  flex: 0 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(2, 50px); justify-content: center;
  gap: 3px; padding: 6px 6px 34px; width: var(--rail-strip-w);
  overflow-y: auto; overflow-x: hidden; scrollbar-width: none;
}
.skinbar .rail-groups::-webkit-scrollbar { display: none; }
.skinbar .rail-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; padding: 2px 0 3px; border-radius: 9px; color: var(--ink-muted);
  transition: background-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.skinbar .rail-tile:hover { color: var(--ink); }
.skinbar .rail-tile[aria-expanded="true"] { background: color-mix(in srgb, var(--ink) 10%, transparent); color: var(--ink); }
.skinbar .rail-tile .tile-thumb {
  position: relative; width: 40px; height: 40px; border-radius: 10px; overflow: hidden; display: grid; place-items: center;
  background: color-mix(in srgb, var(--ink) 7%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 10%, transparent);
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.skinbar .rail-tile:hover .tile-thumb, .skinbar .rail-tile[aria-expanded="true"] .tile-thumb { transform: translateY(-1px); }
.skinbar .rail-tile .tile-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 38% 45%; }
.skinbar .rail-tile .tile-icon { position: relative; width: 20px; height: 20px; color: var(--ink-muted); }
.skinbar .rail-tile .tile-icon svg { width: 20px; height: 20px; }
.skinbar .rail-tile .tile-label { font-size: 9.5px; line-height: 1.1; letter-spacing: .01em; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.skinbar .rail-tile.active .tile-thumb { box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.skinbar .rail-tile.active { color: var(--accent); }
.skinbar .rail-tile[data-kind="none"] .tile-thumb { background: var(--ocean); }
.skinbar .rail-tile[data-kind="none"] .tile-icon { color: var(--sphere-stroke); }
/* the open tile grows a small pointer toward its flyout */
.skinbar .rail-tile[aria-expanded="true"]::after {
  content: ""; position: absolute; right: -7px; top: 50%; margin-top: -9px;
  width: 3px; height: 18px; border-radius: 3px; background: var(--accent); opacity: .9;
}

/* Short screens: the captions are what make the strip tall, and they are the one part of a tile that the
   tooltip, the tile's own title/aria-label and the flyout header all repeat. Dropping them keeps all seven
   groups visible instead of scrolling one under the fold (game mode does the same, css/immersive.css). */
@media (max-height: 860px) and (min-width: 721px) {
  .skinbar .rail-tile .tile-label { display: none; }
}

/* ---------- The flyout: one group's skins, anchored beside its tile -------- */
/* position:fixed + JS-set left/top (src/ui/skinbar.js positionFlyout) so it can never be clipped by the strip and can
   shift up when the group sits near the bottom of the viewport. It stays a *child* of #skinbar so :hover /
   :focus-within, the outside-click guard and the chrome-hiding rules in wow.css keep treating it as part of the rail. */
.skinbar .skin-flyout {
  position: fixed; z-index: 40; width: var(--fly-w); max-width: calc(100vw - 16px);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  opacity: 0; transform: translateX(-6px);
  transition: opacity var(--t-fast), transform var(--t-fast);
}
.skinbar .skin-flyout.show { opacity: 1; transform: none; }
.skinbar .skin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 9px 12px 6px; }
.skinbar .skin-title { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 12.5px; letter-spacing: .01em; }
.skinbar .skin-current { font-size: 11px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skinbar .skin-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0 8px 8px; scrollbar-gutter: stable; }
.skinbar .skin-group { padding: 2px 0 0; }
.skinbar .skin-group[hidden] { display: none !important; }
.skinbar .skin-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }

/* a skin */
.skinbar .skin {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 4px; border-radius: 10px; text-align: left; color: var(--ink);
  transition: background-color var(--t-fast), color var(--t-fast), opacity var(--t-fast);
}
.skinbar .skin:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.skinbar .skin:focus-visible { outline: none; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.skinbar .skin .thumb {
  position: relative; display: block; aspect-ratio: 2 / 1; width: 100%; border-radius: 7px; overflow: hidden;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 10%, transparent);
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.skinbar .skin .thumb img, .skinbar .skin .thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.skinbar .skin .thumb canvas { opacity: 0; transition: opacity var(--t-med); }
.skinbar .skin .thumb.loaded canvas { opacity: 1; }
.skinbar .skin .thumb-none { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, var(--ocean) 0%, var(--ocean-deep) 100%); color: var(--sphere-stroke); }
.skinbar .skin .thumb-none svg { width: 22px; height: 22px; }
.skinbar .skin .thumb-live-ph {
  position: absolute; inset: 0; display: grid; place-items: center; color: color-mix(in srgb, var(--ink) 45%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, var(--panel-solid)) 0%, color-mix(in srgb, var(--ink) 8%, var(--panel-solid)) 100%);
}
.skinbar .skin .thumb-live-ph svg { width: 22px; height: 22px; }
.skinbar .skin .name { font-size: 11.5px; line-height: 1.25; padding: 0 2px 1px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skinbar .skin[aria-checked="true"] .thumb { box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.skinbar .skin[aria-checked="true"] .name { color: var(--accent); font-weight: 600; }
.skinbar .skin:hover .thumb { transform: translateY(-1px); }
.skinbar .skin[aria-disabled="true"] { opacity: .38; cursor: not-allowed; }
.skinbar .skin[aria-disabled="true"]:hover { background: none; }
.skinbar .skin[aria-disabled="true"] .thumb { transform: none; }
.skinbar .skin.unavailable .thumb { filter: grayscale(.9) contrast(.85); }
.skinbar .skin.unavailable .name { color: var(--ink-muted); }
.skinbar .skin.unavailable::after {
  content: "!"; position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: var(--accent-ink); background: var(--danger);
}
.badge.live {
  display: inline-block; padding: 1px 5px 1px 4px; border-radius: 4px; font-size: 8.5px; font-weight: 700; letter-spacing: .08em; line-height: 1.35;
  color: #fff; background: linear-gradient(90deg, #ff5b6e, #ff8a4c); box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.skinbar .skin .badge.live { position: absolute; top: 9px; right: 9px; }
.skinbar .skin .badge.live::before { content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: #fff; margin: 0 3px 1px 0; animation: skin-pulse 1.8s ease-in-out infinite; }
@keyframes skin-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Status line: a small card hanging under the strip -------------- */
/* Absolutely positioned so a transient "loading 8k…" never changes #skinbar's measured height — src/ui/truesize.js
   mirrors that height into --skinbar-h to place the extras rail underneath. */
/* Column width, not 232 px: the flyout opens at --rail-w + 8, so a card that stayed wider than the column
   would sit under it. Two lines of 10 px, the full message on the title. */
.skinbar .skin-status {
  position: absolute; left: 0; bottom: 0; z-index: 2;
  width: var(--rail-strip-w); max-width: calc(100vw - 24px); height: 34px; padding: 4px 7px 5px;
  background: none; border: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
  font-size: 9.5px; line-height: 1.25; color: var(--ink-muted); overflow: hidden;
  opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity var(--t-med), transform var(--t-med);
}
.skinbar .skin-status.show { opacity: 1; transform: none; }
.skinbar .skin-status.error { color: var(--danger); }
.skinbar .skin-status-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.skinbar .skin-status-bar { position: absolute; left: 0; right: 0; top: 0; height: 2px; opacity: 0; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 40% 100%; }
.skinbar.loading .skin-status-bar { opacity: 1; animation: skin-shimmer 1.1s linear infinite; }
@keyframes skin-shimmer { from { background-position: -40% 0; } to { background-position: 140% 0; } }
/* the strip keeps its own slim accent bar so loading is visible without the status card */
.skinbar.loading .rail-groups::after { content: ""; display: block; height: 2px; margin: 2px 2px 0; border-radius: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 40% 100%; animation: skin-shimmer 1.1s linear infinite; }

/* ---------- Tooltip (appended to <body>: .panel's backdrop-filter would trap a fixed child) ---- */
.skin-tip {
  position: fixed; z-index: 45; width: 260px; max-width: calc(100vw - 24px); padding: 10px 12px 11px; border-radius: var(--radius);
  background: var(--panel-solid); border: 1px solid var(--panel-border); box-shadow: var(--shadow); color: var(--ink);
  pointer-events: none; opacity: 0; transform: translateX(-4px); transition: opacity var(--t-fast), transform var(--t-fast);
}
.skin-tip.show { opacity: 1; transform: none; }
.skin-tip .tip-name { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.skin-tip .tip-desc { margin: 0 0 6px; font-size: 12.5px; line-height: 1.45; color: var(--ink); }
.skin-tip .tip-credit { margin: 0; font-size: 10.5px; line-height: 1.4; color: var(--ink-muted); }
.skin-tip .tip-warn { margin: 0 0 6px; font-size: 12px; color: var(--danger); font-weight: 500; }
@media (pointer: coarse) { .skin-tip { display: none; } }

/* ---------- Phones: a horizontal strip of group buttons along the bottom ---- */
@media (max-width: 720px) {
  /* The bottom edge of a phone is shared by three instruments. Bottom-up: the timeline (which publishes --tl-h),
     then this strip (which publishes --sb-h from src/ui/skinbar.js), then the info-card peek — see css/timeline.css.
     All three used to sit at bottom: 8px and drew straight through each other. */
  #skinbar.skinbar {
    left: 8px; right: 8px; top: auto; width: auto; align-items: stretch; gap: 6px;
    bottom: calc(var(--tl-h, 70px) + 14px + var(--safe-b));
    max-height: none; padding-bottom: 0;
    transition: bottom var(--t-med);
  }
  .skinbar .rail-groups {
    display: flex; flex-direction: row; width: auto; gap: 4px; padding: 6px 8px; border-radius: 14px;
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none; justify-content: space-between;
  }
  .skinbar .rail-groups::-webkit-scrollbar { display: none; }
  .skinbar .rail-tile { flex: 0 0 auto; width: 46px; min-width: 46px; }
  .skinbar .rail-tile[aria-expanded="true"]::after { right: auto; left: 50%; top: -7px; margin: 0 0 0 -9px; width: 18px; height: 3px; }
  /* the status card floats above the strip instead of inside the column */
  .skinbar .skin-status {
    top: auto; bottom: 100%; margin: 0 0 6px; left: 0; right: 0; width: auto; max-width: none; height: auto;
    font-size: 11px; padding: 6px 10px 7px;
    background: var(--panel); border: 1px solid var(--panel-border); box-shadow: var(--shadow);
    backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  }
  .skinbar .skin-status-text { -webkit-line-clamp: 1; line-clamp: 1; }
  .skinbar.loading .rail-groups::after { display: none; }
  /* the flyout opens upward (src/ui/skinbar.js sets left/top/width) */
  .skinbar .skin-flyout { width: auto; }
  .skinbar .skin-head { padding: 8px 12px 4px; }
  .skinbar .skin-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .skinbar .skin .name { font-size: 10.5px; }
  .skinbar .skin .badge.live { top: 6px; right: 6px; transform: scale(.85); transform-origin: top right; }
}
