/* ====================================================================
   Avatar Chat Room
   The page is a stage: the bot stands in a spotlight, the controls sit
   on solid "backstage" surfaces that stay legible on any background.
   ==================================================================== */

:root {
  /* Surfaces */
  --ink: #241733;
  --ink-raised: #32224a;
  --ink-sunken: #1b1127;
  --line: #4b3768;

  /* Text */
  --text: #fbf5ff;
  --text-soft: #cdbfdc;

  /* Signals */
  --marigold: #ffb627;
  --marigold-bright: #ffc95c;
  --on-marigold: #2b1800;
  --coral: #ff9385;
  --mint: #84e6b8;

  /* Over the bot (2147483600) but under the chat widget's controls */
  --z-logo: 2147483601;

  /* Above the chat widget's own controls (z-index 2147483640) */
  --z-panel: 2147483642;
  --z-dock: 2147483643;
  --z-pill: 2147483644;
  --z-modal: 2147483645;
  --z-toast: 2147483646;

  /* Driven by app.js */
  --avatar-scale: 0.88;
  --avatar-x: 0px;
  --avatar-y: 25px;

  /* Moves the bot out from behind the settings panel; set in the responsive section */
  --stage-x: 0px;
  --stage-y: 0px;
  --stage-fit: 1;
  --panel-width: min(420px, calc(100vw - 32px));
  --sheet-height: 58dvh;

  color-scheme: dark;
  accent-color: var(--marigold);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--ink-sunken);
  font-family: 'Anuphan', 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--marigold-bright);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ------------------------------ Stage ------------------------------ */

.bg-container {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--ink-sunken);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  transition: filter 0.2s ease;
  pointer-events: none;
}

.bg-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  transition: background-color 0.3s ease;
}

/* No background chosen: a single beam of light on the bot */
.bg-container.is-default {
  background-image: linear-gradient(180deg, #33214a 0%, #241733 62%, #1b1127 100%);
}

.bg-container.is-default::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 340px 54px at 50% 91%, rgba(255, 214, 140, 0.5), transparent 72%),
    conic-gradient(from 160deg at 50% -14%,
      transparent 0deg,
      rgba(255, 214, 140, 0.26) 9deg,
      rgba(255, 224, 165, 0.36) 20deg,
      rgba(255, 214, 140, 0.26) 31deg,
      transparent 40deg);
  animation: lights-up 1.4s ease-out both;
}

@keyframes lights-up {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* The size and position controls move only the bot, not the page UI.
   The doubled ID out-ranks the widget's own !important fullscreen rule. */
#avatar-widget-container#avatar-widget-container.bcw-rt-avatar-fullscreen,
#avatar-widget-container#avatar-widget-container {
  transform:
    translate(calc(var(--avatar-x) + var(--stage-x)), calc(var(--avatar-y) + var(--stage-y)))
    scale(calc(var(--avatar-scale) * var(--stage-fit))) !important;
  transform-origin: bottom center !important;
  transition: transform 0.22s ease-out;
}

/* ------------------------------ Logo ------------------------------- */

.site-logo {
  position: fixed;
  z-index: var(--z-logo);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: grab;
}

.site-logo.dragging {
  cursor: grabbing;
}

.site-logo.is-locked {
  pointer-events: none;
}

.site-logo[data-corner="custom"] {
  left: var(--logo-x, 0);
  top: var(--logo-y, 0);
}

.site-logo[data-corner^="top"] { top: calc(var(--logo-edge, 20px) + var(--logo-push, 0px)); }
.site-logo[data-corner^="bottom"] { bottom: calc(var(--logo-edge, 20px) + var(--logo-push, 0px)); }
.site-logo[data-corner$="left"] { left: var(--logo-edge, 20px); }
.site-logo[data-corner$="right"] { right: calc(var(--logo-edge, 20px) + var(--logo-shift, 0px)); }

/* ------------------------------ Dock ------------------------------- */

.floating-actions {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: var(--z-dock);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(20, 8, 36, 0.45);
  user-select: none;
  touch-action: none;
  cursor: grab;
  transition: opacity 0.2s ease, visibility 0.2s;
}

.floating-actions.dragging {
  cursor: grabbing;
}

.floating-actions.hidden {
  opacity: 0;
  visibility: hidden;
}

.floating-action-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  font-size: 1.05rem;
  color: var(--text);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.floating-action-btn:hover {
  background: var(--ink-raised);
}

