/* XEL HUD + speech — meters, buttons, teach row, lexicon panel, bubbles.
   everything the visitor touches, and everything xel says back. */

/* ================================================================ hud shell */

.hud {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

/* ================================================================ meters */

.hud-meters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.meter {
  --mc: var(--violet);
  background: rgba(22, 13, 52, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  padding: 0.5rem 0.7rem 0.6rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.25s var(--ease-boing), border-color 0.3s, box-shadow 0.3s;
}

.meter[data-stat="hunger"] { --mc: var(--gold); }
.meter[data-stat="mood"]   { --mc: var(--pink); }
.meter[data-stat="chaos"]  { --mc: var(--violet); }
.meter[data-stat="trust"]  { --mc: var(--cyan); }

.meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.35rem;
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
}

.meter-value {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--mc);
  font-variant-numeric: tabular-nums;
}

.meter-track {
  height: 9px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--mc), var(--mc));
  box-shadow: 0 0 10px var(--mc);
  transition: width 0.6s var(--ease-smooth);
}

/* pulse when an action moves a stat */
.meter.pulse-up   { animation: meterPulse 0.55s var(--ease-boing); border-color: var(--seafoam); }
.meter.pulse-down { animation: meterPulse 0.55s var(--ease-boing); border-color: var(--red); }

@keyframes meterPulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.07); }
  100% { transform: scale(1); }
}

/* alarm state: xel is about to write a letter */
.meter.alarm {
  border-color: var(--red);
  animation: meterAlarm 1.1s ease-in-out infinite;
}
.meter.alarm .meter-label { color: var(--red); }
.meter.alarm .meter-fill  { box-shadow: 0 0 14px var(--red); }

@keyframes meterAlarm {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 92, 122, 0); }
  50%      { box-shadow: 0 0 18px rgba(255, 92, 122, 0.5); }
}

/* ================================================================ stage plate */

.stage-plate {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: rgba(22, 13, 52, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  padding: 0.55rem 0.9rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.stage-plate-id {
  display: flex;
  flex-direction: column;
  min-width: 9.5rem;
}

.stage-num {
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
}

.stage-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--seafoam);
  text-shadow: 0 0 14px rgba(125, 249, 224, 0.4);
  white-space: nowrap;
}

.stage-name.evolve-pop { animation: evolvePop 0.8s var(--ease-boing); }

@keyframes evolvePop {
  0%   { transform: scale(0.4) rotate(-6deg); filter: blur(3px); }
  55%  { transform: scale(1.25) rotate(3deg); }
  100% { transform: scale(1) rotate(0); filter: blur(0); }
}

.stage-xp {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.stage-xp-track {
  flex: 1;
  height: 11px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.stage-xp-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--violet), var(--seafoam));
  box-shadow: 0 0 12px rgba(125, 249, 224, 0.45);
  transition: width 0.7s var(--ease-smooth);
}

.stage-xp-track.xp-pulse { animation: meterPulse 0.55s var(--ease-boing); }

/* stage 6: the bar has nowhere left to go. it grooves instead. */
.stage-xp-track.jazzed .stage-xp-fill {
  background: linear-gradient(90deg, var(--gold), var(--pink), var(--gold));
  background-size: 200% 100%;
  animation: jazzShimmer 2.4s linear infinite;
  box-shadow: var(--glow-gold);
}

@keyframes jazzShimmer {
  from { background-position: 0% 0; }
  to   { background-position: 200% 0; }
}

.stage-xp-label {
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stage-xp-label.jazzed {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 214, 107, 0.6);
}

/* ================================================================ action buttons */

.hud-actions {
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.action-btn {
  position: relative;
  overflow: hidden;
  font-size: 1.02rem;
  padding: 0.7rem 1.25rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.a-emoji { font-size: 1.15em; line-height: 1; }

/* cooldown sweep: a light drains off the button for 900ms */
.action-btn.cooling::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.06));
  transform-origin: right;
  animation: coolSweep 0.9s linear forwards;
  pointer-events: none;
}

@keyframes coolSweep {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* the feed ban. tuesdays are legally significant. */
.action-btn.banned {
  background: rgba(255, 92, 122, 0.1);
  border: 1px dashed var(--red);
  color: var(--red);
  opacity: 1;
  animation: bannedThrob 2s ease-in-out infinite;
}

.action-btn.banned .a-label {
  letter-spacing: 0.12em;
  font-weight: 700;
}

@keyframes bannedThrob {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 92, 122, 0); }
  50%      { box-shadow: 0 0 16px rgba(255, 92, 122, 0.35); }
}

