:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1e2933;
  --muted: #607080;
  --line: #d8dee6;
  --accent: #047857;
  --accent-strong: #065f46;
  --credit: #b45309;
  --credit-bg: #fff7ed;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(23, 38, 54, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

main {
  width: calc(100% - 32px);
  margin: 0 auto;
  padding: 28px 0;
}

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.35rem);
  line-height: 1.1;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #98a2b3;
}

.status.connected .status-dot {
  background: #12b76a;
}

.status.error .status-dot {
  background: #f04438;
}

.account-pill {
  position: relative;
  display: inline-grid;
  gap: 2px;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.2;
  white-space: nowrap;
}

.account-pill span:first-child {
  color: var(--text);
  font-weight: 800;
}

.account-credit-balance {
  display: inline-block;
  color: var(--credit);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.account-credit-change {
  position: absolute;
  right: 0;
  bottom: calc(100% + 5px);
  z-index: 2;
  padding: 3px 7px;
  border: 1px solid #fed7aa;
  border-radius: 4px;
  background: var(--credit-bg);
  color: var(--credit);
  font-size: 0.78rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
  animation: credit-change-float 1.5s ease-out both;
}

.account-credit-change.increase {
  border-color: #a7f3d0;
  background: #ecfdf3;
  color: #047857;
}

.account-pill.credits-decrease .account-credit-balance,
.account-pill.credits-increase .account-credit-balance {
  animation: credit-balance-pulse 650ms ease-out;
}

.account-logout {
  margin-top: 5px;
  min-height: 28px;
  padding: 0 9px;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
  font-size: 0.78rem;
}

.account-logout:hover {
  background: #f8fafc;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.layout > * {
  min-width: 0;
}

section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

h2 {
  margin: 0 0 14px;
  font-size: 1rem;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 10px 11px;
  outline: none;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.13);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 42px;
  padding: 0 14px;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

button.secondary:hover {
  background: #f8fafc;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #8f1b13;
}

button.mild-danger {
  background: #c2410c;
}

button.mild-danger:hover {
  background: #9a3412;
}

button.amber {
  background: #b45309;
}

button.amber:hover {
  background: #92400e;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button[data-credit-cost] {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

button[data-credit-cost]::after {
  content: attr(data-credit-cost);
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--credit-bg);
  color: var(--credit);
  font-size: 0.7rem;
  font-weight: 850;
  line-height: 1.2;
  white-space: nowrap;
}

button[data-credit-free="true"]::after {
  background: #ecfdf3;
  color: #047857;
}

.stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.content-stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.live-overview {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 220px);
  gap: 18px;
  align-items: stretch;
  min-width: 0;
}

.action-grid {
  display: grid;
  gap: 10px;
}