.floating-action-btn[aria-expanded="true"] {
  background: var(--marigold);
  color: var(--on-marigold);
}

.floating-action-btn.voice-btn.listening {
  background: var(--coral);
  color: #3a0f0a;
  animation: voice-pulse 1.4s infinite ease-in-out;
}

@keyframes voice-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 147, 133, 0.6); }
  70% { box-shadow: 0 0 0 12px rgba(255, 147, 133, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 147, 133, 0); }
}

.bot-chip {
  height: 44px;
  max-width: 190px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 0 12px;
  background: var(--ink-raised);
  border: 0;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 0.15s ease;
}

.bot-chip:hover {
  background: var(--line);
}

.bot-chip-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--mint);
}

.status-dot[data-state="loading"] {
  background: var(--marigold);
  animation: dot-blink 1s infinite ease-in-out;
}

.status-dot[data-state="error"] {
  background: var(--coral);
}

@keyframes dot-blink {
  50% { opacity: 0.3; }
}

/* ---------------------------- Voice pill --------------------------- */

.voice-live-pill {
  position: fixed;
  top: 80px;
  left: 16px;
  z-index: var(--z-pill);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 10px 12px 10px 18px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 10px 28px rgba(20, 8, 36, 0.45);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.voice-live-pill.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
}

.voice-soundwave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.voice-soundwave span {
  width: 3px;
  height: 6px;
  background: var(--marigold);
  border-radius: 99px;
}

.voice-live-pill.active .voice-soundwave span {
  background: var(--coral);
  animation: soundwave 1s infinite ease-in-out;
}

.voice-soundwave span:nth-child(1) { animation-delay: 0.1s; }
.voice-soundwave span:nth-child(2) { animation-delay: 0.3s; }
.voice-soundwave span:nth-child(3) { animation-delay: 0.2s; }
.voice-soundwave span:nth-child(4) { animation-delay: 0.4s; }
.voice-soundwave span:nth-child(5) { animation-delay: 0.15s; }

@keyframes soundwave {
  0%, 100% { height: 6px; }
  50% { height: 20px; }
}

.voice-text-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}

.voice-status-label {
  font-size: 0.8rem;
  color: var(--text-soft);
}

.voice-transcript {
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-pill-btn {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--text-soft);
}

.voice-pill-btn:hover {
  background: var(--ink-raised);
  color: var(--text);
}

/* ---------------------------- Voice guide -------------------------- */

.voice-guide-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 8, 36, 0.72);
  transition: opacity 0.2s ease, visibility 0.2s;
}

.voice-guide-modal.hidden {
  opacity: 0;
  visibility: hidden;
}

.voice-guide-card {
  width: min(540px, 100%);
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(20, 8, 36, 0.6);
  overflow: hidden;
}

.voice-guide-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 16px 24px;
  border-bottom: 1px solid var(--line);
}

.voice-guide-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
}

.voice-guide-hint {
  font-size: 0.875rem;
  color: var(--text-soft);
}

.voice-guide-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 24px 24px;
  overflow-y: auto;
}

.voice-guide-section h3 {
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-weight: 600;
}

.voice-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.v-tag {
  min-height: 36px;
  padding: 4px 12px;
  background: var(--ink-raised);
  border: 0;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.v-tag:hover {
  background: var(--marigold);
  color: var(--on-marigold);
}

/* ------------------------------ Panel ------------------------------ */

.settings-panel {
  position: fixed;
  top: 80px;
  left: 16px;
  z-index: var(--z-panel);
  width: var(--panel-width);
  max-height: calc(100dvh - 96px);
  display: flex;
  flex-direction: column;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(20, 8, 36, 0.55);
  /* The whole panel scrolls, so the Widget ID moves away and short screens keep room for controls */
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  transform-origin: top left;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, visibility 0.25s;
}

.settings-panel.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.98);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 20px;
}

.panel-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
}

.header-actions {
  display: flex;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text-soft);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--ink-raised);
  color: var(--text);
}

/* Active bot */
.bot-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 20px 16px;
}

.field-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-soft);
}

.field-row {
  display: flex;
  gap: 8px;
}

