@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap");

/*
 * Glassmorphism card: front = live internals, back = settings (flips on hover).
 * Positioned in the viewport centre, sized for the settings panel.
 */
.cc {
  --cc-radius: 26px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: min(400px, calc(100vw - 24px));
  height: min(540px, calc(100vh - 32px));
  perspective: 1600px;
  font-family: "Poppins", Inter, "Segoe UI", Arial, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.cc.cc-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/*
 * Non-rotating hover pad: keeps :hover stable while the inner element swings
 * through rotateY (its projected box shrinks mid-animation).
 */
.cc-hoverpad {
  position: absolute;
  inset: -18px;
  z-index: 0;
  border-radius: calc(var(--cc-radius) + 18px);
}

.cc-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.35, 0.15, 0.2, 1);
}

/* Details overlay is not rotated, so it pins the card to the front face. */
.cc-toolbar {
  position: absolute;
  top: -13px;
  right: 8px;
  z-index: 4;
  display: flex;
  gap: 6px;
}

.cc-details-btn {
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(18, 24, 26, 0.6);
  color: #fff;
  font-family: inherit;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 160ms ease, border-color 160ms ease;
}

.cc-details-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.45);
}

.cc-details-btn[aria-expanded="true"] {
  background: rgba(200, 235, 98, 0.9);
  border-color: rgba(255, 255, 255, 0.5);
  color: #16201a;
}

.cc:hover .cc-inner,
.cc.is-flipped .cc-inner {
  transform: rotateY(180deg);
}

/* "static" mode: telemetry only, no hover flip, settings unreachable. */
.cc.is-static .cc-inner,
.cc.is-static:hover .cc-inner {
  transform: none;
}

/* Open details pin the card to the front face even while hovered. */
.cc.is-details .cc-inner,
.cc.is-details:hover .cc-inner {
  transform: none;
}

.cc-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border-radius: var(--cc-radius);
  background:
    linear-gradient(152deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05) 46%, rgba(255, 255, 255, 0.11)),
    rgba(18, 24, 26, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow:
    0 26px 60px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.cc-back {
  transform: rotateY(180deg);
  padding: 18px 18px 14px;
}

/* Header ------------------------------------------------------------------ */

.cc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cc-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.cc-brand-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-brand-sub {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}

.cc-head-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.cc-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cc-live--muted {
  color: rgba(255, 255, 255, 0.65);
}

.cc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ed86f;
  box-shadow: 0 0 0 3px rgba(158, 216, 111, 0.22);
}

.cc-live.is-idle .cc-dot {
  background: #f0a8bb;
  box-shadow: 0 0 0 3px rgba(240, 168, 187, 0.22);
}

.cc-live.is-live .cc-dot {
  animation: cc-pulse 1.8s ease-in-out infinite;
}

@keyframes cc-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.86);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Front: counters --------------------------------------------------------- */

.tm-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tm-tile {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.tm-tile-label {
  font-size: 8.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}

.tm-tile-value {
  font-size: 24px;
  font-weight: 500;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.tm-tile-sub {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.62);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Front: audio spectrum --------------------------------------------------- */

.tm-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tm-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}

.tm-level {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 46px;
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tm-level span {
  flex: 1 1 0;
  height: 2px;
  min-height: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, #f2ffd2, #c8eb62 45%, #bc5fe8);
  transition: height 90ms linear;
}

/* Front: readouts and log ------------------------------------------------ */

.tm-rows {
  display: flex;
  flex-direction: column;
}

.tm-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.7);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
}

.tm-row:last-child {
  border-bottom: 0;
}

.tm-row b {
  font-weight: 500;
  color: #fff;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tm-log {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  overflow: hidden;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.78);
}

.tm-log-row {
  display: flex;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.tm-log-row time {
  flex: none;
  color: rgba(255, 255, 255, 0.42);
  font-variant-numeric: tabular-nums;
}

.tm-log-row span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tm-log-empty {
  color: rgba(255, 255, 255, 0.38);
}

/* Back: settings --------------------------------------------------------- */

.cc-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  margin-right: -4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.cc-scroll::-webkit-scrollbar {
  width: 6px;
}

.cc-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}

/* Footer ----------------------------------------------------------------- */

.cc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}

.cc-foot kbd {
  font-size: 9px;
  padding: 0 4px;
}

/* Details: algorithm flow ------------------------------------------------ */

.cc-details {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border-radius: var(--cc-radius);
  background:
    linear-gradient(152deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04) 46%, rgba(255, 255, 255, 0.09)),
    rgba(12, 17, 19, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow:
    0 26px 60px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
}

.cc-details[hidden] {
  display: none;
}

.cc-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.cc-close:hover {
  background: rgba(255, 255, 255, 0.24);
}

.dt-scroll {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dt-flow {
  display: flex;
  flex-direction: column;
}

.dt-node {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 9px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.dt-node b {
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.25;
}

.dt-node span {
  font-size: 10px;
  line-height: 1.28;
  color: rgba(255, 255, 255, 0.64);
}

.dt-tag {
  font-size: 8.5px !important;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(200, 235, 98, 0.85) !important;
}

.dt-node--ghost {
  background: rgba(255, 255, 255, 0.04);
  border-style: dashed;
}

.dt-branch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.dt-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 0;
}

.dt-link i {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.12));
}

.dt-link span {
  position: relative;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.4);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 9px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.78);
  text-align: center;
}

.dt-link--loop i {
  background: repeating-linear-gradient(
    180deg,
    rgba(200, 235, 98, 0.55) 0 4px,
    rgba(200, 235, 98, 0.15) 4px 8px
  );
}

.dt-timings {
  display: flex;
  flex-direction: column;
  margin-top: 2px;
  border-top: 1px dashed rgba(255, 255, 255, 0.14);
}

.dt-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.66);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.dt-row:last-child {
  border-bottom: 0;
}

.dt-row b {
  font-weight: 500;
  color: #fff;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Small screens ---------------------------------------------------------- */

/* Short viewports (laptops in a small window): keep the details panel scroll-free. */
@media (max-height: 620px) {
  .cc-details {
    padding: 12px;
    gap: 6px;
  }

  .dt-scroll {
    gap: 6px;
  }

  .dt-node {
    padding: 5px 8px;
  }

  .dt-node span {
    font-size: 9.5px;
    line-height: 1.22;
  }

  .dt-link {
    min-height: 18px;
    padding: 0;
  }

  .dt-branch {
    margin-top: 2px;
  }

  .dt-row {
    padding: 1px 0;
  }

  .dt-row--loops {
    display: none;
  }
}

@media (max-width: 480px) {
  .cc {
    width: calc(100vw - 16px);
    height: min(520px, calc(100vh - 16px));
  }

  .cc-face {
    padding: 16px;
    gap: 10px;
  }

  .tm-tile-value {
    font-size: 20px;
  }

  .tm-level {
    height: 38px;
  }

  .cc-foot {
    font-size: 9px;
  }
}