/* denied / rejected shake */
.shake { animation: hudShake 0.45s ease; }

@keyframes hudShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-7px) rotate(-1deg); }
  35% { transform: translateX(6px) rotate(1deg); }
  55% { transform: translateX(-4px); }
  75% { transform: translateX(3px); }
}

/* ================================================================ teach-a-word */

.hud-teach {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.teach-input {
  flex: 1;
  max-width: 22rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-pill);
  padding: 0.6rem 1.05rem;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.teach-input:focus {
  outline: none;
  border-color: var(--seafoam);
  box-shadow: var(--glow-seafoam);
}

.teach-input::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

.teach-btn { white-space: nowrap; display: inline-flex; align-items: center; gap: 0.4rem; }

/* ================================================================ word chips */

.word-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  min-height: 0;
}

.word-chip {
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: var(--seafoam);
  background: rgba(125, 249, 224, 0.08);
  border: 1px solid rgba(125, 249, 224, 0.35);
  border-radius: var(--r-pill);
  padding: 0.18rem 0.7rem;
  animation: chipIn 0.4s var(--ease-boing);
}

@keyframes chipIn {
  from { transform: scale(0.3); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ================================================================ utility row */

.hud-utility {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.util-btn {
  font-size: 0.85rem;
  padding: 0.45rem 0.95rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(157, 123, 255, 0.25);
  color: var(--ink-dim);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.util-btn:hover { color: var(--ink); }

/* ================================================================ lexicon panel */

.panel-lexicon .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.panel-lexicon .panel-title {
  font-size: 1.3rem;
  color: var(--ink);
  letter-spacing: 0.03em;
}

.panel-lexicon .panel-close {
  position: relative;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-pill);
  color: var(--ink-dim);
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.2s var(--ease-boing), color 0.2s;
}

/* invisible touch target: the button stays 2rem visually but accepts
   taps in at least a 44x44 area. thumbs have rights. */
.panel-lexicon .panel-close::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100%, 44px);
  height: max(100%, 44px);
  transform: translate(-50%, -50%);
}

.panel-lexicon .panel-close:hover { color: var(--ink); transform: rotate(90deg) scale(1.1); }

.panel-lexicon .panel-sub {
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin: 0 0 1rem;
  line-height: 1.45;
}

.lex-stats {
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  color: var(--violet);
  margin: 0 0 0.7rem;
}

.lex-list { display: flex; flex-direction: column; gap: 0.4rem; }

.lex-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(157, 123, 255, 0.2);
  border-radius: var(--r-sm);
  padding: 0.5rem 0.8rem;
  animation: chipIn 0.35s var(--ease-boing);
}

.lex-word {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--seafoam);
  overflow-wrap: anywhere;
}

