/* Ape In! — character dialogue and art avatars.
   The dialogue is a cut-in portrait plus a speech box. Desktop: bottom-left above the
   action bar. Phone: just above the turn box, clear of the drawn card. Each character skins the box below. */

.dlg {
  --c: var(--violet); --pw: 210px;
  position: fixed; z-index: 7; left: max(12px, env(safe-area-inset-left, 0px)); bottom: calc(var(--hud-bottom, 180px) + 4px);
  display: flex; align-items: flex-end; pointer-events: none; max-width: min(560px, calc(100vw - 24px));
}
.dlg[hidden] { display: none; }
.dlg-portrait { position: relative; width: var(--pw); height: var(--pw); flex: none; margin-right: -26px; z-index: 1; }
.dlg-portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: bottom; user-select: none; }
.dlg-glow { position: absolute; left: 6%; right: 6%; bottom: 0; height: 70%; border-radius: 50%; background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 60%, transparent), transparent); filter: blur(6px); }

/* cut-out art: fade the cropped bottom edge, glow in the character colour */
.dlg.art .dlg-portrait img {
  /* fade the cropped bottom edge, and the sides where props (e.g. Nifty's brush) leave the frame */
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 2.5%, #000 78%, transparent 100%), linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(180deg, transparent 0, #000 2.5%, #000 78%, transparent 100%), linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
  mask-composite: intersect;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--c) 55%, transparent)) drop-shadow(0 6px 10px rgba(0, 0, 0, .5));
}
/* placeholder: the square portrait in a frame */
.dlg:not(.art) { --pw: 150px; }
.dlg:not(.art) .dlg-portrait { height: calc(var(--pw) * 1.05); margin-right: -14px; margin-bottom: 8px; }
.dlg:not(.art) .dlg-portrait img { inset: auto 0 0 0; height: var(--pw); object-fit: cover; border-radius: 20px; border: 3px solid var(--c); box-shadow: 0 0 26px color-mix(in srgb, var(--c) 55%, transparent), 0 10px 24px rgba(0, 0, 0, .5); }
.dlg:not(.art) .dlg-portrait.mood-sad img { filter: grayscale(.6) brightness(.75); }
.dlg-portrait::after { content: attr(data-badge); position: absolute; right: 18px; top: 4px; font-size: 30px; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .6)); z-index: 2; }

