/* ===== توکن‌های طراحی =====
   پالت: مخمل شاهانه - تخته‌ی برد با حس ایرانی، گرم و لوکس
*/
:root {
  --wood-dark: #1e1208;
  --wood-mid: #3d2010;
  --wood-border: #7a4a1e;
  --felt: #1f4d3a;
  --cream: #fdf6e8;
  --cream-soft: #ede0c4;
  --cream-dim: #c8b99a;
  --ink: #1e130b;
  --ink-soft: #7a6050;

  --red:    #d63227;
  --red-deep:   #8c1f16;
  --green:  #1a8a52;
  --green-deep: #0f5c35;
  --yellow: #e0a020;
  --yellow-deep:#a07010;
  --blue:   #1a65c8;
  --blue-deep:  #0f3e80;

  --gold:   #c8982a;
  --gold-light: #f0c84a;
  --gold-dark:  #8a6810;

  --radius-lg: 24px;
  --radius-md: 14px;
  --shadow-deep: 0 16px 48px rgba(10,5,0,0.55);
  --shadow-board: 0 0 0 6px #7a4a1e, 0 0 0 10px #3d2010, 0 24px 60px rgba(0,0,0,0.6);
  --font-display: 'Vazirmatn', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  font-family: var(--font-display);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  background: #0e0804;
}

body {
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(100,50,10,0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 85%, rgba(60,20,5,0.4) 0%, transparent 50%),
    repeating-linear-gradient(
      120deg,
      rgba(255,255,255,0.015) 0px, rgba(255,255,255,0.015) 1px,
      transparent 1px, transparent 18px
    ),
    linear-gradient(160deg, #2a1508 0%, #0e0804 60%);
}

#app {
  position: relative;
  width: 100%; height: 100vh; height: 100dvh;
}

.screen {
  display: none;
  width: 100%; height: 100%;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s cubic-bezier(.22,1,.36,1);
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

button { font-family: inherit; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input  { font-family: inherit; }

/* ===== دکمه‌ها ===== */
.btn {
  border-radius: var(--radius-md);
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 800;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  width: 100%;
  letter-spacing: 0.5px;
}
.btn:active { transform: scale(0.96) translateY(2px); }

.btn-primary {
  background: linear-gradient(160deg, var(--gold-light) 0%, var(--gold) 50%, #9a7218 100%);
  color: #2a1a04;
  box-shadow: 0 5px 0 var(--gold-dark), 0 10px 24px rgba(0,0,0,0.4);
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--cream-dim), 0 8px 16px rgba(0,0,0,0.3);
}
.btn-ghost {
  background: transparent;
  color: var(--cream-soft);
  border: 1.5px solid rgba(246,239,226,0.3);
  box-shadow: none;
}
.btn-sm { padding: 10px 16px; font-size: 13px; width: auto; }

/* ===== لابی ===== */
.lobby-wrap {
  width: 100%;
  max-width: 400px;
  padding: 36px 28px 44px;
  background: linear-gradient(170deg, var(--cream) 0%, #ede0c4 100%);
  border-radius: 30px;
  box-shadow:
    0 0 0 3px var(--gold),
    0 0 0 6px var(--wood-border),
    var(--shadow-deep);
  margin: 16px;
  position: relative;
  overflow: hidden;
}
.lobby-wrap::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold-light), transparent);
}

