/* Using Google Fonts for Vazirmatn; removed local @font-face to avoid conflicts */

:root {
  --bg: #fff7fb;
  --bg-2: #fff0f7;
  --text: #37293f;
  --muted: #6a5d74;
  --primary: #ff6fb3;
  --primary-2: #ff93c9;
  --accent: #7dd3fc;
  --success: #6ee7b7;
  --warning: #fde68a;
  --danger: #fca5a5;
  --card: #ffffff;
  --shadow: 0 8px 20px rgba(0,0,0,.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Vazirmatn, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 50% -20%, var(--bg-2), var(--bg));
  color: var(--text);
}
button{
    font-family: inherit;
}
.app-header {
  padding: 20px 16px 8px;
  text-align: center;
}
.brand { display: inline-flex; align-items: center; gap: 10px; }
.logo { font-size: 28px; background: linear-gradient(45deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.title { margin: 0; font-size: 32px; letter-spacing: -0.5px; }
.subtitle { color: var(--muted); margin-top: 8px; }

.container { max-width: 1080px; margin: 0 auto; padding: 12px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.hidden { display: none; }
.show { display: block; }

.players-toolbar { display: flex; justify-content: flex-start; gap: 8px; margin-bottom: 12px; }
.players-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.player-card { display: flex; gap: 12px; align-items: center; background: linear-gradient(180deg, #fff, #fff9fb); padding: 12px; border-radius: 12px; border: 1px solid #ffe3f0; }
.player-card .avatar { width: 56px; height: 56px; border-radius: 50%; background: #fff; display: grid; place-items: center; border: 2px solid #ffd3ea; overflow: hidden; }
.player-card .meta { flex: 1; }
.player-card .name { font-weight: 700; }
.player-card .info { color: var(--muted); font-size: 13px; }
.player-card .actions { display: flex; gap: 6px; }

.player-form { margin: 10px 0; }
.field { display: grid; gap: 6px; margin: 10px 0; }
.field > span { color: var(--muted); font-size: 14px; }
input[type="text"] { height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid #ffd8ec; outline: none; }
input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 0 4px #ffb3d933; }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 10px; }
.avatar-option { border: 2px solid #ffd8ec; border-radius: 12px; background: #fff; padding: 6px; cursor: pointer; transition: .2s; display: grid; place-items: center; aspect-ratio: 1; }
.avatar-option.selected { border-color: var(--primary); box-shadow: 0 0 0 4px #ffb3d933; }
.avatar-option img { width: 90%; height: 90%; object-fit: contain; }

.form-actions { display: flex; gap: 8px; }
.play-panel { margin-top: 16px; display: flex; align-items: center; gap: 12px; }
.selected-player { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.selected-player .avatar { width: 40px; height: 40px; border-radius: 50%; border: 2px solid #ffd3ea; overflow: hidden; display: grid; place-items: center; }

.leaderboard { margin-top: 12px; display: grid; gap: 8px; }
.lb-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: linear-gradient(180deg, #fff, #fff9fb); border: 1px solid #ffe3f0; }
.lb-row .num { width: 28px; height: 28px; border-radius: 8px; background: #fff; border: 1px solid #ffd8ec; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.lb-row .score { font-weight: 800; color: #b91c1c; }

.hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.hud .chip { background: #fff; border: 1px solid #ffe3f0; border-radius: 999px; padding: 6px 10px; color: var(--muted); }

.canvas-wrap { position: relative; border: 2px dashed #ffe3f0; border-radius: 14px; overflow: hidden; background: #fff; }
canvas { display: block; width: 100%; height: auto; }
.overlay { position: absolute; inset: 0; background: rgba(255, 240, 248, .75); display: grid; place-items: center; }
.overlay.hidden { display: none !important; }
.overlay-card { background: #fff; border-radius: 16px; padding: 18px; box-shadow: var(--shadow); border: 1px solid #ffd8ec; text-align: center; }
.overlay-actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }

.help { color: var(--muted); text-align: center; margin-top: 8px; }

.app-footer { text-align: center; color: var(--muted); padding: 16px; }
.app-footer .link-heart { background: none; border: none; color: #e11d48; cursor: pointer; font-size: 1em; padding: 0 2px; }
.app-footer .link-heart:hover { transform: scale(1.1); }

.btn { border: 1px solid #ffd8ec; background: #fff; color: var(--text); border-radius: 10px; padding: 8px 12px; cursor: pointer; transition: .2s; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(90deg, var(--primary), var(--primary-2)); color: #fff; border: none; }
.btn.success { background: linear-gradient(90deg, #34d399, #22c55e); color: #fff; border: none; }
.btn.big { font-size: 18px; padding: 10px 16px; }

/* About Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.25); display: grid; place-items: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-card { width: min(520px, 92vw); background: #fff; border-radius: 16px; padding: 18px; box-shadow: var(--shadow); border: 1px solid #ffd8ec; text-align: center; }
.modal .info { color: var(--muted); font-size: 13px; }
.name-btn { border: none; background: none; color: #7c3aed; cursor: pointer; padding: 0 4px; font-weight: 700; }
.name-btn.revealed { color: #0ea5e9; cursor: default; }

/* Responsive */
@media (max-width: 700px) {
  .hud { flex-direction: column; align-items: stretch; gap: 6px; }
  .lb-row { grid-template-columns: 36px 1fr auto; }
}

/* Mobile-only: larger UI and taller game area (stretched) */
@media (max-width: 700px) {
  /* Bigger controls for readability */
  .btn { font-size: 16px; padding: 10px 14px; }
  .btn.big { font-size: 18px; padding: 12px 16px; }
  .hud .chip { font-size: 15px; padding: 8px 12px; }
  .help { font-size: 14px; }

  /* Preserve aspect ratio on mobile to avoid stretching */
  .container { padding: 8px; }
  #game.card { padding: 8px; }
  .canvas-wrap { height: auto; aspect-ratio: 8 / 3; }
  canvas { height: auto !important; }
}

/* Mobile-only: fullscreen — keep aspect ratio (no stretch) */
@media (max-width: 700px) {
  #game:fullscreen .canvas-wrap, #game:-webkit-full-screen .canvas-wrap, #game:-ms-fullscreen .canvas-wrap {
    height: auto !important;
  }
  #game:fullscreen canvas, #game:-webkit-full-screen canvas, #game:-ms-fullscreen canvas {
    height: auto !important;
  }
}

/* Fullscreen styles */
#game:fullscreen, #game:-webkit-full-screen, #game:-ms-fullscreen {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 10px;
  border-radius: 0;
}
#game:fullscreen .canvas-wrap, #game:-webkit-full-screen .canvas-wrap, #game:-ms-fullscreen .canvas-wrap {
  height: calc(100vh - 140px);
}
#game:fullscreen canvas, #game:-webkit-full-screen canvas, #game:-ms-fullscreen canvas {
  width: 100%;
  height: 100%;
}

/* Mobile-only override placed after general fullscreen rules to take precedence */
@media (max-width: 700px) {
  #game:fullscreen .canvas-wrap, #game:-webkit-full-screen .canvas-wrap, #game:-ms-fullscreen .canvas-wrap {
    height: auto !important;
  }
  #game:fullscreen canvas, #game:-webkit-full-screen canvas, #game:-ms-fullscreen canvas {
    height: auto !important;
  }
}

/* Mobile portrait: block gameplay and show rotate instruction overlay */
@media (max-width: 700px) and (orientation: portrait) {
  #game .canvas-wrap { pointer-events: none; }
  #game .canvas-wrap::after {
    content: '📱↻\A لطفاً برای بازی، گوشی را به حالت افقی بچرخان';
    white-space: pre-line;
    position: absolute; inset: 0;
    display: grid; place-items: center; text-align: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.94);
    color: #37293f; font-weight: 800; font-size: 16px;
    border: 1px dashed #ffd8ec;
  }
}

/* Better avatar rendering */
.avatar-option img { display: block; }

