/*
 * App-shell layout on top of Water CSS (classless).
 *
 *   header   (compact title + help tooltip)
 *   main     (flex row: sidebar | stage)
 *     #sidebar  fixed-width, vertically scrollable: file picker, live telemetry,
 *               collapsible metadata. Never scrolls horizontally — content wraps.
 *     #stage    fills remaining space; two lenses, height-capped
 *   #controls  pinned to the bottom, single line, vertically centered
 */

/* Override Water CSS's centered narrow column — we want a full-bleed app. */
html,
body {
  height: 100%;
  margin: 0;
  max-width: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden; /* the app shell owns scrolling; only the sidebar scrolls */
}

header {
  flex: 0 0 auto;
  padding: 0.5rem 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
}

/* Material Symbols icon font (loaded via <link> in index.html). Each usage sets
   its own font-size; control/icon buttons override below. */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* "help" icon with a CSS tooltip next to the title. */
.help {
  margin-left: 0.4em;
  font-size: 1.2rem;
  opacity: 0.5;
  cursor: help;
  position: relative;
}

.help:hover,
.help:focus {
  opacity: 1;
}

.help::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: 150%;
  width: max-content;
  max-width: 340px;
  padding: 0.5rem 0.7rem;
  background: #1b1b1b;
  color: #eee;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  /* Render the tooltip in normal text, not the inherited Material icon font
     (otherwise its ligatures turn words into glyphs). */
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-feature-settings: normal;
  -webkit-font-feature-settings: normal;
  letter-spacing: normal;
  text-transform: none;
  font-size: 0.8rem;
  font-weight: normal;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

.help:hover::after,
.help:focus::after {
  opacity: 1;
  transform: translateY(0);
}

/* --- main: sidebar + stage ------------------------------------------------ */

main {
  flex: 1 1 auto;
  min-height: 0; /* allow children to scroll instead of growing the page */
  display: flex;
  gap: 1rem;
  padding: 0 1rem;
}

#sidebar {
  flex: 0 0 260px;
  width: 260px;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden; /* never scroll horizontally — content wraps instead */
  padding-bottom: 1rem;
}

/* Custom file picker: a label button + a truncating filename. The native input
   is visually hidden but still operable via the label. */
#file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.file-btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  padding: 0.4rem 0.6rem;
  margin: 0 0 0.4rem;
  border-radius: 6px;
  background: var(--button-base, #2b2f36);
  color: var(--text-bright, #fff);
  cursor: pointer;
  font-size: 0.85rem;
}

.file-btn:hover {
  background: var(--button-hover, #3a3f47);
}

.file-name {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#status {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

#status:empty {
  display: none;
}

#status[data-error='true'] {
  color: #ff6b6b;
  font-weight: bold;
}

/* --- stage: the two lenses ------------------------------------------------ */

#stage {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.empty-hint {
  margin: auto;
  opacity: 0.5;
}

body.has-file .empty-hint {
  display: none;
}

body:not(.has-file) .lenses {
  display: none;
}

.lenses {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.lenses figure {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.lenses figcaption {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: bold;
  font-size: 0.85rem;
  padding: 0.15rem 0 0.35rem;
}

.icon-btn {
  margin: 0;
  padding: 0.1rem 0.35rem;
  font-size: 18px; /* Material download icon */
  line-height: 1;
  border-radius: 5px;
}

.canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Square fisheye canvas scales to fill the cell while preserving aspect ratio
   and never exceeding the available height. */
canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #0a0a0a;
  border-radius: 6px;
}

/* --- controls bar (pinned bottom, single centered line) ------------------- */

#controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  border-top: 1px solid rgba(127, 127, 127, 0.25);
}

#controls button {
  margin: 0;
  padding: 0.2rem 0.5rem;
  font-size: 22px; /* Material icon size for transport buttons */
}

#controls #scrubber {
  flex: 1 1 120px;
  min-width: 100px;
  margin: 0;
  align-self: center;
}

/* Kill the focus outline / "pressed button" look on the scrubber. */
#controls #scrubber:focus,
#controls #scrubber:focus-visible,
#controls #scrubber:active {
  outline: none;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
  transform: none;
}

#controls #frameInfo {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

#controls .speed {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
  font-size: 0.85rem;
  margin: 0;
}

#controls .speed select {
  margin: 0;
  padding: 0.25rem 0.4rem;
  width: auto;
}

/* --- telemetry panel (in the sidebar, a vertical column) ------------------ */

.meta-live {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0 0 1rem;
}

.meta-live .kv {
  background: rgba(127, 127, 127, 0.1);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

.meta-live .kv b {
  display: block;
  font-size: 0.68rem;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.meta-live .kv span {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Collapsible metadata sections — full-width, no odd inset backing. */
#meta details {
  margin: 0.5rem 0;
  background: rgba(127, 127, 127, 0.08);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

#meta details[hidden] {
  display: none;
}

#meta summary {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: bold;
  font-size: 0.85rem;
  list-style: none;
}

/* No underline / focus ring on the accordion header (hover, focus or active). */
#meta summary,
#meta summary:hover,
#meta summary:focus,
#meta summary:focus-visible,
#meta summary:active,
#meta summary .title,
#meta summary .title:hover {
  text-decoration: none;
  border-bottom: none;
  box-shadow: none;
  outline: none;
}

#meta summary::-webkit-details-marker {
  display: none;
}

#meta summary .marker {
  font-size: 18px;
  opacity: 0.7;
  flex: 0 0 auto;
  transition: transform 0.15s;
}

#meta details[open] summary .marker {
  transform: rotate(90deg);
}

#meta summary .title {
  flex: 1 1 auto;
}

.copy-btn {
  margin: 0;
  padding: 0.05rem 0.3rem;
  font-size: 18px; /* Material content_copy / check */
  border-radius: 5px;
  flex: 0 0 auto;
}

dl.meta-info {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 0.6rem;
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
}

dl.meta-info dt {
  font-weight: bold;
  opacity: 0.75;
}

dl.meta-info dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

pre.meta-raw {
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.72rem;
  margin: 0.5rem 0 0;
}

/* --- narrow screens: stack sidebar under the lenses, let the page scroll --- */
@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  main {
    flex-direction: column;
  }

  #sidebar {
    flex: 0 0 auto;
    width: auto;
    order: 2; /* lenses first, params below */
    overflow: visible;
  }

  #stage {
    order: 1;
    min-height: 60vh;
  }

  .lenses {
    flex-direction: column;
  }

  .lenses figure {
    height: auto;
  }

  .canvas-wrap {
    min-height: 40vh;
  }
}
