@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --telegram-blue: #0088cc;
  --telegram-blue-dark: #006ba3;
  --telegram-blue-light: #40a7e3;

  --blue-team: #2196f3;
  --red-team: #e53935;

  --success: #2ecc71;
  --danger: #e74c3c;

  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;

  --text-primary: #212121;
  --text-secondary: #757575;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --board-max-width: 1280px;
  --board-max-height: 520px;
  --board-gap: clamp(10px, 1.6vw, 20px);

  --title-size: clamp(18px, 2.2vw, 30px);
  --panel-title-size: clamp(14px, 1.4vw, 16px);
  --question-size: clamp(14px, 2.2vh, 20px);
  --option-size: clamp(13px, 2vh, 16px);
  --input-size: clamp(16px, 2.4vh, 26px);
  --key-size: clamp(18px, 2.6vh, 24px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

#backgroundMusic {
  display: none;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #c7b3ff;
  color: var(--text-primary);

  height: 100svh;
  overflow: hidden;

  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: stretch;

  user-select: none;
  -webkit-user-select: none;
}

/* =======================
   HEADER / FOOTER
======================= */

.game-header {
  width: 100%;
  text-align: center;
  padding: clamp(10px, 1.4vh, 14px) clamp(10px, 2vw, 18px) clamp(6px, 1vh, 10px);
}

.game-header h1 {
  font-size: var(--title-size);
  font-weight: 800;
  background: linear-gradient(135deg, var(--telegram-blue), var(--telegram-blue-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.6px;
}

.game-subtitle {
  margin-top: 6px;
  font-size: clamp(12px, 1.7vh, 14px);
  color: var(--text-secondary);
  max-width: 980px;
  margin-inline: auto;
  line-height: 1.35;
  padding: 0 10px;
  white-space: pre-line;
}

.game-footer {
  text-align: center;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  margin-top: auto;
  width: 100%;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.author-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.3px;
}

.author-name {
  color: var(--text-primary);
  font-weight: 700;
  background: linear-gradient(135deg, var(--telegram-blue), var(--telegram-blue-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.social-link {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: white;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
  font-size: 18px;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.social-link:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 4px 10px rgba(0, 50, 100, 0.15);
  border-color: var(--telegram-blue);
  color: var(--telegram-blue);
}

.social-link:active {
  transform: scale(0.97);
}

/* =======================
   FIXED BUTTONS
======================= */

.view-controls {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 1002;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 6px 8px;
  border-radius: 14px;

  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
}

.view-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  cursor: pointer;

  background: #f2f5f9;
  color: var(--telegram-blue-dark);
  box-shadow: var(--shadow-sm);

  display: grid;
  place-items: center;
  transition: var(--transition);
}

.view-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.view-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.view-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}

.view-label {
  min-width: 54px;
  text-align: center;
  font-weight: 800;
  font-size: 13px;
  color: var(--telegram-blue-dark);
  user-select: none;
}

.language-selector {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 1000;
  background: var(--bg-secondary);
  padding: 6px;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}

.lang-btn {
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  background: var(--bg-primary);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: grid;
  place-items: center;
}

.lang-btn img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
}

.lang-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.lang-btn.active {
  border-color: var(--telegram-blue);
  background: var(--telegram-blue-light);
  transform: scale(1.03);
}

/* GLOBAL HOME BUTTON */
.global-home-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #1f1f1f;
  color: #fff;
  cursor: pointer;

  display: grid;
  place-items: center;

  z-index: 2000;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, background 0.2s ease;
}

.global-home-btn:hover {
  background: #333;
  transform: scale(1.08);
}

.global-home-btn i {
  font-size: 18px;
}

/* =======================
   MODALS
======================= */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(720px, 92vw);

  max-height: min(86svh, 680px);
  overflow: hidden;
  transform-origin: center;
  animation: slideUp 0.35s ease;
}

.start-modal {
  padding: clamp(18px, 2.5vw, 28px) clamp(16px, 2.5vw, 24px) clamp(18px, 2.5vw, 30px);
}

