/* Messenger: layout, components and animations. Tokens live in theme.css. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
  overflow-x: clip;
  font: var(--text-s)/1.4 var(--font);
  color: var(--ink);
  background-color: var(--sky-mid);
  /* A generic soft sky, a couple of clouds and two rolling hills. */
  background-image:
    radial-gradient(ellipse 70% 34% at 26% 100%, var(--hill-light) 0 58%, rgba(116, 191, 63, 0) 58.4%),
    radial-gradient(ellipse 85% 30% at 82% 100%, var(--hill) 0 60%, rgba(74, 154, 43, 0) 60.3%),
    radial-gradient(ellipse 120% 22% at 50% 100%, var(--hill-far) 0 60%, rgba(61, 132, 36, 0) 60.3%),
    radial-gradient(ellipse 16% 5% at 72% 20%, rgba(255, 255, 255, .85), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 11% 4% at 78% 17%, rgba(255, 255, 255, .7), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 13% 4% at 14% 30%, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 45%, var(--sky-low) 80%);
  background-attachment: fixed;
}

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

button { font: inherit; color: inherit; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- Window ---------- */
.window {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, var(--window-max));
  height: min(var(--window-height), calc(100dvh - 56px));
  min-height: 540px;
  padding: 0 4px 4px;
  background: linear-gradient(90deg, var(--title-deep), var(--title) 3px, var(--title) calc(100% - 3px), var(--title-deep));
  border: 1px solid var(--title-deep);
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  box-shadow: var(--shadow-window);
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  margin: 0 -4px;
  padding: 0 6px 0 6px;
  color: var(--title-ink);
  border-radius: 7px 7px 0 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .28) 0, rgba(255, 255, 255, .06) 45%, rgba(255, 255, 255, 0) 46%),
    linear-gradient(180deg, var(--title-top) 0%, var(--title) 22%, var(--title) 70%, var(--title-deep) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), inset 0 -1px 0 rgba(0, 0, 0, .15);
}
.titlebar :focus-visible { outline-color: #fff; }

.titlebar__icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-s);
  background: none;
  cursor: pointer;
}
.titlebar__icon svg { width: 18px; height: 18px; }

.titlebar__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: var(--text-m);
  font-weight: bold;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 1px 1px 0 var(--title-deep);
}

.room-toggle {
  display: none;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 12px;
  color: #fff;
  font-weight: bold;
  text-shadow: 1px 1px 0 var(--title-deep);
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, .1));
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: var(--radius-s);
  cursor: pointer;
}
.room-toggle:hover { background: linear-gradient(180deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .18)); }

