@import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: inherit;
}

html {
  font-size: 62.5%;
  box-sizing: border-box;
}

body {
  font-family: 'Nunito', sans-serif;
  font-weight: 400;
  height: 100vh;
  color: #333;
  background-image: linear-gradient(to top left, #753682 0%, #bf2e34 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* LAYOUT */
main {
  position: relative;
  width: 100rem;
  height: 60rem;
  background-color: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(200px);
  filter: blur();
  box-shadow: 0 3rem 5rem rgba(0, 0, 0, 0.25);
  border-radius: 9px;
  overflow: hidden;
  display: flex;
}

.player {
  flex: 50%;
  padding: 9rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.75s;
}

/* ELEMENTS */
.name {
  position: relative;
  font-size: 4rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  word-spacing: 2px;
  font-weight: 300;
  margin-bottom: 1rem;
}

.score {
  font-size: 8rem;
  font-weight: 300;
  color: #c7365f;
  margin-bottom: auto;
}

.player--active {
  background-color: rgba(255, 255, 255, 0.4);
}
.player--active .name {
  font-weight: 700;
}
.player--active .score {
  font-weight: 400;
}

.player--active .current {
  opacity: 1;
}

.current {
  background-color: #c7365f;
  opacity: 0.8;
  border-radius: 9px;
  color: #fff;
  width: 65%;
  padding: 2rem;
  text-align: center;
  transition: all 0.75s;
}

.current-label {
  text-transform: uppercase;
  margin-bottom: 1rem;
  font-size: 1.7rem;
  color: #ddd;
}

.current-score {
  font-size: 3.5rem;
}

/* ABSOLUTE POSITIONED ELEMENTS */
.btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: #444;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 1.8rem;
  text-transform: uppercase;
  cursor: pointer;
  font-weight: 400;
  transition: all 0.2s;

  background-color: white;
  background-color: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);

  padding: 0.7rem 2.5rem;
  border-radius: 50rem;
  box-shadow: 0 1.75rem 3.5rem rgba(0, 0, 0, 0.1);
}

.btn::first-letter {
  font-size: 2.4rem;
  display: inline-block;
  margin-right: 0.7rem;
}

.btn--new {
  top: 4rem;
}
.btn--roll {
  top: 39.3rem;
}
.btn--hold {
  top: 46.1rem;
}

.btn:active {
  transform: translate(-50%, 3px);
  box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.15);
}

.btn:focus {
  outline: none;
}

.dice {
  position: absolute;
  left: 50%;
  top: 16.5rem;
  transform: translateX(-50%);
  height: 10rem;
  box-shadow: 0 2rem 5rem rgba(0, 0, 0, 0.2);
}

.player--winner {
  background-color: #2f2f2f;
}

.player--winner .name {
  font-weight: 700;
  color: #c7365f;
}

/* Add  */
.hidden {
  display: none;
}

/* **************************************************************************************************************** */

/* ===== Overlay + Modal ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 90;
}

.modal {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 48rem);
  max-height: 80vh;
  overflow: auto;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  box-shadow: 0 2.4rem 4.8rem rgba(0, 0, 0, 0.25);
  border-radius: 14px;
  z-index: 99;
  color: #2f2f2f;
}

.modal__header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.6rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.modal__header h3 {
  font-size: 2rem;
  font-weight: 700;
  margin-right: auto;
}

.modal__lang {
  display: inline-flex;
  gap: 0.6rem;
}

.lang-btn {
  border: none;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1.4rem;
}

.lang-btn.active {
  background: #c7365f;
  color: #fff;
}

.modal__close {
  border: none;
  background: transparent;
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.6rem;
}

.modal__body {
  padding: 1.2rem 1.6rem 1.6rem;
  font-size: 1.6rem;
}

.modal ol {
  padding-left: 2rem;
}
.modal[dir='rtl'] ol {
  padding-left: 0;
  padding-right: 2rem;
}

.rules[dir='rtl'] {
  text-align: right;
}

/* زر Rules: ديسكتوب */
.btn--rules {
  position: absolute;
  top: 4rem;
  right: 2rem;
  left: auto;
  transform: none;
  font-size: 1.6rem;
  padding: 0.6rem 1.2rem;
}