.lex-uses {
  font-size: 0.75rem;
  color: var(--ink-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.lex-empty {
  color: var(--ink-dim);
  font-style: italic;
  margin: 1.5rem 0 0.3rem;
  text-align: center;
}

.lex-empty-hint {
  color: var(--ink-faint);
  font-size: 0.85rem;
  text-align: center;
  margin: 0;
}

/* ================================================================ speech bubbles */

.speech-bubble {
  position: relative;
  max-width: min(92vw, 540px);
  background: var(--ink);
  color: var(--bg-deep);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.02rem;
  line-height: 1.4;
  padding: 0.72rem 1.1rem;
  border-radius: 18px;
  margin-bottom: 14px;
  box-shadow: 0 8px 32px rgba(5, 2, 20, 0.55), 0 0 26px rgba(125, 249, 224, 0.18);
  transform-origin: 50% 115%;
  overflow-wrap: anywhere;
}

/* tail: points down at the entity */
.speech-bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 15px;
  height: 15px;
  background: var(--ink);
  border-radius: 3px;
  transform: translateX(-50%) rotate(45deg);
}

.speech-bubble.pop-in  { animation: bubbleIn 0.34s var(--ease-boing); }
.speech-bubble.pop-out { animation: bubbleOut 0.3s ease forwards; }

@keyframes bubbleIn {
  from { transform: scale(0.4) translateY(14px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes bubbleOut {
  to { transform: scale(0.5) translateY(10px); opacity: 0; }
}

/* blinking caret while xel types */
.speech-bubble.typing .speech-text::after {
  content: '▍';
  color: var(--violet);
  animation: caretBlink 0.9s steps(2, jump-none) infinite;
}

@keyframes caretBlink {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* screen-reader-only text */
.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;
}

/* ================================================================ responsive */

@media (max-width: 640px) {
  .hud { gap: 0.55rem; }

  /* meters collapse to a 2x2 grid */
  .hud-meters { grid-template-columns: repeat(2, 1fr); gap: 0.45rem; }

  .stage-plate { flex-direction: column; align-items: stretch; gap: 0.35rem; padding: 0.55rem 0.75rem; }
  .stage-plate-id { flex-direction: row; align-items: baseline; gap: 0.6rem; min-width: 0; }

  /* action buttons wrap into two rows */
  .hud-actions { gap: 0.4rem; }
  .action-btn { flex: 1 1 28%; justify-content: center; padding: 0.6rem 0.6rem; font-size: 0.92rem; }

  .teach-input { max-width: none; }
  .util-btn { flex: 1 1 40%; justify-content: center; }

  .speech-bubble { font-size: 0.94rem; padding: 0.6rem 0.9rem; }
}

/* ================================================================ reduced motion */

@media (prefers-reduced-motion: reduce) {
  .meter.pulse-up, .meter.pulse-down,
  .meter.alarm,
  .stage-xp-track.xp-pulse,
  .stage-name.evolve-pop,
  .action-btn.banned,
  .word-chip,
  .lex-item,
  .shake {
    animation: none;
  }
  .stage-xp-track.jazzed .stage-xp-fill { animation-duration: 8s; }
  .speech-bubble.pop-in  { animation: bubbleFadeIn 0.2s ease; }
  .speech-bubble.pop-out { animation: bubbleFadeOut 0.2s ease forwards; }
  .meter-fill, .stage-xp-fill { transition-duration: 0.1s; }
}

@keyframes bubbleFadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes bubbleFadeOut { to { opacity: 0; } }

/* ================================================================ nickname
   the stage plate honors the given name: "mildred · stage 3 · the legs incident" */

.stage-id-row {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 0;
}

.stage-nick {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--pink);
  text-shadow: 0 0 10px rgba(255, 106, 213, 0.35);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 9rem;
}

.stage-nick::after {
  content: '·';
  margin-left: 0.45rem;
  color: var(--ink-faint);
  text-shadow: none;
}

.stage-nick[hidden] { display: none; }

/* ================================================================ quote chip
   a small corner affordance on speech bubbles: save this line as evidence */

.speech-bubble .quote-chip {
  position: absolute;
  top: -11px;
  right: -11px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  border: 1px solid var(--panel-border);
  background: var(--bg-1);
  color: var(--ink);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;              /* revealed only once typing finishes */
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s, transform 0.2s var(--ease-boing), box-shadow 0.2s;
}

.speech-bubble.quotable .quote-chip { visibility: visible; }

.speech-bubble.quotable:hover .quote-chip,
.speech-bubble.quotable:focus-within .quote-chip,
.speech-bubble.quotable .quote-chip:focus-visible {
  opacity: 1;
  transform: scale(1);
}

.speech-bubble .quote-chip:hover,
.speech-bubble .quote-chip:focus-visible {
  border-color: var(--seafoam);
  box-shadow: var(--glow-seafoam);
}

/* touch screens have no hover: keep the chip faintly present */
@media (hover: none) {
  .speech-bubble.quotable .quote-chip { opacity: 0.6; transform: scale(0.9); }
}

/* ================================================================ share modal
   the frame every status/quote card ships in. sibling of .ach-share-overlay. */

.xshare-overlay {
  position: fixed;
  inset: 0;
  z-index: 88; /* above panels, below toasts and fx — same layer as ach cards */
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(7, 3, 18, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.xshare-overlay.open { opacity: 1; }

.xshare-box {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: min(94vw, 680px);
  padding: 1rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--r-lg);
  box-shadow: var(--glow-seafoam), var(--shadow-pop);
  transform: translateY(16px) scale(0.94);
  transition: transform 0.35s var(--ease-boing);
}

.xshare-overlay.open .xshare-box { transform: none; }

/* square quote cards mustn't overflow short viewports */
.xshare-box.quote { width: min(94vw, 68vh, 560px); }

.xshare-kicker {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  color: var(--seafoam);
}

.xshare-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--r-md);
  border: 1px solid rgba(125, 249, 224, 0.25);
}

.xshare-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.xshare-close { margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  .xshare-overlay,
  .xshare-box,
  .speech-bubble .quote-chip {
    transition-duration: 0.01s;
  }
}
