/* Uno-Minispiel – Besitzer: Uno-Agent. Alle Klassen mit Präfix .mg-uno- */
.mg-uno {
  --mg-uno-ink: var(--c-outline, #1b1b2f);
  --mg-uno-red: #e8383d; --mg-uno-yellow: #f7c51e; --mg-uno-green: #2fa84f; --mg-uno-blue: #2a7de1;
  --mg-uno-cw: 62px;            /* Kartenbreite Hand */
  --mg-uno-tw: 70px;            /* Kartenbreite Tisch */
  position: absolute; inset: 0;
  display: grid; grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr); /* sonst wächst die Spalte mit der Hand über den Bildschirm hinaus */
  padding: var(--safe-top, 0px) var(--safe-right, 0px) var(--safe-bottom, 0px) var(--safe-left, 0px);
  background: radial-gradient(ellipse at 50% 45%, #2f9a5a 0%, #1f7444 55%, #155232 100%);
  color: #fff; font-family: system-ui, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none;
  overflow: hidden;
}
.mg-uno.mg-uno-tablet { --mg-uno-cw: 96px; --mg-uno-tw: 104px; }
:where(.mg-uno) button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

/* ---------- Gegner oben ---------- */
.mg-uno-top { display: flex; align-items: flex-start; justify-content: center; gap: 8px; padding: 4px 8px 0; min-height: 0; }
.mg-uno-opps { display: flex; align-items: center; justify-content: center; gap: 4px; flex-wrap: nowrap; overflow: hidden; }
.mg-uno-opp {
  position: relative; display: flex; flex-direction: column; align-items: center;
  min-width: 58px; padding: 3px 6px 4px; border-radius: 12px;
  background: rgba(0,0,0,.28); border: 3px solid transparent;
}
.mg-uno-opp.turn { border-color: var(--c-gold, #ffd23f); background: rgba(255,210,63,.22); box-shadow: 0 0 12px rgba(255,210,63,.6); }
.mg-uno-opp.done { opacity: .55; }
.mg-uno-opp.off { filter: grayscale(.8); }
.mg-uno-oppchar { line-height: 0; }
.mg-uno-oppchar svg { display: block; }
.mg-uno-oppname { font-size: 11px; font-weight: 700; max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-uno-oppcount, .mg-uno-oppplace {
  position: absolute; top: -4px; right: -6px; min-width: 24px; height: 24px; padding: 0 4px; box-sizing: border-box;
  display: grid; place-items: center; border-radius: 12px; font-weight: 900; font-size: 13px;
  background: #fff; color: var(--mg-uno-ink); border: 3px solid var(--mg-uno-ink);
}
.mg-uno-oppplace { background: var(--c-gold, #ffd23f); }
.mg-uno-oppuno, .mg-uno-oppwarn {
  position: absolute; bottom: 14px; left: -6px; padding: 1px 4px; border-radius: 6px; font-size: 10px; font-weight: 900;
  background: var(--mg-uno-red); border: 2px solid var(--mg-uno-ink); transform: rotate(-12deg);
}
.mg-uno-oppwarn { background: var(--mg-uno-yellow); color: var(--mg-uno-ink); animation: mg-uno-blink .6s infinite alternate; }
.mg-uno-oppoff { font-size: 9px; opacity: .8; }
.mg-uno-oppdir { font-size: 22px; font-weight: 900; opacity: .7; }
.mg-uno-opp.mg-uno-flash { animation: mg-uno-flash .45s ease-out; }
.mg-uno-avatar-fb {
  display: grid; place-items: center; border-radius: 50%; background: var(--c-accent, #ff6b35);
  border: 3px solid var(--mg-uno-ink); font-weight: 900; box-sizing: border-box;
}
.mg-uno-clock {
  position: absolute; top: calc(var(--safe-top, 0px) + 6px); right: calc(var(--safe-right, 0px) + 8px);
  padding: 4px 10px; border-radius: 10px; font-weight: 900; font-variant-numeric: tabular-nums;
  background: rgba(0,0,0,.4); border: 3px solid var(--mg-uno-ink);
}
.mg-uno-clock.low { background: var(--mg-uno-red); }

/* ---------- Mitte ---------- */
.mg-uno-mid { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 0; padding: 0 8px; }
.mg-uno-side { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.mg-uno-table { position: relative; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 6px 26px; }
.mg-uno-dir {
  position: absolute; inset: -6px 0; display: grid; place-items: center; font-size: 150px; line-height: 1;
  color: rgba(255,255,255,.12); pointer-events: none; animation: mg-uno-spin 8s linear infinite;
}
.mg-uno-dir.ccw { animation-direction: reverse; }
.mg-uno-tablet .mg-uno-dir { font-size: 230px; }
.mg-uno-slot { width: var(--mg-uno-tw); aspect-ratio: 2 / 3; position: relative; }
.mg-uno-slot > * { width: 100%; height: 100%; box-sizing: border-box; }
.mg-uno-pile {
  position: relative; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 12px;
  box-shadow: 4px 4px 0 rgba(0,0,0,.35), 7px 7px 0 rgba(0,0,0,.2);
}
.mg-uno-pile:disabled { cursor: default; }
.mg-uno-pile.active { animation: mg-uno-bob 1s ease-in-out infinite; box-shadow: 0 0 0 4px var(--c-gold, #ffd23f), 6px 6px 0 rgba(0,0,0,.35); }
.mg-uno-pilecount {
  position: absolute; bottom: -8px; right: -8px; min-width: 26px; height: 26px; border-radius: 13px; display: grid; place-items: center;
  background: #fff; color: var(--mg-uno-ink); border: 3px solid var(--mg-uno-ink); font-weight: 900; font-size: 12px;
}
.mg-uno-pilehint {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 900; padding: 1px 6px;
  border-radius: 8px; background: var(--c-gold, #ffd23f); color: var(--mg-uno-ink); border: 2px solid var(--mg-uno-ink); display: none;
}
.mg-uno-pile.active .mg-uno-pilehint { display: block; }
.mg-uno-discard { position: relative; }
.mg-uno-discard.mg-uno-pop { animation: mg-uno-pop .35s cubic-bezier(.3,1.6,.5,1); }
.mg-uno-colorbadge {
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); padding: 2px 10px; border-radius: 10px;
  border: 3px solid var(--mg-uno-ink); font-size: 12px; font-weight: 900; white-space: nowrap; color: #fff; text-shadow: 1px 1px 0 var(--mg-uno-ink);
}
.mg-uno-bg-red { background: var(--mg-uno-red); }
.mg-uno-bg-yellow { background: var(--mg-uno-yellow); }
.mg-uno-bg-green { background: var(--mg-uno-green); }
.mg-uno-bg-blue { background: var(--mg-uno-blue); }

/* Zug-Timer-Ring */
.mg-uno-turninfo { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mg-uno-ringbox { position: relative; width: 72px; height: 72px; }
.mg-uno-tablet .mg-uno-ringbox { width: 96px; height: 96px; }
.mg-uno-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.mg-uno-ring circle { fill: rgba(0,0,0,.3); stroke-width: 7; }
.mg-uno-ring .bg { stroke: var(--mg-uno-ink); }
.mg-uno-ring .fg { fill: none; stroke: var(--c-gold, #ffd23f); stroke-linecap: round; }
.mg-uno-ringbox.low .fg { stroke: var(--mg-uno-red); }
.mg-uno-ringface { position: absolute; inset: 0; display: grid; place-items: center; line-height: 0; }
.mg-uno-ringsec {
  position: absolute; right: -6px; bottom: -4px; min-width: 24px; height: 24px; border-radius: 12px; display: grid; place-items: center;
  background: #fff; color: var(--mg-uno-ink); border: 3px solid var(--mg-uno-ink); font-weight: 900; font-size: 12px;
}
.mg-uno-ringbox.low .mg-uno-ringsec { background: var(--mg-uno-red); color: #fff; }
.mg-uno-turnname { font-size: 12px; font-weight: 800; text-align: center; text-shadow: 1px 1px 0 var(--mg-uno-ink); }
.mg-uno-myturn .mg-uno-turnname { color: var(--c-gold, #ffd23f); }

/* Buttons */
.mg-uno-btn {
  min-width: var(--btn-min, 48px); min-height: var(--btn-min, 48px); padding: 6px 14px; border-radius: 14px; cursor: pointer;
  border: 4px solid var(--mg-uno-ink); background: #fff; color: var(--mg-uno-ink) !important; font-weight: 900;
  box-shadow: 0 4px 0 var(--mg-uno-ink); touch-action: manipulation;
}
.mg-uno-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--mg-uno-ink); }
.mg-uno-btn:disabled { opacity: .45; cursor: default; }
.mg-uno-unobtn {
  min-width: 96px; min-height: 56px; font-size: 22px; letter-spacing: 1px; background: var(--mg-uno-red); color: #fff !important;
  text-shadow: 2px 2px 0 var(--mg-uno-ink); transform: rotate(-4deg);
}
.mg-uno-tablet .mg-uno-unobtn { min-width: 130px; min-height: 72px; font-size: 30px; }
.mg-uno-unobtn.pulse { animation: mg-uno-pulse .7s ease-in-out infinite alternate; }
.mg-uno-passbtn { background: var(--c-good, #3ddc84); }
.mg-uno-catches { display: flex; flex-direction: column; gap: 6px; }
.mg-uno-catchbtn {
  background: var(--mg-uno-yellow); display: flex; flex-direction: column; align-items: center; line-height: 1.1;
  animation: mg-uno-wobble .5s ease-in-out infinite alternate;
}
.mg-uno-catchbtn small { font-size: 10px; font-weight: 700; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-uno-actions[hidden], .mg-uno-btn[hidden] { display: none; }

/* ---------- Hand ---------- */
.mg-uno-handbar { position: relative; padding: 0 6px 4px; min-height: 0; min-width: 0; }
.mg-uno-handbar[hidden] { display: none; }
.mg-uno-hand {
  display: flex; gap: 4px; padding: 16px 8px 6px; overflow-x: auto; overflow-y: hidden;
  touch-action: pan-x; overscroll-behavior: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.mg-uno-hand::-webkit-scrollbar { display: none; }
.mg-uno-hand:not(.fan) { justify-content: safe center; }
.mg-uno-hcard {
  flex: 0 0 auto; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 10px;
  transition: transform .15s, filter .15s; touch-action: pan-x;
}
.mg-uno-hcard .mg-uno-slot { width: var(--mg-uno-cw); pointer-events: none; }
.mg-uno-hcard.playable { transform: translateY(-10px); filter: drop-shadow(0 0 6px rgba(255,230,90,.95)); }
.mg-uno-hcard.blocked { filter: brightness(.5) saturate(.6); }
.mg-uno-hcard.idle { filter: brightness(.85); }
.mg-uno-hcard.drawn { animation: mg-uno-bob .9s ease-in-out infinite; }
.mg-uno-hcard.new .mg-uno-slot { animation: mg-uno-in .4s ease-out; }
.mg-uno-hcard.mg-uno-shake { animation: mg-uno-shake .3s; }

/* Tablet: Fächer, alle Karten sichtbar, kein Scrollen */
.mg-uno-hand.fan { position: relative; display: block; overflow: visible; touch-action: none; height: calc(var(--mg-uno-cw) * 1.5 + 44px); padding: 0; }
.mg-uno-hand.fan .mg-uno-hcard { position: absolute; top: 20px; transform: var(--fan); transform-origin: 50% 100%; touch-action: none; }
.mg-uno-hand.fan .mg-uno-hcard.playable { transform: var(--fan) translateY(-18px); }
.mg-uno-hand.fan .mg-uno-hcard.mg-uno-shake, .mg-uno-hand.fan .mg-uno-hcard.drawn { animation: none; }

/* ---------- Fallback-Karten (falls Kit keine unoCardHTML liefert) ---------- */
.mg-uno-fcard {
  position: relative; width: 100%; height: 100%; box-sizing: border-box; border-radius: 10%/7%; overflow: hidden;
  border: 3px solid var(--mg-uno-ink); box-shadow: inset 0 0 0 3px #fff; color: #fff;
  font-weight: 900; text-shadow: 2px 2px 0 var(--mg-uno-ink); container-type: inline-size;
}
.mg-uno-fc-red { background: var(--mg-uno-red); }
.mg-uno-fc-yellow { background: var(--mg-uno-yellow); }
.mg-uno-fc-green { background: var(--mg-uno-green); }
.mg-uno-fc-blue { background: var(--mg-uno-blue); }
.mg-uno-fc-wild, .mg-uno-fc-back { background: #222; }
.mg-uno-fc-oval {
  position: absolute; left: 12%; right: 12%; top: 18%; bottom: 18%; border-radius: 50%; background: #fff; transform: rotate(-28deg);
  display: grid; place-items: center; border: 2px solid var(--mg-uno-ink);
}
.mg-uno-fc-oval b { transform: rotate(28deg); font-size: 42cqi; color: inherit; }
.mg-uno-fc-red .mg-uno-fc-oval b { color: var(--mg-uno-red); }
.mg-uno-fc-yellow .mg-uno-fc-oval b { color: var(--mg-uno-yellow); }
.mg-uno-fc-green .mg-uno-fc-oval b { color: var(--mg-uno-green); }
.mg-uno-fc-blue .mg-uno-fc-oval b { color: var(--mg-uno-blue); }
.mg-uno-fc-rainbow {
  background: conic-gradient(var(--mg-uno-red) 0 25%, var(--mg-uno-yellow) 0 50%, var(--mg-uno-green) 0 75%, var(--mg-uno-blue) 0);
}
.mg-uno-fc-rainbow b { color: #fff !important; }
.mg-uno-fc-back .mg-uno-fc-oval { background: var(--mg-uno-red); }
.mg-uno-fc-back .mg-uno-fc-oval b { color: var(--mg-uno-yellow); font-size: 26cqi; }
.mg-uno-fc-corner { position: absolute; font-size: 22cqi; line-height: 1; }
.mg-uno-fc-corner.tl { top: 6%; left: 9%; }
.mg-uno-fc-corner.br { bottom: 6%; right: 9%; transform: rotate(180deg); }

/* ---------- Banner, Farbwahl, Ende ---------- */
.mg-uno-banner {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none; z-index: 20;
}
.mg-uno-bannermsg {
  padding: 6px 16px; border-radius: 14px; background: #fff; color: var(--mg-uno-ink); border: 4px solid var(--mg-uno-ink);
  font-weight: 900; font-size: 16px; white-space: nowrap; box-shadow: 0 4px 0 var(--mg-uno-ink);
  animation: mg-uno-banner 2.2s ease-out forwards;
}
.mg-uno-bannermsg.uno { background: var(--mg-uno-red); color: #fff; font-size: 24px; text-shadow: 2px 2px 0 var(--mg-uno-ink); }
.mg-uno-bannermsg.bad { background: #ffb3b3; }
.mg-uno-bannermsg.good { background: var(--c-gold, #ffd23f); }
.mg-uno-bannermsg.me { background: var(--c-gold, #ffd23f); }
.mg-uno-bannermsg.col-red { background: var(--mg-uno-red); color: #fff; }
.mg-uno-bannermsg.col-yellow { background: var(--mg-uno-yellow); }
.mg-uno-bannermsg.col-green { background: var(--mg-uno-green); color: #fff; }
.mg-uno-bannermsg.col-blue { background: var(--mg-uno-blue); color: #fff; }

.mg-uno-picker { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(0,0,0,.55); }
.mg-uno-picker[hidden], .mg-uno-over[hidden] { display: none; }
.mg-uno-pickbox {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 18px; border-radius: 18px;
  background: var(--c-panel, #fff4e0); border: 4px solid var(--mg-uno-ink); color: var(--mg-uno-ink);
}
.mg-uno-picktitle { font-weight: 900; font-size: 18px; }
.mg-uno-pickgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.mg-uno-pick {
  width: 84px; height: 84px; border-radius: 18px; border: 4px solid var(--mg-uno-ink); cursor: pointer;
  color: #fff; font-weight: 900; font-size: 15px; text-shadow: 2px 2px 0 var(--mg-uno-ink); box-shadow: 0 5px 0 var(--mg-uno-ink);
}
.mg-uno-pick:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--mg-uno-ink); }
.mg-uno-tablet .mg-uno-pick { width: 120px; height: 120px; font-size: 20px; }
.mg-uno-pick-red { background: var(--mg-uno-red); }
.mg-uno-pick-yellow { background: var(--mg-uno-yellow); }
.mg-uno-pick-green { background: var(--mg-uno-green); }
.mg-uno-pick-blue { background: var(--mg-uno-blue); }

.mg-uno-over { position: absolute; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(0,0,0,.45); }
.mg-uno-overbox {
  min-width: 220px; padding: 14px 20px; border-radius: 18px; background: var(--c-panel, #fff4e0); color: var(--mg-uno-ink);
  border: 4px solid var(--mg-uno-ink);
}
.mg-uno-overtitle { font-weight: 900; font-size: 20px; margin-bottom: 8px; text-align: center; }
.mg-uno-overrow { font-size: 15px; padding: 2px 0; }
.mg-uno-overrow span { color: var(--c-good, #1e9e55); font-weight: 900; }

/* Zuschauer: Tisch ohne Hand */
.mg-uno-spectator { grid-template-rows: auto 1fr; }

/* Niedrige Handy-Höhe */
@media (max-height: 380px) {
  .mg-uno { --mg-uno-cw: 54px; --mg-uno-tw: 58px; }
  .mg-uno-ringbox { width: 60px; height: 60px; }
  .mg-uno-dir { font-size: 120px; }
  .mg-uno-pick { width: 70px; height: 70px; }
}

/* ---------- Animationen ---------- */
@keyframes mg-uno-spin { to { transform: rotate(360deg); } }
@keyframes mg-uno-pop { 0% { transform: scale(1.35) rotate(-10deg); } 100% { transform: none; } }
@keyframes mg-uno-bob { 50% { transform: translateY(-6px); } }
@keyframes mg-uno-in { from { transform: translateY(-40px) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes mg-uno-shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes mg-uno-pulse { from { transform: rotate(-4deg) scale(1); } to { transform: rotate(3deg) scale(1.1); } }
@keyframes mg-uno-wobble { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes mg-uno-blink { to { opacity: .35; } }
@keyframes mg-uno-flash { 0% { transform: scale(1.15); background: rgba(255,255,255,.5); } 100% { transform: none; } }
@keyframes mg-uno-banner { 0% { transform: scale(.4); opacity: 0; } 12% { transform: scale(1.1); opacity: 1; } 20% { transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-16px); } }
