:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --red-btn: #ef4444;
  --blue-btn: #3b82f6;
  --yellow-btn: #eab308;
  --green-btn: #10b981;
  --accent-purple: #8b5cf6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body {
  background: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  touch-action: manipulation;
}

input, textarea, [contenteditable="true"] {
  user-select: text !important;
  -webkit-user-select: text !important;
}

button, .opt-card, .tile, .mobile-tile, .player-chip, .symbol, .status-pill {
  user-select: none;
  -webkit-user-select: none;
}

/* ==================== HOST SCREEN (TV / PROJECTOR) ==================== */
.host-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  padding: 24px 36px;
  justify-content: space-between;
}

.host-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.q-counter {
  font-size: 1.4rem;
  font-weight: 800;
  background: #334155;
  padding: 6px 18px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}

.q-title {
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
  flex-grow: 1;
  margin: 0 20px;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 2rem;
  font-weight: 900;
  color: #38bdf8;
  background: rgba(15, 23, 42, 0.8);
  border: 2px solid #38bdf8;
  padding: 4px 18px;
  border-radius: 16px;
  min-width: 100px;
  justify-content: center;
}

.timer-box.urgent {
  color: #ef4444;
  border-color: #ef4444;
  animation: pulse-urgent 0.6s infinite alternate;
}

@keyframes pulse-urgent {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

/* Main Arena: Center Image Grid + Side Clues */
.arena {
  display: flex;
  flex: 1;
  justify-content: center;
  align-items: center;
  gap: 30px;
  position: relative;
  max-height: 58vh;
}

.image-wrapper {
  position: relative;
  width: 480px;
  height: 380px;
  max-width: 45vw;
  max-height: 52vh;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0,0,0,0.7), 0 0 0 4px #334155;
  background: #111827;
}

.target-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 1;
}

/* 4x4 Grid Covering Image */
.tiles-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2px;
  background: transparent !important;
  pointer-events: none;
  z-index: 5;
}

.tile {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: inset 0 0 10px rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 900;
  color: #64748b;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s ease;
  opacity: 1;
  transform: scale(1);
}

.tile.revealed {
  opacity: 0 !important;
  transform: scale(0.3) rotate(15deg);
  pointer-events: none;
}

/* Arena Status Pill */
.arena-side-info {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 200px;
}

.status-pill {
  background: #1e293b;
  border-radius: 16px;
  padding: 16px 20px;
  border: 1px solid #334155;
  text-align: center;
}

.status-pill .label {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1px;
}

.status-pill .val {
  font-size: 2.2rem;
  font-weight: 900;
  color: #38bdf8;
  margin-top: 4px;
}

.hint-pill {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #c4b5fd;
  text-align: center;
}

/* Bottom 4 Options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.opt-card {
  display: flex;
  align-items: center;
  padding: 18px 24px;
  border-radius: 16px;
  font-size: 1.6rem;
  font-weight: 800;
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  transition: transform 0.2s, opacity 0.3s;
}

.opt-card .icon {
  font-size: 2.2rem;
  margin-right: 20px;
  width: 44px;
  text-align: center;
}

.opt-card.opt-0 { background: var(--red-btn); }
.opt-card.opt-1 { background: var(--blue-btn); }
.opt-card.opt-2 { background: var(--yellow-btn); color: #0f172a; }
.opt-card.opt-3 { background: var(--green-btn); }

.opt-card.correct-highlight {
  box-shadow: 0 0 0 6px #ffffff, 0 0 35px #10b981;
  transform: scale(1.03);
  z-index: 10;
}

.opt-card.dimmed {
  opacity: 0.3;
  transform: scale(0.97);
}

/* LOBBY SCREEN (Host) */
.lobby-box {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-around;
  background: rgba(30, 41, 59, 0.7);
  border-radius: 28px;
  border: 2px solid #334155;
  padding: 30px;
}

.qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.qr-img {
  width: 250px;
  height: 250px;
  border-radius: 18px;
  background: white;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.qr-instruction {
  font-size: 1.6rem;
  font-weight: 800;
  color: #38bdf8;
}

.qr-url {
  font-size: 1.3rem;
  color: #cbd5e1;
  background: #0f172a;
  padding: 8px 18px;
  border-radius: 12px;
  font-family: monospace;
}

.players-panel {
  flex: 1;
  max-width: 550px;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: center;
}

.players-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 20px;
  color: #f1f5f9;
}

