/* ==========================================================================
   منچ — استایل مشترک صفحه بازی و پنل ادمین
   طراحی مدرن، شاد، فارسی و راست‌چین، واکنشگرا برای موبایل و دسکتاپ
   ========================================================================== */

:root {
  --color-bg: #0f1024;
  --color-bg-2: #1a1c3a;
  --color-surface: #ffffff;
  --color-surface-dark: #23264d;
  --color-text: #1a1c2e;
  --color-text-invert: #f4f5ff;
  --color-muted: #6b6f92;
  --color-primary: #6d5efc;
  --color-primary-dark: #5346e0;
  --color-accent: #ff7a59;
  --color-success: #23c483;
  --color-danger: #ff4d6d;
  --color-warning: #ffb020;

  --red: #ff4d4d;
  --green: #2fb56b;
  --yellow: #f5c518;
  --blue: #3a8dff;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.28);

  --font: "Vazirmatn", "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;

  --touch: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  color: var(--color-text-invert);
  background:
    radial-gradient(circle at 15% 10%, rgba(109, 94, 252, 0.35), transparent 55%),
    radial-gradient(circle at 85% 90%, rgba(255, 122, 89, 0.28), transparent 55%),
    linear-gradient(160deg, var(--color-bg), var(--color-bg-2));
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.7;
  display: flex;
  flex-direction: column;
}

/* ---------- دسترس‌پذیری ---------- */
.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  background: var(--color-primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 1000;
}
.skip-link:focus {
  inset-inline-start: 12px;
  top: 12px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- هدر ---------- */
.app-header {
  background: rgba(15, 16, 36, 0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.app-title {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(90deg, #fff, #c9c2ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
}

.title-emoji {
  -webkit-text-fill-color: initial;
  font-size: 1.4rem;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- دکمه‌ها ---------- */
.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  box-shadow: 0 8px 20px rgba(109, 94, 252, 0.45);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 10px 26px rgba(109, 94, 252, 0.6);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-invert);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-block {
  width: 100%;
}

/* ---------- چیدمان اصلی ---------- */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 6px;
  font-size: 1.3rem;
}

.card-sub {
  margin: 0 0 18px;
  color: #c3c6e6;
  font-size: 0.95rem;
}

/* ---------- پنل شروع ---------- */
.setup-panel {
  animation: fade-in 0.3s ease;
}

.setup-panel[hidden] {
  display: none;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: #e6e7ff;
}

.select {
  font-family: inherit;
  font-size: 1rem;
  min-height: var(--touch);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--color-surface-dark);
  color: var(--color-text-invert);
  cursor: pointer;
}
.select option {
  color: var(--color-text-invert);
  background: var(--color-surface-dark);
}

/* ---------- ناحیه بازی ---------- */
.game-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.board-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 720px;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(145deg, #fdfdff, #eef0ff);
  box-shadow: var(--shadow-lg);
  touch-action: manipulation;
}

.board-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.fallback-note {
  color: var(--color-text);
  padding: 20px;
  text-align: center;
}

/* ---------- پنل وضعیت ---------- */
.status-panel {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}

.status-top {
  display: flex;
  justify-content: center;
}

.turn-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--color-accent), #ff9f80);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(255, 122, 89, 0.4);
}

.turn-badge.ai-turn {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  box-shadow: 0 6px 16px rgba(109, 94, 252, 0.4);
}

.dice-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 72px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.25);
  border: 2px dashed rgba(255, 255, 255, 0.18);
  font-size: 2rem;
}

.dice-box .dice-face {
  font-size: 2rem;
}

.dice-box .dice-value {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 1.5ch;
  text-align: center;
}

.dice-box.rolling {
  animation: dice-shake 0.4s ease;
}

.status-text {
  margin: 0;
  min-height: 3em;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.98rem;
  color: #e9eaff;
}

/* ---------- بازیکنان ---------- */
.players-section {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
}

.players-title {
  margin: 0 0 10px;
  font-size: 1rem;
}

.players-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.player-item.is-current {
  border-color: var(--color-accent);
  background: rgba(255, 122, 89, 0.16);
}

.player-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.player-name {
  flex: 1;
  font-weight: 700;
}

.player-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #eaeaff;
}
.player-badge.ai {
  background: rgba(109, 94, 252, 0.35);
}

.player-progress {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #c9c2ff;
}

/* رنگ بازیکنان */
.color-red {
  background: var(--red);
}
.color-green {
  background: var(--green);
}
.color-yellow {
  background: var(--yellow);
}
.color-blue {
  background: var(--blue);
}

/* ---------- مودال ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 20, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: linear-gradient(160deg, #ffffff, #eef0ff);
  color: var(--color-text);
  border-radius: var(--radius-lg);
  padding: 30px 26px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.25s ease;
}

.modal-emoji {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 8px;
}

.modal-title {
  margin: 0 0 6px;
  font-size: 1.5rem;
  color: var(--color-primary-dark);
}

.modal-sub {
  margin: 0 0 20px;
  color: var(--color-muted);
}

/* ---------- فوتر ---------- */
.app-footer {
  text-align: center;
  padding: 18px;
  color: #a9acce;
  font-size: 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ==========================================================================
   پنل ادمین
   ========================================================================== */

.admin-main {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

#admin-login {
  max-width: 420px;
  margin: 5vh auto 0;
}

#admin-dashboard[hidden] {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.85rem;
  color: #b9bce0;
  margin-top: 4px;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.difficulty-grid .stat-card {
  padding: 12px;
}

.admin-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.input {
  font-family: inherit;
  font-size: 1rem;
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--color-surface-dark);
  color: var(--color-text-invert);
  width: 100%;
}

.msg {
  margin-top: 10px;
  font-size: 0.9rem;
  min-height: 1.4em;
}
.msg.success {
  color: var(--color-success);
}
.msg.error {
  color: var(--color-danger);
}

.section-title {
  font-size: 1.15rem;
  margin: 0 0 14px;
}

.admin-sub {
  color: #c3c6e6;
  font-size: 0.95rem;
  margin: 0 0 18px;
}

/* ---------- انیمیشن‌ها ---------- */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop-in {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes dice-shake {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-8deg);
  }
  75% {
    transform: rotate(8deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- واکنش‌گرایی ---------- */
@media (max-width: 900px) {
  .game-area {
    grid-template-columns: 1fr;
  }
  .status-panel {
    order: -1;
  }
}

@media (max-width: 560px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  .header-inner {
    padding: 10px 12px;
  }
  .app-main {
    padding: 14px 12px 32px;
  }
  .card,
  .status-panel,
  .admin-card {
    padding: 16px;
    border-radius: var(--radius);
  }
  .difficulty-grid {
    grid-template-columns: 1fr;
  }
  .app-title {
    font-size: 1.2rem;
  }
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    transform: translateY(-1px);
  }
}
