/* MapFun — extras: true-size card, extras rail, area-tint legend, terminator clock. Loaded after components.css. */

/* ---------- Extras rail: the top section of #toolbox (css/nav.css owns the box) --------------------------- */
/* --skinbar-h and --tools-h are published by src/ui/truesize.js from ResizeObservers on #skinbar and
   #toolbox; css/nav.css hangs the box under the rail and css/skins.css caps the rail above the box. */
/* First-paint guesses for the two published heights, close to what the box and the rail actually measure,
   so the column does not visibly re-stack on load. */
:root { --skinbar-h: 250px; --tools-h: 430px; --extras-w: 300px; }
#extras-rail {
  display: grid; grid-template-columns: repeat(2, 40px); justify-content: center; gap: 4px;
}
/* Standalone (a dev harness with no #toolbox): src/ui/truesize.js gives the rail .panel, and it has to
   place itself the way it used to, under the skin rail on the left edge. */
#extras-rail.panel {
  position: absolute; left: 12px; top: calc(var(--topbar-h) + 12px + var(--skinbar-h) + 10px); z-index: 12;
  width: var(--rail-w); padding: 6px;
}
#extras-rail .rail-label { grid-column: 1 / -1; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; text-align: center; color: var(--ink-muted); padding: 0 0 1px; }
#extras-rail .xbtn {
  width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; color: var(--ink-muted); position: relative;
  transition: background-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
#extras-rail .xbtn:hover { background: color-mix(in srgb, var(--ink) 9%, transparent); color: var(--ink); }
#extras-rail .xbtn:active { transform: translateY(1px); }
#extras-rail .xbtn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
#extras-rail .xbtn svg { width: 20px; height: 20px; }
#extras-rail .xbtn.touring svg { animation: xbtn-pulse 1.4s ease-in-out infinite; }
/* the sea-level disclosure: open is an outline, "not today's sea" is the accent dot */
#extras-rail .xbtn[aria-expanded="true"] { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--ink); }
#extras-rail .xbtn.has-value { color: var(--accent); }
#extras-rail .xbtn.has-value::after {
  content: ""; position: absolute; top: 5px; right: 5px; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--panel-solid);
}
@keyframes xbtn-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .55; transform: scale(.9); } }
:root.picker-open #truesize, :root.picker-open #areatint-legend, :root.picker-open #terminator-clock, :root.picker-open #sealevel-slot {
  opacity: 0; pointer-events: none; transition: opacity var(--t-fast);
}