.players-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-height: 260px;
  overflow-y: auto;
  width: 100%;
}

.player-chip {
  background: #0f172a;
  border: 2px solid #38bdf8;
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 1.2rem;
  font-weight: 700;
  animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.start-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  font-size: 1.8rem;
  font-weight: 900;
  border: none;
  padding: 16px 44px;
  border-radius: 20px;
  cursor: pointer;
  margin-top: 30px;
  box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}

.start-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.6);
}

/* LEADERBOARD & PODIUM */
.leaderboard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  justify-content: center;
  gap: 20px;
}

.lb-title {
  font-size: 2.6rem;
  font-weight: 900;
  color: #f59e0b;
  text-shadow: 0 3px 15px rgba(245, 158, 11, 0.4);
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 700px;
}

.lb-row {
  display: flex;
  align-items: center;
  background: #1e293b;
  border-radius: 16px;
  padding: 14px 24px;
  font-size: 1.5rem;
  font-weight: 800;
  border: 1px solid #334155;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.lb-rank {
  width: 48px;
  font-size: 1.8rem;
}

.lb-name {
  flex-grow: 1;
}

.lb-score {
  color: #38bdf8;
  font-size: 1.6rem;
}

.lb-delta {
  font-size: 1.1rem;
  color: #10b981;
  margin-left: 12px;
}

/* ==================== PLAYER MOBILE SCREEN ==================== */
.player-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px 14px;
  justify-content: space-between;
}

.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e293b;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid #334155;
  margin-bottom: 8px;
}

.player-name-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-name {
  font-weight: 800;
  font-size: 1.15rem;
  color: #f8fafc;
}

.change-name-link {
  font-size: 0.85rem;
  color: #38bdf8;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 4px;
}

.player-score {
  font-weight: 900;
  font-size: 1.25rem;
  color: #38bdf8;
}

/* Mobile Image Box with Tiles */
.mobile-image-wrapper {
  position: relative;
  width: 100%;
  height: 180px;
  max-height: 28vh;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0,0,0,0.6);
  background: #0f172a;
  border: 2px solid #334155;
  margin-bottom: 10px;
}

.mobile-target-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 1;
}

.mobile-tiles-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2px;
  background: transparent !important;
  pointer-events: none;
  z-index: 5;
}

.mobile-tile {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1px solid rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
  color: #64748b;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
}

.mobile-tile.revealed {
  opacity: 0 !important;
  transform: scale(0.2);
}

.mobile-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  flex: 1;
  min-height: 200px;
}

.mobile-btn {
  border: none;
  border-radius: 16px;
  font-size: 1.15rem;
  font-weight: 900;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  padding: 10px;
  text-align: center;
}

.mobile-btn:active {
  transform: scale(0.94);
}

.mobile-btn.btn-0 { background: var(--red-btn); }
.mobile-btn.btn-1 { background: var(--blue-btn); }
.mobile-btn.btn-2 { background: var(--yellow-btn); color: #0f172a; }
.mobile-btn.btn-3 { background: var(--green-btn); }

.mobile-btn .symbol {
  font-size: 2.2rem;
}

.mobile-btn .btn-text {
  font-size: 1.05rem;
  line-height: 1.2;
}

/* Player Waiting / Feedback Box */
.feedback-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  gap: 16px;
  padding: 20px;
  border-radius: 20px;
  background: #1e293b;
  margin: 10px 0;
  border: 1px solid #334155;
}

.feedback-icon {
  font-size: 3.5rem;
}

.feedback-title {
  font-size: 1.7rem;
  font-weight: 900;
}

.feedback-subtitle {
  font-size: 1.1rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Join Screen Form */
.join-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 20px;
  text-align: center;
  width: 100%;
}

.join-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.join-input {
  width: 100%;
  max-width: 320px;
  padding: 16px 20px;
  border-radius: 16px;
  border: 2px solid #475569;
  background: #1e293b;
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  -webkit-appearance: none;
}

.join-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.3);
}

.join-submit {
  width: 100%;
  max-width: 320px;
  padding: 16px;
  border-radius: 16px;
  border: none;
  background: #10b981;
  color: white;
  font-size: 1.4rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 15px rgba(16, 185, 129, 0.4);
}

.join-submit:active {
  transform: scale(0.96);
}