.start-modal h2 {
  text-align: center;
  font-size: clamp(20px, 2.2vw, 26px);
  font-weight: 800;
  color: var(--telegram-blue);
  margin-bottom: 16px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =======================
   TEAM SETUP
======================= */

.team-setup {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
}

.team-box {
  flex: 1;
  background: var(--bg-primary);
  padding: 16px 14px;
  border-radius: var(--radius-md);
  text-align: center;
  transition: var(--transition);
}

.team-left { border: 2px solid var(--blue-team); }
.team-right { border: 2px solid var(--red-team); }

.team-icon {
  font-size: 34px;
  margin-bottom: 8px;
}

.team-left .team-icon { color: var(--blue-team); }
.team-right .team-icon { color: var(--red-team); }

.team-box h3 {
  font-size: 16px;
  margin-bottom: 10px;
}

.team-box input {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid #ddd;
  text-align: center;
  font-family: inherit;
  transition: var(--transition);
}

.team-box input:focus {
  outline: none;
  border-color: var(--telegram-blue);
  box-shadow: 0 0 0 3px rgba(0, 136, 204, 0.15);
}

.vs-divider {
  font-size: 22px;
  font-weight: 800;
  color: var(--telegram-blue);
  padding: 6px 14px;
  background: var(--bg-secondary);
  border-radius: 50%;
  min-width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.setup-nav {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
}

.primary-btn,
.secondary-btn {
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: var(--transition);
  border: none;
  box-shadow: var(--shadow-md);
}

.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--telegram-blue), var(--telegram-blue-dark));
}

.secondary-btn {
  color: var(--text-primary);
  background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow-sm);
}

.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.primary-btn:active,
.secondary-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.primary-btn:disabled,
.secondary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}

.nav-btn { min-width: 180px; }

/* Countdown overlay */
.countdown-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.82);
  display: none;
  align-items: center;
  justify-content: center;
  place-items: center;
  z-index: 998;
  font-size: clamp(56px, 10vw, 90px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 22px rgba(0, 136, 204, 0.9);
  text-align: center;
  line-height: 1;
}

.countdown-overlay.go { color: var(--success); }

/* =======================
   GAME BOARD
======================= */

.game-shell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 clamp(10px, 1.8vw, 18px);
  overflow: hidden;
}

.game-stage {
  --game-scale: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(var(--game-scale));
  transform-origin: center;
  transition: transform 0.25s ease;
}

.game-board {
  width: var(--board-max-width);
  max-width: 100%;
  height: var(--board-max-height);
  max-height: 100%;

  display: grid;
  gap: var(--board-gap);
  align-items: stretch;

  grid-template-columns: 0.92fr 1.7fr 0.92fr;
  grid-template-areas: 'left arena right';
}

.panel-left { grid-area: left; }
.panel-right { grid-area: right; }
.arena-container { grid-area: arena; }

.calculator-panel,
.arena-container {
  min-height: 0;
  overflow: hidden;
}

.calculator-panel {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.panel-left { border-top: 4px solid var(--blue-team); }
.panel-right { border-top: 4px solid var(--red-team); }

.panel-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: var(--panel-title-size);
}