/* ترتيب زر Rules فالموبايل مع Grid ديالنا */
@media (max-width: 768px) {
  .btn--rules {
    position: static;
    grid-area: new; /* كيتحط فصف New */
    justify-self: end; /* يجي يمين وNew Game وسط */
    margin: 0;
    font-size: 1.5rem;
    padding: 0.7rem 1.2rem;
  }
}

/* نفس .hidden ديالك شغالة */
/* ------------------------------------------------------------------ */

/* ========================================================================== */
/* ============================  MOBILE RESPONSIVE  ========================= */
/* ========================================================================== */

/* شاشات لابتوب أصغر */
@media (max-width: 1024px) {
  main {
    width: min(92vw, 100rem);
  }
}

/* موبايل ≤ 768px (مُدمجة) */
@media (max-width: 768px) {
  /* الجسم عمودي: يخلي Rules فوق و main تحته */
  body {
    height: auto;
    min-height: 100vh;
    padding: 1.2rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
  }

  /* زر Rules خارج main: static ومتمركز */
  .btn--rules {
    position: static;
    left: auto;
    right: auto;
    transform: none;
    align-self: center;
    width: min(520px, 92vw);
    text-align: center;
    margin: 0;
  }

  /* main: Grid بعمود واحد */
  main {
    width: 100%;
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "new"
      "p1"
      "dice"
      "roll"
      "hold"
      "p2";
    gap: 1.2rem;
    padding: 1.2rem 1rem 1.6rem;
  }

  .player { padding: 3rem 2rem; }
  .player--0 { grid-area: p1; }
  .player--1 { grid-area: p2; }

  .name { font-size: 2.6rem; }
  .score { font-size: 5.2rem; }
  .current { width: 90%; padding: 1.2rem; }
  .current-label { font-size: 1.4rem; }
  .current-score { font-size: 2.6rem; }

  /* الأزرار داخل الشبكة (بلا absolute) */
  .btn {
    position: static;
    left: auto;
    top: auto;
    transform: none;
    width: max-content;
    justify-self: center;
    padding: 0.8rem 1.6rem;
    font-size: 1.6rem;
    box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.10);
    min-height: 44px;
  }
  .btn--new { grid-area: new; }
  .btn--roll { grid-area: roll; }
  .btn--hold { grid-area: hold; }

  /* النرد مرن بالحجم */
  .dice {
    grid-area: dice;
    position: static;
    transform: none;
    width: clamp(64px, 28vw, 96px);
    height: auto;
    justify-self: center;
    box-shadow: 0 1.6rem 3rem rgba(0, 0, 0, 0.18);
  }

  .player--active { background-color: rgba(255, 255, 255, 0.5); }
  .player--winner { background-color: rgba(47, 47, 47, 0.9); }

  .modal {
    width: min(94vw, 44rem);
    max-height: 80vh;
  }

  /* تحسين التركيز للكيبورد */
  .btn:focus-visible,
  .lang-btn:focus-visible,
  .modal__close:focus-visible {
    outline: 3px solid #c7365f;
    outline-offset: 2px;
    border-radius: 12px;
  }
}

/* موبايل صغير جداً ≤ 480px */
@media (max-width: 480px) {
  .player { padding: 2.2rem 1.6rem; }
  .name { font-size: 2.2rem; }
  .score { font-size: 4.4rem; }
  .current { padding: 1rem; }
  .current-score { font-size: 2.4rem; }

  .btn {
    width: 100%;
    justify-self: stretch;
    text-align: center;
    padding: 1rem 1.2rem;
    font-size: 1.5rem;
    border-radius: 12px;
  }

  main { gap: 0.9rem; }
  /* .dice تستخدم clamp فوق، كافية هنا */
}