@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;800&family=Outfit:wght@400;700&display=swap');

:root {
  --primary-color: #7209b7;
  --secondary-color: #b5179e;
  --bg-gradient: linear-gradient(135deg, #0a001e, #1a0033);
  --glass-bg: rgba(25, 0, 50, 0.45);
  --glass-border: rgba(255, 255, 255, 0.1);
  --text-light: #e9dffc;
  --text-highlight: #ffd86b;
  --hex-bg: #4a007f;
  --hex-hover: #7a00ff;
  --success-color: #00c853;
  --danger-color: #ff3366;
}

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

body {
  font-family: "Cairo", sans-serif;
  color: var(--text-light);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: url("img/bg.png") no-repeat center center fixed;
  background-size: cover;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: absolute;
  inset: 0;
  backdrop-filter: blur(12px);
  background: rgba(10, 0, 30, 0.6);
  z-index: 0;
}

nav, .app-container, .twitch-user-box, .toast {
  position: relative;
  z-index: 10;
}

/* ===== Navigation ===== */
nav {
  width: 100%;
  padding: 8px 0;
  background: rgba(20, 0, 40, 0.5);
  backdrop-filter: blur(15px);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.nav-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
}

.nav-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-highlight);
  text-shadow: 0 0 10px rgba(255, 216, 107, 0.5);
  letter-spacing: 1px;
}

/* ===== Twitch Buttons ===== */
.twitch-connect-btn {
  background: linear-gradient(135deg, #9146ff, #b085ff);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 6px 15px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(145, 70, 255, 0.4);
  transition: all 0.3s ease;
}

.twitch-connect-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 25px rgba(145, 70, 255, 0.7);
}

.twitch-user-box {
  position: absolute;
  top: 10px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  font-weight: 700;
  font-size: 14px;
}

.twitch-user-box img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--text-highlight);
}

#logoutBtn {
  background: var(--danger-color);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  font-size: 12px;
  transition: 0.2s;
}

#logoutBtn:hover {
  background: #ff0044;
}

/* ===== Main App Container & Screens ===== */
.app-container {
  width: 100%;
  max-width: 1200px;
  margin: 15px auto;
  display: flex;
  justify-content: center;
  flex: 1;
}

.screen {
  display: none;
  width: 100%;
  animation: fadeIn 0.4s ease-out forwards;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

/* ===== Glass UI Cards ===== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 25px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  text-align: center;
}

/* ===== Setup Screen ===== */
.setup-card {
  max-width: 380px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 50px;
}

.setup-card h2 {
  color: var(--text-highlight);
  font-size: 24px;
  margin-bottom: 0px;
}

.form-group {
  display: flex;
  flex-direction: column;
  text-align: right;
  gap: 5px;
}

.form-group label {
  font-weight: 600;
  font-size: 14px;
  color: #cdb4ff;
}

.form-group input,
.form-group select {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--primary-color);
  color: white;
  padding: 10px;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: 0.3s;
}

.form-group select option {
  background: #2a0a4a;
  color: white;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 10px rgba(181, 23, 158, 0.4);
}

.primary-btn {
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  color: white;
  border: none;
  padding: 12px 25px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  margin-top: 10px;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(114, 9, 183, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(181, 23, 158, 0.6);
}

.secondary-btn {
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.2);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: 0.3s;
}

.secondary-btn:hover {
  background: rgba(255,255,255,0.2);
}

.pulse-glow {
  animation: pulseGlow 2s infinite;
}

@keyframes pulseGlow {
  0% { box-shadow: 0 0 0 0 rgba(181, 23, 158, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(181, 23, 158, 0); }
  100% { box-shadow: 0 0 0 0 rgba(181, 23, 158, 0); }
}

/* ===== Game Screen ===== */
.game-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
}

.round-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.round-control-btn {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--glass-border);
  color: white;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: 0.3s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.round-control-btn:hover {
  background: rgba(181, 23, 158, 0.5);
  box-shadow: 0 0 10px rgba(181, 23, 158, 0.6);
  transform: scale(1.1);
}