.titlebar__controls { display: flex; gap: 2px; }
.glyph, .room__close {
  position: relative;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: var(--radius-s);
  background: linear-gradient(180deg, #5a9bf5, #2a6fe0 60%, #1d59c8);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
  cursor: pointer;
}
.glyph:hover { filter: brightness(1.12); }
.glyph--close, .room__close { background: linear-gradient(180deg, #ec7a5a, #d8431f 55%, #b8330f); }
.glyph__min { width: 8px; height: 3px; margin-top: 8px; background: #fff; }
.glyph__max { width: 10px; height: 10px; border: 1px solid #fff; border-top-width: 3px; }
.glyph__close { position: relative; width: 12px; height: 12px; }
.glyph__close::before, .glyph__close::after {
  content: '';
  position: absolute;
  left: 5px;
  top: -1px;
  width: 2.5px;
  height: 14px;
  background: #fff;
  border-radius: 1px;
  transform: rotate(45deg);
}
.glyph__close::after { transform: rotate(-45deg); }

/* ---------- Menu bar ---------- */
.menubar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  background: var(--window);
  border-bottom: 1px solid var(--window-shade);
  box-shadow: 0 1px 0 var(--window-light);
}
.menubar__item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 9px;
  font-size: var(--text-s);
  color: var(--ink);
  background: none;
  border: 1px solid transparent;
  border-radius: 0;
  cursor: pointer;
}
.menubar__item:hover { color: #fff; background: var(--menu-hover); }
.menubar__link { margin-left: auto; color: var(--link); text-decoration: underline; text-underline-offset: 2px; }

.check__box {
  position: relative;
  flex: none;
  width: 13px;
  height: 13px;
  background: linear-gradient(135deg, #dcdcd7, #fff);
  border: 1px solid #1c5180;
}
.check[aria-pressed="true"] .check__box::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  width: 4px;
  height: 8px;
  border: solid #21a121;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(40deg);
}

/* ---------- Panes ---------- */
.panes {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--threads-w) minmax(0, 1fr) var(--room-w);
  gap: 6px;
  padding: 6px;
  background: var(--window);
}

.threads, .room {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--pane);
  border: 1px solid var(--pane-border);
}

.pane-title, .pane-subtitle {
  margin: 0;
  padding: 10px 10px 6px;
  font-size: var(--text-s);
  font-weight: bold;
  color: var(--heading);
}
.pane-subtitle { margin-top: 4px; border-top: 1px solid #dbe4ef; }

.me {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px;
  text-align: left;
  background: var(--host-bubble);
  border: 0;
  border-bottom: 1px solid var(--host-edge);
  cursor: pointer;
}
.me:hover { background: #dfeafc; }
.me:focus-visible, .thread:focus-visible { outline-offset: -3px; }
.me .avatar { width: 38px; height: 38px; font-size: 17px; }
.me__text { min-width: 0; }
.me__status { color: var(--muted); }
.me__mood { display: block; overflow: hidden; color: var(--muted); font-style: italic; white-space: nowrap; text-overflow: ellipsis; }

.thread-list { margin: 0; padding: 0 4px 8px; list-style: none; }
.thread-list li + li { margin-top: 2px; }

.thread {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: start;
  gap: 9px;
  width: 100%;
  min-height: var(--hit);
  padding: 8px 6px;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  cursor: pointer;
}
.thread:hover { background: #f1f5fc; border-color: #c9d8ee; }
.thread[aria-current="true"] { background: var(--select); border-color: var(--select-edge); }
.thread .pack-mini { margin-top: 2px; }
.thread__text { display: grid; gap: 1px; min-width: 0; }
.thread__name { font-weight: bold; font-size: var(--text-s); }
.thread__short, .thread__brief { display: none; }
.thread__preview { overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.thread__state { font-size: var(--text-xs); font-weight: bold; color: var(--muted); }
.thread[data-state="sealed"] .thread__state { color: var(--ready); }
.thread[data-state="open"] .thread__state { color: var(--progress); }
.thread__badge {
  align-self: center;
  min-width: 20px;
  padding: 1px 6px;
  font-size: var(--text-xs);
  font-weight: bold;
  line-height: 16px;
  text-align: center;
  color: #fff;
  background: var(--menu-hover);
  border-radius: 9px;
}
.thread__badge--wizz { background: var(--wizz-deep); }

/* A tiny sealed pack: booster color with crimped ends. */
.pack-mini {
  position: relative;
  display: block;
  flex: none;
  width: 26px;
  height: 36px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .22) 0 3px, rgba(255, 255, 255, 0) 3px 7px),
    var(--pack, #888);
  border: 1px solid rgba(0, 0, 0, .45);
  border-radius: 2px;
}
.pack-mini::before, .pack-mini::after {
  content: '';
  position: absolute;
  left: -1px;
  right: -1px;
  height: 5px;
  background: repeating-linear-gradient(90deg, rgba(0, 0, 0, .35) 0 1px, rgba(255, 255, 255, .5) 1px 3px);
}
.pack-mini::before { top: 0; }
.pack-mini::after { bottom: 0; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat__head { display: flex; align-items: center; gap: 9px; padding: 2px 2px 8px; }
.chat__head .pack-mini { width: 18px; height: 25px; }
.chat__to { margin: 0; min-width: 0; font-size: var(--text-s); color: var(--muted); }
.chat__to strong { color: var(--ink); font-size: var(--text-m); }
.chat__no { margin-left: 4px; }

.log {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px 20px;
  background: var(--pane);
  border: 1px solid var(--pane-border);
  container-type: inline-size;
}
.log:focus { outline: none; }

.statusbar {
  min-height: 24px;
  margin: 0;
  padding: 4px 2px;
  overflow: hidden;
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.statusbar.is-typing { color: var(--ink); font-style: italic; }

.composer { border-top: 1px solid var(--window-light); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 0 0 6px; }
.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 38px;
  min-height: 34px;
  padding: 0 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  cursor: pointer;
}
.tool:hover { background: linear-gradient(180deg, #fff, #e6ecf5); border-color: var(--pane-border); }
.tool:active { background: #dfe6f1; }
.tool svg { width: 20px; height: 20px; }
.tool--wizz { font-weight: bold; margin-right: 6px; padding-right: 10px; border-right: 1px solid var(--window-shade); border-radius: 0; }
.tool--wizz:hover { border-radius: var(--radius-s); }
.tool--emoji { font-family: var(--font-emoji); font-size: 18px; line-height: 1; }

.replies { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; background: var(--window-light); border: 1px solid var(--groove); border-radius: var(--radius-s); box-shadow: inset 1px 1px 0 #fff; }

/* ---------- Buttons ---------- */
.btn {
  flex: 0 1 auto;
  min-height: 40px;
  padding: 6px 18px;
  font-size: var(--text-m);
  line-height: 1.2;
  color: var(--ink);
  background: linear-gradient(180deg, var(--button-top) 0%, #f3f2ec 45%, var(--button-bottom) 100%);
  border: 1px solid var(--button-edge);
  border-radius: var(--radius-s);
  box-shadow: inset -1px -1px 0 rgba(0, 0, 0, .1);
  cursor: pointer;
}
.btn:hover { box-shadow: inset 0 0 0 2px var(--button-hover); }
.btn:active { background: linear-gradient(180deg, #e2e0d6, #f4f3ee); }
.btn--primary {
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 0 var(--go-deep);
  background: linear-gradient(180deg, var(--go-top) 0%, var(--go) 55%, var(--go-deep) 100%);
  border-color: var(--go-deep);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 -2px 0 rgba(0, 0, 0, .12);
}
.btn--primary:hover { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 0 0 2px #9be08a; }
.btn--primary:active { background: linear-gradient(180deg, var(--go-deep), var(--go)); }
.btn[aria-disabled="true"] { cursor: progress; filter: grayscale(.55); opacity: .7; }
.btn:focus-visible { outline-width: 3px; }

/* ---------- Messages ---------- */
.msg {
  display: grid;
  grid-template-columns: var(--avatar) minmax(0, 1fr);
  column-gap: 10px;
  margin-top: 16px;
}
.msg:first-child { margin-top: 0; }
.msg--grouped { margin-top: 6px; }
.msg--system { display: block; margin-top: 12px; padding-left: calc(var(--avatar) + 10px); }
.msg__main { min-width: 0; }
.msg__who { margin: 0 0 4px; font-size: var(--text-xs); color: var(--muted); }

.avatar {
  display: grid;
  place-items: center;
  width: var(--avatar);
  height: var(--avatar);
  padding: 2px;
  overflow: hidden;
  font-weight: bold;
  background: #fff;
  border: 1px solid var(--pane-border);
  border-radius: var(--radius-m);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, .08);
}
.avatar svg { width: 100%; height: 100%; }
.avatar--you { color: #fff; background: linear-gradient(180deg, #7aa4ea, #3b6fcf); text-shadow: 1px 1px 0 rgba(0, 0, 0, .25); }
.avatar--room { font-family: var(--font-emoji); font-size: 17px; line-height: 1; background: #f5f3e8; }

.bubble {
  display: inline-block;
  max-width: min(100%, 36em);
  margin: 0;
  padding: 8px 12px;
  font-size: var(--text-m);
  line-height: 1.45;
  overflow-wrap: anywhere;
  border: 1px solid;
  border-radius: 2px var(--radius-l) var(--radius-l) var(--radius-l);
}
.bubble p { margin: 0; }
.bubble p + p { margin-top: 4px; }
.bubble--host { background: var(--host-bubble); border-color: var(--host-edge); }
.bubble--you { background: var(--you-bubble); border-color: var(--you-edge); }
.bubble--emoji { padding: 3px 10px; font-family: var(--font-emoji); font-size: 26px; line-height: 1.25; }
.line { margin: 0; padding-top: 1px; font-size: var(--text-m); line-height: 1.45; overflow-wrap: anywhere; }

.rip { font-size: var(--text-xl); font-weight: bold; font-style: italic; letter-spacing: .02em; }

.system { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--text-s); font-style: italic; color: var(--muted); }
.system svg { flex: none; width: 22px; height: 22px; }
.system--wizz { font-size: var(--text-m); font-style: normal; font-weight: bold; color: var(--system-ink); }
.system--wizz svg { width: 26px; height: 26px; }

/* The sealed pack inside the host's first message. */
.pack {
  position: relative;
  display: block;
  width: var(--pack-w);
  aspect-ratio: 5 / 7;
  margin-top: 10px;
  padding: 0;
  background: none;
  border: 0;
  filter: drop-shadow(2px 3px 0 rgba(27, 27, 27, .22));
}
button.pack { cursor: pointer; }
.pack__body {
  position: absolute;
  inset: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  background:
    linear-gradient(100deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, .28) 42%, rgba(255, 255, 255, 0) 54%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .2) 0 8px, rgba(255, 255, 255, 0) 8px 18px),
    var(--pack);
  border-inline: 1px solid rgba(0, 0, 0, .4);
  transition: transform .15s ease-out;
}
.pack__crimp {
  position: absolute;
  left: 0;
  right: 0;
  height: 13px;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .3) 0 1px, rgba(255, 255, 255, 0) 1px 4px),
    color-mix(in srgb, var(--pack) 70%, #fff);
  border: 1px solid rgba(0, 0, 0, .4);
}
.pack__crimp--top { top: 0; border-radius: 2px 2px 0 0; transition: transform .15s ease-out; }
.pack__crimp--bottom { bottom: 0; border-radius: 0 0 2px 2px; }
.pack__brand { font-size: var(--text-s); font-weight: bold; font-style: italic; color: #fff; text-shadow: 1px 1px 0 rgba(0, 0, 0, .45); }
.pack__name {
  width: 100%;
  padding: 3px 4px;
  font-size: var(--text-s);
  font-weight: bold;
  line-height: 1.15;
  text-align: center;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--ink);
}
.pack__no { padding: 0 4px; font-size: var(--text-xs); font-weight: bold; color: var(--ink); background: rgba(255, 255, 255, .85); }
/* Hover or focus shows where it tears. */
button.pack::after {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  top: 12px;
  border-top: 2px dashed var(--ink);
  opacity: 0;
  transition: opacity .15s;
}
button.pack:hover::after, button.pack:focus-visible::after { opacity: 1; }
button.pack:hover .pack__crimp--top, button.pack:focus-visible .pack__crimp--top { transform: translateY(-3px) rotate(-2deg); }
.pack.is-tearing .pack__crimp--top { animation: rip-off .5s ease-in forwards; }
.pack.is-torn .pack__crimp--top { visibility: hidden; }
.pack.is-torn .pack__body {
  filter: saturate(.75);
  clip-path: polygon(0 6px, 6.25% 0, 12.5% 6px, 18.75% 0, 25% 6px, 31.25% 0, 37.5% 6px, 43.75% 0, 50% 6px, 56.25% 0, 62.5% 6px, 68.75% 0, 75% 6px, 81.25% 0, 87.5% 6px, 93.75% 0, 100% 6px, 100% 100%, 0 100%);
}

/* Face-down cards inside the *rrrip* message. */
.slots { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: var(--slot-w);
  padding: 0;
  background: none;
  border: 0;
  border-radius: var(--radius-m);
  cursor: pointer;
}
.slot__face {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 5 / 7;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .95) 0 15px, rgba(255, 255, 255, 0) 16px),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .16) 0 5px, rgba(255, 255, 255, 0) 5px 10px),
    var(--pack);
  border: 1px solid color-mix(in srgb, var(--pack) 50%, #000);
  border-radius: var(--radius-m);
  box-shadow: inset 0 0 0 4px var(--pack), inset 0 0 0 5px rgba(255, 255, 255, .8), var(--shadow-card);
  transition: transform .15s ease-out, box-shadow .15s;
}
.slot__mark { font-size: 20px; font-weight: bold; font-style: italic; color: color-mix(in srgb, var(--pack) 60%, #000); }
.slot__cap { max-width: 100%; font-size: var(--text-xs); line-height: 1.2; text-align: center; color: var(--muted); overflow-wrap: anywhere; }
.slot:not(.is-up):hover .slot__face { transform: translateY(-3px) rotate(-1.5deg); }
.slot.is-up .slot__face { background: #fff; border: 3px solid var(--card); box-shadow: var(--shadow-card); }
.slot__img { width: 100%; height: 100%; object-fit: cover; }
.slot__img.is-contain { object-fit: contain; padding: 4px; }
.slot.is-up .slot__cap { font-weight: bold; color: var(--ink); }
.slot.is-up:hover .slot__cap { text-decoration: underline; }
.slot.is-up .slot__face { animation: flip-in .35s ease-out; }
.slot.is-pending .slot__face { animation: wobble .3s ease-in-out infinite alternate; }
.slot.is-pending[data-hint="Rare"] .slot__face { box-shadow: inset 0 0 0 4px var(--pack), 0 0 0 3px var(--rare), 0 0 16px 4px rgba(70, 160, 230, .75); }
.slot.is-pending[data-hint="Legendary"] .slot__face {
  box-shadow: inset 0 0 0 4px var(--pack), 0 0 0 3px var(--legendary), 0 0 24px 8px rgba(255, 186, 40, .9);
  animation: wobble .16s ease-in-out infinite alternate;
}

/* A card posted face down: it glows by rarity while it waits, then flips. */
.card-back {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(100%, var(--card-w));
  aspect-ratio: 25 / 32;
  background:
    radial-gradient(circle at 50% 46%, rgba(255, 255, 255, .95) 0 30px, rgba(255, 255, 255, 0) 31px),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .16) 0 8px, rgba(255, 255, 255, 0) 8px 16px),
    var(--pack);
  border: 1px solid color-mix(in srgb, var(--pack) 50%, #000);
  border-radius: var(--radius-l);
  box-shadow: inset 0 0 0 8px var(--pack), inset 0 0 0 10px rgba(255, 255, 255, .85), var(--shadow-card);
  animation: land .25s ease-out;
}
.card-back__mark { font-size: 36px; font-weight: bold; font-style: italic; color: color-mix(in srgb, var(--pack) 60%, #000); }
.card-back__brand { position: absolute; bottom: 22px; font-size: var(--text-s); font-weight: bold; font-style: italic; color: #fff; text-shadow: 1px 1px 0 rgba(0, 0, 0, .4); }
.card-back[data-hint="Rare"] { box-shadow: inset 0 0 0 8px var(--pack), inset 0 0 0 10px rgba(255, 255, 255, .85), 0 0 0 3px var(--rare), 0 0 22px 6px rgba(70, 160, 230, .7); }
.card-back[data-hint="Legendary"] {
  box-shadow: inset 0 0 0 8px var(--pack), inset 0 0 0 10px rgba(255, 255, 255, .85), 0 0 0 4px var(--legendary), 0 0 34px 12px rgba(255, 186, 40, .85);
  animation: land .25s ease-out, rumble .12s .25s linear infinite alternate;
}

/* A revealed card, posted as a rich message. */
.card-msg { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.card {
  position: relative;
  width: min(100%, var(--card-w));
  margin: 0;
  padding: 8px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--card) 45%, #000);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
}
.card--legendary {
  background: linear-gradient(135deg, #ffe7a3 0%, var(--legendary) 38%, #f1b43c 68%, #ffe08a 100%);
  border: 2px solid var(--legendary-deep);
}
.card.is-new { animation: flip-in .45s ease-out; }
.card--legendary.is-new::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, rgba(255, 255, 255, 0) 35%, rgba(255, 255, 255, .75) 50%, rgba(255, 255, 255, 0) 65%);
  transform: translateX(-110%);
  animation: sheen 1.1s .35s ease-out forwards;
  pointer-events: none;
}
.card__name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  font-size: var(--text-l);
  background: #fff;
  border: 1px solid color-mix(in srgb, var(--card) 45%, #000);
  border-radius: var(--radius-s);
}
.card__art {
  margin-top: 6px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #fff;
  border: 1px solid color-mix(in srgb, var(--card) 45%, #000);
}
.card__img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card__img.is-contain { object-fit: contain; padding: 10px; }
.card__meta { display: flex; justify-content: space-between; gap: 8px; margin: 6px 2px 0; font-size: var(--text-s); }
.card__rarity { font-weight: bold; }
.card__flavor { margin: 6px 0 0; padding: 6px 8px; font-size: var(--text-s); font-style: italic; line-height: 1.4; background: rgba(255, 255, 255, .72); border-radius: var(--radius-s); }

.reactions { display: flex; flex-wrap: wrap; gap: 6px; }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 48px;
  min-height: 34px;
  padding: 0 10px;
  font-size: var(--text-s);
  font-weight: bold;
  background: linear-gradient(180deg, #fff, #eef2f8);
  border: 1px solid var(--pane-border);
  border-radius: var(--radius-m);
  cursor: pointer;
}
.reaction:hover { border-color: var(--focus); }
.reaction[aria-pressed="true"] { background: var(--select); border-color: var(--focus); box-shadow: inset 0 0 0 1px var(--focus); }
.reaction__count:empty { display: none; }
.reaction__emoji { font-family: var(--font-emoji); font-size: 16px; line-height: 1; }
.reaction.is-bumped .reaction__count { animation: bump .4s ease-out; }

.strip { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0 2px; padding: 0; list-style: none; }
.strip__item { display: flex; flex-direction: column; gap: 2px; width: 92px; font-size: var(--text-xs); line-height: 1.2; overflow-wrap: break-word; }
.strip__img { width: 100%; aspect-ratio: 1; margin-bottom: 3px; object-fit: cover; background: #fff; border: 3px solid var(--card); border-radius: var(--radius-m); }
.strip__img.is-contain { object-fit: contain; padding: 4px; }
.strip__name { font-weight: bold; }
.strip__rarity { color: var(--muted); }

.msg.is-flash .card { animation: flash-ring 1s ease-out; }

/* ---------- Room ---------- */
.room__bar { display: flex; align-items: center; justify-content: space-between; }
.room__close { display: none; margin-right: 6px; }
.people { margin: 0; padding: 0 6px 8px; list-style: none; }
.person { display: grid; grid-template-columns: var(--avatar) minmax(0, 1fr); gap: 8px; align-items: start; padding: 6px 4px; border-radius: var(--radius-s); }
.person__text { display: grid; gap: 1px; min-width: 0; }
.person__name { display: flex; align-items: center; gap: 6px; }
.person__line { color: var(--muted); overflow-wrap: anywhere; }
.person.is-fresh { animation: flash-bg 1.4s ease-out; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--online); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2), 0 0 0 1px rgba(0, 0, 0, .3); }
.dot--away { background: var(--away); }
.room-toggle .dot { box-shadow: 0 0 0 1px #fff; }

.pulls { margin: 0; padding: 0 6px 10px; list-style: none; }
.pull { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 8px; align-items: center; padding: 5px 4px; border-radius: var(--radius-s); }
.pull__img { width: 34px; height: 34px; object-fit: cover; background: #fff; border: 2px solid var(--card); border-radius: var(--radius-s); }
.pull__img.is-contain { object-fit: contain; padding: 2px; }
.pull__text { min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.pull__rarity { display: block; font-size: var(--text-xs); color: var(--muted); }
.pull--you { background: var(--you-bubble); }
.pull.is-fresh { animation: flash-bg 1.4s ease-out; }

.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(8, 40, 110, .35); }

/* ---------- Toast: an old-school sign-in popup ---------- */
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  width: 290px;
  max-width: calc(100vw - 24px);
  padding: 34px 14px 14px;
  font-size: var(--text-s);
  color: var(--ink);
  background: linear-gradient(180deg, #fff, var(--host-bubble));
  border: 1px solid var(--title-deep);
  border-radius: var(--radius-l) var(--radius-l) var(--radius-s) var(--radius-s);
  box-shadow: 0 8px 24px rgba(8, 40, 110, .35);
  animation: toast-in .3s ease-out;
}
.toast::before {
  content: 'Bouzopp Messenger';
  content: 'Bouzopp Messenger' / '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: bold;
  color: #fff;
  background: linear-gradient(180deg, var(--title-top), var(--title) 50%, var(--title-deep));
  border-radius: 7px 7px 0 0;
}

/* ---------- The Wizz ---------- */
.window.is-wizz { --amp: 13px; animation: wizz .9s linear; }
.window.is-nudge { --amp: 6px; animation: wizz .45s linear; }
.window.is-wizz .titlebar { animation: title-flash 1.1s steps(1, end); }

@keyframes wizz {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(calc(var(--amp) * -1), calc(var(--amp) * .3)); }
  20% { transform: translate(var(--amp), calc(var(--amp) * -.4)); }
  30% { transform: translate(calc(var(--amp) * -.9), calc(var(--amp) * -.2)); }
  40% { transform: translate(calc(var(--amp) * .8), calc(var(--amp) * .4)); }
  50% { transform: translate(calc(var(--amp) * -.7), calc(var(--amp) * .2)); }
  60% { transform: translate(calc(var(--amp) * .6), calc(var(--amp) * -.3)); }
  70% { transform: translate(calc(var(--amp) * -.4), calc(var(--amp) * .1)); }
  80% { transform: translate(calc(var(--amp) * .3), calc(var(--amp) * -.1)); }
  90% { transform: translate(calc(var(--amp) * -.1), 0); }
}
@keyframes title-flash {
  0%, 40%, 80% { background: linear-gradient(180deg, #ffd27a 0%, var(--wizz) 30%, var(--wizz) 70%, var(--wizz-deep) 100%); }
  32%, 72%, 100% { background: linear-gradient(180deg, var(--title-top) 0%, var(--title) 22%, var(--title) 70%, var(--title-deep) 100%); }
}
@keyframes rip-off {
  0% { transform: none; opacity: 1; }
  35% { transform: translate(2px, -4px) rotate(-3deg); opacity: 1; }
  100% { transform: translate(26px, -26px) rotate(18deg); opacity: 0; }
}
@keyframes flip-in {
  from { transform: perspective(700px) rotateY(75deg); }
  to { transform: none; }
}
@keyframes sheen { to { transform: translateX(110%); } }
@keyframes land {
  from { transform: translateY(-10px) rotate(-3deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes rumble {
  from { transform: rotate(-1.2deg) translate(-1px, 0); }
  to { transform: rotate(1.2deg) translate(1px, -1px); }
}
@keyframes wobble {
  from { transform: rotate(-2deg) translateY(-2px); }
  to { transform: rotate(2deg) translateY(-2px); }
}
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.6); color: var(--wizz-deep); }
  100% { transform: scale(1); }
}
@keyframes flash-bg {
  0% { background-color: #ffe9a8; }
  100% { background-color: rgba(255, 233, 168, 0); }
}
@keyframes flash-ring {
  0% { box-shadow: 0 0 0 4px var(--focus); }
  100% { box-shadow: 0 0 0 4px rgba(10, 95, 216, 0); }
}
@keyframes toast-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.reaction__count { display: inline-block; }

/* The explicit Animations control switches every animation and transition off. */
.motion-off *, .motion-off *::before, .motion-off *::after { animation: none !important; transition: none !important; }

/* ---------- Tablet: the room moves into a sheet ---------- */
@media (max-width: 1099px) {
  .panes { grid-template-columns: var(--threads-w) minmax(0, 1fr); }
  .room { display: none; }
  .room-toggle { display: inline-flex; }
  .room__close { display: grid; }
  .sheet-open .room {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 40;
    display: flex;
    width: min(340px, calc(100vw - 32px));
    max-height: min(600px, calc(100dvh - 96px));
    border: 1px solid var(--title-deep);
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    box-shadow: var(--shadow-window);
  }
  .sheet-open .room__bar {
    position: sticky;
    top: 0;
    z-index: 1;
    min-height: 34px;
    color: #fff;
    background: linear-gradient(180deg, var(--title-top) 0%, var(--title) 22%, var(--title) 70%, var(--title-deep) 100%);
    border-radius: 7px 7px 0 0;
  }
  .sheet-open .room__bar .pane-title { color: #fff; text-shadow: 1px 1px 0 var(--title-deep); }
  .sheet-open .room__bar :focus-visible { outline-color: #fff; }
  .toast { top: 16px; bottom: auto; }
}

@media (max-width: 900px) {
  :root { --threads-w: 212px; }
}

/* ---------- Phone: one pane, tabs on top, replies in the thumb zone ---------- */
@media (max-width: 759px) {
  :root { --text-xs: 13px; --avatar: 28px; --card-w: 264px; --slot-w: 82px; --pack-w: 124px; }

  body { display: block; padding: 0; }
  .window {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .titlebar {
    min-height: 48px;
    margin: 0;
    padding: env(safe-area-inset-top) 6px 0 2px;
    border-radius: 0;
  }
  .titlebar__icon { width: 44px; height: 44px; }
  .titlebar__icon svg { width: 22px; height: 22px; }
  .titlebar__title { font-size: var(--text-l); }
  .titlebar__controls { display: none; }
  .room-toggle { min-height: 36px; position: relative; }
  .room-toggle::after { content: ''; position: absolute; inset: -5px -2px; }

  .menubar { padding: 0 4px; gap: 0; }
  .menubar__item { min-height: var(--hit); padding: 0 10px; }
  .menubar__item--nav { display: none; }

  .panes { display: flex; flex-direction: column; gap: 0; padding: 0; }

  .threads { flex: none; overflow: visible; background: var(--window); border: 0; border-bottom: 1px solid var(--pane-border); }
  .me { display: none; }
  #threadsTitle { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .thread-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 6px 6px 0; }
  .thread-list li + li { margin-top: 0; }
  .thread {
    position: relative;
    grid-template-columns: 12px minmax(0, 1fr);
    gap: 7px;
    min-height: 52px;
    height: 100%;
    padding: 7px 7px 6px;
    background: linear-gradient(180deg, #fff, #ebe8dc);
    border: 1px solid var(--pane-border);
    border-bottom: 0;
    border-radius: var(--radius-m) var(--radius-m) 0 0;
  }
  .thread:hover { background: linear-gradient(180deg, #fff, #f2f0e8); border-color: var(--pane-border); }
  .thread[aria-current="true"] {
    z-index: 1;
    margin-bottom: -1px;
    padding-bottom: 7px;
    background: var(--pane);
    border-color: var(--pane-border);
    box-shadow: inset 0 3px 0 var(--wizz);
  }
  .thread .pack-mini { width: 12px; height: 17px; margin-top: 1px; }
  .thread .pack-mini::before, .thread .pack-mini::after { height: 3px; }
  .thread__name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .thread__full, .thread__preview, .thread__long { display: none; }
  .thread__short, .thread__brief { display: inline; }
  .thread__state { font-size: var(--text-xs); }
  .thread__badge { position: absolute; top: -6px; right: -2px; }

  .chat { flex: 1; }
  .chat__head { display: none; }
  .log { padding: 14px 12px 18px; border: 0; }
  .statusbar { padding: 4px 12px; background: var(--pane); border-bottom: 1px solid var(--window-shade); }
  .composer { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); border-top: 0; }
  .toolbar { gap: 0; padding-bottom: 6px; }
  .tool { min-width: var(--hit); min-height: var(--hit); }
  .tool--emoji { font-size: 20px; }
  .replies { padding: 6px; gap: 6px; }
  .btn { flex: 0 0 auto; min-height: 48px; padding: 6px 14px; white-space: nowrap; }
  .btn--primary { flex: 1 1 0; min-width: 0; white-space: normal; }
  .reaction { min-height: var(--hit); min-width: 54px; justify-content: center; }

  .room { display: none; }
  .sheet-open .room {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 78dvh;
    padding-bottom: env(safe-area-inset-bottom);
    border-width: 1px 0 0;
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    box-shadow: var(--shadow-sheet);
  }
  .sheet-open .room__bar { min-height: 48px; padding-left: 4px; }
  .room__close { width: var(--hit); height: 36px; }

  .toast { top: calc(4px + env(safe-area-inset-top)); right: 8px; left: 8px; bottom: auto; width: auto; padding: 30px 12px 10px; }
}

@media (max-width: 359px) {
  .menubar__item { padding: 0 7px; }
  .tool { min-width: 40px; }
}
