/* KARIN character system — identity-safe motion built around the supplied transparent cutout. */
.jh-karin {
  --karin-gold: #e7c77b;
  box-sizing: border-box; display: flex; align-items: center; gap: 8px;
  position: fixed; z-index: 64; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
  width: min(270px, calc(100vw - 24px)); min-height: 0; padding: 6px 8px 7px 5px;
  border: 1px solid rgba(218,180,105,.7); border-radius: 13px;
  color: #fff3d8; font-family: 'Noto Sans KR', sans-serif;
  background: linear-gradient(110deg, rgba(36,23,16,.95), rgba(13,11,12,.96));
  box-shadow: 0 12px 38px rgba(0,0,0,.42), inset 0 1px rgba(255,255,255,.06), 0 0 25px rgba(211,171,90,.08);
  transform-origin: 90% 100%; animation: karin-arrive .56s cubic-bezier(.18,.88,.28,1.12) both;
  contain: layout paint; isolation: isolate;
}
.jh-karin.game-active { position: relative; inset: auto; z-index: 3; width: 100%; min-height: 0; margin: 13px 0 15px; padding: 8px 13px 9px 7px; animation: karin-game-arrive .5s cubic-bezier(.2,.8,.2,1) both; }
.jh-karin.game-active { margin: 5px 0 8px; padding: 5px 8px 6px 5px; border-radius: 12px; }
.jh-karin.karin-inline { position: relative; inset: auto; width: min(100%, 560px); margin: 7px auto 10px; }
.karin-portrait-wrap { width: 78px; flex: 0 0 78px; align-self: stretch; display: flex; align-items: center; justify-content: center; min-height: 96px; overflow: visible; }
.game-active .karin-portrait-wrap { width: 88px; flex-basis: 88px; min-height: 112px; margin: -6px 0 -8px -5px; }
.karin-portrait-stage { position: relative; width: 100%; max-width: 88px; aspect-ratio: 953 / 1299; display: flex; justify-content: center; align-items: flex-end; transform-origin: 50% 38%; filter: drop-shadow(0 5px 9px rgba(0,0,0,.24)); animation: karin-breathe 4.2s ease-in-out infinite; }
.karin-portrait { display: block; width: 100%; height: 100%; max-height: 116px; object-fit: contain; object-position: center bottom; user-select: none; -webkit-user-drag: none; }
/* Tiny eyelid/lip overlays follow the face coordinates of the supplied full-body art. */
.karin-eye,.karin-mouth { position: absolute; z-index: 2; display: block; pointer-events: none; opacity: 0; }
.karin-eye { top: 20.9%; width: 4.3%; height: .8%; border-radius: 0 0 55% 55%; background: linear-gradient(180deg, #d2aca0 0%, #e7c2b0 75%, #b57e78 100%); transform: scaleY(.12); transform-origin: top; }
.karin-eye-left { left: 34.6%; }
.karin-eye-right { left: 41.2%; }
.karin-mouth { left: 39.2%; top: 23.4%; width: 2.8%; height: .55%; border-radius: 50%; background: radial-gradient(ellipse at 50% 35%, #8e5552 0 30%, #bc807a 72%, #d7aaa0 100%); transform: scaleY(.2); transform-origin: center; }
.karin-blink .karin-eye { opacity: .96; animation: karin-blink .17s ease-in-out both; }
.karin-speaking .karin-mouth { opacity: .88; animation: karin-mouth .2s ease-in-out infinite alternate; }
.karin-speaking .karin-portrait-stage { animation: karin-talk 1.8s ease-in-out infinite; }
.karin-dialog { min-width: 0; flex: 1; align-self: center; }
.karin-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.karin-name { color: #f2d58d; font-size: 10px; font-weight: 900; letter-spacing: .13em; white-space: nowrap; }
.karin-name small { display: block; margin-top: 4px; color: #bca77f; font-size: 9px; letter-spacing: 0; font-weight: 600; }
.karin-actions { display: flex; gap: 5px; }
.karin-actions button,.karin-reopen { min-width: 40px; min-height: 36px; padding: 5px 7px; border: 1px solid #92703d; border-radius: 8px; color: #f7e8c4; background: #2a2118; font: 800 10px/1.2 'Noto Sans KR',sans-serif; cursor: pointer; touch-action: manipulation; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.karin-actions button:hover,.karin-reopen:hover { border-color: var(--karin-gold); transform: translateY(-1px); }
.karin-actions button:active,.karin-reopen:active { transform: scale(.97); }
.karin-actions button:focus-visible,.karin-reopen:focus-visible { outline: 2px solid #fff0bc; outline-offset: 2px; }
.karin-copy { display: flex; align-items: center; gap: 7px; min-height: 35px; margin-top: 6px; padding: 6px 8px; border: 1px solid rgba(255,255,255,.035); border-radius: 9px; background: rgba(255,255,255,.065); }
.karin-mood { color: var(--karin-gold); font-size: 18px; line-height: 1; text-shadow: 0 0 10px rgba(236,198,111,.35); }
.karin-copy p { margin: 0; color: #fff4dc; font-size: 11px; font-weight: 800; line-height: 1.4; word-break: keep-all; }
.karin-payout { margin: 5px 2px 0; color: #ffe7a0; font: 900 16px/1.15 'Noto Serif KR','Noto Sans KR',serif; letter-spacing: .025em; font-variant-numeric: tabular-nums; text-shadow: 0 0 17px #e9ba54aa; animation: karin-payout .46s cubic-bezier(.17,.8,.26,1.3) both; }
.karin-payout[hidden] { display: none; }
.jh-karin[data-mood="win"] { border-color: #ffe29a; box-shadow: 0 0 25px rgba(255,211,86,.24), 0 12px 38px rgba(0,0,0,.42), inset 0 1px rgba(255,255,255,.1); }
.jh-karin[data-mood="win"] .karin-mood { color: #ffe17b; text-shadow: 0 0 15px #ffd45e; }
.jh-karin[data-mood="lose"] .karin-mood { color: #bdc7d4; }
.jh-karin[data-mood="bet"] .karin-portrait-stage { animation: karin-react .58s cubic-bezier(.18,.9,.3,1.2) 1, karin-breathe 4.2s .58s ease-in-out infinite; }
.jh-karin[data-mood="waiting"] .karin-portrait-stage { animation: karin-tension 2.2s ease-in-out infinite; }
.jh-karin[data-mood="win"] .karin-portrait-stage { animation: karin-celebrate .62s cubic-bezier(.18,.9,.28,1.2) 2; }
.jh-karin[data-mood="lose"] .karin-portrait-stage { animation: karin-disappoint .7s ease-in-out 1; }
.jh-karin.is-collapsed { width: auto; min-height: 0; padding: 6px; border-radius: 12px; }
.jh-karin.is-collapsed .karin-portrait-wrap,.jh-karin.is-collapsed .karin-dialog { display: none; }
.karin-reopen { display: none; color: #ffe6aa; border-color: #d7b66e; background: #241a10; font-size: 11px; font-weight: 900; }
.jh-karin.is-collapsed .karin-reopen { display: block; }
.jh-karin.karin-exit { animation: karin-exit .25s ease-in both; }

/* Opening the actual game modal adds an understated focus wash; controls and game area remain unobscured. */
.game-modal.karin-game-enter { animation: karin-modal-focus .82s cubic-bezier(.2,.8,.2,1) both; }
#gameDisplay.karin-stage-enter { animation: karin-stage-in .62s cubic-bezier(.2,.8,.2,1) both; }
.game-modal.karin-result-win { box-shadow: 0 28px 100px #000d, 0 0 0 1px #e6c47a33, 0 0 52px rgba(213,169,70,.18); }
.game-modal.karin-result-lose #gameDisplay { animation: karin-stage-loss .72s ease-out both; }
.karin-celebrate-layer { position: fixed; z-index: 63; inset: 0; overflow: hidden; pointer-events: none; contain: strict; }
.karin-coin { position: absolute; left: var(--x); bottom: -24px; color: #ffe19a; font-size: var(--size); font-style: normal; text-shadow: 0 0 9px #f2c451aa; animation: karin-coin-fall 2.2s cubic-bezier(.12,.58,.32,1) var(--delay) both; }

@keyframes karin-arrive { from { opacity: 0; transform: translate3d(0,16px,0) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes karin-game-arrive { from { opacity: 0; transform: translate3d(0,-10px,0) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes karin-exit { to { opacity: 0; transform: translate3d(0,9px,0) scale(.98); } }
@keyframes karin-breathe { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-2px) scale(1.006,1.01); } }
@keyframes karin-talk { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-2px) scale(1.008,1.01); } }
@keyframes karin-mouth { from { transform: scaleY(.18) scaleX(.88); } to { transform: scaleY(1.35) scaleX(1.06); } }
@keyframes karin-blink { 0%,100% { transform: scaleY(.08); } 44%,70% { transform: scaleY(1); } }
@keyframes karin-react { 0% { transform: translateY(0) rotate(0); } 45% { transform: translateY(-5px) rotate(-1deg); } 100% { transform: translateY(0) rotate(0); } }
@keyframes karin-tension { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-1px) rotate(.35deg); } }
@keyframes karin-celebrate { 0%,100% { transform: translateY(0) scale(1); } 45% { transform: translateY(-6px) scale(1.018); } }
@keyframes karin-disappoint { 0%,100% { transform: translateY(0) rotate(0); } 35% { transform: translateY(3px) rotate(.6deg); } }
@keyframes karin-payout { from { opacity: 0; transform: translateY(6px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes karin-modal-focus { 0% { box-shadow: 0 28px 100px #000d; } 35% { box-shadow: 0 28px 100px #000d, 0 0 56px rgba(224,184,99,.22); } 100% { box-shadow: 0 28px 100px #000d, 0 0 30px rgba(224,184,99,.08); } }
@keyframes karin-stage-in { from { opacity: .75; transform: translateY(8px) scale(.992); } to { opacity: 1; transform: none; } }
@keyframes karin-stage-loss { 0% { filter: none; } 45% { filter: saturate(.76) brightness(.88); } 100% { filter: none; } }
@keyframes karin-coin-fall { 0% { opacity: 0; transform: translate3d(0,0,0) rotate(0) scale(.7); } 14% { opacity: .9; } 100% { opacity: 0; transform: translate3d(var(--dx),-82vh,0) rotate(540deg) scale(.42); } }
@media (max-width: 760px) {
  .jh-karin:not(.game-active):not(.karin-inline) { right: 8px; bottom: max(8px,env(safe-area-inset-bottom)); width: min(240px,calc(100vw - 16px)); min-height: 0; gap: 6px; padding: 5px 6px 6px 4px; }
  .jh-karin:not(.game-active):not(.karin-inline) .karin-portrait-wrap { width: 60px; flex-basis: 60px; min-height: 76px; }
  .game-active .karin-portrait-wrap { width: 68px; flex-basis: 68px; min-height: 84px; margin: -4px 0 -5px -3px; }
  .jh-karin.game-active { gap: 6px; padding: 5px 6px 6px 4px; margin: 5px 0 7px; }
  .karin-copy { min-height: 32px; margin-top: 5px; padding: 5px 7px; }
  .karin-copy p { font-size: 10px; }
  .karin-actions button,.karin-reopen { min-height: 40px; min-width: 40px; padding: 5px; }
  .karin-name { font-size: 8px; }
  .karin-name small { font-size: 7px; }
  .karin-payout { font-size: 15px; }
}
@media (max-width: 420px) {
  .jh-karin.game-active { gap: 5px; }
  .game-active .karin-portrait-wrap { width: 58px; flex-basis: 58px; min-height: 72px; }
  .karin-name small { font-size: 7px; }
  .karin-copy { gap: 5px; }
  .karin-copy p { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .jh-karin,.jh-karin *,.jh-karin::before,.jh-karin::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .karin-celebrate-layer { display: none; }
}