.text-field {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  background: var(--ink-sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.95rem;
  transition: border-color 0.15s ease;
}

.text-field::placeholder {
  color: #a795bb;
}

.text-field:focus {
  outline: none;
  border-color: var(--marigold);
}

.text-field[aria-invalid="true"] {
  border-color: var(--coral);
}

.widget-id-field {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.bot-status-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 21px;
}

.bot-status {
  font-size: 0.875rem;
  color: var(--text-soft);
}

.bot-status[data-state="ok"] { color: var(--mint); }
.bot-status[data-state="error"] { color: var(--coral); }

.link-btn {
  flex: none;
  background: none;
  border: 0;
  font-size: 0.875rem;
  color: var(--marigold-bright);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-primary {
  flex: none;
  height: 44px;
  padding: 0 18px;
  background: var(--marigold);
  border: 0;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--on-marigold);
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.btn-primary:hover {
  background: var(--marigold-bright);
}

.btn-primary:disabled {
  background: var(--ink-raised);
  color: var(--text-soft);
  cursor: progress;
}

.btn-secondary {
  min-height: 44px;
  padding: 0 14px;
  background: var(--ink-raised);
  border: 0;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background-color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--line);
}

.full-width {
  width: 100%;
}

/* Tabs */
.tabs-nav {
  position: sticky;
  top: 0;
  z-index: 2;
  flex: none;
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--ink);
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  position: relative;
  flex: 1;
  height: 44px;
  background: transparent;
  border: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-soft);
  transition: color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  font-weight: 600;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 3px;
  background: var(--marigold);
  border-radius: 3px 3px 0 0;
}

.tab-panels {
  flex: none;
}

.tab-content {
  display: none;
  flex-direction: column;
  gap: 20px;
  padding: 18px 20px 20px;
}

.tab-content.active {
  display: flex;
}

.section-group,
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-group {
  gap: 14px;
}

.section-label {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Color: the point under the cursor is exactly the color you get */
.color-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.color-pad {
  position: relative;
  height: clamp(110px, 22dvh, 170px);
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, hsl(var(--pad-hue, 222) 100% 50%));
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
}

.color-pad-cursor {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.hue-slider {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.hue-slider::-webkit-slider-runnable-track {
  height: 14px;
  background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  border-radius: 99px;
}

.hue-slider::-moz-range-track {
  height: 14px;
  background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  border-radius: 99px;
}

.hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -5px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.hue-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.color-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-preview-box {
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.color-inputs {
  flex: 1;
  min-width: 0;
}

.input-with-button {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 12px;
  background: var(--ink-sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.input-with-button:focus-within {
  border-color: var(--marigold);
}

#color-hex-input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  font-size: 0.95rem;
  text-transform: uppercase;
}

.native-picker-trigger {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--text-soft);
  cursor: pointer;
}

.native-picker-trigger:hover {
  background: var(--ink-raised);
  color: var(--text);
}

/* Sliders */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.92rem;
}

.slider-value {
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

.slider-desc {
  font-size: 0.85rem;
  color: var(--text-soft);
}

input[type="range"] {
  width: 100%;
  height: 24px;
  cursor: pointer;
}

/* Swatches */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.preset-chip {
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  transition: transform 0.12s ease;
}

.preset-chip:hover {
  transform: scale(1.08);
}

.preset-chip.active,
.wallpaper-chip.active {
  outline: 2px solid var(--marigold);
  outline-offset: 2px;
}

/* Image */
.upload-dropzone {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 20px 16px;
  background: var(--ink-sunken);
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--marigold);
  background: var(--ink-raised);
}

.upload-icon {
  margin-bottom: 6px;
  font-size: 1.5rem;
  color: var(--marigold);
}

.dropzone-text {
  font-size: 0.95rem;
  font-weight: 500;
}

.dropzone-hint {
  font-size: 0.85rem;
  color: var(--text-soft);
}

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

.wallpaper-chip {
  position: relative;
  aspect-ratio: 16 / 11;
  overflow: hidden;
  background-color: var(--ink-raised);
  background-size: cover;
  background-position: center;
  border: 0;
  border-radius: 10px;
}

.wallpaper-chip span {
  position: absolute;
  inset: auto 0 0;
  padding: 12px 6px 3px;
  background: linear-gradient(transparent, rgba(20, 8, 36, 0.9));
  font-size: 0.78rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Logo: a small screen to drag on, beside four corner shortcuts */
.logo-place {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background-color: var(--ink-sunken);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  touch-action: none;
}

.logo-stage.has-logo {
  cursor: move;
}

.logo-stage-thumb {
  position: absolute;
  height: auto;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.corner-buttons {
  flex: none;
  display: grid;
  grid-template-columns: 48px 48px;
  gap: 6px;
  border: 0;
}

.corner-btn {
  position: relative;
  height: 48px;
  cursor: pointer;
}

/* The tile is drawn as a little screen with a block in the chosen corner */
.corner-icon {
  position: absolute;
  inset: 0;
  background: var(--ink-sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.corner-icon::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 10px;
  width: 26px;
  height: 18px;
  border: 2px solid var(--text-soft);
  border-radius: 4px;
}

.corner-icon::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 6px;
  background: var(--text-soft);
  border-radius: 1px;
}

.corner-icon[data-corner^="top"]::after { top: 18px; }
.corner-icon[data-corner^="bottom"]::after { top: 22px; }
.corner-icon[data-corner$="left"]::after { left: 14px; }
.corner-icon[data-corner$="right"]::after { left: 24px; }

.corner-btn:hover .corner-icon {
  border-color: var(--text-soft);
  background: var(--ink-raised);
}

.corner-btn input:checked + .corner-icon {
  background: var(--marigold);
  border-color: var(--marigold);
}

.corner-btn input:checked + .corner-icon::before {
  border-color: var(--on-marigold);
}

.corner-btn input:checked + .corner-icon::after {
  background: var(--on-marigold);
}

.corner-btn input:focus-visible + .corner-icon {
  outline: 2px solid var(--marigold-bright);
  outline-offset: 2px;
}

/* Layout */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.92rem;
}

.segmented-control {
  display: flex;
  padding: 3px;
  background: var(--ink-sunken);
  border-radius: 10px;
}

.segment-btn {
  min-height: 36px;
  padding: 0 12px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text-soft);
}

.segment-btn.active {
  background: var(--ink-raised);
  color: var(--text);
  font-weight: 600;
}

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

/* Saved background */
.panel-footer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--ink-sunken);
  border-top: 1px solid var(--line);
}

