/* Lane A. Tier styling follows the table in docs/PERSONA.md → Rage tiers. */

:root {
  --bg: #fbf6ea;
  --bg-2: #f4ecd8;
  --ink: #2a2420;
  --muted: #7a6f66;
  --karen: #ffffff;
  --user: #e9e0cf;
  --brad: #e3ecf7;
  --accent: #b4574a;
  --edge: transparent;
  --avatar-scale: 1;
  --avatar-tilt: 0deg;
  --shake: 0px;
  font-family: "Georgia", "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  color: var(--ink);
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 60%);
  transition: background 900ms ease;
  box-shadow: inset 0 0 0 0 var(--edge);
  transition: background 900ms ease, box-shadow 900ms ease;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#stage {
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(0, 320px);
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

#flair-wall:empty {
  display: none;
}

@media (max-width: 900px) {
  #stage {
    grid-template-columns: minmax(0, 1fr);
  }
}

#chat {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 72px);
}

#karen-head {
  display: flex;
  align-items: center;
  gap: calc(18px + 56px * (var(--avatar-scale) - 1));
  padding: calc(8px + 40px * (var(--avatar-scale) - 1)) 0 16px calc(56px * (var(--avatar-scale) - 1));
  transition: gap 700ms ease, padding 700ms ease;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

#avatar-wrap {
  width: 112px;
  height: 112px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  transform: scale(var(--avatar-scale)) rotate(var(--avatar-tilt));
  transition: transform 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-origin: 50% 60%;
}

#avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#avatar-wrap.speaking {
  animation: speak 500ms ease-in-out infinite alternate;
}

@keyframes speak {
  from {
    transform: scale(var(--avatar-scale)) rotate(var(--avatar-tilt));
  }
  to {
    transform: scale(calc(var(--avatar-scale) * 1.04)) rotate(calc(var(--avatar-tilt) * -1));
  }
}

#karen-meta h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.02em;
}

#karen-status {
  margin: 4px 0 0;
  color: var(--muted);
  font-style: italic;
  font-size: 15px;
}

#log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 0;
}

.msg {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 17px;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  animation: pop 220ms ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.msg.karen {
  align-self: flex-start;
  background: var(--karen);
  border-bottom-left-radius: 4px;
}

.msg.brad {
  align-self: flex-start;
  background: var(--brad);
  border-bottom-left-radius: 4px;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
  border-bottom-right-radius: 4px;
}

.msg .who {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 4px;
  font-family: "Helvetica Neue", Arial, sans-serif;
}

.msg.typing .text::after {
  content: "▍";
  animation: blink 900ms steps(2) infinite;
  color: var(--muted);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

#composer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding-bottom: 12px;
}

#input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: #fff;
  color: var(--ink);
  outline: none;
}

#input:focus {
  border-color: var(--accent);
}

#input:disabled,
#send:disabled {
  opacity: 0.45;
  filter: grayscale(1);
  cursor: not-allowed;
}

#send {
  font: inherit;
  font-size: 16px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 0;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}

#break-notice {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
}

/* ---- rage tiers -------------------------------------------------------- */

html[data-tier="1"] {
  --bg: #fbeee9;
  --bg-2: #f8e3dc;
}

html[data-tier="2"] {
  --bg: #f7dcd0;
  --bg-2: #f2c9b9;
  --avatar-scale: 1.12;
  --avatar-tilt: -4deg;
}

html[data-tier="3"] {
  --bg: #f2cdbf;
  --bg-2: #eab3a1;
  --edge: rgba(170, 30, 20, 0.35);
  --avatar-scale: 1.2;
  --avatar-tilt: -6deg;
}

html[data-tier="3"] body {
  box-shadow: inset 0 0 120px 20px var(--edge);
}

html[data-tier="4"],
html[data-tier="5"] {
  --bg: #e9b2a3;
  --bg-2: #d98a78;
  --edge: rgba(150, 10, 10, 0.55);
  --avatar-scale: 1.45;
  --avatar-tilt: -8deg;
}

html[data-tier="4"] body,
html[data-tier="5"] body {
  box-shadow: inset 0 0 200px 60px var(--edge);
}

html[data-tier="4"] #avatar-wrap,
html[data-tier="5"] #avatar-wrap {
  border-color: #f3d6cf;
}

/* tier 3: a slight shake on send; tier 4+: the whole screen shakes */
html[data-tier="3"] body.sent {
  animation: shake 320ms ease-in-out 1;
  --shake: 3px;
}

html[data-tier="4"] body,
html[data-tier="5"] body {
  --shake: 5px;
  animation: shake 900ms ease-in-out infinite;
}

html[data-tier="4"] body.sent,
html[data-tier="5"] body.sent {
  --shake: 10px;
  animation: shake 220ms linear infinite;
}

@keyframes shake {
  0% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(calc(var(--shake) * -1), var(--shake));
  }
  40% {
    transform: translate(var(--shake), calc(var(--shake) * -0.5));
  }
  60% {
    transform: translate(calc(var(--shake) * -0.6), calc(var(--shake) * -1));
  }
  80% {
    transform: translate(calc(var(--shake) * 0.7), var(--shake));
  }
  100% {
    transform: translate(0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  body.sent,
  #avatar-wrap.speaking {
    animation: none !important;
  }
}

/* ---- tier 5: the manager ------------------------------------------------ */

#manager-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 40px));
  background: #111418;
  color: #e8ecf1;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  z-index: 50;
  font-family: "Helvetica Neue", Arial, sans-serif;
  animation: ring 700ms ease-out;
}

#manager-panel[hidden] {
  display: none;
}

@keyframes ring {
  0% {
    transform: translateY(40px) scale(0.9);
    opacity: 0;
  }
  60% {
    transform: translateY(-6px) scale(1.02);
    opacity: 1;
  }
  100% {
    transform: none;
  }
}

#call-chrome {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  background: #1b2027;
}

#call-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e3413a;
  box-shadow: 0 0 0 0 rgba(227, 65, 58, 0.6);
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 8px rgba(227, 65, 58, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(227, 65, 58, 0);
  }
}

#call-title {
  flex: 1;
}

#call-timer {
  font-variant-numeric: tabular-nums;
  color: #9aa6b5;
}

#call-faces {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 6px;
  padding: 6px;
}

#call-faces figure {
  margin: 0;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

#call-faces img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: 1;
}

#call-faces figcaption {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
}

#call-faces figure.speaking {
  outline: 3px solid #5ac36d;
  outline-offset: -3px;
}

#call-karen img {
  filter: saturate(1.1);
}

#flair-manager:empty {
  display: none;
}