.brand { text-align: center; margin-bottom: 34px; }
.brand-token {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}
/* مهره‌های لابی - شبیه مهره‌های سه‌بعدی */
.dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  position: relative;
  box-shadow:
    inset 0 -4px 0 rgba(0,0,0,0.25),
    inset 2px 3px 4px rgba(255,255,255,0.4),
    0 4px 8px rgba(0,0,0,0.3);
}
.dot::after {
  content: '';
  position: absolute;
  top: 4px; left: 5px;
  width: 6px; height: 5px;
  background: rgba(255,255,255,0.55);
  border-radius: 50%;
}
.dot-red    { background: radial-gradient(circle at 35% 30%, #f05040, var(--red-deep)); }
.dot-green  { background: radial-gradient(circle at 35% 30%, #28c070, var(--green-deep)); }
.dot-yellow { background: radial-gradient(circle at 35% 30%, #f0c040, var(--yellow-deep)); }
.dot-blue   { background: radial-gradient(circle at 35% 30%, #3080f0, var(--blue-deep)); }

.brand h1 {
  font-size: 46px;
  font-weight: 900;
  margin: 0;
  color: var(--ink);
  letter-spacing: -2px;
  line-height: 1;
}
.brand-sub {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.lobby-actions { display: flex; flex-direction: column; gap: 14px; }

.divider {
  display: flex; align-items: center;
  color: var(--ink-soft); font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; flex: 1;
  border-bottom: 1.5px solid var(--cream-dim);
}
.divider span { padding: 0 12px; }

.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; min-width: 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 2px solid var(--cream-dim);
  background: #fffdf5;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 4px;
  text-align: center;
  color: var(--ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.join-row input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,152,42,0.2);
}
.join-row .btn { width: auto; padding: 14px 20px; }

.error-text {
  color: var(--red-deep);
  font-size: 13px;
  text-align: center;
  margin: 12px 0 0;
  min-height: 16px;
  font-weight: 600;
}

/* ===== اتاق انتظار ===== */
.waiting-wrap {
  width: 100%;
  max-width: 400px;
  padding: 36px 28px;
  background: linear-gradient(170deg, var(--cream) 0%, #ede0c4 100%);
  border-radius: 30px;
  box-shadow:
    0 0 0 3px var(--gold),
    0 0 0 6px var(--wood-border),
    var(--shadow-deep);
  margin: 16px;
  text-align: center;
}
.room-code-label { color: var(--ink-soft); font-size: 12px; margin: 0 0 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; }
.room-code-box {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 10px;
  background: #fffdf5;
  border: 2px dashed var(--gold);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--ink);
  margin-bottom: 14px;
  text-indent: 10px; /* جبران letter-spacing در وسط */
}

.players-list {
  display: flex; flex-direction: column;
  gap: 8px; margin: 20px 0;
}
.player-row {
  display: flex; align-items: center;
  gap: 12px; padding: 12px 16px;
  border-radius: var(--radius-md);
  background: #fffdf5;
  border: 1.5px solid var(--cream-dim);
}
.player-row .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 900; font-size: 14px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2), inset 2px 3px 4px rgba(255,255,255,0.3);
}
.player-row .pname { font-weight: 700; font-size: 14px; flex: 1; text-align: right; }
.player-row .pstatus { font-size: 11px; color: var(--ink-soft); }
.player-row.host .pname::after { content: ' (میزبان)'; font-size: 11px; color: var(--gold); font-weight: 700; }
.player-row.empty { opacity: 0.4; border-style: dashed; }

.waiting-hint { color: var(--ink-soft); font-size: 13px; margin-bottom: 20px; font-weight: 600; }

/* ===== صفحه بازی ===== */
.game-wrap {
  width: 100%; height: 100%;
  position: relative; overflow: hidden;
}

/* تخته: تمام صفحه، مربع وسط‌چین */
.board-stage {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-svg {
  /* کل صفحه رو پُر کن - بدون محدودیت مربع */
  width:  100vw;
  height: 100dvh;
  display: block;
  flex-shrink: 0;
}

/* نوار نوبت: شناور روی تخته، بالا */
.game-topbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 400px;
  z-index: 20;
}
.turn-indicator {
  display: flex;
  align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(15, 8, 2, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 999px;
  padding: 10px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08);
  font-weight: 800; font-size: 14px;
  color: var(--cream-soft);
  border: 1.5px solid rgba(200,152,42,0.3);
  transition: border-color 0.3s ease;
}
.turn-indicator.my-turn {
  border-color: var(--gold);
  color: #fff;
  animation: pulseTurn 1.8s ease-in-out infinite;
}
@keyframes pulseTurn {
  0%, 100% { box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
  50%       { box-shadow: 0 4px 30px rgba(200,152,42,0.5), 0 0 0 3px rgba(200,152,42,0.15); }
}
.turn-dot {
  width: 14px; height: 14px; border-radius: 50%;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.25), inset 2px 2px 3px rgba(255,255,255,0.35);
  flex-shrink: 0;
  transition: background 0.25s ease;
}

/* کنترل‌های پایین: شناور روی تخته */
.game-controls {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 420px;
  z-index: 20;
  display: flex;
  align-items: center; justify-content: space-between;
  gap: 10px;
  background: rgba(10, 5, 1, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: 20px;
  padding: 10px 14px;
  border: 1px solid rgba(200,152,42,0.2);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
}

.players-strip { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.pstrip-item {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 6px 12px 6px 7px;
  font-size: 12px; color: var(--cream-dim);
  font-weight: 700;
  border: 1px solid rgba(255,255,255,0.08);
  transition: background 0.2s, border-color 0.2s;
}
.pstrip-item.current {
  background: rgba(200,152,42,0.2);
  border-color: rgba(200,152,42,0.5);
  color: #fff;
}
.pstrip-item .mini-dot {
  width: 20px; height: 20px; border-radius: 50%;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.25), inset 2px 2px 3px rgba(255,255,255,0.3);
  flex-shrink: 0;
}
.pstrip-item .pcount { font-size: 10px; opacity: 0.65; margin-right: 2px; }

/* ===== تاس ===== */
.dice-area { display: flex; flex-direction: column; align-items: center; gap: 5px; flex-shrink: 0; }

.dice-btn {
  width: 76px; height: 76px;
  border-radius: 20px;
  background: linear-gradient(145deg, #fffdf5, #e8d8b0);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  box-shadow:
    0 6px 0 #9a8050,
    0 8px 20px rgba(0,0,0,0.5),
    inset 0 2px 0 rgba(255,255,255,0.8);
}
.dice-btn:not(:disabled) {
  box-shadow:
    0 6px 0 var(--gold-dark),
    0 0 0 2px var(--gold),
    0 10px 28px rgba(0,0,0,0.5),
    inset 0 2px 0 rgba(255,255,255,0.8);
}
.dice-btn:active:not(:disabled) {
  transform: scale(0.9) translateY(4px);
  box-shadow:
    0 2px 0 var(--gold-dark),
    0 0 0 2px var(--gold),
    0 4px 12px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.6);
}
.dice-btn:disabled { opacity: 0.4; filter: grayscale(0.5); cursor: not-allowed; }

.dice-svg { width: 60px; height: 60px; }

.dice-btn.rolling .dice-svg { animation: diceRoll 0.55s cubic-bezier(.36,.07,.19,.97); }
@keyframes diceRoll {
  0%   { transform: rotate(0deg) scale(1); }
  20%  { transform: rotate(-20deg) scale(1.1); }
  40%  { transform: rotate(15deg) scale(0.95); }
  60%  { transform: rotate(-10deg) scale(1.05); }
  80%  { transform: rotate(6deg) scale(0.98); }
  100% { transform: rotate(0deg) scale(1); }
}
.dice-hint { font-size: 11px; color: var(--cream-dim); margin: 0; font-weight: 700; opacity: 0.75; }

/* ===== صفحه پایان ===== */
.over-wrap {
  text-align: center;
  background: linear-gradient(170deg, var(--cream) 0%, #ede0c4 100%);
  padding: 44px 32px;
  border-radius: 30px;
  box-shadow:
    0 0 0 3px var(--gold),
    0 0 0 6px var(--wood-border),
    var(--shadow-deep);
  margin: 16px;
  max-width: 380px;
  position: relative; overflow: hidden;
}
.over-wrap h2 { font-size: 30px; margin: 0 0 10px; font-weight: 900; }
.over-wrap p  { color: var(--ink-soft); margin: 0 0 28px; font-weight: 600; }

/* ===== توست ===== */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(140%);
  background: rgba(20,10,4,0.92);
  backdrop-filter: blur(10px);
  color: var(--cream-soft);
  padding: 13px 22px;
  border-radius: 999px;
  font-size: 13px; font-weight: 700;
  border: 1px solid rgba(200,152,42,0.3);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  transition: transform 0.3s cubic-bezier(.22,1,.36,1);
  z-index: 50;
  max-width: 88vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== مهره‌ها ===== */
.piece {
  cursor: default;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1);
}
.piece.movable {
  cursor: pointer;
}
.piece.movable .movable-ring {
  animation: spin 2.5s linear infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.piece.movable .piece-body {
  animation: piecePulse 1s ease-in-out infinite;
}
@keyframes piecePulse {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-5px); }
}

@media (max-width: 360px) {
  .lobby-wrap, .waiting-wrap { padding: 24px 18px; }
  .brand h1 { font-size: 38px; }
}