.bg-saved-thumb {
  width: 48px;
  height: 34px;
  flex: none;
  background-color: var(--ink-raised);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.bg-saved-status {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--text-soft);
}

.bg-saved-status[data-state="error"] {
  color: var(--coral);
}

.btn-remove {
  flex: none;
  min-height: 40px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--coral);
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--coral);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.btn-remove:hover:not(:disabled) {
  background: var(--coral);
  color: #3a0f0a;
}

.btn-remove:disabled {
  border-color: var(--line);
  color: #a795bb;
  cursor: not-allowed;
}

/* ------------------------------ Toast ------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: var(--z-toast);
  max-width: calc(100vw - 32px);
  padding: 10px 20px;
  background: var(--text);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(20, 8, 36, 0.5);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%);
}

/* ---------------------------- Responsive --------------------------- */

/* Laptops and landscape tablets: the bot steps aside into the free space */
@media (max-width: 1180px) {
  :root {
    --panel-width: min(400px, 46vw);
  }

  body.panel-open {
    --stage-x: calc(var(--panel-width) / 2 + 8px);
    --stage-fit: 0.85;
  }
}

@media (max-width: 600px) {
  .floating-actions {
    top: 10px;
    left: 10px;
  }

  .voice-live-pill {
    top: 74px;
    left: 10px;
    max-width: calc(100vw - 20px);
  }
}

/* Phones and upright tablets: the panel is a sheet, the bot stands on top of it */
@media (max-width: 600px), (max-width: 1023px) and (orientation: portrait) {
  :root {
    --panel-width: 100%;
  }

  body.panel-open {
    --stage-x: 0px;
    --stage-y: calc(var(--sheet-height) * -1);
    --stage-fit: 0.45;
  }

  .settings-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--sheet-height);
    max-height: none;
    border-width: 1px 0 0;
    border-radius: 20px 20px 0 0;
  }

  .settings-panel.hidden {
    transform: translateY(100%);
  }

  .panel-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  .tabs-nav {
    gap: 0;
    padding: 0 8px;
  }

  .tab-btn {
    font-size: 0.875rem;
  }
}

/* Phones on their side: panel on the left, bot on the right */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --panel-width: min(420px, 56vw);
  }

  body.panel-open {
    --stage-x: calc(var(--panel-width) / 2 + 8px);
    --stage-y: 0px;
    --stage-fit: 0.9;
  }

  .settings-panel {
    top: 8px;
    left: 8px;
    right: auto;
    bottom: 8px;
    height: auto;
    max-height: none;
    border-width: 1px;
    border-radius: 16px;
  }

  .settings-panel.hidden {
    transform: translateX(-16px);
  }

  .floating-actions {
    top: 8px;
    left: auto;
    right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
