* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, 'Segoe UI', Arial, sans-serif;
  background: radial-gradient(ellipse at center, #1d4d2b 0%, #12351e 60%, #0a2413 100%);
  min-height: 100vh;
  color: #eee;
}

.screen { display: none; }
.screen.active { display: block; }

.panel {
  max-width: 560px;
  margin: 6vh auto;
  padding: 26px;
  background: rgba(0, 0, 0, .38);
  border: 1px solid rgba(201, 163, 92, .35);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}

h1 { margin: 0 0 4px; text-align: center; color: #ffd98a; font-size: 28px; }
h2 { margin: 0 0 6px; text-align: center; color: #ffd98a; }
.suit-red { color: #e06262; }
.sub { text-align: center; color: #bbb; margin-bottom: 18px; font-size: 14px; }

.field { margin: 12px 0; }
.field label { display: block; margin-bottom: 4px; color: #ccc; font-size: 14px; }
.field label.chkline { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.field label.chkline input { width: auto; }
input[type=text], select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #666;
  background: #20262e;
  color: #eee;
  font-size: 15px;
}
input[type=text]:focus, select:focus { outline: 2px solid #c99a3e; border-color: transparent; }

button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #c99a3e;
  color: #1a1a1a;
  font-weight: 600;
  cursor: pointer;
  font-size: 15px;
}
button:hover { background: #e0b04e; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.small { padding: 6px 10px; font-size: 13px; margin-top: 6px; }
.btn-secondary { background: #3a6ea5; }
.btn-secondary:hover { background: #4d84bd; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row button { flex: 1; }
.separator { text-align: center; color: #888; margin: 20px 0 6px; font-size: 13px; }

/* ---- Raum-Lobby ---- */
#room-code-big {
  font-size: 38px;
  letter-spacing: 6px;
  color: #ffd98a;
  text-align: center;
  font-weight: 700;
  margin-bottom: 4px;
}
#room-code-big, #btn-copy-code { display: block; margin-left: auto; margin-right: auto; }
#seat-list { list-style: none; padding: 0; margin: 14px 0; }
#seat-list li { padding: 10px 12px; margin: 6px 0; background: rgba(255,255,255,.08); border-radius: 8px; }
#seat-list li .seatp { font-size: 16px; }
#seat-list li.free { opacity: .55; }
.meta { color: #ccc; margin: 8px 0 14px; }
#lwait { color: #ffd98a; margin-top: 10px; }

/* ---- Spieltisch ---- */
#screen-game { max-width: 1700px; margin: 0 auto; padding: 8px 10px 16px; }

#banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, .35);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 15px;
}
.team.t0 b { color: #ff6b6b; }
.team.t1 b { color: #6bb2ff; }
#roundlabel { color: #ffd98a; font-weight: 600; }
#roundcenter { display: flex; align-items: center; gap: 12px; }
#roomcode {
  color: #ffd98a;
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 13px;
  background: rgba(255, 217, 138, .1);
  border: 1px solid rgba(255, 217, 138, .4);
  border-radius: 6px;
  padding: 2px 9px;
}

#turninfo {
  text-align: center;
  padding: 6px 0 10px;
  font-size: 15px;
  color: #cfcfcf;
  min-height: 28px;
}
#turninfo.mine { color: #ffd98a; font-weight: 700; }

#endstatus {
  text-align: center;
  padding: 0 0 8px;
  font-size: 13px;
  color: #9fb0c8;
  min-height: 18px;
}

#pickwrap {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  justify-items: center;
  align-items: center;
  gap: 14px;
  padding: 10px;
}
body.pick #pickwrap { display: grid; }
body.pick #deckwrap, body.pick #pilewrap { display: none; }
.stackback {
  width: 56px;
  height: 80px;
  border-radius: 7px;
  background: linear-gradient(135deg, #4a3f8f, #2f1f5e);
  border: 1px solid #000;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  user-select: none;
}
.stackback .backpips { font-size: 22px; opacity: .85; }
.stackback .stacknum { font-size: 13px; opacity: .7; margin-top: 4px; }
.stackback.clickable { cursor: pointer; box-shadow: 0 0 14px rgba(255, 217, 138, .85); }
.stackback.clickable:hover { box-shadow: 0 0 20px rgba(255, 217, 138, 1); }
.teampool { display: inline-flex; vertical-align: middle; margin-left: 6px; }
.stackback.mini { width: 30px; height: 42px; border-radius: 4px; font-size: 10px; }
.stackback.mini .backpips { font-size: 13px; }
.stackback.mini .stacknum { font-size: 9px; margin-top: 2px; }

#btn-reset {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 6;
}

/* ---- Spielbrett-Modus (Tablet/2. Rechner) ---- */
#boardtag {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 6;
  background: rgba(0, 0, 0, .45);
  border: 1px solid rgba(201, 163, 92, .5);
  color: #ffd98a;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 5px 12px;
  border-radius: 8px;
}
body.board #boardtag { display: block; }
body.board #hand,
body.board #actions,
body.board #log { display: none !important; }
body.board { padding-bottom: 0; }

/* ---- Smartphone-Ansicht (nur eigene Karten) ---- */
#btn-view {
  position: fixed;
  top: 52px;
  right: 10px;
  z-index: 6;
}
body.board #btn-view { display: none; }
#pilecounts {
  display: none;
  text-align: center;
  color: #ddd;
  font-size: 14px;
  padding: 2px 0 4px;
}
body.phone #pilecounts { display: block; }
body.phone #log { display: none !important; }
body.phone .seatwrap { display: none; }
body.phone #deckwrap,
body.phone #pilewrap { display: none; }
body.phone #table { display: block; min-height: 0; }
body.phone .center { display: block; min-height: 0; padding: 4px 0; }
body.phone #hand { min-height: 0; padding: 10px 10px 4px; }
.phhead { color: #ffd98a; font-size: 13px; text-align: center; margin: 6px 0; }
.phmeld {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  padding: 4px 8px;
  margin: 6px auto;
  cursor: pointer;
}
.phmeld.target { outline: 2px solid #ffd98a; background: rgba(255, 217, 138, .15); }
.phlbl { color: #ffd98a; font-size: 13px; }

#table {
  display: grid;
    grid-template-columns: minmax(640px, 800px) 1fr minmax(640px, 800px);
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-height: 760px;
}
#wrap-top    { grid-column: 1 / -1; grid-row: 1; }
#wrap-left   { grid-column: 1; grid-row: 2; }
#wrap-right  { grid-column: 3; grid-row: 2; }
#wrap-bottom { grid-column: 1 / -1; grid-row: 3; }
.center      { grid-column: 2; grid-row: 2; display: flex; align-items: center; justify-content: center; gap: 40px; }

.seatwrap { display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-start; min-height: 0; }
#wrap-left, #wrap-right { justify-content: center; }

.nameplate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(0, 0, 0, .35);
  border-radius: 10px;
  padding: 6px 14px;
  border: 1px solid transparent;
}
.nameplate.active { border-color: #ffd98a; box-shadow: 0 0 14px rgba(255,217,138,.55); }
.nameplate.off { opacity: .55; }
.nameplate .nm { font-weight: 600; }
.nameplate .cnt { font-size: 12px; color: #bbb; }

.melds { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#wrap-left .melds, #wrap-right .melds { gap: 10px; }
.meld {
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 4px;
}
.meld.mine { border-color: rgba(255,217,138,.45); }
.meld.clickable { cursor: pointer; }
.meld.target { outline: 2px solid #ffd98a; background: rgba(255,217,138,.15); }
.meldlabel { font-size: 13px; color: #ffd98a; text-align: center; padding: 1px 2px 3px; }
.cardrow { display: flex; }
#wrap-left .cardrow .card, #wrap-right .cardrow .card { margin-right: -18px; }
#wrap-left .cardrow .card:last-child, #wrap-right .cardrow .card:last-child { margin-right: 0; }

/* ---- Karten ---- */
.card {
  position: relative;
  width: 92px;
  height: 132px;
  border-radius: 10px;
  background: linear-gradient(160deg, #fff, #e8e4da);
  border: 1px solid #9a948a;
  color: #222;
  box-shadow: 1px 2px 4px rgba(0, 0, 0, .4);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
  line-height: 1.1;
}
.card .rank { font-size: 30px; font-weight: 700; }
.card .suit { font-size: 26px; }
.card.suit-H, .card.suit-D { color: #c22; }
.card.suit-S { color: #1d2a44; }
.card.suit-C { color: #14843b; background: linear-gradient(160deg, #f4fbf5, #e4efe3); }
.card.joker { background: linear-gradient(160deg, #8a2a37, #4a0f18); color: #ffd98a; }
.card.selected { transform: translateY(-30px); box-shadow: 0 4px 10px rgba(0,0,0,.55); outline: 2px solid #ffd98a; }
.card.jokersel { outline: 3px solid #ffd700; box-shadow: 0 0 8px rgba(255,215,0,.8); }
.card.clickable { cursor: pointer; }
.card.small { width: 54px; height: 80px; border-radius: 7px; }
.card.small .rank { font-size: 22px; }
.card.small .suit { font-size: 20px; }
.card.small.joker .suit { font-size: 22px; }
.wildsub {
  position: absolute;
  top: -8px;
  right: -5px;
  background: #1a1a1a;
  color: #ffd98a;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  border: 1px solid #ffd98a;
  z-index: 3;
}

/* ---- Karten-Flug-Animationen ---- */
.fly-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 97;
  pointer-events: none;
  margin: 0;
  transform-origin: 0 0;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .6);
}
.back-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 97;
  pointer-events: none;
  width: 44px;
  height: 62px;
  border-radius: 6px;
  background: linear-gradient(135deg, #4a3f8f, #2f1f5e);
  border: 1px solid #000;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .55);
  transform-origin: 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  opacity: .95;
}
.back-ghost::before { content: '♠'; }

/* ---- Deck / Stapel ---- */
#deckwrap, #pilewrap { text-align: center; }
#deck {
  width: 140px;
  height: 190px;
  border-radius: 14px;
  background: repeating-linear-gradient(45deg, #3a5a3a, #3a5a3a 12px, #2f4d2f 12px, #2f4d2f 24px);
  border: 3px solid #c9a35c;
  cursor: default;
  margin: 0 auto;
}
#deck.clickable { cursor: pointer; box-shadow: 0 0 16px rgba(255,217,138,.75); }
#deckcount, #pilecount { color: #ddd; margin-top: 8px; font-size: 15px; }
#pile { min-width: 92px; min-height: 132px; display: flex; align-items: center; justify-content: center; }
#pile.clickable { cursor: pointer; }
#pile.clickable .card { box-shadow: 0 0 14px rgba(255,217,138,.8); }

/* ---- Hand ---- */
#hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: 150px;
  background: rgba(0, 0, 0, .25);
  border-radius: 10px;
  padding: 12px 14px 6px;
  margin-top: 10px;
  overflow-x: auto;
}
#hand .card { cursor: pointer; margin-right: -32px; flex-shrink: 0; }
#hand .card:last-child { margin-right: 0; }

#actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 12px 0 6px;
  flex-wrap: wrap;
  min-height: 58px;
}
#actions .hint { color: #ffd98a; font-size: 13px; }

#log {
  max-height: 110px;
  overflow-y: auto;
  background: rgba(0, 0, 0, .3);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: #ccc;
}
#log div { padding: 1px 0; }

/* ---- Modal ---- */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .62);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#modal.show { display: flex; }
.modalbox {
  background: #203a28;
  border: 1px solid #c9a35c;
  border-radius: 14px;
  padding: 26px 36px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55);
  max-width: 460px;
}
.modalbox h2 { margin-top: 0; }
.modalbox button { margin-top: 14px; }

/* ---- Toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(140px);
  background: #7d1f2b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  z-index: 99;
  transition: transform .25s;
  max-width: 92%;
  text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast:not(.err) { background: #1f5d3a; }

@media (max-width: 900px) {
  #table {
    grid-template-columns: 150px 1fr 150px;
    min-height: 620px;
  }
  .card { width: 56px; height: 80px; }
  .card .rank { font-size: 18px; }
  .card .suit { font-size: 16px; }
  .card.small { width: 36px; height: 52px; }
  .card.small .rank { font-size: 15px; }
  .card.small .suit { font-size: 13px; }
  .stackback { width: 38px; height: 54px; }
  .stackback .backpips { font-size: 16px; }
  .stackback .stacknum { font-size: 11px; }
  #hand .card { margin-right: -30px; }
  #wrap-left .cardrow .card, #wrap-right .cardrow .card { margin-right: -14px; }

  /* Smartphone-Modus: Karten deutlich größer */
  body.phone #hand .card { width: 84px; height: 120px; margin-right: -18px; }
  body.phone #hand .card .rank { font-size: 30px; }
  body.phone #hand .card .suit { font-size: 26px; }
  body.phone #hand .card.selected { transform: translateY(-24px); }
  body.phone .phmeld .card { width: 50px; height: 72px; }
  body.phone .phmeld .card .rank { font-size: 19px; }
  body.phone .phmeld .card .suit { font-size: 17px; }
  body.phone #pickwrap .stackback { width: 64px; height: 92px; }
  body.phone #pickwrap .stackback .backpips { font-size: 22px; }
  body.phone #pickwrap .stackback .stacknum { font-size: 14px; }
}