.round-badge {
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 15px;
  border-radius: 15px;
  font-size: 14px;
  font-weight: bold;
  border: 1px solid var(--secondary-color);
  color: var(--text-highlight);
}

.timer-display {
  font-family: 'Outfit', sans-serif;
  font-size: 46px; /* المصغر ليناسب الشاشات العادية */
  font-weight: 800;
  line-height: 1;
  background: -webkit-linear-gradient(45deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 5px 20px rgba(255, 154, 158, 0.3);
  letter-spacing: 2px;
}

.timer-display.danger {
  background: -webkit-linear-gradient(45deg, #ff0844 0%, #ffb199 100%);
  -webkit-background-clip: text;
  animation: shake 0.5s infinite alternate;
}

@keyframes shake {
  from { transform: translateX(-2px); }
  to { transform: translateX(2px); }
}

.progress-section {
  width: 100%;
  max-width: 550px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
  background: var(--glass-bg);
  padding: 8px 18px;
  border-radius: 15px;
  border: 1px solid var(--glass-border);
}

.progress-bar {
  flex: 1;
  height: 14px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5a0eff, #ff00cc);
  border-radius: 10px;
  transition: width 0.4s ease-out;
  position: relative;
}

.progress-fill::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.4) 50%, rgba(255,255,255,0) 100%);
  animation: shimmer 1.5s infinite linear;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.progress-text {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  min-width: 60px;
  text-align: center;
}

.goal-text {
  font-size: 12px;
  color: #cdb4ff;
  font-weight: 600;
}

/* ===== Game Layout (Flex) ===== */
.game-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
  max-width: 1100px;
  padding: 0 15px;
}