.dlg-box { position: relative; margin-bottom: calc(var(--pw) * .16); min-width: 0; max-width: 320px; display: grid; }
.dlg-plate { grid-area: 1 / 1; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.dlg-plate b { font-size: 15px; }
.dlg-plate span { font-size: 10.5px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; opacity: .8; }
.dlg-text, .dlg-text-ghost { grid-area: 2 / 1; margin: 0; font-size: 17px; line-height: 1.3; }
.dlg-text-ghost { visibility: hidden; }
.dlg-word { display: inline-block; transform: rotate(var(--rot)); white-space: pre; animation: wordIn .25s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes wordIn { from { opacity: 0; transform: rotate(var(--rot)) translateY(8px) scale(.6); } }
.dlg-cursor { display: inline-block; width: .55em; height: 1.05em; vertical-align: -0.15em; margin-left: 2px; background: currentColor; animation: blink .9s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* enter / leave */
.dlg.show .dlg-portrait { animation: dlgRise .45s cubic-bezier(.2, 1.2, .3, 1) both; }
.dlg.show .dlg-box { animation: dlgPop .4s .1s cubic-bezier(.2, 1.5, .4, 1) both; }
.dlg.leave .dlg-portrait { animation: dlgSink .3s ease-in both; }
.dlg.leave .dlg-box { animation: dlgFade .25s ease-in both; }
@keyframes dlgRise { from { opacity: 0; transform: translateY(40px) scale(.9); } }
@keyframes dlgSink { to { opacity: 0; transform: translateY(30px) scale(.95); } }
@keyframes dlgPop { from { opacity: 0; transform: translateX(-16px) scale(.85); } }
@keyframes dlgFade { to { opacity: 0; transform: translateY(6px); } }

/* moods on the cut-in image (the seat-avatar mood glow and motion don't apply to the wrapper) */
.dlg-portrait[class*="mood-"] { animation: none; box-shadow: none; }
.dlg-portrait.mood-happy img { animation: moodHappy .55s ease-out 2; transform-origin: 50% 100%; }
.dlg-portrait.mood-anxious img { animation: moodAnxious .22s linear infinite; }
.dlg-portrait.mood-shocked img { animation: moodShocked .45s cubic-bezier(.2, 1.6, .4, 1) both; transform-origin: 50% 90%; }
.dlg-portrait.mood-smug img { animation: smugTilt .5s ease-out both; transform-origin: 50% 100%; }
.dlg-portrait.mood-sad img { animation: sadSink .6s ease-out both; }
@keyframes smugTilt { to { transform: rotate(4deg); } }
@keyframes sadSink { to { transform: translateY(6px); } }

/* ---- Sandy: warm, bubbly sticker ---- */
.dlg[data-char="sandy"] .dlg-box {
  font-family: 'Fredoka', var(--body); color: #3a1d05; padding: 12px 16px 14px 34px; border-radius: 24px;
  background: linear-gradient(180deg, #fff8ec, #ffe6c7); border: 3px solid #ff9a3c; box-shadow: 0 6px 0 #c2621a, 0 14px 30px rgba(0, 0, 0, .35);
  rotate: -1.5deg;
}
.dlg[data-char="sandy"] .dlg-plate b { font-weight: 700; color: #fff; background: #ff8a1f; padding: 1px 10px; border-radius: 99px; font-size: 14px; }
.dlg[data-char="sandy"] .dlg-plate span { color: #b85a12; }
.dlg[data-char="sandy"] .dlg-text, .dlg[data-char="sandy"] .dlg-text-ghost { font-weight: 600; font-size: 18px; }

/* ---- Aida: black glass, gold hairlines, serif ---- */
.dlg[data-char="aida"] .dlg-box {
  font-family: var(--body); color: #f5ecd8; padding: 14px 18px 16px 34px; border-radius: 6px;
  background: linear-gradient(180deg, rgba(20, 16, 26, .94), rgba(8, 6, 12, .94)); border: 1px solid #d4a74a;
  box-shadow: inset 0 0 0 4px rgba(8, 6, 12, .9), inset 0 0 0 5px rgba(212, 167, 74, .35), 0 16px 34px rgba(0, 0, 0, .5);
}
.dlg[data-char="aida"] .dlg-plate { border-bottom: 1px solid rgba(212, 167, 74, .4); padding-bottom: 6px; margin-bottom: 8px; }
.dlg[data-char="aida"] .dlg-plate b { font-family: 'DM Serif Display', serif; font-weight: 400; font-size: 19px; color: #e9c46a; letter-spacing: .5px; }
.dlg[data-char="aida"] .dlg-plate span { color: #c9b48a; }
.dlg[data-char="aida"] .dlg-text, .dlg[data-char="aida"] .dlg-text-ghost { font-family: 'DM Serif Display', serif; font-size: 19px; font-style: italic; }
.dlg[data-char="aida"].show .dlg-box { animation: aidaIn .5s .1s ease-out both; }
@keyframes aidaIn { from { opacity: 0; transform: translateY(10px); } }

/* ---- Nifty: paint-splashed, wobbly, marker ---- */
.dlg[data-char="nifty"] .dlg-box { margin-right: 18px;
  font-family: 'Permanent Marker', var(--body); color: #14204a; padding: 14px 18px 16px 36px;
  border-radius: 255px 18px 225px 18px / 18px 225px 18px 255px; rotate: 2deg;
  background: linear-gradient(#fff, #f2fbff) padding-box, linear-gradient(120deg, #ff4fd8, #ffd23f, #3ddc84, #4dc9ff, #b77dff) border-box;
  border: 4px solid transparent; box-shadow: 0 14px 30px rgba(0, 0, 0, .4);
}
.dlg[data-char="nifty"] .dlg-box::after { content: ''; position: absolute; right: -20px; top: -22px; width: 34px; height: 34px; border-radius: 50% 40% 55% 45%; background: radial-gradient(circle at 35% 35%, #ffd23f, #ff4fd8); box-shadow: -14px 30px 0 -8px #4dc9ff, 8px 40px 0 -11px #3ddc84; }
.dlg[data-char="nifty"] .dlg-plate b { font-size: 18px; background: linear-gradient(90deg, #ff4fd8, #b77dff, #4dc9ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.dlg[data-char="nifty"] .dlg-plate span { font-family: var(--body); color: #4a5a8a; }
.dlg[data-char="nifty"] .dlg-text, .dlg[data-char="nifty"] .dlg-text-ghost { font-size: 19px; }
.dlg[data-char="nifty"].show .dlg-box { animation: niftyIn .5s .08s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes niftyIn { from { opacity: 0; transform: rotate(-14deg) scale(.5); } }

/* ---- Lana: brass-cased amber terminal (steampunk workshop), cut corners, rivets, mono ---- */
.dlg[data-char="lana"] .dlg-box {
  font-family: 'Share Tech Mono', ui-monospace, monospace; color: #ffc46b; padding: 13px 20px 15px 36px;
  background:
    radial-gradient(circle at 10px 22px, #e9b25a 0 2.5px, #7a4b16 3px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 10px) 10px, #e9b25a 0 2.5px, #7a4b16 3px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 22px) calc(100% - 10px), #e9b25a 0 2.5px, #7a4b16 3px, transparent 3.5px),
    radial-gradient(circle at 10px calc(100% - 10px), #e9b25a 0 2.5px, #7a4b16 3px, transparent 3.5px),
    repeating-linear-gradient(180deg, rgba(255, 170, 60, .06) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, rgba(34, 20, 8, .96), rgba(16, 9, 3, .96));
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  box-shadow: inset 0 0 0 2px #b8812f, inset 0 0 0 4px rgba(16, 9, 3, .96), inset 0 0 0 5px rgba(233, 178, 90, .45), inset 0 0 26px rgba(255, 140, 30, .12);
  filter: drop-shadow(0 0 14px rgba(255, 150, 40, .4));
}
.dlg[data-char="lana"] .dlg-plate b { font-size: 13px; color: #f0b25a; letter-spacing: 1px; text-transform: uppercase; }
.dlg[data-char="lana"] .dlg-plate b::before { content: '◆ '; color: #ff7a1a; }
.dlg[data-char="lana"] .dlg-plate span { color: #b8874a; font-family: inherit; }
.dlg[data-char="lana"] .dlg-text, .dlg[data-char="lana"] .dlg-text-ghost { font-size: 16px; letter-spacing: .3px; }
.dlg[data-char="lana"] .dlg-text { text-shadow: 0 0 8px rgba(255, 150, 40, .55); }
.dlg[data-char="lana"] .dlg-cursor { color: #ff7a1a; box-shadow: 0 0 8px #ff7a1a; }
.dlg[data-char="lana"].show .dlg-box { animation: glitchIn .45s .08s steps(6) both; }
@keyframes glitchIn { 0% { opacity: 0; transform: translateX(-8px); } 20% { opacity: 1; transform: translateX(4px) skewX(8deg); } 40% { opacity: .3; } 60% { opacity: 1; transform: translateX(-2px); } 100% { transform: none; } }

/* ---- En-J1n: slanted, heavy, neon red ---- */
.dlg[data-char="enj1n"] .dlg-box {
  font-family: 'Russo One', var(--display); color: #fff; padding: 12px 20px 14px 38px;
  background: linear-gradient(100deg, #12040a, #1d0610 60%, #2a0812); transform: skewX(-9deg);
  border: 2px solid #ff3b3b; border-left-width: 8px; box-shadow: 0 0 26px rgba(255, 59, 59, .55), 0 14px 30px rgba(0, 0, 0, .5);
}
.dlg[data-char="enj1n"] .dlg-box > * { transform: skewX(9deg); }
.dlg[data-char="enj1n"] .dlg-plate b { color: #ff4d4d; font-size: 15px; letter-spacing: 1.5px; text-transform: uppercase; }
.dlg[data-char="enj1n"] .dlg-plate span { color: #4dff7a; }
.dlg[data-char="enj1n"] .dlg-text, .dlg[data-char="enj1n"] .dlg-text-ghost { font-size: 20px; letter-spacing: .5px; text-shadow: 0 0 12px rgba(255, 59, 59, .6); }
.dlg[data-char="enj1n"].show .dlg-box { animation: slamIn .38s .05s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes slamIn { 0% { opacity: 0; transform: skewX(-9deg) scale(1.6); } 60% { transform: skewX(-9deg) scale(.96) translateX(-4px); } 80% { transform: skewX(-9deg) translateX(3px); } 100% { transform: skewX(-9deg); } }

/* Phones: dialogue sits just above the turn box, over the deck and die, so the drawn card stays visible */
@media (max-width: 700px) {
  .dlg { --pw: 112px; top: auto; bottom: calc(var(--hud-bottom, 180px) + 2px); align-items: flex-end; }
  .dlg:not(.art) { --pw: 84px; }
  .dlg:not(.art) .dlg-portrait { margin-bottom: 0; }
  .dlg-box { margin-bottom: 10px; margin-top: 0; max-width: calc(100vw - var(--pw) - 14px); }
  .dlg-text, .dlg-text-ghost { font-size: 15px !important; }
  .dlg-plate b { font-size: 13px !important; }
  .dlg-plate span { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .dlg.show .dlg-portrait, .dlg.show .dlg-box, .dlg-portrait img { animation: none !important; }
}

/* ===================================================== art avatars ===== */
/* Seats, turn bar and banners zoom into the face of cut-out art on a colour glow. */
.av-clip { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; display: block; }
.av-clip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.has-art { background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--c) 70%, #fff 10%), color-mix(in srgb, var(--c) 25%, #12062a) 75%) !important; }
.has-art .av-clip img { transform: scale(1.75); transform-origin: 50% 22%; }
.mode-card .avatar.art { display: block; position: relative; overflow: hidden; background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--c) 75%, #fff 10%), color-mix(in srgb, var(--c) 20%, #12062a) 80%); }
.mode-card .avatar.art img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.55); transform-origin: 50% 20%; transition: transform .25s; }
.mode-card:hover .avatar.art img { transform: scale(1.7) translateY(2px); }

/* result screen character */
.result-char { --c: var(--violet); width: 160px; height: 160px; margin: -6px auto 0; position: relative; }
.result-char img { width: 100%; height: 100%; object-fit: contain; -webkit-mask-image: linear-gradient(180deg, #000 75%, transparent); mask-image: linear-gradient(180deg, #000 75%, transparent); filter: drop-shadow(0 0 14px color-mix(in srgb, var(--c) 55%, transparent)); }
.result-char.framed { height: 126px; }
.result-char.framed img { object-fit: cover; border-radius: 22px; border: 3px solid var(--c); -webkit-mask-image: none; mask-image: none; width: 120px; height: 120px; margin: 0 auto; display: block; }
.result-quote { font-weight: 700; color: #e6dbff; margin: 6px 0 0; font-style: italic; }
