/* ==========================================================================
   Listen.  (views/listen.js)
   Full-bleed, calm. The circle is the only continuous motion in the app.
   The orb is a canvas drawn by js/listen/orb.js (colours from the --listen-* tokens).
   ========================================================================== */

.listen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(var(--space-4), var(--safe-top))
    max(var(--gutter), var(--safe-right))
    max(var(--space-4), var(--safe-bottom))
    max(var(--gutter), var(--safe-left));
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
}

.listen-simple {
  display: grid;
  flex: 1 1 auto;
  place-items: center;
}

/* ---- Head: name + one status line ---------------------------------------- */

.listen-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  max-width: var(--w-sheet);
  margin-inline: auto;
  text-align: center;
}

.listen-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.listen-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.listen-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--listen-paused);
}

.listen-status[data-kind="live"] .listen-status-dot {
  background: var(--accent);
}

.listen-status[data-kind="quiet"] .listen-status-dot {
  background: var(--listen-quiet);
}

.listen-status[data-kind="danger"] {
  background: var(--danger-soft);
  box-shadow: none;
  color: var(--danger-strong);
}

.listen-status[data-kind="danger"] .listen-status-dot {
  background: var(--danger);
}

/* speech heard but not recognised; connection lost (listening goes on): the colours of their warn banners */
.listen-status[data-kind="net"],
.listen-status[data-kind="warn"] {
  background: var(--warning-soft);
  box-shadow: none;
  color: var(--warning);
}

.listen-status[data-kind="net"] .listen-status-dot,
.listen-status[data-kind="warn"] .listen-status-dot {
  background: var(--warning);
}

@media (prefers-reduced-motion: no-preference) {
  .listen-status[data-kind="live"] .listen-status-dot {
    animation: listen-dot 1.6s var(--ease-in-out) infinite alternate;
  }
}

@keyframes listen-dot {
  to {
    opacity: 0.35;
  }
}

/* ---- Main: circle + numbers ---------------------------------------------- */

.listen-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding-block: var(--space-6);
}

.listen-orb {
  display: block;
  width: min(78vw, 340px, 44dvh);
  aspect-ratio: 1;
  height: auto;
}

.listen-stats .stat-value {
  letter-spacing: -0.02em;
}

.listen-left {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(100%, 280px);
}

.listen-left-label {
  display: flex;
  justify-content: space-between;
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.listen-left-bar {
  height: 8px;
}

/* low balance: the bar and the number turn amber */
.listen-left.is-low .listen-left-label {
  color: var(--warning);
}

.listen-left.is-low .listen-left-bar {
  background: var(--warning-soft);
}

.listen-left.is-low .listen-left-bar::before {
  background: var(--warning);
}

.listen-note {
  gap: var(--space-2);
}

.listen-warn,
.listen-problem {
  width: 100%;
  max-width: var(--w-sheet);
}

/* One listening warning (views/listen.js evaluate()): a short title and a hint on its own line. */
.listen-problem .banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.listen-problem-title {
  font-weight: var(--weight-semibold);
}

.listen-problem-hint {
  color: var(--ink-2);
}

@media (prefers-reduced-motion: no-preference) {
  .listen-problem .banner {
    animation: listen-problem-in var(--dur-3) var(--ease-out);
  }
}

@keyframes listen-problem-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---- Controls: pause · «Чухал» · stop ------------------------------------- */

.listen-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  max-width: var(--w-sheet);
  margin-inline: auto;
}

.listen-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.listen-side {
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.listen-stop {
  color: var(--danger);
}

.listen-control-label {
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.listen-mark {
  position: relative;
  min-width: 152px;
  height: 88px;
  border-radius: var(--radius-full);
  font-size: var(--text-lg);
  overflow: hidden;
}

.listen-mark-count:empty {
  display: none;
}

.listen-mark-count {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: rgb(var(--ink-rgb) / 0.12);
  font-size: var(--text-sm);
}

/* ripple on each mark */
.listen-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgb(255 255 255 / 0.55);
  opacity: 0;
  pointer-events: none;
}

.listen-mark.is-ripple::after {
  animation: listen-ripple 520ms var(--ease-out);
}

@keyframes listen-ripple {
  from {
    opacity: 0.9;
    transform: scale(0.85);
  }

  to {
    opacity: 0;
    transform: scale(1);
  }
}

@media (min-width: 640px) {
  .listen-mark {
    min-width: 200px;
  }
}

/* ---- Hover hints with the keyboard shortcut (mouse and keyboard users only) ---- */

.has-hint {
  position: relative;
}

@media (hover: hover) and (pointer: fine) {
  .has-hint::before {
    content: attr(data-hint) "  " attr(data-keys);
    position: absolute;
    bottom: calc(100% + var(--space-2));
    left: 50%;
    z-index: var(--z-raised);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--toast-bg);
    box-shadow: var(--shadow-2);
    color: var(--toast-ink);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-snug);
    white-space: pre;
    opacity: 0;
    transform: translate(-50%, 4px);
    pointer-events: none;
    transition:
      opacity var(--dur-2) var(--ease-out),
      transform var(--dur-2) var(--ease-out);
  }

  .has-hint:hover::before,
  .has-hint:focus-visible::before {
    opacity: 1;
    transform: translate(-50%, 0);
    transition-delay: 300ms;
  }

  .has-hint:disabled::before {
    display: none;
  }
}

/* «Чухал»: the hint must escape the button; the ripple (::after) stays inside by never scaling past 1 */
.listen-mark.has-hint {
  overflow: visible;
}

/* ?debug=1 : hearing numbers for tuning */
.listen-debug {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 4px);
  transform: translateX(-50%);
  margin: 0;
  padding: 2px var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--text-xs);
  white-space: nowrap;
  pointer-events: none;
}
