/* Skyjo – Oberfläche. Dark-Theme im Stil der übrigen jbm-herzwerk-Seiten. */
:root {
  --bg: #0e0e14;
  --panel: #16161f;
  --panel-2: #1e1e2a;
  --line: #2a2a38;
  --text: #e8e8f0;
  --muted: #9a9ab0;
  --accent: #ff6b35;
  --accent-2: #3aa0ff;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);

  /* Kartenwert-Farbcodierung (angelehnt an Skyjo) */
  --c-purple: #8b5cf6; /* -2, -1 */
  --c-blue:   #3b82f6; /* 0 */
  --c-green:  #22c55e; /* 1–4 */
  --c-yellow: #eab308; /* 5–8 */
  --c-red:    #ef4444; /* 9–12 */
}

* { box-sizing: border-box; }
/* Muss VOR den display-Regeln (z. B. .screen{display:flex}) greifen: ein Element
   mit [hidden] bleibt sonst sichtbar und fängt Klicks ab. */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 50% -10%, #1a1a28 0%, var(--bg) 60%);
  color: var(--text);
  font-family: "Barlow", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2 { font-family: "Barlow Semi Condensed", "Barlow", sans-serif; }

.back {
  position: fixed; top: 12px; left: 14px; z-index: 50;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  background: rgba(0, 0, 0, 0.3); padding: 6px 10px; border-radius: 8px;
}
.back:hover { color: var(--text); }

.screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }

/* ---------- Buttons / Felder ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit; font-weight: 600; padding: 11px 18px;
  border-radius: 10px; cursor: pointer; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { background: #262636; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, #ff7d4d, var(--accent)); border-color: #ff6b35; color: #1a0e08; }
.btn-primary:hover { background: linear-gradient(180deg, #ff8a5e, #ff7339); }
.btn-small { padding: 7px 12px; font-size: .9rem; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; text-align: left; }
.field span, .opt span { color: var(--muted); font-size: .85rem; font-weight: 600; }
input, select {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  padding: 11px 12px; border-radius: 10px; font: inherit; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
#input-code { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; }

/* ---------- Home ---------- */
.home-card, .lobby-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; width: min(560px, 100%); text-align: center;
}
.logo {
  font-size: 3rem; letter-spacing: .08em; margin: 0;
  background: linear-gradient(90deg, var(--c-purple), var(--c-blue), var(--c-green), var(--c-yellow), var(--c-red));
  -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 800;
}
.subtitle { color: var(--muted); margin: 4px 0 18px; }
.home-actions { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: stretch; margin-top: 8px; }
.home-block { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.home-block h2 { margin: 0 0 10px; font-size: 1.05rem; }
.home-block .btn { width: 100%; margin-top: 8px; }
.home-sep { align-self: center; color: var(--muted); font-weight: 700; }
.opt { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.error-msg { color: #ff8f8f; margin-top: 14px; min-height: 1em; }

/* ---------- Lobby ---------- */
.code-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 8px 0 14px; }
.code-label { color: var(--muted); font-size: .8rem; text-align: left; }
.code-value { font-family: "Barlow Semi Condensed"; font-size: 2.2rem; font-weight: 800; letter-spacing: .25em; color: var(--accent); }
.opt-row { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 12px; }
.opt-row select { width: auto; }
.player-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.player-list li { display: flex; align-items: center; gap: 10px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.player-list .pl-name { font-weight: 600; flex: 1; text-align: left; }
.badge { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge-host { background: rgba(255,107,53,.18); color: var(--accent); }
.badge-ready { background: rgba(34,197,94,.18); color: var(--c-green); }
.badge-wait { background: rgba(154,154,176,.15); color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; }
.dot.on { background: var(--c-green); box-shadow: 0 0 8px var(--c-green); }
.lobby-controls { display: flex; gap: 10px; justify-content: center; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 10px; min-height: 1em; }

/* ---------- Spiel ---------- */
#screen-game { align-items: stretch; padding: 0; }
.game-wrap { width: 100%; display: flex; flex-direction: column; min-height: 100dvh; }
/* Im Spiel ist „Verlassen" vorhanden – der globale Zurück-Link entfällt (aufgeräumter). */
body.in-game .back { display: none; }
.game-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: rgba(0,0,0,.25); border-bottom: 1px solid var(--line); }
.gb-left, .gb-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.gb-right { justify-content: flex-end; }
.gb-round { color: var(--muted); font-weight: 700; }
.gb-turn { font-weight: 700; font-size: 1.05rem; padding: 6px 14px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.gb-turn.you { background: linear-gradient(180deg, #ff7d4d, var(--accent)); color: #1a0e08; border-color: var(--accent); }

.game-main { flex: 1; display: flex; gap: 16px; padding: 18px; min-height: 0; }
.board { flex: 1; display: flex; flex-direction: column; gap: 18px; min-width: 0;
  align-items: center; justify-content: space-between; }

/* Reihenfolge im Board: eigene Auslage oben, Stapel Mitte, Gegner unten (order). */
.opponents { order: 3; width: 100%; display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.opp { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 150px; transition: box-shadow .2s, border-color .2s; }
.opp.current { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,107,53,.35); }
.opp.offline { opacity: .55; }
.opp-head { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; }
.opp-name { font-weight: 700; font-size: .95rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp-score { color: var(--muted); font-size: .82rem; }

/* Karten-Raster: 4 Spalten × 3 Reihen */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-flow: column; grid-template-rows: repeat(3, auto); gap: 5px; }
.opp .grid { gap: 4px; }

.center-row { order: 2; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
/* Zug-Anzeige sitzt neben den Stapeln; auf schmalen Schirmen bricht sie sauber darüber um. */
.pile-row { width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px; }
.pile-area { display: flex; gap: 24px; align-items: flex-start; justify-content: center;
  background: rgba(255,255,255,.025); border: 1px solid var(--line); border-radius: 16px; padding: 14px 24px; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.pile-label { color: var(--muted); font-size: .78rem; }
/* Restzahl des Nachziehstapels als lesbares Badge unten – überlagert nicht das SKYJO der Rückseite. */
.pile-count { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  background: rgba(0,0,0,.72); color: #fff; font-weight: 800; font-size: .85rem;
  padding: 2px 9px; border-radius: 999px; line-height: 1.25; }
.action-hint { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.action-hint:empty { display: none; }

.self-area { order: 1; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: radial-gradient(130% 100% at 50% 100%, rgba(255,107,53,.07), transparent 70%);
  border-radius: 16px; padding: 8px 0 6px; }
.self-head { display: flex; align-items: center; gap: 10px; }
.self-name { font-weight: 800; font-size: 1.05rem; }
.self-score { color: var(--muted); }
.self-area .grid { gap: 7px; }

/* ---------- Karte ---------- */
.card {
  position: relative; width: 78px; height: 109px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-family: "Barlow Semi Condensed"; font-weight: 800; font-size: 2rem; color: #0c0c10;
  border: 2px solid rgba(0,0,0,.25); user-select: none;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.35);
  transition: transform .18s ease, box-shadow .2s, opacity .35s;
}
.opp .card { width: 44px; height: 62px; font-size: 1.1rem; border-radius: 7px; border-width: 1.5px; }
.pile-card { width: 92px; height: 129px; font-size: 2.1rem; }

.card-back {
  background-image: url('assets/kartenbilder/karte_ruecken.png?v=4');
  background-size: cover; background-position: center;
  color: transparent; border-color: #1c3b1c;
}
/* Aufgedeckte Karte = Bild der Vorderseite (URL wird per JS gesetzt) */
.card.face {
  background-size: cover; background-position: center;
  color: transparent; border-color: rgba(0,0,0,.35);
}
.card.removed { background: transparent !important; border: 2px dashed var(--line); box-shadow: none; color: transparent; }
.card.empty { background: transparent; border: 2px dashed var(--line); box-shadow: none; color: var(--muted); font-size: .8rem; }

/* Wertfarben */
.v-purple { background: linear-gradient(180deg, #a78bfa, var(--c-purple)); }
.v-blue   { background: linear-gradient(180deg, #60a5fa, var(--c-blue)); }
.v-green  { background: linear-gradient(180deg, #4ade80, var(--c-green)); }
.v-yellow { background: linear-gradient(180deg, #fde047, var(--c-yellow)); }
.v-red    { background: linear-gradient(180deg, #f87171, var(--c-red)); }

/* interaktiv hervorheben */
.card.selectable { cursor: pointer; box-shadow: 0 0 0 2px var(--accent-2), 0 2px 6px rgba(0,0,0,.35); animation: pulse 1.2s infinite; }
.card.selectable:hover { transform: translateY(-3px) scale(1.04); }
.pile-card.selectable { animation: pulse 1.2s infinite; cursor: pointer; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 2px var(--accent-2); } 50% { box-shadow: 0 0 0 5px rgba(58,160,255,.25); } }

/* Animationen */
/* Aufdecken: echter 3D-Flip – die Rückseite dreht sichtbar weg, die Vorderseite herein.
   Die Perspektive sitzt am Raster, die Rückseite ist ein um 180° gedrehtes ::after. */
.grid { perspective: 800px; }
.card.flip-in { animation: flipIn .5s cubic-bezier(.45,.05,.25,1); transform-style: preserve-3d; backface-visibility: hidden; }
.card.flip-in::after {
  content: ''; position: absolute; inset: -2px; border-radius: inherit;
  background: url('assets/kartenbilder/karte_ruecken.png?v=4') center/cover;
  backface-visibility: hidden; transform: rotateY(180deg);
}
@keyframes flipIn { 0% { transform: rotateY(180deg); } 100% { transform: rotateY(0deg); } }

/* Frei über das Board fliegende Karten-Abbilder (Spalte weg / vom Stapel ziehen). */
.removal-ghost, .fly-ghost { z-index: 95; border: 2px solid rgba(0,0,0,.3); box-shadow: 0 8px 22px rgba(0,0,0,.55); }
.fly-ghost { z-index: 92; }

.pulse-pile { animation: pilePulse .5s ease; }
@keyframes pilePulse { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* Strafe ×2: rotes Aufblitzen + Zittern. */
.card.penalty-flash { animation: penaltyFlash .6s ease; z-index: 5; }
@keyframes penaltyFlash {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-3px); box-shadow: 0 0 0 3px var(--c-red), 0 0 18px rgba(239,68,68,.75); }
  30%, 60%, 90% { transform: translateX(3px);  box-shadow: 0 0 0 3px var(--c-red), 0 0 18px rgba(239,68,68,.75); }
}

/* Sieg-Konfetti. */
.confetti-layer { position: fixed; inset: 0; z-index: 75; overflow: hidden; pointer-events: none; }
.confetti-piece {
  position: absolute; top: -16px; width: 9px; height: 15px; border-radius: 2px;
  animation-name: confettiFall; animation-timing-function: linear; animation-iteration-count: 1; will-change: transform, opacity;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(108vh) rotate(680deg); opacity: .85; }
}

/* ---------- Drag & Drop (Maus + Finger, Pointer Events) ---------- */
.draggable { cursor: grab; touch-action: none; } /* touch-action:none = Finger zieht statt zu scrollen */
.draggable:active { cursor: grabbing; }
.card.drag-src { opacity: .4; }
.card.drop-ok, .pile-card.drop-ok {
  outline: 3px dashed var(--accent); outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(255,107,53,.25), 0 2px 6px rgba(0,0,0,.35);
}
/* Mitgezogenes Karten-Abbild unter dem Finger/Cursor */
.drag-ghost {
  position: fixed; z-index: 90; pointer-events: none; margin: 0;
  opacity: .92; transform: scale(1.06) rotate(-3deg);
  box-shadow: 0 10px 24px rgba(0,0,0,.5);
}

/* ---------- Logo (animierter Kartenfächer + Shimmer-Schriftzug) ---------- */
@keyframes sl-shimmer { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@keyframes sl-float1 { 0%, 100% { transform: rotate(-18deg) translateY(0); } 50% { transform: rotate(-18deg) translateY(-5px); } }
@keyframes sl-float2 { 0%, 100% { transform: rotate(-6deg) translateY(0); } 50% { transform: rotate(-6deg) translateY(-4px); } }
@keyframes sl-float3 { 0%, 100% { transform: rotate(8deg) translateY(0); } 50% { transform: rotate(8deg) translateY(-6px); } }

.skyjo-logo { display: flex; flex-direction: column; align-items: center; user-select: none; margin: 0 auto 4px; }
.sl-fan { position: relative; width: 184px; height: 112px; margin-bottom: -6px; }
.sl-card { position: absolute; width: 68px; height: 95px; border-radius: 8px; background: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.sl-card::before { content: ''; position: absolute; inset: 4px; border-radius: 4px; background: var(--sl-c); }
.sl-card::after { content: ''; position: absolute; inset: 4px; border-radius: 4px;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.55) 0%, rgba(255,255,255,.18) 38%, transparent 65%); }
.sl-card span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'Abril Fatface', Georgia, serif; font-size: 40px; line-height: 1; z-index: 1;
  -webkit-text-stroke: 3px var(--sl-stroke); paint-order: stroke fill; color: var(--sl-fg); }
.sl-l { left: 8px;  top: 22px; --sl-c: #2e48e0; --sl-fg: #fff;    --sl-stroke: #000; animation: sl-float1 3.4s ease-in-out infinite; }
.sl-m { left: 58px; top: 9px;  --sl-c: #55b038; --sl-fg: #070d04; --sl-stroke: #fff; animation: sl-float2 3.8s ease-in-out infinite; }
.sl-r { left: 108px;top: 18px; --sl-c: #f03232; --sl-fg: #0e0404; --sl-stroke: #fff; animation: sl-float3 3.1s ease-in-out infinite; }

.sl-word {
  font-family: 'Abril Fatface', Georgia, serif; font-weight: 400; line-height: 1;
  font-size: 76px; letter-spacing: 4px;
  background: linear-gradient(110deg, #2e48e0 0%, #38aafc 22%, #55b038 40%, #fad000 58%, #f03232 80%, #a020f0 100%);
  background-size: 200% 200%; -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: sl-shimmer 5s ease-in-out infinite; filter: drop-shadow(0 4px 12px rgba(0,0,0,.35));
}
.sl-tag { font-family: Georgia, serif; font-size: 14px; letter-spacing: 3px; color: var(--muted);
  text-transform: uppercase; font-style: italic; margin-top: 8px; }

/* Kleiner Schriftzug in der Spielleiste (nur Wortmarke, kein Fächer) */
.sl-word-sm { font-size: 24px; letter-spacing: 1px; vertical-align: middle; filter: none; }

/* ---------- Leave / Ergebnis-Button ---------- */
.btn-leave { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-leave:hover { color: #ff8f8f; border-color: #ff8f8f; background: rgba(255,90,90,.08); }
#btn-leave-lobby { margin-top: 14px; }
.btn-show-result {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 65;
}

/* ---------- Chat ---------- */
.chat { width: 280px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; max-height: calc(100dvh - 120px); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 700; }
.chat-head .btn-small { display: none; }
.chat-messages { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { font-size: .9rem; line-height: 1.3; }
.chat-msg .who { font-weight: 700; color: var(--accent-2); }
.chat-msg.system { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }

/* ---------- Overlay ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8,8,12,.78); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.overlay-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; width: min(520px, 100%); text-align: center; }
.overlay-card h2 { margin: 0 0 14px; font-size: 1.6rem; }
.score-table { width: 100%; border-collapse: collapse; margin: 6px 0 14px; }
.score-table th, .score-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.score-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.score-table tr.winner td { color: var(--c-green); font-weight: 700; }
.score-table .pen { color: var(--c-red); font-size: .8rem; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80;
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); }

/* ---------- Responsive / Mobil ---------- */
@media (max-width: 820px) {
  .home-actions { grid-template-columns: 1fr; }
  .home-sep { padding: 4px 0; }
  .game-main { flex-direction: column; }
  .chat {
    position: fixed; right: 10px; bottom: 10px; left: 10px; width: auto;
    z-index: 70; max-height: 50dvh; box-shadow: var(--shadow);
  }
  .chat.collapsed { display: none; }
  .chat-head .btn-small { display: inline-block; }
  /* Tablet: etwas kleiner als Desktop, aber deutlich größer als Handy */
  .card { width: 66px; height: 92px; font-size: 1.7rem; }
  .opp .card { width: 38px; height: 53px; font-size: 1rem; }
  .pile-card { width: 78px; height: 109px; font-size: 1.8rem; }
  .sl-word-sm { font-size: 22px; }
}
/* Handy: kompaktes Format (vom Nutzer als „super" bestätigt) */
@media (max-width: 560px) {
  .card { width: 50px; height: 70px; font-size: 1.3rem; }
  .opp .card { width: 26px; height: 36px; font-size: .8rem; }
  .pile-card { width: 64px; height: 88px; font-size: 1.5rem; }
  .self-area .grid { gap: 5px; }
  .game-main { padding: 12px; gap: 12px; }
  .pile-area { gap: 16px; padding: 12px 16px; }
  .gb-turn { font-size: .9rem; padding: 5px 11px; }
  .sl-word-sm { font-size: 20px; }
  .game-bar { padding: 8px 12px; gap: 8px; }
  /* Home-Logo kompakter auf dem Handy */
  .sl-fan { transform: scale(.82); margin-bottom: -16px; }
  .sl-word { font-size: 60px; }
}
@media (min-width: 821px) {
  #btn-chat-toggle, #btn-chat-close { display: none; }
}
/* Aktions-Buttons sind standardmäßig IMMER da (Ziehen ist Kür, Buttons Pflicht –
   auf manchen Tablets klappt Touch-Drag nicht). Per Schalter (🅰 in der Leiste)
   lassen sie sich ausblenden; der Zustand steckt in localStorage. */
body.hide-actions #action-hint .btn { display: none; }
#btn-toggle-actions.off { opacity: .5; }