.center-panel {
  flex: 1;
  max-width: 550px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.side-panel {
  width: 200px;
  flex-shrink: 0;
}

/* ===== Game Area (Hex & Words) ===== */
.game-container {
  width: 100%;
  max-width: 550px;
  text-align: center;
  position: relative;
}

.words-list {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 10px;
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  min-height: 45px;
  max-height: 100px;
  overflow-y: auto;
  justify-content: center;
  align-items: center;
}

.words-list span {
  background: rgba(255,255,255,0.1);
  padding: 4px 10px;
  border-radius: 6px;
  animation: popIn 0.3s ease;
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.current-word {
  min-height: 40px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 4px;
  margin-bottom: 10px;
  color: #ff99ff;
  text-shadow: 0 0 10px #ff00cc;
  line-height: 1;
}

/* Hex Grid */
.hex-grid {
  position: relative;
  width: 250px;
  height: 220px;
  margin: 0 auto 5px;
  transform: scale(0.85); /* تصغير حجم الحروف لتناسب المساحة */
  transform-origin: top center;
}

.hex {
  position: absolute;
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #5c0099, #3c0066);
  clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  color: #e9dffc;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.hex:hover {
  transform: scale(1.12);
  background: linear-gradient(135deg, #7a00ff, #5c0099);
  z-index: 2;
}

.hex:active {
  transform: scale(0.95);
}

.hex.center {
  background: radial-gradient(circle, #c77dff 0%, #7209b7 100%);
  color: #fff;
  transform: scale(1.15);
  box-shadow: inset 0 0 15px rgba(255,255,255,0.2), 0 0 20px rgba(181, 23, 158, 0.6);
  z-index: 1;
}

.hex.center:hover {
  transform: scale(1.2);
  box-shadow: 0 0 30px rgba(215, 169, 255, 0.8);
}

.center { top: 75px; left: 90px; }
.right { top: 74px; left: 164px; }
.left { top: 75px; left: 15px; }
.top-right { top: 12px; left: 130px; }
.top-left  { top: 12px; left: 51px; }
.bottom-right { top: 140px; left: 128px; }
.bottom-left  { top: 141px; left: 50px; }

/* Controls */
.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
}

.controls button {
  background: linear-gradient(90deg, #5a189a, #7b2cbf);
  border: none;
  color: #f3e8ff;
  font-size: 16px;
  font-weight: bold;
  padding: 8px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.controls button:hover {
  background: linear-gradient(90deg, #7209b7, #b5179e);
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(181, 23, 158, 0.5);
}

.controls button:active {
  transform: translateY(1px);
}

.refresh {
  font-size: 26px;
  cursor: pointer;
  color: #c77dff;
  transition: transform 0.4s ease, color 0.3s;
  padding: 5px;
}

.refresh:hover {
  transform: rotate(180deg);
  color: #fff;
}

/* ===== Hints ===== */
.hint-box {
  width: 100%;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--secondary-color);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 0 15px rgba(181, 23, 158, 0.2);
}

.hint-btn {
  background: linear-gradient(90deg, #6a00f4, #b5179e);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  transition: 0.3s;
}

.hint-btn:hover {
  box-shadow: 0 0 12px rgba(181, 23, 158, 0.6);
}

.hints-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
}

.hints-list span {
  background: rgba(255,255,255,0.1);
  padding: 6px;
  border-radius: 6px;
  text-align: center;
  font-weight: 600;
  letter-spacing: 2px;
  font-size: 14px;
}

/* ===== Leaderboard ===== */
.leaderboard {
  width: 100%;
  padding: 15px;
  background: var(--glass-bg); /* Because it uses glass-card class, but let's override flex handling just in case */
}

.tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
  background: rgba(0,0,0,0.3);
  padding: 4px;
  border-radius: 8px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #aaa;
  padding: 6px;
  font-size: 12px;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.3s;
}

.tab-btn.active {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 0 10px rgba(114, 9, 183, 0.5);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.leader-list {
  list-style: none;
  max-height: 250px;
  overflow-y: auto;
}

.leader-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 14px;
  transition: 0.2s;
}

.leader-list li:first-child {
  color: var(--text-highlight);
  font-weight: 800;
  font-size: 15px;
  background: rgba(255, 216, 107, 0.1);
  border-radius: 6px;
}

.leader-list li:hover {
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
}

/* ===== Intermission Screen ===== */
.intermission-card {
  max-width: 450px;
  width: 90%;
  margin-top: 40px;
}

.intermission-card h2 {
  font-size: 28px;
  color: var(--text-highlight);
  margin-bottom: 20px;
}

.winners-podium {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  background: rgba(0,0,0,0.3);
  padding: 15px;
  border-radius: 12px;
}

.winner-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: linear-gradient(90deg, rgba(114, 9, 183, 0.5), rgba(181, 23, 158, 0.5));
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
}

.winner-1 { transform: scale(1.05); border: 2px solid #ffd700; background: linear-gradient(90deg, rgba(255, 215, 0, 0.2), rgba(255, 140, 0, 0.2)); color: #ffd700; }
.winner-2 { border: 2px solid #c0c0c0; color: #c0c0c0; }
.winner-3 { border: 2px solid #cd7f32; color: #cd7f32; }

/* ===== Toast Alerts ===== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: rgba(30, 0, 60, 0.9);
  backdrop-filter: blur(10px);
  color: #fff;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  pointer-events: none;
  box-shadow: 0 8px 25px rgba(0,0,0,0.4);
  border: 1px solid var(--glass-border);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-success { border-bottom: 3px solid var(--success-color); }
.toast-error { border-bottom: 3px solid var(--danger-color); }
.toast-info { border-bottom: 3px solid var(--secondary-color); }

/* Responsive adjustments */
@media (max-width: 1000px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }
  
  .side-panel {
    width: 100%;
    max-width: 550px;
    margin-top: 15px;
  }

  .hint-box {
    margin: 0;
  }
  
  .leaderboard {
    margin: 0;
  }
}

@media (max-width: 600px) {
  .timer-display { font-size: 38px; }
  .hex-grid { transform: scale(0.75); margin-bottom: 0px; margin-top: -10px; }
  .controls { gap: 10px; }
  .nav-title { font-size: 16px; }
}
