@font-face {
  font-family: system-fa;
  src: local("Vazirmatn"), local("IRANSans"), local("Tahoma");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #071c18;
  --felt: #123f34;
  --felt-deep: #0c332a;
  --felt-light: #1c5b4c;
  --cream: #fff9e9;
  --ink: #16201d;
  --muted: #a9c9bf;
  --gold: #f1c56a;
  --gold-deep: #be8d31;
  --red: #c83e4d;
  --red-soft: #ff7784;
  --blue: #6baed6;
  --shadow: 0 18px 50px rgba(0, 0, 0, .36);
  --card-w: clamp(48px, 15vw, 70px);
  --card-h: calc(var(--card-w) * 1.42);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  min-height: 100dvh;
  overflow: hidden;
  font-family: system-fa, Tahoma, Arial, sans-serif;
  color: #fff;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, select, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100dvh; }
.welcome-screen {
  min-height: 100dvh;
  padding: calc(34px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  background:
    radial-gradient(circle at 20% 12%, rgba(241, 197, 106, .15), transparent 30%),
    radial-gradient(circle at 80% 82%, rgba(80, 164, 135, .18), transparent 33%),
    linear-gradient(145deg, #0a2922, #061713 70%);
}
.brand-mark {
  width: 122px;
  height: 122px;
  border-radius: 34px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  place-items: center;
  font-size: 34px;
  color: var(--gold);
  background: linear-gradient(145deg, rgba(255,255,255,.12), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.12);
  transform: rotate(-3deg);
  margin-bottom: 28px;
}
.brand-mark span:nth-child(2), .brand-mark span:nth-child(3) { color: var(--red-soft); }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: 13px; font-weight: 800; letter-spacing: .02em; }
.welcome-screen h1 { margin: 0; font-size: clamp(42px, 12vw, 70px); line-height: 1; }
.welcome-copy { max-width: 430px; margin: 18px 0 28px; color: #cbe0da; line-height: 1.9; font-size: 15px; }
.welcome-actions { width: min(100%, 360px); display: grid; gap: 11px; }
.primary-btn, .secondary-btn, .danger-btn, .play-card-btn, .sort-btn {
  border: 0;
  border-radius: 15px;
  min-height: 48px;
  padding: 12px 20px;
  font-weight: 900;
  transition: transform .16s ease, opacity .16s ease, box-shadow .16s ease;
}
.primary-btn { color: #243016; background: linear-gradient(135deg, #f7d886, #e7ae45); box-shadow: 0 10px 28px rgba(219, 161, 55, .23); }
.secondary-btn { color: #fff; background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.14); }
.danger-btn { color: #ffdadd; background: rgba(200, 62, 77, .16); border: 1px solid rgba(255, 119, 132, .25); width: 100%; }
.primary-btn:active, .secondary-btn:active, .danger-btn:active, .play-card-btn:active, .sort-btn:active { transform: scale(.98); }
.text-btn { border: 0; background: transparent; color: #d2e4df; margin-top: 18px; text-decoration: underline; text-underline-offset: 5px; }
.offline-note { margin-top: 30px; color: #779b90; font-size: 12px; }

.game-screen { min-height: 100dvh; background: var(--felt-deep); }
.top-bar {
  position: relative;
  z-index: 20;
  height: calc(62px + var(--safe-top));
  padding: calc(8px + var(--safe-top)) 10px 8px;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  align-items: center;
  background: rgba(4, 24, 20, .88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid rgba(255,255,255,.11);
  color: #fff;
  background: rgba(255,255,255,.07);
  font-size: 20px;
}
.scoreboard { display: grid; grid-template-columns: 1fr 1.25fr 1fr; align-items: stretch; gap: 6px; min-width: 0; }
.score-team, .round-status {
  min-width: 0;
  border-radius: 12px;
  padding: 5px 7px;
  text-align: center;
  background: rgba(255,255,255,.06);
}
.score-team span, .round-status span { display: block; color: var(--muted); font-size: 10px; white-space: nowrap; }
.score-team strong { display: block; font-size: 19px; line-height: 1.1; }
.round-status strong { display: block; margin-top: 2px; color: var(--gold); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-team-us { box-shadow: inset 0 -2px var(--gold); }
.score-team-them { box-shadow: inset 0 -2px var(--red-soft); }

.table-wrap {
  position: relative;
  height: calc(100dvh - 62px - var(--safe-top));
  min-height: 540px;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(56, 136, 111, .45), transparent 55%),
    linear-gradient(145deg, var(--felt-light), var(--felt-deep));
  isolation: isolate;
}
.table-wrap::after {
  content: "";
  position: absolute;
  inset: 12px;
  z-index: -1;
  border: 1px solid rgba(241,197,106,.22);
  border-radius: 32px;
  pointer-events: none;
}
.felt-pattern {
  position: absolute;
  inset: 0;
  z-index: -2;
  opacity: .2;
  background-image: radial-gradient(rgba(255,255,255,.2) .65px, transparent .65px);
  background-size: 8px 8px;
}

.player-seat { position: absolute; z-index: 4; display: grid; justify-items: center; gap: 3px; }
.player-north { top: 14px; left: 50%; transform: translateX(-50%); }
.player-west { left: 12px; top: 38%; transform: translateY(-50%); }
.player-east { right: 12px; top: 38%; transform: translateY(-50%); }
.player-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 115px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(2, 20, 16, .72);
  border: 1px solid rgba(255,255,255,.1);
  box-shadow: 0 8px 20px rgba(0,0,0,.16);
}
.player-avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #14241e;
  background: #ddebe7;
  font-size: 12px;
  font-weight: 900;
  position: relative;
}
.player-info { min-width: 0; }
.player-name { display: block; max-width: 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; font-weight: 800; }
.player-sub { display: block; color: #9fc2b7; font-size: 9px; white-space: nowrap; }
.player-seat.is-turn .player-chip { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(241,197,106,.12), 0 8px 20px rgba(0,0,0,.2); }
.player-seat.is-turn .player-avatar { background: var(--gold); }
.hakem-crown {
  position: absolute;
  top: -8px;
  right: -5px;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #372509;
  background: var(--gold);
  font-size: 10px;
  box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.bot-cards { height: 30px; min-width: 62px; position: relative; }
.mini-card-back {
  position: absolute;
  top: 0;
  width: 22px;
  height: 30px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.45);
  background:
    linear-gradient(45deg, transparent 42%, rgba(255,255,255,.18) 42% 58%, transparent 58%),
    linear-gradient(135deg, transparent 42%, rgba(255,255,255,.18) 42% 58%, transparent 58%),
    #8a2940;
  background-size: 8px 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,.25);
}
.mini-card-back:nth-child(1) { left: 7px; transform: rotate(-10deg); }
.mini-card-back:nth-child(2) { left: 20px; }
.mini-card-back:nth-child(3) { left: 33px; transform: rotate(10deg); }
.card-count-badge {
  position: absolute;
  right: -5px;
  bottom: -4px;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #15221e;
  background: #fff;
  font-size: 10px;
  font-weight: 900;
}

.center-area {
  position: absolute;
  inset: 20% 18% 31%;
  z-index: 3;
  display: grid;
  place-items: center;
}
.turn-message {
  position: absolute;
  top: 0;
  max-width: 90%;
  padding: 6px 12px;
  border-radius: 999px;
  color: #e7f4f0;
  background: rgba(3, 26, 21, .62);
  border: 1px solid rgba(255,255,255,.08);
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trick-area { position: relative; width: min(72vw, 300px); height: min(44vw, 190px); margin-top: 14px; }
.trick-slot { position: absolute; width: calc(var(--card-w) * .78); height: calc(var(--card-h) * .78); display: grid; place-items: center; }
.trick-north { left: 50%; top: 0; transform: translateX(-50%) rotate(2deg); }
.trick-south { left: 50%; bottom: 0; transform: translateX(-50%) rotate(-2deg); }
.trick-west { left: 3%; top: 50%; transform: translateY(-50%) rotate(90deg); }
.trick-east { right: 3%; top: 50%; transform: translateY(-50%) rotate(-90deg); }
.trick-score {
  position: absolute;
  bottom: 0;
  display: flex;
  gap: 14px;
  color: #bdd8d0;
  font-size: 11px;
}
.trick-score strong { color: #fff; font-size: 13px; }

.playing-card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  flex: 0 0 var(--card-w);
  border: 0;
  border-radius: 8px;
  color: #17201e;
  background: linear-gradient(145deg, #fffef9, #eee9dc);
  box-shadow: 0 8px 18px rgba(0,0,0,.25), inset 0 0 0 1px rgba(0,0,0,.08);
  overflow: hidden;
  user-select: none;
  transform-origin: bottom center;
}
.playing-card.red { color: #be263b; }
.card-corner { position: absolute; top: 5px; left: 6px; display: grid; justify-items: center; font-family: Arial, sans-serif; font-weight: 900; line-height: .92; font-size: calc(var(--card-w) * .23); }
.card-corner.bottom { top: auto; left: auto; right: 6px; bottom: 5px; transform: rotate(180deg); }
.card-suit-large { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--card-w) * .52); opacity: .94; }
.card-trump-dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold-deep); box-shadow: 0 0 0 2px rgba(241,197,106,.28); }
.trick-slot .playing-card { width: calc(var(--card-w) * .78); height: calc(var(--card-h) * .78); border-radius: 6px; pointer-events: none; animation: cardDrop .25s ease both; }
.trick-slot .card-corner { font-size: calc(var(--card-w) * .18); }
.trick-slot .card-suit-large { font-size: calc(var(--card-w) * .4); }

.human-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  min-height: 31%;
  padding: 0 10px calc(8px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(4, 25, 20, .58) 28%, rgba(3, 20, 16, .95));
}
.human-meta { height: 46px; display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.human-identity .player-chip { background: rgba(2,20,16,.8); }
.timer-shell { position: relative; width: 40px; height: 40px; display: grid; place-items: center; }
.timer-shell svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer-track, .timer-progress { fill: none; stroke-width: 3.5; }
.timer-track { stroke: rgba(255,255,255,.12); }
.timer-progress { stroke: var(--gold); stroke-linecap: round; stroke-dasharray: 100.53; stroke-dashoffset: 0; transition: stroke-dashoffset .2s linear; }
.timer-shell span { position: relative; z-index: 1; font-size: 10px; font-weight: 900; }
.human-hand {
  --overlap: -29px;
  min-height: calc(var(--card-h) + 24px);
  width: 100%;
  display: flex;
  direction: ltr;
  justify-content: center;
  align-items: end;
  padding: 22px 4px 0;
  overflow: visible;
}
.human-hand .playing-card { margin-left: var(--overlap); transition: transform .16s ease, filter .16s ease, opacity .16s ease; }
.human-hand .playing-card:first-child { margin-left: 0; }
.human-hand .playing-card:hover { transform: translateY(-5px); }
.human-hand .playing-card.selected { transform: translateY(-19px); box-shadow: 0 15px 30px rgba(0,0,0,.35), 0 0 0 3px var(--gold); z-index: 30 !important; }
.human-hand .playing-card.illegal { filter: saturate(.35) brightness(.72); opacity: .58; }
.human-hand .playing-card.legal-hint:not(.selected) { box-shadow: 0 8px 18px rgba(0,0,0,.25), 0 0 0 2px rgba(241,197,106,.38); }
.hand-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 4px; }
.play-card-btn { min-height: 42px; color: #213019; background: var(--gold); }
.play-card-btn:disabled { opacity: .45; cursor: default; }
.sort-btn { min-height: 42px; color: #fff; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1); }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(160px + var(--safe-bottom));
  transform: translate(-50%, 18px);
  max-width: calc(100vw - 32px);
  padding: 9px 14px;
  border-radius: 12px;
  color: #fff;
  background: rgba(2, 18, 15, .92);
  border: 1px solid rgba(255,255,255,.12);
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  font-size: 12px;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.game-dialog {
  width: min(calc(100vw - 28px), 470px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  color: #fff;
  background: transparent;
  overflow: visible;
}
.game-dialog::backdrop { background: rgba(0, 10, 8, .76); backdrop-filter: blur(8px); }
.dialog-card {
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 24px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(145deg, #143e35, #0a2922);
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: var(--shadow);
}
.dialog-card h2 { margin: 0 0 10px; font-size: 24px; }
.dialog-card p { color: #c6dcd6; line-height: 1.8; font-size: 13px; }
.dialog-icon { width: 58px; height: 58px; margin: 0 auto 13px; display: grid; place-items: center; border-radius: 18px; color: #31240c; background: var(--gold); font-size: 28px; }
.first-five-preview { display: flex; direction: ltr; justify-content: center; margin: 20px 0; }
.first-five-preview .playing-card { width: 52px; height: 74px; margin-left: -18px; }
.first-five-preview .playing-card:first-child { margin-left: 0; }
.first-five-preview .card-corner { font-size: 12px; }
.first-five-preview .card-suit-large { font-size: 25px; }
.suit-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suit-choice { min-height: 58px; border: 0; border-radius: 15px; color: #1e2825; background: #f8f4e9; font-weight: 900; }
.suit-choice span { display: inline-block; margin-left: 6px; font-size: 24px; vertical-align: middle; }
.suit-choice.red { color: #b92338; }
.result-score { display: flex; justify-content: center; gap: 12px; margin: 20px 0; }
.result-score span { min-width: 86px; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.07); }
.result-dialog .primary-btn, .result-dialog .secondary-btn { width: 100%; margin-top: 9px; }
.dialog-heading-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; text-align: right; }
.dialog-heading-row h2 { margin: 0; }
.close-dialog-btn { width: 38px; height: 38px; border: 0; border-radius: 12px; color: #fff; background: rgba(255,255,255,.08); font-size: 24px; }
.settings-card { text-align: right; }
.setting-row, .setting-column { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid rgba(255,255,255,.07); color: #dfebe8; font-size: 14px; }
.setting-column { align-items: stretch; flex-direction: column; }
.setting-row input { width: 21px; height: 21px; accent-color: var(--gold-deep); }
.setting-column select { min-height: 44px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 0 12px; color: #fff; background: rgba(255,255,255,.07); }
.settings-card hr { border: 0; border-top: 1px solid rgba(255,255,255,.08); margin: 18px 0; }
.settings-card .secondary-btn { width: 100%; margin-bottom: 10px; }
.history-card, .help-card { text-align: right; }
.history-list { display: grid; gap: 8px; }
.history-item { display: grid; grid-template-columns: 42px 1fr auto; gap: 9px; align-items: center; padding: 10px; border-radius: 13px; background: rgba(255,255,255,.06); }
.history-number { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: var(--gold); background: rgba(241,197,106,.12); font-weight: 900; }
.history-cards { direction: ltr; display: flex; gap: 3px; font-family: Arial, sans-serif; font-size: 12px; }
.history-winner { color: #bcd6cf; font-size: 11px; }
.empty-history { padding: 26px 8px; text-align: center; color: #a7c3bb; }
.help-card ol { margin: 0; padding-right: 21px; color: #d7e6e2; line-height: 2; font-size: 13px; }

@keyframes cardDrop { from { opacity: 0; transform: translateY(12px) scale(.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes pulseTurn { 50% { box-shadow: 0 0 0 7px rgba(241,197,106,0); } }

.reduce-motion * {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-height: 650px) {
  :root { --card-w: clamp(43px, 13vw, 59px); }
  .top-bar { height: calc(56px + var(--safe-top)); }
  .table-wrap { height: calc(100dvh - 56px - var(--safe-top)); min-height: 470px; }
  .center-area { inset-top: 18%; }
  .human-zone { min-height: 29%; }
  .human-meta { height: 38px; }
  .hand-actions { margin-top: 0; }
  .play-card-btn, .sort-btn { min-height: 37px; padding-block: 8px; }
}

@media (min-width: 700px) {
  :root { --card-w: 74px; }
  .game-screen { display: grid; place-items: center; background: #061a16; }
  .top-bar, .table-wrap { width: min(100vw, 760px); }
  .table-wrap { border-left: 1px solid rgba(255,255,255,.08); border-right: 1px solid rgba(255,255,255,.08); }
  .human-hand { --overlap: -24px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  :root { --card-w: 47px; }
  .top-bar { height: calc(50px + var(--safe-top)); padding-top: calc(4px + var(--safe-top)); padding-bottom: 4px; }
  .table-wrap { height: calc(100dvh - 50px - var(--safe-top)); min-height: 360px; }
  .center-area { inset: 8% 25% 18%; }
  .human-zone { left: 17%; right: 17%; min-height: 32%; }
  .player-west { left: 3%; top: 45%; }
  .player-east { right: 3%; top: 45%; }
  .player-north { top: 4px; }
  .human-meta { height: 34px; }
  .human-hand { min-height: calc(var(--card-h) + 8px); padding-top: 8px; --overlap: -20px; }
  .hand-actions { position: absolute; right: -110px; bottom: calc(8px + var(--safe-bottom)); width: 102px; grid-template-columns: 1fr; }
  .play-card-btn, .sort-btn { min-height: 36px; padding: 6px; font-size: 11px; }
  .turn-message { top: -6px; }
}