.panel-left .panel-header {
  background: linear-gradient(135deg, var(--blue-team), #1976d2);
  color: #fff;
}

.panel-right .panel-header {
  background: linear-gradient(135deg, var(--red-team), #c62828);
  color: #fff;
}

.panel-header h3 {
  flex: 1;
  margin-right: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-badge {
  background: #fff;
  color: var(--telegram-blue);
  padding: 4px 10px;
  border-radius: 18px;
  font-size: clamp(16px, 2.2vh, 20px);
  font-weight: 900;
  min-width: 36px;
  text-align: center;
}

.problem-display {
  padding: 12px 12px;
  text-align: center;
  font-size: var(--question-size);
  font-weight: 800;
  min-height: 86px;
  max-height: clamp(86px, 18vh, 150px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  word-break: break-word;
}

.panel-left .problem-display {
  background: #e3f2fd;
  color: var(--blue-team);
}

.panel-right .problem-display {
  background: #ffebee;
  color: var(--red-team);
}

/* =======================
   ANSWER INPUT (gap)
======================= */

.answer-input-wrap {
  padding: 6px 12px 10px;
}

.answer-input {
  width: 100%;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: var(--input-size);
  font-weight: 800;
  text-align: center;
  background: #fff;
  outline: none;
  transition: var(--transition);
}

.answer-input:focus {
  border-color: #90caf9;
  box-shadow: 0 0 0 3px rgba(144, 202, 249, 0.35);
}

.answer-input.good {
  border-color: #2e7d32;
  background: #e8f5e9;
}

.answer-input.bad {
  border-color: #c62828;
  background: #ffebee;
}

/* =======================
   KEYPAD (numbers + C + GO)
======================= */

.quiz-keypad {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 10px;
  padding: 12px 12px 14px;
  background: var(--bg-primary);
  align-content: stretch;
}

.key-btn {
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);

  font-size: var(--key-size);
  font-weight: 900;
  font-family: inherit;

  display: grid;
  place-items: center;
  min-height: 0;
  padding: 10px;
}

.key-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.key-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.key-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =======================
   ARENA
======================= */

.arena-container {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px 12px 14px;
  display: flex;
  flex-direction: column;
}

.arena-scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
  border-radius: 12px;
  font-size: 13px;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  min-width: 84px;
}

.score-value {
  font-size: clamp(18px, 2.8vh, 26px);
  font-weight: 900;
  color: var(--telegram-blue);
}

.timer-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(14px, 2vh, 18px);
  font-weight: 900;
  color: var(--telegram-blue);
}

.arena {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: #ffffff;
  border-radius: 14px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
}

.center-line {
  position: absolute;
  left: 48%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: repeating-linear-gradient(to bottom, #333 0, #333 8px, transparent 8px, transparent 16px);
  transform: translateX(-50%);
  z-index: 2;
  opacity: 0.7;
}

.rope-container {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 92%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.rope-container video {
  width: 100%;
  height: auto;
  display: block;
}

#win-video,
.win-video-wrap {
  position: absolute;
  left: 50%;
  top: 15%;
  transform: translate(-50%, -50%);
  width: 92%;
  z-index: 3;
  pointer-events: none;
}

.win-video {
  position: absolute;
  inset: 0;
  width: 100%;
}

.winner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

/* =======================
   RESPONSIVE
======================= */

@media (max-width: 820px) {
  :root { --board-max-height: 100%; }

  .game-board {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 0.82fr 1.18fr;
    grid-template-areas:
      'arena arena'
      'left right';
  }

  .team-setup { flex-direction: column; }

  .nav-btn { min-width: 0; flex: 1; }
  .setup-nav { flex-wrap: wrap; }

  .score-item { min-width: 70px; }
}

@media (max-width: 480px) {
  :root { --option-size: clamp(11px, 1.8vh, 14px); }

  .language-selector {
    top: 10px;
    right: 10px;
    padding: 5px;
    gap: 5px;
  }

  .lang-btn { width: 30px; height: 30px; }
}

@media (hover: none) and (pointer: coarse) {
  .key-btn:hover,
  .primary-btn:hover,
  .secondary-btn:hover,
  .lang-btn:hover,
  .social-link:hover {
    transform: none;
    box-shadow: none;
  }

  .key-btn:active,
  .primary-btn:active,
  .secondary-btn:active {
    transform: scale(0.98);
  }
}

/* Custom Question Input (kept, in case you still use it) */
.question-input-area {
  width: 100%;
  height: clamp(150px, 30vh, 320px);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(0, 0, 0, 0.1);
  background: var(--bg-primary);
  font-family: monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  margin-bottom: 20px;
  transition: var(--transition);
}

.question-input-area:focus {
  outline: none;
  border-color: var(--telegram-blue);
  box-shadow: 0 0 0 4px rgba(0, 136, 204, 0.1);
}