/* ---------- True size card -------------------------------------------------------------------------------- */
#truesize {
  position: absolute; left: calc(12px + var(--rail-w) + 10px); top: calc(var(--topbar-h) + 12px); z-index: 13;
  width: var(--extras-w); max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px;
  max-height: calc(100vh - var(--topbar-h) - 24px); max-height: calc(100dvh - var(--topbar-h) - 24px);
  animation: pop-in var(--t-med);
}
#truesize .ts-head { display: flex; align-items: center; gap: 4px; }
#truesize .ts-head h2 { margin: 0; flex: 1; font-family: var(--font-display); font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }
#truesize .ts-eyebrow { color: var(--ink); }
#truesize .ts-head .btn.icon { width: 28px; height: 28px; color: var(--ink-muted); }
#truesize .ts-head .btn.icon:hover { color: var(--ink); }
#truesize .ts-collapse { display: none; }
#truesize .ts-chip { display: none; }
/* the reused search component: full width, no "/" keycap, results drop below the field inside the card */
#truesize .ts-search .field, #truesize .ts-search .field:focus-within { width: 100%; background: color-mix(in srgb, var(--ink) 7%, transparent); }
#truesize .ts-search .field:focus-within { background: var(--panel-solid); }
#truesize .ts-search .field .kbd { display: none; }
#truesize .ts-search .results { width: 100%; z-index: 31; }
#truesize .ts-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#truesize .ts-units { display: inline-flex; padding: 2px; border-radius: 7px; background: color-mix(in srgb, var(--ink) 6%, transparent); gap: 2px; }
#truesize .ts-unit { height: 24px; padding: 0 10px; border-radius: 5px; font-size: 12px; font-weight: 500; color: var(--ink-muted); font-variant-numeric: tabular-nums; transition: background-color var(--t-fast), color var(--t-fast); }
#truesize .ts-unit[aria-pressed="true"] { background: var(--panel-solid); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
#truesize .ts-clear { height: 26px; padding: 0 10px; font-size: 12.5px; color: var(--ink-muted); }
#truesize .ts-clear:disabled { opacity: .4; }
#truesize .ts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; overflow: auto; max-height: 40vh; }
#truesize .ts-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 8px; border-radius: 8px;
  transition: background-color var(--t-fast);
}
#truesize .ts-row:hover, #truesize .ts-row.hot { background: color-mix(in srgb, var(--ink) 6%, transparent); }
#truesize .ts-swatch { width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid; flex: none; }
#truesize .ts-text { flex: 1; min-width: 0; }
#truesize .ts-name { font-weight: 600; font-size: 13.5px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#truesize .ts-meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--ink-muted); line-height: 1.3; font-variant-numeric: tabular-nums; }
#truesize .ts-area { color: var(--ink); font-weight: 500; }
#truesize .ts-ratio::before { content: '·'; margin-right: 6px; opacity: .5; }
#truesize .ts-remove { width: 26px; height: 26px; color: var(--ink-muted); opacity: 0; transition: opacity var(--t-fast), color var(--t-fast); }
#truesize .ts-row:hover .ts-remove, #truesize .ts-row.hot .ts-remove, #truesize .ts-remove:focus-visible { opacity: 1; }
#truesize .ts-remove:hover { color: var(--danger); }
#truesize .ts-hint { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-muted); }
#truesize .ts-hint.ts-warn { color: var(--danger); }
#stage.ghost-hover { cursor: move; }
#stage.ghost-drag { cursor: grabbing; }
@media (pointer: coarse) { #truesize .ts-remove { opacity: 1; } }

/* ---------- Area tint legend ------------------------------------------------------------------------------ */
/* right of the left column, not under it */
#areatint-legend {
  position: absolute; left: calc(12px + var(--rail-w) + 10px); bottom: calc(50px + var(--safe-b)); z-index: 12;
  width: 190px; padding: 7px 10px 8px; border-radius: 8px; font-size: 10.5px; color: var(--ink-muted);
  animation: pop-in var(--t-med);
}
#areatint-legend .title { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; font-weight: 600; margin-bottom: 5px; }
#areatint-legend .bar { height: 8px; border-radius: 4px; border: 1px solid var(--panel-border); background: linear-gradient(90deg, #5b8def, transparent, #ff7a45); }
#areatint-legend .labels { display: flex; justify-content: space-between; margin-top: 3px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Terminator clock chip --------------------------------------------------------------------------- */
/* bottom-LEFT, stacked over the coords bar: the open info card owns the bottom-right corner on desktop */
#terminator-clock {
  position: absolute; left: calc(12px + var(--rail-w) + 10px); bottom: calc(46px + var(--safe-b)); z-index: 12;
  transition: bottom var(--t-med);
  display: flex; align-items: center; gap: 8px; padding: 6px 11px 6px 9px; border-radius: 999px;
  font-family: var(--font-mono); font-size: 12px; color: var(--ink); font-variant-numeric: tabular-nums; animation: pop-in var(--t-med);
}
#terminator-clock .sun-dot { width: 9px; height: 9px; border-radius: 50%; background: #ffb454; box-shadow: 0 0 10px 2px rgba(255, 180, 84, .55); flex: none; }
:root[data-theme="atlas"] #terminator-clock .sun-dot { background: #c98a1a; box-shadow: 0 0 8px 1px rgba(201, 138, 26, .45); }
#terminator-clock .sub { color: var(--ink-muted); font-size: 11px; }
/* both chips live in the bottom-left corner above #coords: the clock steps over the legend when both are on */
:root:has(#areatint-legend:not([hidden])) #terminator-clock { bottom: calc(120px + var(--safe-b)); }

/* ---------- Responsive ------------------------------------------------------------------------------------- */
@media (max-width: 960px) { #terminator-clock .sub { display: none; } }
@media (max-width: 720px) {
  /* the skin rail lies along the bottom on phones: extras stay a horizontal row under the top bar */
  #extras-rail { display: flex; flex-direction: row; width: auto; gap: 2px; }
  #extras-rail .rail-label { display: none; }
  #extras-rail .xbtn { width: 40px; height: 40px; }
  /* the card sits under the rail; collapsed it is a single chip so the map stays free for dragging */
  #truesize { left: 8px; right: 8px; width: auto; top: calc(var(--topbar-h) + 8px + 48px + 8px); max-height: 46vh; max-height: 46dvh; }
  #truesize .ts-collapse { display: inline-flex; }
  #truesize.collapsed { width: auto; right: auto; padding: 0; gap: 0; background: var(--panel); }
  #truesize.collapsed > :not(.ts-chip) { display: none; }
  #truesize.collapsed .ts-chip {
    display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px 0 10px; border-radius: 999px; color: var(--accent); font-weight: 600; font-size: 13px;
  }
  #truesize.collapsed .ts-chip svg { width: 16px; height: 16px; }
  #truesize.collapsed .ts-chip-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; display: inline-grid; place-items: center; }
  #truesize.collapsed .ts-chip-count:empty { display: none; }
  #truesize .ts-list { max-height: 26vh; }
  #areatint-legend { left: 8px; bottom: calc(72px + var(--safe-b)); width: 170px; }
  #terminator-clock, #areatint-legend { left: 8px; }
  /* phones hide #coords but the info card's peek bar (~51 px) owns the bottom edge: stack above it */
  #terminator-clock { left: 8px; right: auto; bottom: calc(72px + var(--safe-b)); }
  :root:has(#areatint-legend:not([hidden])) #terminator-clock { bottom: calc(142px + var(--safe-b)); }
}
