/* ── Genie widget ── uses tokens from global.css, no theme logic of its own */

.genie {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  font-family: var(--mono);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ─── closed tab ─── */
.genie__tab {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-dim);
  padding: 11px 16px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: .82rem;
  letter-spacing: .02em;
  transition: border-color var(--snap), color var(--snap), transform var(--snap), box-shadow var(--snap);
}
.genie__tab:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translate(-2px, -2px);
  box-shadow: 3px 3px 0 var(--accent);
}
.genie__tab:active { transform: translate(0, 0); box-shadow: none; }
.genie__tab-dots { display: flex; gap: 4px; }
.genie__dot {
  width: 7px; height: 7px;
  background: var(--accent);
  transition: background 150ms ease, opacity 150ms ease;
}
.genie__dot.spent { background: var(--border); opacity: .5; }
.genie__tab-glyph {
  font-size: .95rem;
  color: var(--accent);
  animation: genie-flicker 2.6s ease-in-out infinite;
}
@keyframes genie-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}
.genie.open .genie__tab { display: none; }

/* ─── panel ─── */
.genie__panel {
  /* Absolutely positioned (not in flex flow) while closed, so its
     520px height never pushes the closed .genie__tab up the page —
     .genie is a fixed-height-agnostic wrapper, and this panel is
     only ever meant to overlay from the wrapper's bottom-right. */
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 120px));
  background: var(--bg-card);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: 6px 6px 0 var(--accent-dim);
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(.92) translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.genie.open .genie__panel {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  .genie__panel { transition: opacity 1ms; }
  .genie__tab-glyph { animation: none; }
}

/* ─── panel titlebar ─── */
.genie__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  background: var(--bg-hover);
  flex-shrink: 0;
}
.genie__bar-left { display: flex; align-items: center; gap: 9px; }
.genie__bar-title {
  font-size: .78rem;
  color: var(--text);
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 500;
}
.genie__bar-pips { display: flex; gap: 5px; }
.genie__pip {
  width: 9px; height: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  transition: background 200ms ease, border-color 200ms ease;
}
.genie__pip.spent { background: transparent; border-color: var(--border); }
.genie__bar-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: .9rem;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}
.genie__bar-close:hover { color: #e0725a; }

/* ─── transcript ─── */
.genie__body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: .84rem;
  line-height: 1.55;
}
.genie__line { display: flex; flex-direction: column; gap: 3px; }
.genie__who {
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.genie__line--sys .genie__who { color: var(--text-muted); }
.genie__line--sys .genie__msg { color: var(--text-dim); }
.genie__line--user .genie__who { color: var(--accent-2); }
.genie__line--user .genie__msg { color: var(--text); }
.genie__line--genie .genie__who { color: var(--accent); }
.genie__line--genie .genie__msg { color: var(--text); }
.genie__who::before { content: attr(data-prompt); opacity: .7; margin-right: 6px; }

.genie__msg { white-space: pre-wrap; }
.genie__msg .genie-caret {
  display: inline-block;
  width: 6px; height: 1em;
  background: var(--accent);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: genie-blink 1s steps(1) infinite;
}
@keyframes genie-blink { 50% { opacity: 0; } }

.genie__speak {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .04em;
  padding: 3px 8px;
  cursor: pointer;
  transition: border-color var(--snap), color var(--snap);
}
.genie__speak:hover { border-color: var(--accent-2); color: var(--accent-2); }
.genie__speak.playing { border-color: var(--accent-2); color: var(--accent-2); }
.genie__speak .genie-bars { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 8px; }
.genie__speak .genie-bars i {
  width: 2px; background: currentColor; display: block; font-style: normal;
  animation: none;
}
.genie__speak.playing .genie-bars i { animation: genie-wave 900ms ease-in-out infinite; }
.genie__speak .genie-bars i:nth-child(1) { height: 40%; animation-delay: 0ms; }
.genie__speak .genie-bars i:nth-child(2) { height: 100%; animation-delay: 120ms; }
.genie__speak .genie-bars i:nth-child(3) { height: 65%; animation-delay: 240ms; }
.genie__speak .genie-bars i:nth-child(4) { height: 85%; animation-delay: 360ms; }
@keyframes genie-wave {
  0%, 100% { transform: scaleY(.4); }
  50% { transform: scaleY(1); }
}

/* ─── limit-reached state ─── */
.genie__limit {
  border: 1px dashed var(--border);
  padding: 10px 12px;
  font-size: .78rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.genie__limit a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  align-self: flex-start;
}
.genie__limit a:hover { color: var(--text); border-color: var(--text); }

/* ─── input row ─── */
.genie__inputwrap {
  border-top: 2px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
  background: var(--bg-card);
}
.genie__inputrow {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 10px;
}
.genie__inputrow:focus-within { border-color: var(--accent); }
.genie__prompt-glyph { color: var(--accent); font-size: .84rem; flex-shrink: 0; }
.genie__input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: .84rem;
  min-width: 0;
}
.genie__input::placeholder { color: var(--text-muted); }
.genie__input:disabled { cursor: not-allowed; }
.genie__mic {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .95rem;
  padding: 2px 4px;
  flex-shrink: 0;
  transition: color var(--snap);
}
.genie__mic:hover { color: var(--accent-2); }
.genie__mic:disabled { cursor: not-allowed; opacity: .5; }
.genie__mic.listening { color: #e0725a; animation: genie-pulse 1s ease-in-out infinite; }
@keyframes genie-pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.genie__send {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: .84rem;
  font-family: var(--mono);
  font-weight: 700;
  padding: 2px 4px;
  flex-shrink: 0;
}
.genie__send:hover { color: var(--text); }
.genie__send:disabled { color: var(--border); cursor: not-allowed; }

.genie__foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: .66rem;
  color: var(--text-muted);
  letter-spacing: .03em;
}
.genie__foot b { color: var(--text-dim); }

@media (max-width: 480px) {
  .genie { right: 14px; bottom: 14px; }
  .genie__tab span:not(.genie__tab-glyph):not(.genie__tab-dots) {
    display: none; /* icon + dots only on very small screens */
  }
}