.compact-actions {
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.compact-actions .full-span {
  grid-column: 1 / -1;
}

.action-grid button {
  width: 100%;
  min-width: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.chat-form textarea {
  min-height: 42px;
  resize: vertical;
}

.chat-panel {
  padding: 12px 18px;
}

.chat-status {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  min-height: 20px;
  grid-column: 1 / -1;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
  min-width: 0;
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.stat-value {
  margin-top: 5px;
  font-size: 1.1rem;
  font-weight: 800;
  word-break: break-word;
}

.stat select {
  margin-top: 7px;
  min-width: 0;
}

.step-control {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 7px;
  align-items: center;
  margin-top: 7px;
}

.step-control .stat-value {
  margin-top: 0;
  text-align: center;
}

.electro-step {
  min-height: 34px;
  padding: 0;
}

.tremble-speed-stat {
  display: grid;
  gap: 8px;
}

.full-span {
  grid-column: 1 / -1;
}

.queue-list {
  margin-top: 7px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 650;
  line-height: 1.45;
  white-space: pre-line;
}

.speed-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  min-width: 0;
  height: 34px;
  font-size: 0.9rem;
  line-height: 1;
}

.speed-preset-grid {
  display: grid;
  grid-template-columns: 20px repeat(5, minmax(32px, 1fr)) 20px;
  gap: 4px;
  align-items: center;
  margin-top: 7px;
}

.speed-preset {
  min-height: 46px;
  padding: 3px 0;
  border-color: var(--line);
}

.speed-preset[data-credit-cost] {
  display: grid;
  place-items: center;
  gap: 1px;
}

.speed-preset[data-credit-cost]::after {
  padding: 0;
  background: transparent;
  font-size: 0.6rem;
}

.speed-preset[data-level="1"] {
  background: #ecfdf3;
  color: #05603a;
}

.speed-preset[data-level="2"] {
  background: #dcfae6;
  color: #067647;
}

.speed-preset[data-level="3"] {
  background: #fef7c3;
  color: #93370d;
}

.speed-preset[data-level="4"] {
  background: #ffead5;
  color: #9c2a10;
}

.speed-preset[data-level="5"] {
  background: #fee4e2;
  color: #b42318;
}

.speed-preset.active,
.speed-preset.active:hover {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.speed-preset.active::after {
  color: #fdba74;
}

.speed-meter {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f6;
}

.speed-meter-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #16a34a 0%, #f59e0b 55%, #dc2626 100%);
  transition: width 180ms ease;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 7px;
}

.segmented-control button {
  min-height: 34px;
  padding: 0 8px;
}

.segmented-control button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.messages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.video-frame {
  background: #101828;
  width: 100%;
  line-height: 0;
}

.video-panel {
  min-width: 0;
}

video {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(34vh, 320px);
  object-fit: contain;
  background: #101828;
}

.video-log {
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 20px;
  padding: 12px 18px 16px;
}

.heart-rate-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-top: 4px solid #cbd5e1;
}

.heart-rate-panel.active {
  border-top-color: #dc2626;
}

.heart-rate-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.heart-rate-heading h2 {
  margin: 0;
}

.heart-rate-reading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: auto;
  white-space: nowrap;
}

.heart-rate-value {
  font-size: 4.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.heart-rate-unit {
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 800;
}

.heart-rate-beat {
  color: #cbd5e1;
  font-size: 2.15rem;
  line-height: 1;
  transform-origin: center;
  will-change: opacity, transform;
}

.heart-rate-panel.active .heart-rate-beat {
  color: #dc2626;
  animation: heart-rate-beat var(--heart-beat-duration, 0.8s) ease-in-out infinite;
}

.heart-rate-meta {
  margin-top: auto;
  padding-top: 18px;
  color: #98a2b3;
  font-size: 0.78rem;
  line-height: 1.4;
}

@keyframes heart-rate-beat {
  0%,
  100% {
    opacity: 0.22;
    transform: scale(0.8);
  }

  12% {
    opacity: 1;
    transform: scale(1.2);
  }

  30% {
    opacity: 0.7;
    transform: scale(0.96);
  }
}

@keyframes credit-balance-pulse {
  0% {
    transform: scale(1);
  }

  42% {
    transform: scale(1.13);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes credit-change-float {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }

  18%,
  68% {
    opacity: 1;
    transform: translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .account-credit-change,
  .account-pill.credits-decrease .account-credit-balance,
  .account-pill.credits-increase .account-credit-balance {
    animation-duration: 1ms;
  }
}

.message-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.timer-panel {
  margin-bottom: 0;
}

.timer-body {
  padding: 18px;
}

.timer-value {
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.timer-meta {
  color: var(--muted);
  margin-top: 10px;
}

.messages {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 610px;
  overflow: auto;
}

.empty {
  color: var(--muted);
  padding: 28px 18px;
  text-align: center;
}

.message {
  padding: 4px 18px;
}

.guest-message {
  background: #fff7ed;
  border-left: 4px solid #f97316;
  padding-left: 14px;
}

.guest-message pre::before {
  content: "Guest ";
  color: #9a3412;
  font-weight: 800;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.25;
}

.log {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  min-height: 20px;
}

@media (max-width: 780px) {
  main {
    width: calc(100% - 22px);
    padding: 18px 0;
  }

  header,
  .layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .status {
    justify-self: start;
  }

  .timer-value {
    font-size: 2.8rem;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .live-overview {
    grid-template-columns: 1fr;
  }

  .heart-rate-panel {
    min-height: 180px;
  }
}
