:root {
  --felt-1: #1d6b45;
  --felt-2: #0e3d28;
  --brass: #c9a24b;
  --brass-hi: #ecd48a;
  --ink: #1b1a17;
  --red: #c0302b;
  --panel: rgba(8, 20, 14, 0.82);
  --text: #f0ead6;
  --muted: #a9b8a8;
  --danger: #e0584f;
  --radius: 14px;
  font-family: "Cormorant Garamond", "Palatino Linotype", Palatino, Georgia, serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; touch-action: manipulation; }
body { background: radial-gradient(ellipse at 50% -10%, #1b3a2a 0%, #0b1a12 55%, #050c08 100%) fixed; color: var(--text); font-size: 18px; }
main { max-width: 980px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
h1, h2, h3 { font-weight: 600; margin: 0; letter-spacing: 0.04em; }
button, input { font: inherit; }

/* ------------------------------------------------------------ Bausteine */
.card-panel { background: var(--panel); border: 1px solid rgba(201, 162, 75, 0.35); border-radius: var(--radius); padding: 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
.start { max-width: 460px; margin: 5vh auto 0; text-align: center; }
.logo { font-size: clamp(32px, 8vw, 50px); color: var(--brass-hi); text-shadow: 0 2px 0 #5c4616, 0 0 24px rgba(236, 212, 138, 0.25); }
.sub { color: var(--muted); font-style: italic; margin: 6px 0 18px; }
.stack { display: grid; gap: 12px; text-align: left; }
input[type="text"], input[type="password"] { width: 100%; background: #0b1f15; border: 1px solid rgba(201, 162, 75, 0.45); border-radius: 10px; padding: 11px 14px; color: var(--text); outline: none; }
input:focus { border-color: var(--brass-hi); box-shadow: 0 0 0 2px rgba(236, 212, 138, 0.2); }
.btn { background: linear-gradient(#d9b861, #a98532); color: #1d1505; border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 700; cursor: pointer; box-shadow: 0 2px 0 #5c4616, 0 6px 14px rgba(0, 0, 0, 0.35); white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--brass-hi); border: 1px solid rgba(201, 162, 75, 0.6); box-shadow: none; }
.btn.big { padding: 14px 22px; font-size: 1.05em; }
.btn.small { padding: 6px 12px; font-size: 0.85em; }
.hint { color: var(--muted); font-size: 0.85em; }
.fine { display: block; margin-top: 4px; font-size: 0.8em; opacity: 0.65; }
.legal { margin-top: 16px; color: var(--muted); font-size: 0.8em; }
.legal a { color: var(--muted); }
.formerr { color: var(--danger); margin: 0; }
.langsw { display: inline-flex; gap: 2px; background: rgba(0, 0, 0, 0.45); border-radius: 8px; padding: 2px; vertical-align: middle; }
.langsw button { background: transparent; color: #e8e2d0; border: 0; padding: 4px 9px; border-radius: 6px; font: 600 12px/1 inherit; cursor: pointer; }
.langsw button.on { background: #d9b24c; color: #1b1b1b; }
.authtop { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.net { position: fixed; top: 0; left: 0; right: 0; background: #7a2420; color: #fff; text-align: center; padding: 6px; z-index: 50; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); max-width: 92vw; background: #1b2a22; border: 1px solid var(--brass); color: var(--text); padding: 10px 16px; border-radius: 10px; z-index: 60; text-align: center; }
details.rules { margin-top: 14px; text-align: left; color: var(--muted); font-size: 0.92em; }
details.rules summary { cursor: pointer; color: var(--brass-hi); }
details.rules ul { margin: 8px 0 0; padding-left: 18px; }

/* ----------------------------------------------------------------- Lobby */
.userbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.92em; flex-wrap: wrap; }
.userright { display: inline-flex; align-items: center; gap: 8px; }
.userbar b { color: var(--brass-hi); }
.lobby h2 { margin: 6px 0 4px; color: var(--brass-hi); }
.tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 12px 0; }
.tcard { background: var(--panel); border: 1px solid rgba(201, 162, 75, 0.35); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; }
.tcard h3 { color: var(--brass-hi); font-size: 1.15em; }
.tcard .meta { color: var(--muted); font-size: 0.88em; }
.pips { display: flex; gap: 6px; }
.pip { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(201, 162, 75, 0.6); background: transparent; }
.pip.h { background: var(--brass-hi); }
.pip.b { background: #5b7a68; }
.tcard .row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ----------------------------------------------------------------- Tisch */
.table { max-width: 800px; margin: 0 auto; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.scoreboard { display: flex; gap: 14px; align-items: center; font-size: 0.95em; flex-wrap: wrap; }
.scoreboard .sc { background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(201, 162, 75, 0.35); border-radius: 10px; padding: 4px 12px; }
.scoreboard .sc b { color: var(--brass-hi); font-size: 1.15em; }
.red { color: #ff6a60; }
.felt { position: relative; border-radius: 4px; border: 8px solid #3b2a12; background: radial-gradient(ellipse at 50% 40%, var(--felt-1), var(--felt-2)); box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5), 0 10px 40px rgba(0, 0, 0, 0.5);
  display: grid; grid-template-columns: 1fr minmax(0, 2fr) 1fr; grid-template-rows: auto minmax(110px, 1fr) auto; aspect-ratio: 4 / 3; grid-template-areas: ". top ." "left mid right" "me me me"; gap: 6px; padding: 8px 12px; }
.seat { text-align: center; padding: 6px 8px; border-radius: 12px; background: rgba(0, 0, 0, 0.35); border: 1px solid transparent; align-self: center; justify-self: center; min-width: 0; max-width: 100%; }
.seat.p1 { grid-area: right; } .seat.p2 { grid-area: top; } .seat.p3 { grid-area: left; } .seat.p0 { grid-area: me; justify-self: center; }
.seat .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.seat .sub2 { font-size: 0.78em; color: var(--muted); }
.seat.turn { border-color: var(--brass-hi); box-shadow: 0 0 16px rgba(236, 212, 138, 0.55); }
.seat.team-me .nm { color: var(--brass-hi); }
.seat.empty { opacity: 0.4; }
.crown { color: var(--brass-hi); }
.hk { display: inline-block; background: linear-gradient(#ecd48a, #c9a24b); color: #2a1d04; font-weight: 800; font-size: 0.8em; padding: 1px 9px; border-radius: 3px; letter-spacing: 0.03em; box-shadow: 0 1px 0 #5c4616; }
.seat.hakem { border-color: var(--brass-hi); background: rgba(60, 45, 8, 0.65); }
.seat.hakem.turn { box-shadow: 0 0 16px rgba(236, 212, 138, 0.55); }
.me-wrap.hakem .hand { box-shadow: 0 0 0 2px var(--brass-hi); border-radius: 4px; padding: 10px 8px 4px; background: rgba(236, 212, 138, 0.12); }
.backs { display: flex; justify-content: center; margin-top: 4px; min-height: 22px; }
.backs i { width: 14px; height: 20px; margin-left: -8px; border-radius: 3px; background: repeating-linear-gradient(45deg, #7a2420, #7a2420 3px, #4d1613 3px, #4d1613 6px); border: 1px solid #e6dcc0; }
.backs i:first-child { margin-left: 0; }
.mid { grid-area: mid; position: relative; min-height: 112px; }
.tslot { position: absolute; }
.tslot.p0 { bottom: 0; left: 50%; transform: translateX(-50%); }
.tslot.p2 { top: 0; left: 50%; transform: translateX(-50%); }
.tslot.p3 { left: 4%; top: 50%; transform: translateY(-50%); }
.tslot.p1 { right: 4%; top: 50%; transform: translateY(-50%); }
.tslot.win .card { box-shadow: 0 0 0 3px var(--brass-hi), 0 0 18px rgba(236, 212, 138, 0.8); }
.msgbox { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; padding: 4px; }
.msgbox > div { background: rgba(0, 0, 0, 0.55); border: 1px solid var(--brass); border-radius: 12px; padding: 8px 14px; max-width: 100%; }

.card { position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: 54px; height: 78px; background: #fbf8ee; color: #1b1a17; border: 1px solid #b9b19a; border-radius: 7px; font-weight: 700; font-size: 20px; line-height: 1.05; padding: 0; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); cursor: default; font-family: Georgia, serif; }
.card .sy { font-size: 24px; }
.card.r { color: #c0302b; }
.card.sm { width: 38px; height: 54px; font-size: 15px; }
.card.sm .sy { font-size: 17px; }
.hand { display: flex; justify-content: center; flex-wrap: nowrap; max-width: 100%; margin-top: 4px; padding: 10px 0 0; }
.me-wrap { grid-area: me; display: grid; gap: 6px; justify-items: center; min-width: 0; }
.hand .card { margin-left: -24px; flex: 0 0 auto; align-items: flex-start; padding-left: 6px; transition: transform 0.12s; }
.hand .card:last-child { padding-right: 0; }
.hand .card:first-child { margin-left: 0; }
.hand .card.ok { cursor: pointer; }
.hand .card.ok:hover { transform: translateY(-10px); }
.hand .card.dim { background: #9a9788; color: #3a3a35; }
.hand .card.dim.r { color: #7d3a36; }
.turnbanner { color: var(--brass-hi); font-weight: 700; min-height: 1.4em; text-align: center; }
.hokmtag { display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 3px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--brass); font-weight: 700; font-size: 0.85em; white-space: nowrap; }
.trumppick { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.trumppick .btn { font-size: 1.3em; padding: 8px 16px; }
.log { margin-top: 10px; background: rgba(0, 0, 0, 0.3); border-radius: 10px; padding: 8px 12px; font-size: 0.85em; color: var(--muted); max-height: 120px; overflow: auto; }
.log div:last-child { color: var(--text); }
.botsrow { margin: 6px 0; font-size: 0.9em; color: var(--muted); }

/* ----------------------------------------------------------------- Handy */
@media (max-width: 700px) {
  body { font-size: 16px; }
  main { padding: 8px; }
  .bar { gap: 6px; }
  .scoreboard { order: 3; width: 100%; justify-content: space-between; gap: 6px; font-size: 0.88em; }
  .scoreboard .sc { padding: 3px 8px; flex: 1; text-align: center; }
  .felt { aspect-ratio: auto; padding: 8px 6px 10px; border-width: 5px; border-radius: 3px; grid-template-columns: 1fr 1.5fr 1fr; grid-template-rows: auto minmax(104px, auto) auto; gap: 6px; }
  .card { width: 44px; height: 64px; font-size: 16px; }
  .card .sy { font-size: 19px; }
  .card.sm { width: 40px; height: 58px; font-size: 15px; }
  .card.sm .sy { font-size: 18px; }
  /* Handkarten auf dem Handy: zwei Reihen ohne Überlappung, gut lesbar und treffsicher */
  .hand { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px 4px; width: 100%; padding: 8px 2px 2px; }
  .hand .card, .hand .card:first-child { margin-left: 0; width: 100%; height: auto; aspect-ratio: 5 / 7; align-items: center; padding: 0; font-size: 18px; }
  .hand .card .sy { font-size: 20px; }
  .me-wrap.hakem .hand { padding: 8px 4px 4px; }
  .seat { padding: 4px 6px; }
  .seat .nm { max-width: 86px; font-size: 0.92em; }
  .seat .sub2 { font-size: 0.72em; }
  .seat.p2 { max-width: 80%; }
  .backs i { width: 10px; height: 15px; margin-left: -6px; }
  .mid { min-height: 104px; }
  .turnbanner { font-size: 0.95em; }
}

/* Persisch (rechts nach links): Texte laufen von rechts, der Spieltisch bleibt wie er ist
   (links/rechts-Plätze, Kartenreihenfolge), nur Beschriftungen darin sind RTL. */
html[lang="fa"] body { font-family: Vazirmatn, Tahoma, "Segoe UI", "Geeza Pro", sans-serif; }
html[dir="rtl"] .felt, html[dir="rtl"] .hand, html[dir="rtl"] .langsw { direction: ltr; }
html[dir="rtl"] .felt .seat, html[dir="rtl"] .felt .msgbox, html[dir="rtl"] .felt .turnbanner, html[dir="rtl"] .felt .sub2 { direction: rtl; }
html[dir="rtl"] .hokmtag { margin-left: 0; margin-right: 6px; }
.langsw button[lang="fa"] { font-family: Tahoma, "Geeza Pro", sans-serif; }

/* Feedback-Dialog */
.modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.6); }
.modal[hidden] { display: none; }
.modal form { width: min(520px, 100%); max-height: 100%; overflow: auto; }
.modal h2 { margin: 0; }
.modal textarea { width: 100%; box-sizing: border-box; background: #0b1f15; border: 1px solid rgba(201, 162, 75, 0.45); border-radius: 10px; padding: 11px 14px; color: var(--text); font: inherit; resize: vertical; }
.modal textarea:focus { outline: none; border-color: var(--brass-hi); box-shadow: 0 0 0 2px rgba(236, 212, 138, 0.2); }
.legal a[data-fb] { color: var(--muted); }
.modal .row { display: flex; gap: 10px; flex-wrap: wrap; }
html[dir="rtl"] .stack { text-align: right; }
