:root {
  --felt: #0E4D3A;
  --felt-2: #13614A;
  --felt-dark: #093527;
  --paper: #FFFDF7;
  --cream: #F4EEDF;
  --ink: #1B1F24;
  --muted: #667066;
  --gold: #F5C542;
  --gold-dark: #C99A1C;
  --red: #D23A3A;
  --blue: #2F6FDB;
  --display: 'Secular One', 'Assistant', 'Arial Hebrew', sans-serif;
  --body: 'Assistant', 'Segoe UI', 'Arial Hebrew', Arial, sans-serif;
  --card-w: 64px;
  --card-h: 92px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html, body, button, .card { touch-action: manipulation; }
body {
  background: var(--felt) radial-gradient(ellipse at 50% 35%, var(--felt-2) 0%, transparent 70%) no-repeat fixed;
  color: var(--ink);
  font: 16px/1.5 var(--body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
input, select {
  font-size: 16px; /* מונע זום אוטומטי באייפון */
  border: 2px solid #d9d2bf; border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.muted { color: var(--muted); }
.muted-light { color: #cfe3d8; font-size: .9rem; }
.center { text-align: center; }
.spacer { flex: 1; }
.error { color: var(--red); min-height: 1.5em; margin: 8px 0 0; font-weight: 600; text-align: center; }
.note { font-size: .88rem; color: var(--muted); margin: 8px 0 0; }

/* כפתורים */
.btn {
  border: 2px solid var(--ink); background: #fff; color: var(--ink); border-radius: 12px;
  padding: 9px 16px; font-weight: 700; cursor: pointer; line-height: 1.2;
  box-shadow: 0 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); }
.btn.big { font-size: 1.1rem; padding: 12px 22px; width: 100%; }
.btn.small { font-size: .88rem; padding: 6px 12px; box-shadow: 0 2px 0 var(--ink); }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 4px; font-size: .9rem; }
.link.light { color: #e6f2ec; }
.small-link { font-size: .8rem; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 2px 8px; border-radius: 6px; }
.icon-btn:hover { background: #0001; color: var(--red); }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

/* דף הבית ולובי */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.card-panel {
  width: min(420px, 100%); background: var(--paper); border-radius: 20px; padding: 28px 22px;
  border: 3px solid var(--ink); box-shadow: 0 8px 0 var(--felt-dark);
}
.logo {
  font-family: var(--display); font-weight: 400; font-size: clamp(3rem, 14vw, 4.2rem);
  line-height: 1; margin: 0; text-align: center; color: var(--ink);
  text-shadow: 3px 3px 0 var(--gold);
}
.tagline { text-align: center; margin: 10px 0 22px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; font-size: .9rem; }
.or { display: flex; align-items: center; gap: 10px; margin: 22px 0 12px; color: var(--muted); font-size: .9rem; }
.or::before, .or::after { content: ''; flex: 1; height: 2px; background: #e4ddca; }
.join-row { display: flex; gap: 8px; }
.code-input { text-transform: uppercase; letter-spacing: .25em; font-weight: 800; text-align: center; }
.card-panel .link { display: block; margin: 10px auto 0; }
.big-code {
  font-family: var(--display); font-size: 2.8rem; letter-spacing: .15em; text-align: center;
  line-height: 1.1; margin: 0 0 12px;
}
#shareBtn { display: block; margin: 0 auto; }
.section-title { font-size: 1rem; margin: 22px 0 8px; }
.lobby-players { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.lobby-players li {
  display: flex; align-items: center; gap: 8px; background: var(--cream);
  border-radius: 10px; padding: 8px 12px;
}
.pname { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #b9b9b9; flex: none; display: inline-block; }
.dot.on { background: #2fbf71; }
.badge {
  font-size: .72rem; font-weight: 800; padding: 1px 8px; border-radius: 999px;
  background: var(--ink); color: #fff; white-space: nowrap;
}
.badge.me { background: var(--blue); }
.badge.win { background: #2fbf71; }
.badge.warn { background: var(--gold); color: var(--ink); }
.badge.out { background: var(--red); }

.settings { display: grid; gap: 8px; margin-top: 16px; }
.setting { display: flex; align-items: center; gap: 10px; font-size: .92rem; font-weight: 600; }
.setting > span { flex: 1; }
.setting select { width: auto; padding: 6px 10px; }
.setting.check { gap: 8px; }
.setting.check input { width: 20px; height: 20px; flex: none; }
.setting.check span { font-weight: 400; }

/* משחק */
.game {
  min-height: 100vh; display: flex; flex-direction: column; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px calc(12px + env(safe-area-inset-bottom, 0px));
  max-width: 820px; margin: 0 auto; color: #fff;
}
.topbar { display: flex; align-items: center; gap: 10px; }
.room-tag {
  font-family: var(--display); letter-spacing: .12em; background: var(--felt-dark);
  padding: 2px 10px; border-radius: 8px; direction: ltr;
}

.opponents { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.opp {
  background: #0006; border: 2px solid transparent; border-radius: 12px;
  padding: 6px 10px; min-width: 104px; text-align: center; transition: border-color .2s, background .2s;
}
.opp.turn { border-color: var(--gold); background: #0009; box-shadow: 0 0 0 3px #f5c54233; }
.opp.out { opacity: .45; }
.opp-name {
  font-weight: 700; font-size: .9rem; display: flex; align-items: center; justify-content: center; gap: 6px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.opp-cards { display: flex; justify-content: center; min-height: 30px; align-items: center; padding: 3px 0 0 8px; font-size: .85rem; }
.mini-back {
  width: 18px; height: 26px; border-radius: 3px; margin-left: -8px;
  background: repeating-linear-gradient(45deg, #b33 0 3px, #d45 3px 6px); border: 1.5px solid #fff;
}
.opp-score { font-size: .82rem; color: #d6e9df; }

.table {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; min-height: 170px;
  border: 2px dashed #ffffff26; border-radius: 22px; padding: 14px 10px;
}
.pile-area { display: flex; align-items: center; gap: 26px; }
.deck {
  position: relative; background: none; border: 0; padding: 0; cursor: pointer; border-radius: 10px;
}
.deck:disabled { cursor: default; }
.deck .card.back { box-shadow: 3px 3px 0 #fff, 6px 6px 0 #0004; }
.deck.ready .card.back { outline: 3px solid var(--gold); outline-offset: 3px; animation: pulse 1.2s infinite; }
.deck-count {
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: .75rem; font-weight: 800;
  padding: 0 7px; border-radius: 999px;
}
.pile { display: flex; min-height: var(--card-h); direction: ltr; }
.pile .card + .card { margin-left: -26px; }
.status { text-align: center; margin: 0; min-height: 3em; font-weight: 600; max-width: 480px; }
.status.bad { color: #ffd2d2; }
.status .last { display: block; font-weight: 400; font-size: .85rem; color: #cfe3d8; }

/* קלף */
.card {
  position: relative; display: inline-flex; flex-direction: column; justify-content: center; align-items: center;
  width: var(--card-w); height: var(--card-h); flex: none;
  background: var(--paper); color: var(--ink); border-radius: 9px; border: 1.5px solid #0003;
  box-shadow: 0 2px 4px #0005; user-select: none; -webkit-user-select: none;
  transition: transform .12s, box-shadow .12s, outline-color .12s;
}
.card.red { color: var(--red); }
.card .c-rank { position: absolute; top: 3px; left: 7px; font-weight: 800; font-size: 1.05rem; line-height: 1; }
.card .c-corner { position: absolute; top: 20px; left: 7px; font-size: .8rem; line-height: 1; }
.card .c-suit { font-size: 2rem; line-height: 1; margin-top: 10px; }
.card.joker { background: linear-gradient(160deg, #fff7d6, #ffe08a); color: #7a4b00; }
.card.joker .c-rank { font-size: 1.1rem; }
.card.joker .c-suit { font-size: .85rem; font-weight: 800; }
.card.back {
  background: repeating-linear-gradient(45deg, #b33 0 6px, #d45 6px 12px);
  border: 3px solid #fff;
}
.card.dim { filter: brightness(.7); }
.card.pick { cursor: pointer; }
.card.pick.ready { outline: 3px solid var(--gold); outline-offset: 2px; z-index: 1; }
.card.pick.ready:hover { transform: translateY(-6px); }
.card.tiny { --card-w: 30px; --card-h: 42px; border-radius: 5px; }
.card.tiny .c-rank { font-size: .72rem; top: 2px; left: 3px; }
.card.tiny .c-corner { display: none; }
.card.tiny .c-suit { font-size: .9rem; margin-top: 8px; }
.card.tiny.joker .c-suit { font-size: .5rem; }

/* היד שלי */
.me { background: #0000004d; border-radius: 18px; padding: 10px 12px 14px; }
.me-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.me-name { font-weight: 800; }
.me-name.turn { color: var(--gold); }
.me-name.turn::before { content: '● '; }
.me-sum { color: #d6e9df; font-size: .9rem; }
.hand { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; min-height: calc(var(--card-h) + 16px); padding-top: 14px; direction: ltr; }
.hand .card { cursor: default; }
.hand.active .card { cursor: pointer; }
.hand.active .card:hover { transform: translateY(-4px); }
.hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--gold), 0 8px 14px #0006; }
.hand.active .card.sel:hover { transform: translateY(-16px); }
.me-actions { display: flex; justify-content: center; margin-top: 10px; }
.btn.yaniv {
  font-family: var(--display); font-weight: 400; font-size: 1.35rem; padding: 8px 34px;
  background: var(--gold); border-color: var(--ink);
}
.btn.yaniv:not(:disabled) { animation: pulse 1.4s infinite; }

@keyframes pulse { 50% { box-shadow: 0 3px 0 var(--ink), 0 0 0 8px #f5c54240; } }

/* לוג וצ'אט */
.chat-panel { background: #00000040; border-radius: 14px; padding: 8px 10px; }
.log {
  list-style: none; margin: 0; padding: 0; max-height: 120px; overflow-y: auto;
  font-size: .85rem; color: #d6e9df; display: grid; gap: 2px;
}
.log-yaniv { color: var(--gold); font-weight: 700; }
.log-chat { color: #fff; }
.chat { display: flex; gap: 6px; margin-top: 8px; }
.chat input { padding: 6px 10px; background: #fff; color: var(--ink); }

/* חיבור */
.conn {
  position: fixed; top: 0; inset-inline: 0; z-index: 90; text-align: center;
  background: var(--red); color: #fff; font-weight: 700; padding: 6px;
}

/* מודאל */
.modal {
  position: fixed; inset: 0; z-index: 80; background: #0009;
  display: grid; place-items: center; padding: 16px;
}
.modal-box {
  position: relative; background: var(--paper); color: var(--ink); border: 3px solid var(--ink);
  border-radius: 18px; padding: 22px 18px 18px; width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 8px 0 var(--felt-dark);
}
.modal-box h2 { margin-top: 0; }
.modal-box h3 { margin-bottom: 4px; }
.modal-box ol { padding-inline-start: 20px; }
.modal-x { position: absolute; top: 8px; left: 10px; background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--muted); }
.result-title { font-family: var(--display); font-weight: 400; font-size: 2.4rem; text-align: center; margin: 0; line-height: 1.2; }
.result-title.assaf { color: var(--red); }
.result-wrap { overflow-x: auto; margin: 12px 0 4px; }
.result { width: 100%; border-collapse: collapse; font-size: .9rem; }
.result th { text-align: start; font-size: .78rem; color: var(--muted); padding: 4px; }
.result td { padding: 6px 4px; border-top: 1px solid #e8e1cf; vertical-align: middle; }
.result tr.mine td { background: #fff3c4; }
.r-name { font-weight: 700; }
.r-name .badge { margin-inline-start: 4px; }
.r-hand { direction: ltr; white-space: nowrap; }
.r-hand .card { margin-right: 2px; }
.r-num { text-align: center; font-variant-numeric: tabular-nums; direction: ltr; }
.r-num.strong { font-weight: 800; }
.modal-box .btn.big { margin-top: 14px; }

.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  z-index: 95; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-weight: 600; max-width: min(90vw, 460px); text-align: center; box-shadow: 0 6px 20px #0006;
}

@media (max-width: 480px) {
  :root { --card-w: 54px; --card-h: 78px; }
  .card .c-suit { font-size: 1.6rem; }
  .opp { min-width: 88px; padding: 5px 8px; }
  .pile-area { gap: 18px; }
  .r-hand .card.tiny { --card-w: 24px; --card-h: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .deck.ready .card.back, .btn.yaniv:not(:disabled) { animation: none; }
  .card, .btn { transition: none; }
}

/* חזרה לעמוד המשחקים של AlexFunny — קיים בכל משחק */
.back-link {
  display: inline-block; margin: -10px 0 14px; font-size: .9rem; font-weight: 700;
  color: var(--muted); text-decoration: none;
}
.back-link:hover { color: var(--ink); text-decoration: underline; }
